32from pycde
import (AppID, Clock, Module, Reset, Signal, System, generator)
33from pycde.bsp
import get_bsp
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)
42SendI8 = Bundle([BundledChannel(
"send", ChannelDirection.FROM, Bits(8))])
43RecvI8 = Bundle([BundledChannel(
"recv", ChannelDirection.TO, Bits(8))])
44SendI0 = Bundle([BundledChannel(
"send", ChannelDirection.FROM, Bits(0))])
45RecvI0 = Bundle([BundledChannel(
"recv", ChannelDirection.TO, Bits(0))])
66 summary=
"IP which simply echos bytes",
70 depth = Constant(UInt(32), 5)
74 data_in_bundle = HostComms.Recv(AppID(
"loopback_tohw"))
75 data_in = data_in_bundle.unpack()[
"recv"]
77 data_out_bundle = HostComms.Send(AppID(
"loopback_fromhw"))
78 data_out_bundle.unpack(send=data_in)
80 send_bundle = MyService.Recv(AppID(
"mysvc_recv"))
81 send_chan = send_bundle.unpack()[
"recv"]
82 sendi0_bundle = MyService.Send(AppID(
"mysvc_send"))
83 sendi0_bundle.unpack(send=send_chan)
112 result_wire = Wire(Channel(ResultStruct))
113 args = esi.FuncService.get_call_chans(AppID(
"structFunc"),
117 ready = Wire(Bits(1))
118 arg_data, valid = args.unwrap(ready)
119 b_val = arg_data[
"b"]
120 b_plus_one = (b_val + SInt(8)(1)).as_sint(8)
122 result_chan, result_ready = Channel(ResultStruct).
wrap(result, valid)
123 ready.assign(result_ready)
124 result_wire.assign(result_chan)
131 result_wire = Wire(Channel(OddStruct))
132 args = esi.FuncService.get_call_chans(AppID(
"oddStructFunc"),
136 ready = Wire(Bits(1))
137 arg_data, valid = args.unwrap(ready)
138 a_val = (arg_data[
"a"] + UInt(12)(1)).as_uint(12)
139 b_val = (arg_data[
"b"] + SInt(7)(-3)).as_sint(7)
140 inner = arg_data[
"inner"]
141 p_val = (inner[
"p"] + UInt(8)(5)).as_uint(8)
142 q_val = (inner[
"q"] + SInt(8)(2)).as_sint(8)
143 r0_val = (inner[
"r"][0] + UInt(8)(1)).as_uint(8)
144 r1_val = (inner[
"r"][1] + UInt(8)(2)).as_uint(8)
147 inner=
OddInner(p=p_val, q=q_val, r=[r0_val, r1_val]))
148 result_chan, result_ready = Channel(OddStruct).
wrap(result, valid)
149 ready.assign(result_ready)
150 result_wire.assign(result_chan)
153ArgArray = SInt(8) * 1
154ResultArray = TypeAlias(SInt(8) * 2,
"ResultArray")
161 result_wire = Wire(Channel(ResultArray))
162 args = esi.FuncService.get_call_chans(AppID(
"arrayFunc"),
166 ready = Wire(Bits(1))
167 arg_data, valid = args.unwrap(ready)
169 elem_plus_one = (elem + SInt(8)(1)).as_sint(8)
172 result_chan, result_ready = Channel(ResultArray).
wrap(result_array, valid)
173 ready.assign(result_ready)
174 result_wire.assign(result_chan)
177MemA = esi.DeclareRandomAccessMemory(Bits(64), 20, name=
"MemA")
186 MemA.instantiate_builtin(appid=AppID(
"mem"),
189 inputs=[ports.clk, ports.rst])
191 write_bundle = MemA.write(AppID(
"internal_write"))
192 write_req_type = MemA.write.type.req
193 write_req, _ = write_req_type.wrap(
195 "address": UInt(MemA.address_width)(0),
199 write_bundle.unpack(req=write_req)
206 result_wire = Wire(Channel(UInt(16)))
207 args = esi.FuncService.get_call_chans(AppID(
"func1"),
211 ready = Wire(Bits(1))
212 _, valid = args.unwrap(ready)
213 result_chan, result_ready = Channel(UInt(16)).
wrap(UInt(16)(0), valid)
214 ready.assign(result_ready)
215 result_wire.assign(result_chan)
219 """Loopback a si4 value: returns the input unchanged."""
223 result_wire = Wire(Channel(SInt(4)))
224 args = esi.FuncService.get_call_chans(AppID(
"sint4Func"),
228 ready = Wire(Bits(1))
229 arg_data, valid = args.unwrap(ready)
230 result_chan, result_ready = Channel(SInt(4)).
wrap(arg_data, valid)
231 ready.assign(result_ready)
232 result_wire.assign(result_chan)
241 Loopback(clk=ports.clk, appid=AppID(
"loopback_inst", 0))
242 Loopback(clk=ports.clk, appid=AppID(
"loopback_inst", 1))
251if __name__ ==
"__main__":
252 bsp = get_bsp(sys.argv[2]
if len(sys.argv) > 2
else None)
253 s = System(
bsp(Top), name=
"Loopback", output_directory=sys.argv[1])
return wrap(CMemoryType::get(unwrap(ctx), baseType, numElements))