|
| 1 | +from cmsis_stream.cg.scheduler import * |
| 2 | +from pathlib import Path |
| 3 | +import subprocess |
| 4 | +from nodes import * |
| 5 | + |
| 6 | +cwd = Path.cwd() |
| 7 | +target = (cwd / "../hello_graph").resolve() |
| 8 | + |
| 9 | +if not target.exists(): |
| 10 | + print(f"The script must be launched from the python folder but you launched it from {cwd}.") |
| 11 | + |
| 12 | +the_graph = Graph() |
| 13 | + |
| 14 | +src = DebugSource("src", CType(F32), 10) |
| 15 | +process = DebugProcess("process", CType(F32), 10) |
| 16 | +sink = DebugSink("sink", CType(F32)) |
| 17 | +evtSink = DebugEvtSink("evtSink") |
| 18 | + |
| 19 | +the_graph.connect(src.o, process.i) |
| 20 | +the_graph.connect(process.o, sink.i) |
| 21 | +the_graph.connect(sink["oev0"], evtSink["iev0"]) |
| 22 | + |
| 23 | +conf = Configuration() |
| 24 | +conf.CMSISDSP = False |
| 25 | +conf.asynchronous = False |
| 26 | + |
| 27 | +conf.horizontal = True |
| 28 | +conf.nodeIdentification = True |
| 29 | +conf.schedName = "scheduler_hello" |
| 30 | +conf.schedulerCFileName = "scheduler_hello" |
| 31 | +conf.memoryOptimization = True |
| 32 | + |
| 33 | +conf.appConfigCName = "app_config.hpp" |
| 34 | +conf.cOptionalInitArgs = ["helloParams_t *params"] |
| 35 | +conf.appNodesCName = "AppNodes_hello.hpp" |
| 36 | +conf.prefix = "stream_hello_" |
| 37 | + |
| 38 | +scheduling = the_graph.computeSchedule(config=conf) |
| 39 | + |
| 40 | +print("Schedule length = %d" % scheduling.scheduleLength) |
| 41 | +print("Memory usage %d bytes" % scheduling.memory) |
| 42 | + |
| 43 | +scheduling.ccode("../hello_graph", conf) |
| 44 | +scheduling.genJsonIdentification("../hello_graph/json", conf) |
| 45 | +scheduling.genJsonSelectorsInit("../hello_graph/json", conf) |
| 46 | + |
| 47 | +class MyStyle(Style): |
| 48 | + def edge_color(self, edge): |
| 49 | + nb = self.fifoLength(edge) |
| 50 | + if nb is None: |
| 51 | + nb = 0 |
| 52 | + d = self.edgeDstNode(edge) |
| 53 | + |
| 54 | + if d.nodeName == "display": |
| 55 | + return "magenta" |
| 56 | + if nb > 512: |
| 57 | + return "orange" |
| 58 | + return super().edge_color(edge) |
| 59 | + |
| 60 | +myStyle = MyStyle() |
| 61 | + |
| 62 | +with open("../hello_graph/hello.dot", "w") as f: |
| 63 | + scheduling.graphviz(f, style=myStyle) |
| 64 | + |
| 65 | +subprocess.run(["dot", "-Tpng", "../hello_graph/hello.dot", "-o", "../hello_graph/hello.png"]) |
0 commit comments