21from pycde
import AppID, Clock, Module, Reset, System, generator
24from pycde.types
import Bits, Channel, StructType, UInt
39 RespType = StructType([(
"data", UInt(width)), (
"last", UInt(8))])
42 module_name = f
"HostMemReadDut_{width}"
48 clk, rst = ports.clk, ports.rst
50 host_req = esi.ChannelService.from_host(AppID(
"req"), ReqType)
51 burst_req_type = esi.HostMem.read_req_burst_type(32)
52 req = host_req.transform(
lambda r: burst_req_type({
57 req_xact, _ = req.snoop_xact()
58 accepted = Counter(32)(clk=clk,
62 esi.Telemetry.report_signal(clk, rst, AppID(
"accepted"), accepted.out)
64 gate_in = esi.ChannelService.from_host(AppID(
"gate"), UInt(8))
65 gate_data, gate_valid = gate_in.unwrap(Bits(1)(1))
66 gate_open = Reg(Bits(1), clk=clk, rst=rst, rst_value=0, name=
"gate_open")
67 gate_open.assign(Mux(gate_valid, gate_open, gate_data.as_bits()[0]))
69 resp = esi.HostMem.read_list(appid=AppID(
"host"),
71 element_type=Bits(width),
73 resp_ready = Wire(Bits(1))
74 frame, resp_valid = resp.unwrap(resp_ready)
75 frame = frame.unwrap()
76 out, out_ready = Channel(RespType).
wrap(
78 "data": frame[
"data"][0].as_uint(),
79 "last": frame[
"last"].as_uint(8),
80 }), resp_valid & gate_open)
81 resp_ready.assign(out_ready & gate_open)
82 esi.ChannelService.to_host(AppID(
"resp"), out)
95 address = esi.ChannelService.from_host(AppID(
"req"), UInt(64))
96 req = address.transform(
lambda addr: esi.HostMem.ReadReqType({
100 resp = esi.HostMem.read(AppID(
"host"), req, Bits(width))
101 esi.ChannelService.to_host(
103 resp.transform(
lambda r: r.data.as_uint((width + 7) // 8 * 8)))