graph_complex.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # Include definitions from the Python package to
  2. # define datatype for the IOs and to have access to the
  3. # Graph class
  4. from cmsisdsp.cg.scheduler import *
  5. # Include definition of the nodes
  6. from nodes import *
  7. class ProcessingNode12(GenericNode):
  8. def __init__(self,name,theType,inLength,outLength):
  9. GenericNode.__init__(self,name)
  10. self.addInput("i",theType,inLength)
  11. self.addOutput("oa",theType,outLength)
  12. self.addOutput("ob",theType,outLength)
  13. @property
  14. def typeName(self):
  15. return "ProcessingNode12"
  16. class ProcessingNode13(GenericNode):
  17. def __init__(self,name,theType,inLength,outLength):
  18. GenericNode.__init__(self,name)
  19. self.addInput("i",theType,inLength)
  20. self.addOutput("oa",theType,outLength)
  21. self.addOutput("ob",theType,outLength)
  22. self.addOutput("oc",theType,outLength)
  23. @property
  24. def typeName(self):
  25. return "ProcessingNode13"
  26. class ProcessingNode21(GenericNode):
  27. def __init__(self,name,theType,inLength,outLength):
  28. GenericNode.__init__(self,name)
  29. self.addInput("ia",theType,inLength)
  30. self.addInput("ib",theType,inLength)
  31. self.addOutput("o",theType,outLength)
  32. @property
  33. def typeName(self):
  34. return "ProcessingNode21"
  35. class Sink(GenericSink):
  36. def __init__(self,name,theType,inLength):
  37. GenericSink.__init__(self,name)
  38. self.addInput("i",theType,inLength)
  39. @property
  40. def typeName(self):
  41. return "Sink"
  42. class Source(GenericSource):
  43. def __init__(self,name,theType,inLength):
  44. GenericSource.__init__(self,name)
  45. self.addOutput("o",theType,inLength)
  46. @property
  47. def typeName(self):
  48. return "Source"
  49. class ProcessingNode(GenericNode):
  50. def __init__(self,name,theType,inLength,outLength):
  51. GenericNode.__init__(self,name)
  52. self.addInput("i",theType,inLength)
  53. self.addOutput("o",theType,outLength)
  54. @property
  55. def typeName(self):
  56. return "ProcessingNode"
  57. ### Define nodes
  58. floatType=CType(F32)
  59. src=Source("source",floatType,128)
  60. srcb=Source("sourceb",floatType,16)
  61. srcc=Source("sourcec",floatType,16)
  62. pa=ProcessingNode("procA",floatType,128,128)
  63. pb=ProcessingNode("procB",floatType,128,128)
  64. pc=ProcessingNode("procC",floatType,128,128)
  65. pd=ProcessingNode("procD",floatType,128,128)
  66. pe=ProcessingNode("procE",floatType,128,256)
  67. p12=ProcessingNode12("proc12",floatType,16,16)
  68. p13=ProcessingNode13("proc13",floatType,16,16)
  69. p21A=ProcessingNode21("proc21A",floatType,16,16)
  70. p21B=ProcessingNode21("proc21B",floatType,16,16)
  71. #dsp=Dsp("add",floatType,NB)
  72. sink=Sink("sink",floatType,100)
  73. sinkb=Sink("sinkB",floatType,16)
  74. sinkc=Sink("sinkC",floatType,16)
  75. sinkd=Sink("sinkD",floatType,16)
  76. sinke=Sink("sinkE",floatType,16)
  77. the_graph = Graph()
  78. the_graph.connect(src.o,pa.i)
  79. the_graph.connect(pa.o,pb.i)
  80. the_graph.connect(pb.o,pc.i)
  81. the_graph.connect(pc.o,pd.i)
  82. the_graph.connect(pd.o,pe.i)
  83. the_graph.connect(pe.o,sink.i)
  84. the_graph.connect(pc.o,p12.i)
  85. the_graph.connect(pc.o,p13.i)
  86. the_graph.connect(pd.o,p21A.ia)
  87. the_graph.connect(p12.oa,p21A.ib)
  88. the_graph.connect(p12.ob,p21B.ia)
  89. the_graph.connect(p13.oa,p21B.ib)
  90. the_graph.connect(p13.ob,sinkb.i)
  91. the_graph.connect(p13.oc,sinkc.i)
  92. the_graph.connect(p21A.o,sinkd.i)
  93. the_graph.connect(p21B.o,sinke.i)