1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_cfft_init_q31.c
4  * Description:  Initialization function for cfft q31 instance
5  *
6  * $Date:        23 April 2021
7  * $Revision:    V1.9.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 
29 
30 /**
31  * @defgroup ComplexFFTQ31 Complex FFT Q31
32  */
33 
34 /**
35   @ingroup groupTransforms
36  */
37 
38 /**
39   @addtogroup ComplexFFT
40   @{
41  */
42 
43 /**
44   @addtogroup ComplexFFTQ31
45   @{
46  */
47 
48 #include "dsp/transform_functions.h"
49 #include "arm_common_tables.h"
50 #include "arm_const_structs.h"
51 
52 #if defined(ARM_MATH_MVEI)  && !defined(ARM_MATH_AUTOVECTORIZE)
53 
54 #include "arm_vec_fft.h"
55 #include "arm_mve_tables.h"
56 
57 #define CFFT_RADIX4BY2_REARRANGE_TWIDDLES_Q31(LEN)                                           \
58 static arm_status arm_cfft_radix4by2_rearrange_twiddles_##LEN##_q31(arm_cfft_instance_q31 *S)\
59 {                                                                                            \
60     S->rearranged_twiddle_tab_stride1_arr = rearranged_twiddle_tab_stride1_arr_##LEN##_q31;  \
61     S->rearranged_twiddle_stride1  =  rearranged_twiddle_stride1_##LEN##_q31;                \
62                                                                                              \
63     S->rearranged_twiddle_tab_stride2_arr = rearranged_twiddle_tab_stride2_arr_##LEN##_q31;  \
64     S->rearranged_twiddle_stride2  =  rearranged_twiddle_stride2_##LEN##_q31;                \
65                                                                                              \
66     S->rearranged_twiddle_tab_stride3_arr = rearranged_twiddle_tab_stride3_arr_##LEN##_q31;  \
67     S->rearranged_twiddle_stride3  =  rearranged_twiddle_stride3_##LEN##_q31;                                                     \
68     return(ARM_MATH_SUCCESS);                                                                \
69 }
70 
71 CFFT_RADIX4BY2_REARRANGE_TWIDDLES_Q31(4096);
72 CFFT_RADIX4BY2_REARRANGE_TWIDDLES_Q31(1024);
73 CFFT_RADIX4BY2_REARRANGE_TWIDDLES_Q31(256);
74 CFFT_RADIX4BY2_REARRANGE_TWIDDLES_Q31(64);
75 CFFT_RADIX4BY2_REARRANGE_TWIDDLES_Q31(16);
76 
77 
78 #define CFFTINIT_Q31(LEN,LENTWIDDLE)                                    \
79 arm_status arm_cfft_init_##LEN##_q31(                                \
80   arm_cfft_instance_q31 * S)                                         \
81 {                                                                    \
82     /*  Initialise the default arm status */                         \
83     arm_status status = ARM_MATH_SUCCESS;                            \
84                                                                      \
85     /*  Initialise the FFT length */                                 \
86     S->fftLen = LEN;                                                 \
87                                                                      \
88     /*  Initialise the Twiddle coefficient pointer */                \
89     S->pTwiddle = NULL;                                              \
90                                                                      \
91     /*  Initialise the bit reversal table modifier */                \
92     S->bitRevLength = ARMBITREVINDEXTABLE_FIXED_##LEN##_TABLE_LENGTH;      \
93     S->pBitRevTable = (uint16_t *)armBitRevIndexTable_fixed_##LEN;   \
94     S->pTwiddle = (q31_t *)twiddleCoef_##LEN##_q31;                  \
95     status=arm_cfft_radix4by2_rearrange_twiddles_##LENTWIDDLE##_q31(S);\
96                                                                      \
97     return (status);                                                 \
98 };
99 
100 
101 
102 #else
103 
104 #define FFTINIT(EXT,SIZE)                                           \
105   S->bitRevLength = arm_cfft_sR_##EXT##_len##SIZE.bitRevLength;        \
106   S->pBitRevTable = arm_cfft_sR_##EXT##_len##SIZE.pBitRevTable;         \
107   S->pTwiddle = arm_cfft_sR_##EXT##_len##SIZE.pTwiddle;
108 
109 #define CFFTINIT_Q31(LEN,LENTWIDDLE)                                      \
110 arm_status arm_cfft_init_##LEN##_q31(arm_cfft_instance_q31 * S)\
111 {                                                              \
112     /*  Initialise the default arm status */                   \
113         arm_status status = ARM_MATH_SUCCESS;                  \
114                                                                \
115         /*  Initialise the FFT length */                       \
116         S->fftLen = LEN;                                       \
117                                                                \
118         /*  Initialise the Twiddle coefficient pointer */      \
119         S->pTwiddle = NULL;                                    \
120                                                                \
121         FFTINIT(q31,LEN);                                      \
122                                                                \
123         return (status);                                       \
124 };
125 
126 
127 #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
128 
129 /**
130   @brief         Initialization function for the cfft q31 function for 4096 samples
131   @param[in,out] S              points to an instance of the floating-point CFFT structure
132   @return        execution status
133                    - \ref ARM_MATH_SUCCESS        : Operation successful
134                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
135 
136   @par          Use of this function is mandatory only for the MVE version of the FFT.
137                 Other versions can still initialize directly the data structure using
138                 variables declared in arm_const_structs.h
139  */
140 CFFTINIT_Q31(4096,4096);
141 
142 /**
143   @brief         Initialization function for the cfft q31 function for 2048 samples
144   @param[in,out] S              points to an instance of the floating-point CFFT structure
145   @return        execution status
146                    - \ref ARM_MATH_SUCCESS        : Operation successful
147                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
148 
149   @par          Use of this function is mandatory only for the MVE version of the FFT.
150                 Other versions can still initialize directly the data structure using
151                 variables declared in arm_const_structs.h
152  */
153 CFFTINIT_Q31(2048,1024);
154 
155 /**
156   @brief         Initialization function for the cfft q31 function for 1024 samples
157   @param[in,out] S              points to an instance of the floating-point CFFT structure
158   @return        execution status
159                    - \ref ARM_MATH_SUCCESS        : Operation successful
160                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
161 
162   @par          Use of this function is mandatory only for the MVE version of the FFT.
163                 Other versions can still initialize directly the data structure using
164                 variables declared in arm_const_structs.h
165  */
166 CFFTINIT_Q31(1024,1024);
167 
168 /**
169   @brief         Initialization function for the cfft q31 function for 512 samples
170   @param[in,out] S              points to an instance of the floating-point CFFT structure
171   @return        execution status
172                    - \ref ARM_MATH_SUCCESS        : Operation successful
173                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
174 
175   @par          Use of this function is mandatory only for the MVE version of the FFT.
176                 Other versions can still initialize directly the data structure using
177                 variables declared in arm_const_structs.h
178  */
179 CFFTINIT_Q31(512,256);
180 
181 /**
182   @brief         Initialization function for the cfft q31 function for 256 samples
183   @param[in,out] S              points to an instance of the floating-point CFFT structure
184   @return        execution status
185                    - \ref ARM_MATH_SUCCESS        : Operation successful
186                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
187 
188   @par          Use of this function is mandatory only for the MVE version of the FFT.
189                 Other versions can still initialize directly the data structure using
190                 variables declared in arm_const_structs.h
191  */
192 CFFTINIT_Q31(256,256);
193 
194 /**
195   @brief         Initialization function for the cfft q31 function for 128 samples
196   @param[in,out] S              points to an instance of the floating-point CFFT structure
197   @return        execution status
198                    - \ref ARM_MATH_SUCCESS        : Operation successful
199                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
200 
201   @par          Use of this function is mandatory only for the MVE version of the FFT.
202                 Other versions can still initialize directly the data structure using
203                 variables declared in arm_const_structs.h
204  */
205 CFFTINIT_Q31(128,64);
206 
207 /**
208   @brief         Initialization function for the cfft q31 function for 64 samples
209   @param[in,out] S              points to an instance of the floating-point CFFT structure
210   @return        execution status
211                    - \ref ARM_MATH_SUCCESS        : Operation successful
212                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
213 
214   @par          Use of this function is mandatory only for the MVE version of the FFT.
215                 Other versions can still initialize directly the data structure using
216                 variables declared in arm_const_structs.h
217  */
218 CFFTINIT_Q31(64,64);
219 
220 /**
221   @brief         Initialization function for the cfft q31 function for 32 samples
222   @param[in,out] S              points to an instance of the floating-point CFFT structure
223   @return        execution status
224                    - \ref ARM_MATH_SUCCESS        : Operation successful
225                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
226 
227   @par          Use of this function is mandatory only for the MVE version of the FFT.
228                 Other versions can still initialize directly the data structure using
229                 variables declared in arm_const_structs.h
230  */
231 CFFTINIT_Q31(32,16);
232 
233 /**
234   @brief         Initialization function for the cfft q31 function for 16 samples
235   @param[in,out] S              points to an instance of the floating-point CFFT structure
236   @return        execution status
237                    - \ref ARM_MATH_SUCCESS        : Operation successful
238                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
239 
240   @par          Use of this function is mandatory only for the MVE version of the FFT.
241                 Other versions can still initialize directly the data structure using
242                 variables declared in arm_const_structs.h
243  */
244 CFFTINIT_Q31(16,16);
245 
246 /**
247   @brief         Generic initialization function for the cfft q31 function
248   @param[in,out] S              points to an instance of the floating-point CFFT structure
249   @param[in]     fftLen         fft length (number of complex samples)
250   @return        execution status
251                    - \ref ARM_MATH_SUCCESS        : Operation successful
252                    - \ref ARM_MATH_ARGUMENT_ERROR : an error is detected
253 
254   @par          Use of this function is mandatory only for the MVE version of the FFT.
255                 Other versions can still initialize directly the data structure using
256                 variables declared in arm_const_structs.h
257 
258   @par
259                 This function should be used only if you don't know the FFT sizes that
260                 you'll need at build time. The use of this function will prevent the
261                 linker from removing the FFT tables that are not needed and the library
262                 code size will be bigger than needed.
263 
264   @par
265                 If you use CMSIS-DSP as a static library, and if you know the FFT sizes
266                 that you need at build time, then it is better to use the initialization
267                 functions defined for each FFT size.
268  */
arm_cfft_init_q31(arm_cfft_instance_q31 * S,uint16_t fftLen)269 arm_status arm_cfft_init_q31(
270   arm_cfft_instance_q31 * S,
271   uint16_t fftLen)
272 {
273 
274         /*  Initialise the default arm status */
275         arm_status status = ARM_MATH_SUCCESS;
276 
277 
278 
279         /*  Initializations of Instance structure depending on the FFT length */
280         switch (fftLen) {
281             /*  Initializations of structure parameters for 4096 point FFT */
282         case 4096U:
283             /*  Initialise the bit reversal table modifier */
284             status=arm_cfft_init_4096_q31(S);
285             break;
286 
287             /*  Initializations of structure parameters for 2048 point FFT */
288         case 2048U:
289             /*  Initialise the bit reversal table modifier */
290             status=arm_cfft_init_2048_q31(S);
291             break;
292 
293             /*  Initializations of structure parameters for 1024 point FFT */
294         case 1024U:
295             /*  Initialise the bit reversal table modifier */
296             status=arm_cfft_init_1024_q31(S);
297             break;
298 
299             /*  Initializations of structure parameters for 512 point FFT */
300         case 512U:
301             /*  Initialise the bit reversal table modifier */
302             status=arm_cfft_init_512_q31(S);
303             break;
304 
305         case 256U:
306             status=arm_cfft_init_256_q31(S);
307             break;
308 
309         case 128U:
310             status=arm_cfft_init_128_q31(S);
311             break;
312 
313         case 64U:
314             status=arm_cfft_init_64_q31(S);
315             break;
316 
317         case 32U:
318             status=arm_cfft_init_32_q31(S);
319             break;
320 
321         case 16U:
322             /*  Initializations of structure parameters for 16 point FFT */
323             status=arm_cfft_init_16_q31(S);
324             break;
325 
326         default:
327             /*  Reporting argument error if fftSize is not valid value */
328             status = ARM_MATH_ARGUMENT_ERROR;
329             break;
330         }
331 
332 
333         return (status);
334 }
335 /**
336   @} end of ComplexFFTQ31 group
337  */
338 
339 /**
340   @} end of ComplexFFT group
341  */