AppNodes.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 << (int)b[i] << std::endl;
  52. }
  53. return(0);
  54. };
  55. };
  56. template<typename OUT,int outputSize>
  57. class Source: GenericSource<OUT,outputSize>
  58. {
  59. public:
  60. Source(FIFOBase<OUT> &dst):GenericSource<OUT,outputSize>(dst),mCounter(0){};
  61. int prepareForRunning() override
  62. {
  63. if (this->willOverflow()
  64. )
  65. {
  66. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  67. }
  68. return(0);
  69. };
  70. int run(){
  71. OUT *b=this->getWriteBuffer();
  72. printf("Source\n");
  73. for(int i=0;i<outputSize;i++)
  74. {
  75. b[i] = (OUT)mCounter++;
  76. }
  77. return(0);
  78. };
  79. int mCounter;
  80. };
  81. template<typename IN1, int inputSize1,
  82. typename IN2, int inputSize2,
  83. typename OUT,int outputSize>
  84. class ProcessingNode;
  85. template<int inputSize>
  86. class ProcessingNode<float32_t,inputSize,
  87. float32_t,inputSize,
  88. float32_t,inputSize>:
  89. public GenericNode21<float32_t,inputSize,
  90. float32_t,inputSize,
  91. float32_t,inputSize>
  92. {
  93. public:
  94. ProcessingNode(FIFOBase<float32_t> &src1,
  95. FIFOBase<float32_t> &src2,
  96. FIFOBase<float32_t> &dst):
  97. GenericNode21<float32_t,inputSize,
  98. float32_t,inputSize,
  99. float32_t,inputSize>(src1,src2,dst){};
  100. int prepareForRunning() override
  101. {
  102. if (this->willOverflow() ||
  103. this->willUnderflow1() ||
  104. this->willUnderflow2()
  105. )
  106. {
  107. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  108. }
  109. return(0);
  110. };
  111. int run(){
  112. printf("ProcessingNode\n");
  113. float32_t *a=this->getReadBuffer1();
  114. float32_t *b=this->getReadBuffer2();
  115. float32_t *c=this->getWriteBuffer();
  116. for(int i=0;i<inputSize;i++)
  117. {
  118. c[i] = a[i] + 0.5f*b[i];
  119. }
  120. return(0);
  121. };
  122. };
  123. #endif