AppNodes.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: AppNodes.h
  4. * Description: Application nodes for Example simple
  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() final
  34. {
  35. if (this->willUnderflow())
  36. {
  37. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  38. }
  39. return(0);
  40. };
  41. int run() final
  42. {
  43. IN *b=this->getReadBuffer();
  44. printf("Sink\n");
  45. for(int i=0;i<inputSize;i++)
  46. {
  47. std::cout << (int)b[i] << std::endl;
  48. }
  49. return(0);
  50. };
  51. };
  52. template<typename OUT,int outputSize>
  53. class Source: public GenericSource<OUT,outputSize>
  54. {
  55. public:
  56. Source(FIFOBase<OUT> &dst):GenericSource<OUT,outputSize>(dst){};
  57. int prepareForRunning() final
  58. {
  59. if (this->willOverflow())
  60. {
  61. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  62. }
  63. return(0);
  64. };
  65. int run() final{
  66. OUT *b=this->getWriteBuffer();
  67. printf("Source\n");
  68. for(int i=0;i<outputSize;i++)
  69. {
  70. b[i] = (OUT)i;
  71. }
  72. return(0);
  73. };
  74. };
  75. template<typename IN, int inputSize,
  76. typename OUT, int outputSize>
  77. class ProcessingNode;
  78. template<typename IN, int inputOutputSize>
  79. class ProcessingNode<IN,inputOutputSize,IN,inputOutputSize>: public GenericNode<IN,inputOutputSize,IN,inputOutputSize>
  80. {
  81. public:
  82. ProcessingNode(FIFOBase<IN> &src,
  83. FIFOBase<IN> &dst):GenericNode<IN,inputOutputSize,
  84. IN,inputOutputSize>(src,dst){};
  85. int prepareForRunning() final
  86. {
  87. if (this->willOverflow() ||
  88. this->willUnderflow())
  89. {
  90. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  91. }
  92. return(0);
  93. };
  94. int run() final{
  95. printf("ProcessingNode\n");
  96. IN *a=this->getReadBuffer();
  97. IN *b=this->getWriteBuffer();
  98. for(int i=0;i<inputOutputSize;i++)
  99. {
  100. b[i] = a[i]+1;
  101. }
  102. return(0);
  103. };
  104. };
  105. #endif