AppNodes.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: AppNodes.h
  4. * Description: Application nodes for Example 10
  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. #include <cstdio>
  29. #include "NullSink.h"
  30. static int count=0;
  31. template<typename OUT,int outputSize>
  32. class SourceOdd;
  33. template<typename OUT,int outputSize>
  34. class SourceEven;
  35. template<>
  36. class SourceOdd<int16_t,1>: public GenericSource<int16_t,1>
  37. {
  38. public:
  39. SourceOdd(FIFOBase<int16_t> &dst):
  40. GenericSource<int16_t,1>(dst){};
  41. int prepareForRunning() override
  42. {
  43. if (this->willOverflow())
  44. {
  45. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  46. }
  47. return(0);
  48. };
  49. int run() override{
  50. if (count & 1)
  51. {
  52. int16_t *b=this->getWriteBuffer();
  53. b[0] = count;
  54. }
  55. return(0);
  56. };
  57. };
  58. template<>
  59. class SourceEven<int16_t,1>: public GenericSource<int16_t,1>
  60. {
  61. public:
  62. SourceEven(FIFOBase<int16_t> &dst):
  63. GenericSource<int16_t,1>(dst){};
  64. int prepareForRunning() override
  65. {
  66. if (this->willOverflow())
  67. {
  68. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  69. }
  70. return(0);
  71. };
  72. int run() override{
  73. if (!(count & 1))
  74. {
  75. int16_t *b=this->getWriteBuffer();
  76. b[0] = count;
  77. }
  78. return(0);
  79. };
  80. };
  81. template<typename INA, int inputSizeA,
  82. typename INB, int inputSizeB,
  83. typename OUT,int outputSize>
  84. class ProcessingOddEven;
  85. template<>
  86. class ProcessingOddEven<int16_t,1,
  87. int16_t,1,
  88. int16_t,1>:
  89. public GenericNode21<int16_t,1,
  90. int16_t,1,
  91. int16_t,1>
  92. {
  93. public:
  94. ProcessingOddEven(FIFOBase<int16_t> &srcOdd,
  95. FIFOBase<int16_t> &srcEven,
  96. FIFOBase<int16_t> &dst):
  97. GenericNode21<int16_t,1,
  98. int16_t,1,
  99. int16_t,1>(srcOdd,srcEven,dst){};
  100. int prepareForRunning() override
  101. {
  102. if (this->willOverflow())
  103. {
  104. return(CG_SKIP_EXECUTION_ID_CODE);
  105. }
  106. return(0);
  107. };
  108. int run() override{
  109. int16_t oddVal=0;
  110. int16_t evenVal=0;
  111. if (!this->willUnderflow1())
  112. {
  113. int16_t *odd=this->getReadBuffer1();
  114. oddVal=odd[0];
  115. }
  116. if (!this->willUnderflow2())
  117. {
  118. int16_t *even=this->getReadBuffer2();
  119. evenVal=even[0];
  120. }
  121. int16_t *dst=this->getWriteBuffer();
  122. dst[0] = (evenVal + oddVal);
  123. return(0);
  124. };
  125. };
  126. template<typename IN, int inputSize>
  127. class SinkAsync;
  128. template<int inputSize>
  129. class SinkAsync<int16_t,inputSize>:
  130. public GenericSink<int16_t, inputSize>
  131. {
  132. public:
  133. SinkAsync(FIFOBase<int16_t> &src):
  134. GenericSink<int16_t,inputSize>(src){
  135. };
  136. int prepareForRunning() override
  137. {
  138. if (this->willUnderflow())
  139. {
  140. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  141. }
  142. return(0);
  143. };
  144. int run() override
  145. {
  146. int16_t *b=this->getReadBuffer();
  147. for(int i=0;i<inputSize;i++)
  148. {
  149. printf("%d\n",b[i]);
  150. }
  151. return(0);
  152. };
  153. };
  154. void compute(int16_t *in,int16_t *out, int nb)
  155. {
  156. out[0] = in[0];
  157. }
  158. #endif