8from pycde.common
import AppID, Clock, Input, Output
12from pycde.types
import (Bits, Bundle, BundledChannel, Channel,
14from pycde.constructs
import ControlReg, NamedWire, Reg, Wire
28def CosimBSP(user_module: Type[Module], emulate_dma: bool =
False) -> Module:
29 """Wrap and return a cosimulation 'board support package' containing
32 class ESI_Cosim_UserTopWrapper(Module):
33 """Wrap the user module along with 'standard' service generators so that
34 those generators can issue their own service requests to be picked up by the
35 actual top-level catch-all cosim service generator."""
40 mmio = Input(esi.MMIO.read_write.type)
45 ChannelHostMemModule = ChannelHostMem(read_width=HostMemWidth,
46 write_width=HostMemWidth)
48 hostmem_read = ChannelHostMemModule.read
49 hostmem_write = ChannelHostMemModule.write
53 user_module(clk=ports.clk, rst=ports.rst)
54 esi.TelemetryMMIO(esi.Telemetry,
60 ChannelEngineService(OneItemBuffersToHost, OneItemBuffersFromHost)(
75 hostmem = ESI_Cosim_UserTopWrapper.ChannelHostMemModule(
80 ports.hostmem_read = hostmem.read
81 ports.hostmem_write = hostmem.write
83 class ESI_Cosim_Top(Module):
89 System.current().platform =
"cosim"
91 mmio_read_write = esi.FuncService.get(
92 esi.AppID(
"__cosim_mmio_read_write"), esi.MMIO.read_write.type)
93 wrapper = ESI_Cosim_UserTopWrapper(clk=ports.clk,
97 resp_channel = esi.ChannelService.from_host(
101 (
"data", Bits(ESI_Cosim_UserTopWrapper.HostMemWidth)),
103 req = wrapper.hostmem_read.unpack(resp=resp_channel)[
'req']
104 esi.ChannelService.to_host(
esi.AppID(
"__cosim_hostmem_read_req"), req)
106 ack_wire = Wire(Channel(UInt(8)))
107 write_req = wrapper.hostmem_write.unpack(ackTag=ack_wire)[
'req']
108 ack_tag = esi.CallService.call(
esi.AppID(
"__cosim_hostmem_write"),
110 ack_wire.assign(ack_tag)
112 cosim_svc = raw_esi.ServiceInstanceOp(
114 appID=AppID(
"cosim")._appid,
116 impl_type=ir.StringAttr.get(
"cosim"),
117 inputs=[ports.clk.value, ports.rst.value],
119 core_freq = System.current().core_freq
120 if core_freq
is not None:
121 cosim_svc.operation.attributes[
122 "esi.core_clock_frequency_hz"] = ir.IntegerAttr.get(
123 ir.IntegerType.get_unsigned(64), core_freq)