int main(void)
{
int i,j;
int res;
float time[2];
static int error_flag = 0;
/* MCU 配置*/
/* 重置所有外设,初始化Flash 接口和Systick. */
HAL_Init();
/* 系统时钟配置 */
SystemClock_Config();
/* 初始化所有已配置的外设 */
MX_GPIO_Init();
MX_USART6_UART_Init();
MX_TIM3_Init();
usart6.initialize(115200); //串口波特设置
usart6.printf("\x0c"); //清屏
usart6.printf("\033[1;32;40m"); //设置终端字体为绿色
usart6.printf("Hello, I am iCore4!\r\n\r\n");
usart6.printf("DSP BasicMath TEST......\r\n");
while (1)
{
timeout = 0;
__HAL_TIM_SET_COUNTER(&htim3,0); //重设 TIM3 定时器的计数器值
for(j = 0;j < 10000;j++){
for(i = 0;i < MAX_BLOCKSIZE;i ++){
res = SinCos_Test(testInput_f32[i],0);
if(res != 0)error_flag ++;
}
}
time[0] = __HAL_TIM_GET_COUNTER(&htim3)+ timeout*5000;
timeout = 0;
__HAL_TIM_SET_COUNTER(&htim3,0);
for(j = 0;j < 10000;j++){
for(i = 0;i < MAX_BLOCKSIZE;i ++){
res = SinCos_Test(testInput_f32[i],1);
if(res != 0)error_flag ++;
}
}
time[1] = __HAL_TIM_GET_COUNTER(&htim3)+ timeout*5000;
if(error_flag == 0){
usart6.printf("*NO DSP MATHLIB runtime:%0.1fms *USE DSP MATHLIB runtime:%0.1fms\r",time[0] / 10, time[1] / 10);
LED_GREEN_ON;
LED_RED_OFF;
LED_BLUE_OFF;
}
else{//测试失败
usart6.printf("Error\r");
LED_GREEN_OFF;
LED_RED_ON;
LED_BLUE_OFF;
}
}
}
int SinCos_Test(float testInput,unsigned char mode)
{
float Sinx,Cosx;
float Result;
switch (mode){
case 0://不使用DSP MATH库
Sinx = sinf(testInput); //不使用DSP优化的sin,cos函数
Cosx = cosf(testInput);
Result = Sinx*Sinx + Cosx*Cosx; //计算结果应该等于1
Result = fabsf(Result-1.0f); //对比与1的差值
if(Result > DELTA)return -1; //判断
break;
case 1://使用DSP MATH库
Sinx = arm_sin_f32(testInput); //使用DSP优化的sin,cos函数
Cosx = arm_cos_f32(testInput);
Result = Sinx*Sinx + Cosx*Cosx; //计算结果应该等于1
Result = fabsf(Result-1.0f); //对比与1的差值
if(Result > DELTA)return -1; //判断
break;
default:
break;
}
return 0;
}