CIRCT 24.0.0git
Loading...
Searching...
No Matches
custom_channel_service.py
Go to the documentation of this file.
1# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2# See https://llvm.org/LICENSE.txt for license information.
3# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5import sys
6
7from pycde import AppID, Clock, Module, Reset, System, esi, generator
8from pycde.types import UInt
9
10from esiaccel.bsp.cosim import CosimBSP
11from esiaccel.bsp.dma import OneItemBuffersFromHost, OneItemBuffersToHost
12
13
15 clk = Clock()
16 rst = Reset()
17
18 @generator
19 def build(ports):
20 for i in range(2):
21 channel = esi.ChannelService.from_host(AppID(f"loopback_in_{i}"),
22 UInt(256))
23 esi.ChannelService.to_host(AppID(f"loopback_out_{i}"), channel)
24
25
26class CustomChannelService(esi.ServiceImplementation):
27 """Serve this test's channels without delegating to ChannelEngineService."""
28
29 clk = Clock()
30 rst = Reset()
31
32 @generator
33 def build(ports, bundles):
34 assert len(bundles.to_client_reqs) == 4
35 for bundle in bundles.to_client_reqs:
36 assert bundle.port in ("from_host", "to_host")
37 from_host = bundle.port == "from_host"
38 engine_module = (OneItemBuffersFromHost(UInt(256))
39 if from_host else OneItemBuffersToHost(UInt(256)))
40 name = "custom_" + bundle.client_name_str
41 mmio_appid = AppID(name + ".mmio")
42 inputs = {
43 "clk":
44 ports.clk,
45 "rst":
46 ports.rst,
47 "mmio":
48 esi.MMIO.read_write(mmio_appid),
49 "hostmem_write":
50 esi.HostMem.write_from_bundle(AppID(name + ".write"),
51 engine_module.hostmem_write.type),
52 }
53 if from_host:
54 inputs["hostmem_read"] = esi.HostMem.read_from_bundle(
55 AppID(name + ".read"), engine_module.hostmem_read.type)
56 else:
57 client_bundle, channels = bundle.type.pack()
58 bundle.assign(client_bundle)
59 inputs["input_channel"] = channels["data"]
60
61 engine = engine_module(appid=AppID(name), **inputs)
62 if from_host:
63 client_bundle, _ = bundle.type.pack(data=engine.output_channel)
64 bundle.assign(client_bundle)
65
66 record = bundles.emit_engine(engine,
67 details={
68 "engine_inst": engine.appid,
69 "mmio": mmio_appid,
70 })
71 record.add_record(bundle, {"data": {}})
72
73
74if __name__ == "__main__":
75 system = System(CosimBSP(Loopbacks, channel_service=CustomChannelService),
76 name="CustomChannelServiceTest",
77 output_directory=sys.argv[1])
78 system.compile()
79 system.package()