AppNodes.h 4.2 KB

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