32from pycde
import (AppID, Clock, Module, Reset, Signal, System, generator)
34from pycde.common
import Constant
35from pycde.constructs
import Wire
36from pycde.module
import Metadata
37from pycde.signals
import Struct
38from pycde.types
import (Bits, Bundle, BundledChannel, Channel,
39 ChannelDirection, SInt, TypeAlias, UInt)
44SendI8 = Bundle([BundledChannel(
"send", ChannelDirection.FROM, Bits(8))])
45RecvI8 = Bundle([BundledChannel(
"recv", ChannelDirection.TO, Bits(8))])
46SendI0 = Bundle([BundledChannel(
"send", ChannelDirection.FROM, Bits(0))])
47RecvI0 = Bundle([BundledChannel(
"recv", ChannelDirection.TO, Bits(0))])
68 summary=
"IP which simply echos bytes",
72 depth = Constant(UInt(32), 5)
76 data_in_bundle = HostComms.Recv(AppID(
"loopback_tohw"))
77 data_in = data_in_bundle.unpack()[
"recv"]
79 data_out_bundle = HostComms.Send(AppID(
"loopback_fromhw"))
80 data_out_bundle.unpack(send=data_in)
82 send_bundle = MyService.Recv(AppID(
"mysvc_recv"))
83 send_chan = send_bundle.unpack()[
"recv"]
84 sendi0_bundle = MyService.Send(AppID(
"mysvc_send"))
85 sendi0_bundle.unpack(send=send_chan)
114 result_wire = Wire(Channel(ResultStruct))
115 args = esi.FuncService.get_call_chans(AppID(
"structFunc"),
119 ready = Wire(Bits(1))
120 arg_data, valid = args.unwrap(ready)
121 b_val = arg_data[
"b"]
122 b_plus_one = (b_val + SInt(8)(1)).as_sint(8)
124 result_chan, result_ready = Channel(ResultStruct).
wrap(result, valid)
125 ready.assign(result_ready)
126 result_wire.assign(result_chan)
133 result_wire = Wire(Channel(OddStruct))
134 args = esi.FuncService.get_call_chans(AppID(
"oddStructFunc"),
138 ready = Wire(Bits(1))
139 arg_data, valid = args.unwrap(ready)
140 a_val = (arg_data[
"a"] + UInt(12)(1)).as_uint(12)
141 b_val = (arg_data[
"b"] + SInt(7)(-3)).as_sint(7)
142 inner = arg_data[
"inner"]
143 p_val = (inner[
"p"] + UInt(8)(5)).as_uint(8)
144 q_val = (inner[
"q"] + SInt(8)(2)).as_sint(8)
145 r0_val = (inner[
"r"][0] + UInt(8)(1)).as_uint(8)
146 r1_val = (inner[
"r"][1] + UInt(8)(2)).as_uint(8)
149 inner=
OddInner(p=p_val, q=q_val, r=[r0_val, r1_val]))
150 result_chan, result_ready = Channel(OddStruct).
wrap(result, valid)
151 ready.assign(result_ready)
152 result_wire.assign(result_chan)
155ArgArray = SInt(8) * 1
156ResultArray = TypeAlias(SInt(8) * 2,
"ResultArray")
163 result_wire = Wire(Channel(ResultArray))
164 args = esi.FuncService.get_call_chans(AppID(
"arrayFunc"),
168 ready = Wire(Bits(1))
169 arg_data, valid = args.unwrap(ready)
171 elem_plus_one = (elem + SInt(8)(1)).as_sint(8)
174 result_chan, result_ready = Channel(ResultArray).
wrap(result_array, valid)
175 ready.assign(result_ready)
176 result_wire.assign(result_chan)
179MemA = esi.DeclareRandomAccessMemory(Bits(64), 20, name=
"MemA")
188 MemA.instantiate_builtin(appid=AppID(
"mem"),
191 inputs=[ports.clk, ports.rst])
193 write_bundle = MemA.write(AppID(
"internal_write"))
194 write_req_type = MemA.write.type.req
195 write_req, _ = write_req_type.wrap(
197 "address": UInt(MemA.address_width)(0),
201 write_bundle.unpack(req=write_req)
208 result_wire = Wire(Channel(UInt(16)))
209 args = esi.FuncService.get_call_chans(AppID(
"func1"),
213 ready = Wire(Bits(1))
214 _, valid = args.unwrap(ready)
215 result_chan, result_ready = Channel(UInt(16)).
wrap(UInt(16)(0), valid)
216 ready.assign(result_ready)
217 result_wire.assign(result_chan)
221 """Loopback a si4 value: returns the input unchanged."""
225 result_wire = Wire(Channel(SInt(4)))
226 args = esi.FuncService.get_call_chans(AppID(
"sint4Func"),
230 ready = Wire(Bits(1))
231 arg_data, valid = args.unwrap(ready)
232 result_chan, result_ready = Channel(SInt(4)).
wrap(arg_data, valid)
233 ready.assign(result_ready)
234 result_wire.assign(result_chan)
243 Loopback(clk=ports.clk, appid=AppID(
"loopback_inst", 0))
244 Loopback(clk=ports.clk, appid=AppID(
"loopback_inst", 1))
254 instance_name=
"coord_translator_serial",
255 appid=AppID(
"coord_translator_serial"),
259if __name__ ==
"__main__":
260 bsp = get_bsp(sys.argv[2]
if len(sys.argv) > 2
else None)
261 s = System(
bsp(Top), name=
"Loopback", output_directory=sys.argv[1])
return wrap(CMemoryType::get(unwrap(ctx), baseType, numElements))