CFFT.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: CFFT.h
  4. * Description: Node for CMSIS-DSP cfft
  5. *
  6. *
  7. * Target Processor: Cortex-M and Cortex-A cores
  8. * --------------------------------------------------------------------
  9. *
  10. * Copyright (C) 2021-2023 ARM Limited or its affiliates. All rights reserved.
  11. *
  12. * SPDX-License-Identifier: Apache-2.0
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the License); you may
  15. * not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at
  17. *
  18. * www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  22. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. */
  26. #ifndef _CFFT_H_
  27. #define _CFFT_H_
  28. template<typename IN, int inputSize,typename OUT,int outputSize>
  29. class CFFT;
  30. /*
  31. The CMSIS-DSP CFFT F32
  32. */
  33. template<int inputSize>
  34. class CFFT<float32_t,inputSize,float32_t,inputSize>: public GenericNode<float32_t,inputSize,float32_t,inputSize>
  35. {
  36. public:
  37. CFFT(FIFOBase<float32_t> &src,FIFOBase<float32_t> &dst):GenericNode<float32_t,inputSize,float32_t,inputSize>(src,dst){
  38. status=arm_cfft_init_f32(&sfft,inputSize>>1);
  39. };
  40. int prepareForRunning() final
  41. {
  42. if (this->willOverflow() ||
  43. this->willUnderflow()
  44. )
  45. {
  46. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  47. }
  48. return(0);
  49. };
  50. int run() final
  51. {
  52. if (status!=ARM_MATH_SUCCESS)
  53. {
  54. return(CG_INIT_FAILURE);
  55. }
  56. float32_t *a=this->getReadBuffer();
  57. float32_t *b=this->getWriteBuffer();
  58. memcpy((void*)b,(void*)a,inputSize*sizeof(float32_t));
  59. arm_cfft_f32(&sfft,b,0,1);
  60. return(0);
  61. };
  62. arm_cfft_instance_f32 sfft;
  63. arm_status status;
  64. };
  65. #if defined(ARM_FLOAT16_SUPPORTED)
  66. /*
  67. The CMSIS-DSP CFFT F32
  68. */
  69. template<int inputSize>
  70. class CFFT<float16_t,inputSize,float16_t,inputSize>: public GenericNode<float16_t,inputSize,float16_t,inputSize>
  71. {
  72. public:
  73. CFFT(FIFOBase<float16_t> &src,FIFOBase<float16_t> &dst):GenericNode<float16_t,inputSize,float16_t,inputSize>(src,dst){
  74. status=arm_cfft_init_f16(&sfft,inputSize>>1);
  75. };
  76. int prepareForRunning() final
  77. {
  78. if (this->willOverflow() ||
  79. this->willUnderflow()
  80. )
  81. {
  82. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  83. }
  84. return(0);
  85. };
  86. int run() final
  87. {
  88. if (status!=ARM_MATH_SUCCESS)
  89. {
  90. return(CG_INIT_FAILURE);
  91. }
  92. float16_t *a=this->getReadBuffer();
  93. float16_t *b=this->getWriteBuffer();
  94. memcpy((void*)b,(void*)a,inputSize*sizeof(float16_t));
  95. arm_cfft_f16(&sfft,b,0,1);
  96. return(0);
  97. };
  98. arm_cfft_instance_f16 sfft;
  99. arm_status status;
  100. };
  101. #endif
  102. /*
  103. The CMSIS-DSP CFFT Q15
  104. */
  105. template<int inputSize>
  106. class CFFT<q15_t,inputSize,q15_t,inputSize>: public GenericNode<q15_t,inputSize,q15_t,inputSize>
  107. {
  108. public:
  109. CFFT(FIFOBase<q15_t> &src,FIFOBase<q15_t> &dst):GenericNode<q15_t,inputSize,q15_t,inputSize>(src,dst){
  110. status=arm_cfft_init_q15(&sfft,inputSize>>1);
  111. };
  112. int prepareForRunning() final
  113. {
  114. if (this->willOverflow() ||
  115. this->willUnderflow()
  116. )
  117. {
  118. return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
  119. }
  120. return(0);
  121. };
  122. int run() final
  123. {
  124. if (status!=ARM_MATH_SUCCESS)
  125. {
  126. return(CG_INIT_FAILURE);
  127. }
  128. q15_t *a=this->getReadBuffer();
  129. q15_t *b=this->getWriteBuffer();
  130. memcpy((void*)b,(void*)a,inputSize*sizeof(q15_t));
  131. arm_cfft_q15(&sfft,b,0,1);
  132. return(0);
  133. };
  134. arm_cfft_instance_q15 sfft;
  135. arm_status status;
  136. };
  137. #endif