Other Parts Discussed in Thread: FFTLIB
Tool/software:
Hi TI Expert:
When I was developing for DSP C7x, I encountered an issue where when continuously calling the FFTLIB_fft1dBatched_i16sc_c16sc_o16sc_kernel function, the result of the first FFT calculation was normal, but the result of the second FFT calculation was abnormal. When performing either FFT calculation separately (using only the first FFT or only the second FFT), the results were both correct. The input array for the first FFT has 128 channels with 1024 sampling points, and the input array for the second FFT has 512 channels with 128 sampling points. The code is as follows:
__attribute__((section(".l2mem"), aligned(64))) int16_t l2_user_array0[128][2048]; // 512k
__attribute__((section(".l2mem"), aligned(64))) int16_t l2_user_array1[128][2048]; // 512k
__attribute__((section(".l2mem"), aligned(64))) int16_t l2_user_array2[512][256]; // 256k
__attribute__((section(".l2mem"), aligned(64))) int16_t l2_user_array3[512][256]; // 256k
void func()
{
battch_fft1d_info_type l_battch_fft1d_info = {0};
l_battch_fft1d_info.num_shifts = 5;
l_battch_fft1d_info.channel = 128;
l_battch_fft1d_info.num_points = 1024;
l_battch_fft1d_info.data_type = FFTLIB_INT16;
bsp_dsppro_battch_fft1d((int16_t *)l2_user_array0, (int16_t *)l2_user_array1, &l_battch_fft1d_info);
l_battch_fft1d_info.num_shifts = 3;
l_battch_fft1d_info.channel = 512;
l_battch_fft1d_info.num_points = 128;
l_battch_fft1d_info.data_type = FFTLIB_INT16;
bsp_dsppro_battch_fft1d((int16_t *)l2_user_array2, (int16_t *)l2_user_array3, &l_battch_fft1d_info);
}
uint8_t bsp_dsppro_battch_fft1d(int16_t *input, int16_t *output, battch_fft1d_info_type *battch_fft1d_info)
{
uint8_t l_u8_ret = 0;
int16_t *pX;
int16_t *pY;
int16_t *pW;
uint32_t *pShift;
FFTLIB_bufParams1D_t bufParamsData;
FFTLIB_bufParams1D_t bufParamsShift;
FFTLIB_bufParams1D_t bufParamsTw;
FFTLIB_STATUS status_opt = FFTLIB_SUCCESS;
uint32_t numShifts = battch_fft1d_info->num_shifts; // 5:1024, 3:128
uint32_t l_u32_channel = battch_fft1d_info->channel; // 128 chirp, 1024 point
uint32_t numPoints = battch_fft1d_info->num_points; // 1024 point, 128 chirp
uint32_t dataMemSize = l_u32_channel * numPoints * 2; /* Kernel requires input/output */
/* buffers to be atleast
* 128 elements long */
uint8_t *pblock = NULL;
pblock = FFTLIB_fft1dbatched_i16sc_c16sc_o16sc_pBlock;
pX = (int16_t *)input;
pY = (int16_t *)output;
pW = malloc(numPoints * 2 * sizeof (int16_t));
pShift = malloc(numShifts * sizeof (uint32_t));
if ((pX == NULL) || (pY == NULL) || (pW == NULL) || (pShift == NULL))
{
DebugP_log("[info]pX is NULL!\r\n");
l_u8_ret = 1;
goto error;
}
bufParamsData.dim_x = dataMemSize;
bufParamsData.data_type = FFTLIB_INT16;
bufParamsShift.dim_x = numShifts;
bufParamsShift.data_type = FFTLIB_UINT32;
bufParamsTw.dim_x = numPoints * 2;
bufParamsTw.data_type = FFTLIB_INT16;
tw_gen (pW, numPoints);
/* 批量fft变换 */
/* 批量fft初始化 */
status_opt = FFTLIB_fft1dBatched_i16sc_c16sc_o16sc_init((int16_t *) pX, &bufParamsData, (int16_t *) pW, &bufParamsTw,
(int16_t *) pY, &bufParamsData, (uint32_t *) pShift, &bufParamsShift,
numPoints, l_u32_channel, pblock);
if (status_opt != FFTLIB_SUCCESS)
{
l_u8_ret = 1;
goto error;
// /* 批量fft参数检查 */
// status_opt = FFTLIB_fft1dBatched_i16sc_c16sc_o16sc_checkParams((int16_t *) pX, &bufParamsData, (int16_t *) pW, &bufParamsTw,
// (int16_t *) pY, &bufParamsData, (uint32_t *) pShift, &bufParamsShift,
// numPoints, l_u32_channel, pblock);
// if (status_opt != FFTLIB_SUCCESS)
// {
// l_u8_ret = 2;
// goto error;
// }
/* 批量执行fft */
status_opt = FFTLIB_fft1dBatched_i16sc_c16sc_o16sc_kernel((int16_t *) pX, &bufParamsData, (int16_t *) pW, &bufParamsTw,
(int16_t *) pY, &bufParamsData, (uint32_t *) pShift, &bufParamsShift,
numPoints, l_u32_channel, pblock);
if (status_opt != FFTLIB_SUCCESS)
{
l_u8_ret = 3;
goto error;
}
error:
/* 释放内存 */
if (pW != NULL)
{
free(pW);
}
if (pShift != NULL)
{
free(pShift);
}
return l_u8_ret;
}
Have I missed any steps that cause the continuous calls not to work properly? If I want to calculate the FFT continuously, how should I modify the code? I hope the TI engineers can help point out the problem.