graph.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. from cmsisdsp.cg.scheduler import *
  2. ### Define new types of Nodes
  3. class SinkAsync(GenericSink):
  4. def __init__(self,name,theType,inLength):
  5. GenericSink.__init__(self,name)
  6. self.addInput("i",theType,inLength)
  7. @property
  8. def typeName(self):
  9. return "SinkAsync"
  10. class SourceOdd(GenericSource):
  11. def __init__(self,name,theType,inLength):
  12. GenericSource.__init__(self,name)
  13. self.addOutput("o",theType,inLength)
  14. @property
  15. def typeName(self):
  16. return "SourceOdd"
  17. class SourceEven(GenericSource):
  18. def __init__(self,name,theType,inLength):
  19. GenericSource.__init__(self,name)
  20. self.addOutput("o",theType,inLength)
  21. @property
  22. def typeName(self):
  23. return "SourceEven"
  24. class ProcessingOddEven(GenericNode):
  25. def __init__(self,name,theType,inLength,outLength):
  26. GenericNode.__init__(self,name)
  27. self.addInput("ia",theType,inLength)
  28. self.addInput("ib",theType,inLength)
  29. self.addOutput("o",theType,outLength)
  30. @property
  31. def typeName(self):
  32. return "ProcessingOddEven"
  33. ### Define nodes
  34. dataType=CType(SINT16)
  35. odd=SourceOdd("sourceOdd",dataType,1)
  36. even=SourceEven("sourceEven",dataType,1)
  37. proc=ProcessingOddEven("proc",dataType,1,1)
  38. comp=Unary("compute",dataType,1)
  39. sinka=SinkAsync("sinka",dataType,1)
  40. sinkb=SinkAsync("sinkb",dataType,1)
  41. g = Graph()
  42. # Option to customize the default class
  43. # to use for Duplicate and FIFO
  44. # FIFO class can also be changed in the connect
  45. # function to change the class for a specific
  46. # connection
  47. g.defaultFIFOClass = "FIFO"
  48. g.duplicateNodeClassName = "Duplicate"
  49. g.connect(odd.o,proc.ia)
  50. g.connect(even.o,proc.ib)
  51. g.connect(proc.o,comp.i)
  52. g.connect(comp.o,sinka.i)
  53. g.connect(comp.o,sinkb.i)
  54. print("Generate graphviz and code")
  55. conf=Configuration()
  56. conf.debugLimit=10
  57. conf.cOptionalArgs=""
  58. # It is disabled in asynchronous mode
  59. # since the schedule has no mor any reason to
  60. # be periodic and thus the FIFO content can
  61. # overlap several executions of the schedule
  62. conf.memoryOptimization=True
  63. conf.codeArray = True
  64. conf.switchCase = True
  65. # Asynchronous mode enable. It implies
  66. # switchCase and codeArray true
  67. conf.asynchronous = True
  68. # Increase size of synchronous FIFOs by 100%
  69. # for the asynchronous case (so 2 samples
  70. # instead of 1 in this example)
  71. conf.FIFOIncrease = 100 # percent
  72. #conf.displayFIFOSizes=True
  73. # Prefix for global FIFO buffers
  74. #conf.prefix="sched1"
  75. #conf.dumpSchedule = True
  76. sched = g.computeSchedule(config=conf)
  77. #print(sched.schedule)
  78. print("Schedule length = %d" % sched.scheduleLength)
  79. print("Memory usage %d bytes" % sched.memory)
  80. #
  81. #conf.postCustomCName = "post.h"
  82. #conf.CAPI = True
  83. #conf.prefix="global"
  84. #conf.dumpFIFO = True
  85. #conf.CMSISDSP = False
  86. #conf.codeArray = False
  87. #conf.switchCase = False
  88. # For pure functions (like CMSIS-DSP) which are not
  89. # packaged in a C++ class, we have to decide of the
  90. # asynchronous policy. What must be done in case of
  91. # FIFO overflow or underflow.
  92. # By default, the execution is skipped.
  93. conf.asyncDefaultSkip = True
  94. sched.ccode("./generated",conf)
  95. with open("test.dot","w") as f:
  96. sched.graphviz(f)