5from typing
import Callable, Optional, Tuple, Type
11from pycde.types
import (Bits, Channel, StructType, UInt)
27 user_module: Type[Module],
28 dma_engine_pair: Optional[Tuple[Callable, Callable]] =
None,
30 """Wrap and return a cosimulation 'board support package' containing
33 class ESI_Cosim_UserTopWrapper(Module):
34 """Wrap the user module along with 'standard' service generators so that
35 those generators can issue their own service requests to be picked up by the
36 actual top-level catch-all cosim service generator."""
41 mmio = Input(esi.MMIO.read_write.type)
46 ChannelHostMemModule = ChannelHostMem(read_width=HostMemWidth,
47 write_width=HostMemWidth)
49 hostmem_read = ChannelHostMemModule.read
50 hostmem_write = ChannelHostMemModule.write
54 user_module(clk=ports.clk, rst=ports.rst)
55 esi.TelemetryMMIO(esi.Telemetry,
60 if dma_engine_pair
is not None:
61 ChannelEngineService(dma_engine_pair[0], dma_engine_pair[1])(
76 hostmem = ESI_Cosim_UserTopWrapper.ChannelHostMemModule(
81 ports.hostmem_read = hostmem.read
82 ports.hostmem_write = hostmem.write
84 class ESI_Cosim_Top(Module):
90 System.current().platform =
"cosim"
92 mmio_read_write = esi.FuncService.get(
93 esi.AppID(
"__cosim_mmio_read_write"), esi.MMIO.read_write.type)
94 wrapper = ESI_Cosim_UserTopWrapper(clk=ports.clk,
98 resp_channel = esi.ChannelService.from_host(
102 (
"data", Bits(ESI_Cosim_UserTopWrapper.HostMemWidth)),
104 req = wrapper.hostmem_read.unpack(resp=resp_channel)[
'req']
105 esi.ChannelService.to_host(
esi.AppID(
"__cosim_hostmem_read_req"), req)
107 ack_wire = Wire(Channel(UInt(8)))
108 write_req = wrapper.hostmem_write.unpack(ackTag=ack_wire)[
'req']
109 ack_tag = esi.CallService.call(
esi.AppID(
"__cosim_hostmem_write"),
111 ack_wire.assign(ack_tag)
113 cosim_svc = raw_esi.ServiceInstanceOp(
115 appID=AppID(
"cosim")._appid,
117 impl_type=ir.StringAttr.get(
"cosim"),
118 inputs=[ports.clk.value, ports.rst.value],
120 core_freq = System.current().core_freq
121 if core_freq
is not None:
122 cosim_svc.operation.attributes[
123 "esi.core_clock_frequency_hz"] = ir.IntegerAttr.get(
124 ir.IntegerType.get_unsigned(64), core_freq)