一、除法协处理器使用方式
void MATH_Init()
{
SCU_GENERAL->PASSWD = 0xC0U;
SCU_CLK->CGATCLR0 |= 0x100; //MATH
SCU_GENERAL->PASSWD = 0xC3U;
//MATH->DIVCON |= 0x02; // Signed division is selected
MATH->DIVCON |= 0x06; // Unsigned division is selected
}
uint32_t MDU_Divider(uint32_t Dividend,uint32_t Divisor)
{
MATH->DVD=Dividend;
MATH->DVS=Divisor;
MATH->DIVCON |=0x05; //start
while(MATH->DIVST & 0x01){}
return((uint32_t)MATH->QUOT);
}
1、在main函数中调用 MATH_Init();
2、调用uint32_t MDU_Divider(uint32_t Dividend,uint32_t Divisor)进行除法运算
如:temp = data1 / data2;
temp = MDU_Divider(data1 ,data2);
二、代码在RAM中运行
在函数中增加 __attribute__((section (".ram_code"))) 声明
如果:bool PwmModeCtrl(uint16_t vbat, uint16_t ibat, uint16_t duty, uint16_t Lf)
定义函数在RAM中运行:bool __attribute__((section (".ram_code"))) PwmModeCtrl(uint16_t vbat, uint16_t ibat, uint16_t duty, uint16_t Lf)
三、可适当提高代码优化等级
提高代码优化等级,可以缩短代码执行时间。 |