AppNodes.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: AppNodes.h
  4. * Description: Application nodes for Example 9
  5. *
  6. * Target Processor: Cortex-M and Cortex-A cores
  7. * --------------------------------------------------------------------
  8. *
  9. * Copyright (C) 2021-2023 ARM Limited or its affiliates. All rights reserved.
  10. *
  11. * SPDX-License-Identifier: Apache-2.0
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the License); you may
  14. * not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at
  16. *
  17. * www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  21. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. */
  25. #ifndef _APPNODES_H_
  26. #define _APPNODES_H_
  27. #include <iostream>
  28. template<typename IN, int inputSize>
  29. class Sink: public GenericSink<IN, inputSize>
  30. {
  31. public:
  32. Sink(FIFOBase<IN> &src):GenericSink<IN,inputSize>(src){};
  33. int prepareForRunning() override
  34. {
  35. if (this->willUnderflow()
  36. )
  37. {
  38. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  39. }
  40. return(0);
  41. };
  42. int run()
  43. {
  44. IN *b=this->getReadBuffer();
  45. printf("Sink\n");
  46. for(int i=0;i<inputSize;i++)
  47. {
  48. std::cout << (int)b[i] << std::endl;
  49. }
  50. return(0);
  51. };
  52. };
  53. template<typename OUT,int outputSize>
  54. class Source: GenericSource<OUT,outputSize>
  55. {
  56. public:
  57. Source(FIFOBase<OUT> &dst):GenericSource<OUT,outputSize>(dst),mCounter(0){};
  58. int prepareForRunning() override
  59. {
  60. if (this->willOverflow()
  61. )
  62. {
  63. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  64. }
  65. return(0);
  66. };
  67. int run(){
  68. OUT *b=this->getWriteBuffer();
  69. printf("Source\n");
  70. for(int i=0;i<outputSize;i++)
  71. {
  72. b[i] = (OUT)mCounter++;
  73. }
  74. return(0);
  75. };
  76. int mCounter;
  77. };
  78. template<typename IN1, int inputSize1,
  79. typename IN2, int inputSize2,
  80. typename OUT,int outputSize>
  81. class ProcessingNode;
  82. template<int inputSize>
  83. class ProcessingNode<float32_t,inputSize,
  84. float32_t,inputSize,
  85. float32_t,inputSize>:
  86. public GenericNode21<float32_t,inputSize,
  87. float32_t,inputSize,
  88. float32_t,inputSize>
  89. {
  90. public:
  91. ProcessingNode(FIFOBase<float32_t> &src1,
  92. FIFOBase<float32_t> &src2,
  93. FIFOBase<float32_t> &dst):
  94. GenericNode21<float32_t,inputSize,
  95. float32_t,inputSize,
  96. float32_t,inputSize>(src1,src2,dst){};
  97. int prepareForRunning() override
  98. {
  99. if (this->willOverflow() ||
  100. this->willUnderflow1() ||
  101. this->willUnderflow2()
  102. )
  103. {
  104. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  105. }
  106. return(0);
  107. };
  108. int run(){
  109. printf("ProcessingNode\n");
  110. float32_t *a=this->getReadBuffer1();
  111. float32_t *b=this->getReadBuffer2();
  112. float32_t *c=this->getWriteBuffer();
  113. for(int i=0;i<inputSize;i++)
  114. {
  115. c[i] = a[i] + 0.5f*b[i];
  116. }
  117. return(0);
  118. };
  119. };
  120. #endif