AppNodes.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 IN, int inputSize,typename OUT,int outputSize>
  82. class ProcessingNode: public GenericNode<IN,inputSize,OUT,outputSize>
  83. {
  84. public:
  85. ProcessingNode(FIFOBase<IN> &src,FIFOBase<OUT> &dst,int,const char*,int):GenericNode<IN,inputSize,OUT,outputSize>(src,dst){};
  86. int prepareForRunning() override
  87. {
  88. if (this->willOverflow() ||
  89. this->willUnderflow()
  90. )
  91. {
  92. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  93. }
  94. return(0);
  95. };
  96. int run(){
  97. printf("ProcessingNode\n");
  98. IN *a=this->getReadBuffer();
  99. OUT *b=this->getWriteBuffer();
  100. b[0] =(OUT)a[3];
  101. return(0);
  102. };
  103. };
  104. #endif