314 lines
12 KiB
C
Executable File
314 lines
12 KiB
C
Executable File
/****************************************************************************
|
|
|
|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
|
|
|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
|
be copied by any method or incorporated into another program without
|
|
the express written consent of Aerospace C.Power. This Information or any portion
|
|
thereof remains the property of Aerospace C.Power. The Information contained herein
|
|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
|
liability for its use in any way and conveys no license or title under
|
|
any patent or copyright and makes no representation or warranty that this
|
|
Information is free from patent or copyright infringement.
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef IOT_MATRIX_API_H
|
|
#define IOT_MATRIX_API_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/** \defgroup AFFT_APIs AFFT APIs
|
|
* @brief AFFT APIs
|
|
*
|
|
*
|
|
*/
|
|
|
|
/** @addtogroup AFFT_APIs
|
|
* @{
|
|
*
|
|
*/
|
|
|
|
/**
|
|
* @brief Usage:
|
|
// AFFT apis are used for FFT calculation.
|
|
FFT size support 256, 512, 1024, 2048 read data, and 128, 256, 512, 1024
|
|
complex data.
|
|
|
|
// test case : calculate 2048 FFT, data format is low 24 bits valid.
|
|
|
|
// the pointer of input data
|
|
uint32_t *src = ...;
|
|
|
|
// the pointer of output data
|
|
uint32_t *dst = ...;
|
|
|
|
// the length of data
|
|
uint32_t data_len = ...;
|
|
|
|
// get fft/ifft result
|
|
iot_afft_real_fft(dst, src, 2048, AFFT_FMT_LOW_24BIT, AFFT_REAL_2048);
|
|
|
|
|
|
// another calling function:
|
|
uint32_t addr = iot_afft_get_address();
|
|
|
|
iot_real_fft_cfg(AFFT_FMT_LOW_24BIT, AFFT_REAL_2048);
|
|
|
|
// move data into afft addr
|
|
...;
|
|
|
|
// start
|
|
iot_afft_start();
|
|
|
|
// get the output data from afft addr
|
|
...;
|
|
*/
|
|
/**
|
|
* @brief afft_data_fmt_t - input word format
|
|
* @param AFFT_FMT_LOW_24BIT low 24 bit valid
|
|
* @param AFFT_FMT_HIGH_24BIT high 24 bit valid
|
|
* @param AFFT_FMT_FLOAT_32BIT 32 bit valid
|
|
* @param AFFT_FMT_16BIT data[0]: low 16 bit, data[1]: high 16 bit
|
|
*/
|
|
/* [TODO]: KL3 need to adapt the previous program */
|
|
typedef enum {
|
|
/* KL2 */
|
|
AFFT_FMT_LOW_24BIT = 0,
|
|
AFFT_FMT_HIGH_24BIT,
|
|
AFFT_FMT_FLOAT_32BIT,
|
|
AFFT_FMT_16BIT,
|
|
/* KL3 */
|
|
AFFT_FMT_KL3_32BIT = 0,
|
|
AFFT_FMT_KL3_LOW_28BIT,
|
|
AFFT_FMT_KL3_FLOAT_32BIT,
|
|
AFFT_FMT_KL3_DOUBLE_16BIT_0, //high 16bits is data1, low 16bits is data0
|
|
AFFT_FMT_KL3_LOW_24BIT,
|
|
AFFT_FMT_KL3_LOW_20BIT,
|
|
AFFT_FMT_KL3_LOW_18BIT,
|
|
AFFT_FMT_KL3_DOUBLE_16BIT_1, //high 16bits is data0, low 16bits is data1
|
|
} afft_data_fmt_t;
|
|
|
|
typedef enum {
|
|
AFFT_REAL_256 = 0,
|
|
AFFT_REAL_512,
|
|
AFFT_REAL_1024,
|
|
AFFT_REAL_2048,
|
|
AFFT_REAL_64,
|
|
AFFT_REAL_128,
|
|
} afft_real_mode_t;
|
|
|
|
typedef enum {
|
|
AFFT_COMPLEX_128 = 0,
|
|
AFFT_COMPLEX_256,
|
|
AFFT_COMPLEX_512,
|
|
AFFT_COMPLEX_1024,
|
|
AFFT_COMPLEX_32,
|
|
AFFT_COMPLEX_64,
|
|
} afft_complex_mode_t;
|
|
|
|
typedef enum {
|
|
AFFT_WIN_RECTANGULAR = 0,
|
|
AFFT_WIN_HANNING,
|
|
AFFT_WIN_HAMMING,
|
|
} afft_win_sel_t;
|
|
|
|
/**
|
|
* @brief iot_afft_real_fft() - calculate real data fft
|
|
input format as below:
|
|
0 31 0 31 0 ... 31 0 31
|
|
|---------|---------|---------|---------|
|
|
| real[0] | real[1] | ... | real[n] |,
|
|
data type is real, n is the number of input real data,
|
|
support 256,512,1024,2048 FFT calculation, reference
|
|
to afft_real_mode_t struct.
|
|
|
|
Output format as below:
|
|
0 31 0 31 0 ... 31 0 31 0 31
|
|
|---------|---------|---------|---------|---------|
|
|
| real[0] | imag[1] | ... | real[m] | imag[m] |,
|
|
ouput complex data, include real and imaginary part.
|
|
m is the number of complex data, m = n/2.
|
|
|
|
* @param dst the destination pointer of FFT
|
|
* @param src the source pointer of real data
|
|
* @param len the length of source data, uint is word
|
|
* @param bit the format of data, reference to afft_data_fmt_t
|
|
* @param mode the mode of TTF, reference to afft_real_mode_t
|
|
* @param stage the right shift bits of twiddle stage
|
|
* @param lsf_in the left-shift bits of fft/ifft input
|
|
* @param rsf_out the right-shift bits of fft/ifft output
|
|
*/
|
|
void iot_afft_real_fft(uint32_t *dst, uint32_t *src, uint32_t len,
|
|
uint8_t bit, uint8_t mode, uint8_t stage, uint8_t lsf_in, uint8_t rsf_out);
|
|
|
|
/**
|
|
* @brief iot_afft_real_ifft() - calculate real data ifft
|
|
input format as below:
|
|
0 31 0 31 0 ... 31 0 31
|
|
|---------|---------|---------|---------|
|
|
| real[0] | real[1] | ... | real[n] |,
|
|
data type is real, n is the number of input real data,
|
|
support 256,512,1024,2048 FFT calculation, reference
|
|
to afft_real_mode_t struct.
|
|
|
|
Output format as below:
|
|
0 31 0 31 0 ... 31 0 31 0 31
|
|
|---------|---------|---------|---------|---------|
|
|
| real[0] | imag[1] | ... | real[m] | imag[m] |,
|
|
ouput complex data, include real and imaginary part.
|
|
m is the number of complex data, m = n/2.
|
|
|
|
* @param dst the destination pointer of IFFT
|
|
* @param src the source pointer of real data
|
|
* @param len the length of source data, uint is word
|
|
* @param bit the format of data, reference to afft_data_fmt_t
|
|
* @param mode the mode of TTF, reference to afft_real_mode_t
|
|
* @param stage the right shift bits of twiddle stage
|
|
* @param lsf_in the left-shift bits of fft/ifft input
|
|
* @param rsf_out the right-shift bits of fft/ifft output
|
|
*/
|
|
void iot_afft_real_ifft(uint32_t *dst, uint32_t *src, uint32_t len,
|
|
uint8_t bit, uint8_t mode, uint8_t stage, uint8_t lsf_in, uint8_t rsf_out);
|
|
|
|
/**
|
|
* @brief iot_afft_complex_fft() - calculate complex data fft
|
|
input format as below:
|
|
0 31 0 31 0 ... 31 0 31 0 31
|
|
|---------|---------|---------|---------|---------|
|
|
| real[0] | imag[1] | ... | real[n] | imag[n] |,
|
|
data type is complex,n is the number of input real data,
|
|
support 128,256,512,1024 FFT calculation, reference
|
|
to afft_complex_mode_t struct.
|
|
|
|
Output format as below:
|
|
0 31 0 31 0 ... 31 0 31 0 31
|
|
|---------|---------|---------|---------|---------|
|
|
| real[0] | imag[1] | ... | real[m] | imag[m] |,
|
|
ouput complex data, include real and imaginary part.
|
|
m is the number of complex data, m = n.
|
|
|
|
* @param dst the destination pointer of FFT
|
|
* @param src the source pointer of complex data
|
|
* @param len the length of source data, uint is word
|
|
* @param bit the format of data, reference to afft_data_fmt_t
|
|
* @param mode the mode of TTF, reference to afft_complex_mode_t
|
|
* @param stage the right shift bits of twiddle stage
|
|
* @param lsf_in the left-shift bits of fft/ifft input
|
|
* @param rsf_out the right-shift bits of fft/ifft output
|
|
*/
|
|
void iot_afft_complex_fft(uint32_t *dst, uint32_t *src, uint32_t len,
|
|
uint8_t bit, uint8_t mode, uint8_t stage, uint8_t lsf_in, uint8_t rsf_out);
|
|
|
|
/**
|
|
* @brief iot_afft_complex_ifft() - calculate complex data ifft
|
|
input format as below:
|
|
0 31 0 31 0 ... 31 0 31 0 31
|
|
|---------|---------|---------|---------|---------|
|
|
| real[0] | imag[1] | ... | real[n] | imag[n] |,
|
|
data type is complex,n is the number of input real data,
|
|
support 128,256,512,1024 FFT calculation, reference
|
|
to afft_complex_mode_t struct.
|
|
|
|
Output format as below:
|
|
0 31 0 31 0 ... 31 0 31 0 31
|
|
|---------|---------|---------|---------|---------|
|
|
| real[0] | imag[1] | ... | real[m] | imag[m] |,
|
|
ouput complex data, include real and imaginary part.
|
|
m is the number of complex data, m = n.
|
|
|
|
* @param dst the destination pointer of IFFT
|
|
* @param src the source pointer of complex data
|
|
* @param len the length of source data, uint is word
|
|
* @param bit the format of data, reference to afft_data_fmt_t
|
|
* @param mode the mode of TTF, reference to afft_complex_mode_t
|
|
* @param stage the right shift bits of twiddle stage
|
|
* @param lsf_in the left-shift bits of fft/ifft input
|
|
* @param rsf_out the right-shift bits of fft/ifft output
|
|
*/
|
|
void iot_afft_complex_ifft(uint32_t *dst, uint32_t *src, uint32_t len,
|
|
uint8_t bit, uint8_t mode, uint8_t stage, uint8_t lsf_in, uint8_t rsf_out);
|
|
|
|
void iot_afft_init();
|
|
|
|
/**
|
|
* @brief iot_real_fft_cfg() - real data fft configuration
|
|
* @param bit the format of data, reference to afft_data_fmt_t
|
|
* @param mode the mode of TTF, reference to afft_real_mode_t
|
|
* @param stage the right shift bits of twiddle stage
|
|
* @param lsf_in the left-shift bits of fft/ifft input
|
|
* @param rsf_out the right-shift bits of fft/ifft output
|
|
*/
|
|
void iot_real_fft_cfg(uint8_t bit, uint8_t mode, uint8_t stage, uint8_t lsf_in, uint8_t rsf_out);
|
|
|
|
/**
|
|
* @brief iot_real_ifft_cfg() - real data ifft configuration
|
|
* @param bit the format of data, reference to afft_data_fmt_t
|
|
* @param mode the mode of TTF, reference to afft_real_mode_t
|
|
* @param stage the right shift bits of twiddle stage
|
|
* @param lsf_in the left-shift bits of fft/ifft input
|
|
* @param rsf_out the right-shift bits of fft/ifft output
|
|
*/
|
|
void iot_real_ifft_cfg(uint8_t bit, uint8_t mode, uint8_t stage, uint8_t lsf_in, uint8_t rsf_out);
|
|
|
|
/**
|
|
* @brief iot_complex_fft_cfg() - complex data fft configuration
|
|
* @param bit the format of data, reference to afft_data_fmt_t
|
|
* @param mode the mode of TTF, reference to afft_real_mode_t
|
|
* @param stage the right shift bits of twiddle stage
|
|
* @param lsf_in the left-shift bits of fft/ifft input
|
|
* @param rsf_out the right-shift bits of fft/ifft output
|
|
*/
|
|
void iot_complex_fft_cfg(uint8_t bit, uint8_t mode, uint8_t stage, uint8_t lsf_in, uint8_t rsf_out);
|
|
|
|
/**
|
|
* @brief iot_complex_ifft_cfg() - complex data ifft configuration
|
|
* @param bit the format of data, reference to afft_data_fmt_t
|
|
* @param mode the mode of TTF, reference to afft_real_mode_t
|
|
* @param stage the right shift bits of twiddle stage
|
|
* @param lsf_in the left-shift bits of fft/ifft input
|
|
* @param rsf_out the right-shift bits of fft/ifft output
|
|
*/
|
|
void iot_complex_ifft_cfg(uint8_t bit, uint8_t mode, uint8_t stage, uint8_t lsf_in, uint8_t rsf_out);
|
|
|
|
/**
|
|
* @brief iot_complex_fft_win() - select window
|
|
* @param win window, see afft_win_sel_t
|
|
* @return ERR_OK - success; ERR_NOSUPP - not support
|
|
*/
|
|
uint8_t iot_complex_fft_win(afft_win_sel_t win);
|
|
|
|
/**
|
|
* @brief iot_afft_start() - start to run afft module
|
|
*/
|
|
void iot_afft_start();
|
|
|
|
/**
|
|
* @brief iot_afft_get_address() - get afft address to read or write
|
|
|
|
* @return return the afft address
|
|
*/
|
|
uint32_t iot_afft_get_address();
|
|
|
|
/**
|
|
* @brief iot_afft_real_mode_id_get() - get afft mode id
|
|
|
|
* @return return the afft mode id, see afft_real_mode_t
|
|
*/
|
|
uint8_t iot_afft_real_mode_id_get(uint32_t data_len);
|
|
|
|
/**
|
|
* @brief iot_afft_complex_mode_id_get() - get complex fft mode id
|
|
|
|
* @return return the complex mode id, see afft_complex_mode_t
|
|
*/
|
|
uint8_t iot_afft_complex_mode_id_get(uint32_t data_len);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif //IOT_AFFT_API_H
|