AppNodes.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. template<typename IN, int inputSize>
  32. class Sink: public GenericSink<IN, inputSize>
  33. {
  34. public:
  35. Sink(FIFOBase<IN> &src):GenericSink<IN,inputSize>(src){};
  36. int prepareForRunning() override
  37. {
  38. if (this->willUnderflow()
  39. )
  40. {
  41. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  42. }
  43. return(0);
  44. };
  45. int run()
  46. {
  47. IN *b=this->getReadBuffer();
  48. printf("Sink\n");
  49. for(int i=0;i<inputSize;i++)
  50. {
  51. std::cout << b[i].re << " + I " << b[i].im << std::endl;
  52. }
  53. return(0);
  54. };
  55. };
  56. template<typename OUT,int outputSize>
  57. class Source;
  58. template<int outputSize>
  59. class Source<complex,outputSize>: GenericSource<complex,outputSize>
  60. {
  61. public:
  62. Source(FIFOBase<complex> &dst):GenericSource<complex,outputSize>(dst),mCounter(0){};
  63. int prepareForRunning() override
  64. {
  65. if (this->willOverflow()
  66. )
  67. {
  68. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  69. }
  70. return(0);
  71. };
  72. int run(){
  73. complex *b=this->getWriteBuffer();
  74. printf("Source\n");
  75. for(int i=0;i<outputSize;i++)
  76. {
  77. b[i].re = (float32_t)mCounter++;
  78. b[i].im = 0.0;
  79. }
  80. return(0);
  81. };
  82. int mCounter;
  83. };
  84. template<typename IN, int inputSize,
  85. typename OUT1,int outputSize1,
  86. typename OUT2,int outputSize2>
  87. class ProcessingNode: public GenericNode12<IN,inputSize,
  88. OUT1,outputSize1,
  89. OUT2,outputSize2>
  90. {
  91. public:
  92. ProcessingNode(FIFOBase<IN> &src,
  93. FIFOBase<OUT1> &dst1,
  94. FIFOBase<OUT2> &dst2,
  95. int,const char*,int):
  96. GenericNode12<IN,inputSize,
  97. OUT1,outputSize1,
  98. OUT2,outputSize2>(src,dst1,dst2){};
  99. int prepareForRunning() override
  100. {
  101. if (this->willOverflow1() ||
  102. this->willOverflow2() ||
  103. this->willUnderflow()
  104. )
  105. {
  106. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  107. }
  108. return(0);
  109. };
  110. int run(){
  111. printf("ProcessingNode\n");
  112. IN *a=this->getReadBuffer();
  113. OUT1 *b=this->getWriteBuffer1();
  114. OUT2 *c=this->getWriteBuffer2();
  115. b[0] =(OUT1)a[3];
  116. c[0] =(OUT2)a[3];
  117. return(0);
  118. };
  119. };
  120. #endif