AppNodes.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: AppNodes.h
  4. * Description: Application nodes for Example 8
  5. *
  6. * Target Processor: Cortex-M and Cortex-A cores
  7. * --------------------------------------------------------------------
  8. *
  9. * Copyright (C) 2010-2021 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 << b[i].re << " + I " << b[i].im << std::endl;
  49. }
  50. return(0);
  51. };
  52. };
  53. template<typename OUT,int outputSize>
  54. class Source;
  55. template<int outputSize>
  56. class Source<complex,outputSize>: GenericSource<complex,outputSize>
  57. {
  58. public:
  59. Source(FIFOBase<complex> &dst):GenericSource<complex,outputSize>(dst),mCounter(0){};
  60. int prepareForRunning() override
  61. {
  62. if (this->willOverflow()
  63. )
  64. {
  65. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  66. }
  67. return(0);
  68. };
  69. int run(){
  70. complex *b=this->getWriteBuffer();
  71. printf("Source\n");
  72. for(int i=0;i<outputSize;i++)
  73. {
  74. b[i].re = (float32_t)mCounter++;
  75. b[i].im = 0.0;
  76. }
  77. return(0);
  78. };
  79. int mCounter;
  80. };
  81. template<typename IN, int inputSize,
  82. typename OUT1,int outputSize1,
  83. typename OUT2,int outputSize2>
  84. class ProcessingNode: public GenericNode12<IN,inputSize,
  85. OUT1,outputSize1,
  86. OUT2,outputSize2>
  87. {
  88. public:
  89. ProcessingNode(FIFOBase<IN> &src,
  90. FIFOBase<OUT1> &dst1,
  91. FIFOBase<OUT2> &dst2,
  92. int,const char*,int):
  93. GenericNode12<IN,inputSize,
  94. OUT1,outputSize1,
  95. OUT2,outputSize2>(src,dst1,dst2){};
  96. int prepareForRunning() override
  97. {
  98. if (this->willOverflow1() ||
  99. this->willOverflow2() ||
  100. this->willUnderflow()
  101. )
  102. {
  103. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  104. }
  105. return(0);
  106. };
  107. int run(){
  108. printf("ProcessingNode\n");
  109. IN *a=this->getReadBuffer();
  110. OUT1 *b=this->getWriteBuffer1();
  111. OUT2 *c=this->getWriteBuffer2();
  112. b[0] =(OUT1)a[3];
  113. c[0] =(OUT2)a[3];
  114. return(0);
  115. };
  116. };
  117. #endif