Skip to content

Commit b44ffd6

Browse files
Added Python description to the hello posix example
1 parent 3fec1e0 commit b44ffd6

8 files changed

Lines changed: 140 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"process": 0,
3+
"sink": 1,
4+
"src": 2,
5+
"evtSink": 3
6+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"DebugProcess<float,10,float,1>": {
3+
"isTemplate": true,
4+
"selectors": []
5+
},
6+
"DebugSink<float,1>": {
7+
"isTemplate": true,
8+
"selectors": [
9+
"SEL_MESSAGE_ID"
10+
]
11+
},
12+
"DebugSource<float,10>": {
13+
"isTemplate": true,
14+
"selectors": []
15+
},
16+
"DebugEvtSink": {
17+
"isTemplate": false,
18+
"selectors": [
19+
"SEL_MESSAGE_ID"
20+
]
21+
}
22+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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"])
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from cmsis_stream.cg.scheduler import *
2+
3+
class DebugEvtSink(BaseNode):
4+
def __init__(self, name):
5+
BaseNode.__init__(self, name, selectors=["message"])
6+
self.addEventInput()
7+
8+
@property
9+
def typeName(self):
10+
return "DebugEvtSink"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from cmsis_stream.cg.scheduler import *
2+
3+
class DebugProcess(GenericNode):
4+
def __init__(self, name, theType, inLength):
5+
GenericNode.__init__(self, name, identified=True)
6+
self.addInput("i", theType, inLength)
7+
self.addOutput("o", theType, 1)
8+
9+
@property
10+
def typeName(self):
11+
return "DebugProcess"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from cmsis_stream.cg.scheduler import *
2+
3+
class DebugSink(GenericSink):
4+
def __init__(self, name, theType):
5+
GenericSink.__init__(self, name, selectors=["message"])
6+
self.addInput("i", theType, 1)
7+
self.addEventOutput()
8+
9+
@property
10+
def typeName(self):
11+
return "DebugSink"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from cmsis_stream.cg.scheduler import *
2+
3+
class DebugSource(GenericSource):
4+
def __init__(self, name, theType, inLength):
5+
GenericSource.__init__(self, name, identified=True)
6+
self.addOutput("o", theType, inLength)
7+
self.addVariableArg(f"params->{name}")
8+
9+
@property
10+
def typeName(self):
11+
return "DebugSource"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .DebugEvtSink import *
2+
from .DebugProcess import *
3+
from .DebugSource import *
4+
from .DebugSink import *

0 commit comments

Comments
 (0)