appnodes.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. ###########################################
  2. # Project: CMSIS DSP Library
  3. # Title: appnodes.py
  4. # Description: Application nodes for Example 4
  5. #
  6. # $Date: 29 July 2021
  7. # $Revision: V1.10.0
  8. #
  9. # Target Processor: Cortex-M and Cortex-A cores
  10. # -------------------------------------------------------------------- */
  11. #
  12. # Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
  13. #
  14. # SPDX-License-Identifier: Apache-2.0
  15. #
  16. # Licensed under the Apache License, Version 2.0 (the License); you may
  17. # not use this file except in compliance with the License.
  18. # You may obtain a copy of the License at
  19. #
  20. # www.apache.org/licenses/LICENSE-2.0
  21. #
  22. # Unless required by applicable law or agreed to in writing, software
  23. # distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. # See the License for the specific language governing permissions and
  26. # limitations under the License.
  27. ############################################
  28. from cmsisdsp.cg.static.nodes.simu import *
  29. from custom import *
  30. from cmsisdsp.cg.static.nodes.Duplicate import *
  31. class Sink(GenericSink):
  32. def __init__(self,inputSize,fifoin):
  33. GenericSink.__init__(self,inputSize,fifoin)
  34. def run(self):
  35. # The null sink must at least get a buffer from the FIFO
  36. # or the FIFO will never be emptied
  37. # and the scheduling will fail
  38. print("Sink")
  39. i=self.getReadBuffer()
  40. for c in i:
  41. print("%f + I %f" % (c.re,c.im))
  42. return(0)
  43. class ProcessingNode(GenericNode12):
  44. def __init__(self,inputSize,outputSize1,outputSize2,fifoin,fifoout1,fifoout2,i,s,v):
  45. GenericNode12.__init__(self,inputSize,outputSize1,outputSize2,fifoin,fifoout1,fifoout2)
  46. def run(self):
  47. print("ProcessingNode");
  48. a=self.getReadBuffer()
  49. b=self.getWriteBuffer1()
  50. c=self.getWriteBuffer2()
  51. # Python objects have reference semantic and not
  52. # value semantic.
  53. # So in a write buffer, we can change the
  54. # fields of an object but we should not
  55. # replace the object and risk creating sharing
  56. # Duplicating the a object may be ok
  57. b[0]=a[3]
  58. c[0]=a[3]
  59. return(0)
  60. class Source(GenericSource):
  61. def __init__(self,outputSize,fifoout):
  62. GenericSource.__init__(self,outputSize,fifoout)
  63. self._counter=0
  64. def run(self):
  65. print("Source");
  66. a=self.getWriteBuffer()
  67. # Python objects have reference semantic and not
  68. # value semantic.
  69. # So in a write buffer, we can change the
  70. # fields of an object but we should not
  71. # replace the object and risk creating sharing
  72. # Creating a new object may be ok
  73. for i in range(self._outputSize):
  74. #a[i].re = 1.0*self._counter
  75. #a[i].im = 0.0
  76. a[i] = MyComplex(1.0*self._counter, 0.0)
  77. self._counter = self._counter + 1
  78. return(0)