7from pycde
import (AppID, Clock, Module, Reset, Signal, System, generator)
9from pycde.common
import Constant
10from pycde.constructs
import Wire
11from pycde.module
import Metadata
12from pycde.signals
import Struct
13from pycde.types
import (Bits, Bundle, BundledChannel, Channel,
14 ChannelDirection, SInt, TypeAlias, UInt)
19SendI8 = Bundle([BundledChannel(
"send", ChannelDirection.FROM, Bits(8))])
20RecvI8 = Bundle([BundledChannel(
"recv", ChannelDirection.TO, Bits(8))])
21SendI0 = Bundle([BundledChannel(
"send", ChannelDirection.FROM, Bits(0))])
22RecvI0 = Bundle([BundledChannel(
"recv", ChannelDirection.TO, Bits(0))])
43 summary=
"IP which simply echos bytes",
47 depth = Constant(UInt(32), 5)
51 data_in_bundle = HostComms.Recv(AppID(
"loopback_tohw"))
52 data_in = data_in_bundle.unpack()[
"recv"]
54 data_out_bundle = HostComms.Send(AppID(
"loopback_fromhw"))
55 data_out_bundle.unpack(send=data_in)
57 send_bundle = MyService.Recv(AppID(
"mysvc_recv"))
58 send_chan = send_bundle.unpack()[
"recv"]
59 sendi0_bundle = MyService.Send(AppID(
"mysvc_send"))
60 sendi0_bundle.unpack(send=send_chan)
89 result_wire = Wire(Channel(ResultStruct))
90 args = esi.FuncService.get_call_chans(AppID(
"structFunc"),
95 arg_data, valid = args.unwrap(ready)
97 b_plus_one = (b_val + SInt(8)(1)).as_sint(8)
99 result_chan, result_ready = Channel(ResultStruct).
wrap(result, valid)
100 ready.assign(result_ready)
101 result_wire.assign(result_chan)
108 result_wire = Wire(Channel(OddStruct))
109 args = esi.FuncService.get_call_chans(AppID(
"oddStructFunc"),
113 ready = Wire(Bits(1))
114 arg_data, valid = args.unwrap(ready)
115 a_val = (arg_data[
"a"] + UInt(12)(1)).as_uint(12)
116 b_val = (arg_data[
"b"] + SInt(7)(-3)).as_sint(7)
117 inner = arg_data[
"inner"]
118 p_val = (inner[
"p"] + UInt(8)(5)).as_uint(8)
119 q_val = (inner[
"q"] + SInt(8)(2)).as_sint(8)
120 r0_val = (inner[
"r"][0] + UInt(8)(1)).as_uint(8)
121 r1_val = (inner[
"r"][1] + UInt(8)(2)).as_uint(8)
124 inner=
OddInner(p=p_val, q=q_val, r=[r0_val, r1_val]))
125 result_chan, result_ready = Channel(OddStruct).
wrap(result, valid)
126 ready.assign(result_ready)
127 result_wire.assign(result_chan)
130ArgArray = SInt(8) * 1
131ResultArray = TypeAlias(SInt(8) * 2,
"ResultArray")
138 result_wire = Wire(Channel(ResultArray))
139 args = esi.FuncService.get_call_chans(AppID(
"arrayFunc"),
143 ready = Wire(Bits(1))
144 arg_data, valid = args.unwrap(ready)
146 elem_plus_one = (elem + SInt(8)(1)).as_sint(8)
149 result_chan, result_ready = Channel(ResultArray).
wrap(result_array, valid)
150 ready.assign(result_ready)
151 result_wire.assign(result_chan)
154MemA = esi.DeclareRandomAccessMemory(Bits(64), 20, name=
"MemA")
163 MemA.instantiate_builtin(appid=AppID(
"mem"),
166 inputs=[ports.clk, ports.rst])
168 write_bundle = MemA.write(AppID(
"internal_write"))
169 write_req_type = MemA.write.type.req
170 write_req, _ = write_req_type.wrap(
172 "address": UInt(MemA.address_width)(0),
176 write_bundle.unpack(req=write_req)
183 result_wire = Wire(Channel(UInt(16)))
184 args = esi.FuncService.get_call_chans(AppID(
"func1"),
188 ready = Wire(Bits(1))
189 _, valid = args.unwrap(ready)
190 result_chan, result_ready = Channel(UInt(16)).
wrap(UInt(16)(0), valid)
191 ready.assign(result_ready)
192 result_wire.assign(result_chan)
196 """Loopback a si4 value: returns the input unchanged."""
200 result_wire = Wire(Channel(SInt(4)))
201 args = esi.FuncService.get_call_chans(AppID(
"sint4Func"),
205 ready = Wire(Bits(1))
206 arg_data, valid = args.unwrap(ready)
207 result_chan, result_ready = Channel(SInt(4)).
wrap(arg_data, valid)
208 ready.assign(result_ready)
209 result_wire.assign(result_chan)
218 Loopback(clk=ports.clk, appid=AppID(
"loopback_inst", 0))
219 Loopback(clk=ports.clk, appid=AppID(
"loopback_inst", 1))
229 instance_name=
"coord_translator_serial",
230 appid=AppID(
"coord_translator_serial"),
234if __name__ ==
"__main__":
235 bsp = get_bsp(sys.argv[2]
if len(sys.argv) > 2
else None)
236 s = System(
bsp(Top), name=
"Loopback", output_directory=sys.argv[1])
return wrap(CMemoryType::get(unwrap(ctx), baseType, numElements))