AppNodes.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: AppNodes.h
  4. * Description: Application nodes for Example 1
  5. *
  6. * Target Processor: Cortex-M and Cortex-A cores
  7. * -------------------------------------------------------------------- */
  8. /*
  9. * Copyright (C) 2021-2023 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 << (int)b[i] << std::endl;
  49. }
  50. return(0);
  51. };
  52. };
  53. template<typename OUT,int outputSize>
  54. class Source: GenericSource<OUT,outputSize>
  55. {
  56. public:
  57. Source(FIFOBase<OUT> &dst):GenericSource<OUT,outputSize>(dst),mCounter(0){};
  58. int prepareForRunning() override
  59. {
  60. if (this->willOverflow()
  61. )
  62. {
  63. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  64. }
  65. return(0);
  66. };
  67. int run(){
  68. OUT *b=this->getWriteBuffer();
  69. printf("Source\n");
  70. for(int i=0;i<outputSize;i++)
  71. {
  72. b[i] = (OUT)mCounter++;
  73. }
  74. return(0);
  75. };
  76. int mCounter;
  77. };
  78. template<typename IN, int inputSize,typename OUT,int outputSize>
  79. class ProcessingNode: public GenericNode<IN,inputSize,OUT,outputSize>
  80. {
  81. public:
  82. ProcessingNode(FIFOBase<IN> &src,FIFOBase<OUT> &dst,int,const char*,int):GenericNode<IN,inputSize,OUT,outputSize>(src,dst){};
  83. int prepareForRunning() override
  84. {
  85. if (this->willOverflow() ||
  86. this->willUnderflow()
  87. )
  88. {
  89. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  90. }
  91. return(0);
  92. };
  93. int run(){
  94. printf("ProcessingNode\n");
  95. IN *a=this->getReadBuffer();
  96. OUT *b=this->getWriteBuffer();
  97. b[0] =(OUT)a[3];
  98. return(0);
  99. };
  100. };
  101. #endif