appnodes.py 2.9 KB

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