Other Parts Discussed in Thread: FFTLIB
你好
我在开发dsp c7x时碰到连续调用FFTLIB_fft1dBatched_i16sc_c16sc_o16sc_kernel函数时,第一次fft计算结果正常,第二次fft计算结果异常,单独进行某一次的fft(只使用第一次fftt或者只使用第二次fft)结果均正确。第一次fft输入数组为128通道1024个采样点,第二次输入数组为512通道128个采样点,代码如下:
__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;
}
是否是我遗漏了什么步骤,导致连续调用不能正常工作,若我想连续计算fft,该如何修改代码?希望ti工程师能帮忙指出问题。