CIRCT 23.0.0git
Loading...
Searching...
No Matches
esi_ram.py
Go to the documentation of this file.
1# REQUIRES: esi-runtime, esi-cosim, rtl-sim
2# RUN: rm -rf %t
3# RUN: mkdir %t && cd %t
4# RUN: %PYTHON% %s %t 2>&1
5# RUN: esi-cosim.py -- %PYTHON% %S/test_software/esi_ram.py cosim env
6
7import pycde
8from pycde import (AppID, Clock, Input, Module, generator)
9from pycde.esi import DeclareRandomAccessMemory, ServiceDecl
10from pycde.bsp import get_bsp
11from pycde.module import Metadata
12from pycde.types import Bits
13
14import sys
15
16RamI64x8 = DeclareRandomAccessMemory(Bits(64), 256)
17WriteType = RamI64x8.write.type.req
18
19
20@ServiceDecl
22 write = RamI64x8.write.type.inverted()
23 read = RamI64x8.read.type.inverted()
24
25
26class Dummy(Module):
27 """To test completely automated metadata collection."""
28
29 @generator
30 def construct(ports):
31 pass
32
33
34class MemWriter(Module):
35 """Write to address 3 the contents of address 2."""
36
37 metadata = Metadata(version="0.1", misc={"numWriters": 1, "style": "stupid"})
38
39 clk = Clock()
40 rst = Input(Bits(1))
41
42 @generator
43 def construct(ports):
44 read_bundle_type = RamI64x8.read.type
45 address = 2
46 (address_chan, ready) = read_bundle_type.address.wrap(address, True)
47 read_bundle = RamI64x8.read(AppID("int_reader"))
48 bundled_channels = read_bundle.unpack(address=address_chan)
49 data_chan = bundled_channels["data"]
50 read_data, read_valid = data_chan.unwrap(True)
51
52 write_bundle_type = RamI64x8.write.type
53 write_data, _ = write_bundle_type.req.wrap({
54 'data': read_data,
55 'address': 3
56 }, read_valid)
57 write_bundle = RamI64x8.write(appid=AppID("int_writer"))
58 write_bundle.unpack(req=write_data)
59
60
61def Top(xrt: bool):
62
63 class Top(Module):
64 clk = Clock()
65 rst = Input(Bits(1))
66
67 @generator
68 def construct(ports):
69 Dummy(appid=AppID("dummy"))
70 MemWriter(clk=ports.clk, rst=ports.rst, appid=AppID("mem_writer"))
71
72 # We don't have support for host--device channel communication on XRT yet.
73 if not xrt:
74 # Pass through reads and writes from the host.
75 ram_write_host = MemComms.write(AppID("write"))
76 ram_write = RamI64x8.write(AppID("ram_write"))
77 ram_write.connect(ram_write_host)
78
79 ram_read_host = MemComms.read(AppID("read"))
80 ram_read = RamI64x8.read(AppID("ram_read"))
81 ram_read.connect(ram_read_host)
82
83 # Instantiate the RAM.
84 RamI64x8.instantiate_builtin(appid=AppID("mem"),
85 builtin="sv_mem",
86 result_types=[],
87 inputs=[ports.clk, ports.rst])
88
89 return Top
90
91
92if __name__ == "__main__":
93 is_xrt = len(sys.argv) > 2 and sys.argv[2].startswith("xrt")
94 bsp = get_bsp(sys.argv[2] if len(sys.argv) > 2 else None)
95 s = pycde.System(bsp(Top(is_xrt)),
96 name="ESIMem",
97 output_directory=sys.argv[1])
98 s.compile()
99 s.package()
construct(ports)
Definition esi_ram.py:30
construct(ports)
Definition esi_ram.py:43
Top(bool xrt)
Definition esi_ram.py:61