AppNodes.h 4.2 KB

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