高级会员
- 积分
- 602
- 金钱
- 602
- 注册时间
- 2013-10-18
- 在线时间
- 59 小时
|
鉴于复旦微官方提供的RTThread存在bug,重新修改进行测试,满足项目实际要求
原官方休眠处理如下:
static void sleep(void)
{
rt_tick_t timeout_tick, delta_tick;
rt_uint32_t ret, freq = 32768;
static rt_uint32_t os_tick_remain = 0;
timeout_tick = rt_timer_next_timeout_tick() - rt_tick_get();
if (timeout_tick >= 2)
{
fm33xx_lptimer_start(freq * timeout_tick / RT_TICK_PER_SECOND);
DeepSleep();
ret = fm33xx_lptimer_get_current_tick();
delta_tick = (ret * RT_TICK_PER_SECOND + os_tick_remain) / freq;
os_tick_remain += (ret * RT_TICK_PER_SECOND);
os_tick_remain %= freq;
fm33xx_lptimer_stop();
rt_tick_set(rt_tick_get() + delta_tick);
rt_timer_check();
}
}
修改后如下:
rt_tick_t timeout_tick, delta_tick;
rt_uint32_t ret1, freq = 32768;
void SleepAppHookHandle(void)
{
// rt_tick_t timeout_tick, delta_tick;
// rt_uint32_t ret, freq = 32768;
static rt_uint32_t os_tick_remain = 0;
timeout_tick = rt_timer_next_timeout_tick() - rt_tick_get();
if ((timeout_tick >= 2))
{
__disable_irq();
CLEAR_BIT(SysTick->CTRL, (rt_uint32_t)SysTick_CTRL_TICKINT_Msk);
BspLpTimerStart(freq * timeout_tick / RT_TICK_PER_SECOND);
SleepAppDeepSleep();
ret1 = BspLpTimerGetCurrentTick();
delta_tick = (ret1 * RT_TICK_PER_SECOND * 10u ) / freq;
if((delta_tick%10u) > 1u)
{
delta_tick = (delta_tick + 10u)/10u;
}
else
{
delta_tick = (delta_tick)/10u;
}
SET_BIT(SysTick->CTRL, (rt_uint32_t)SysTick_CTRL_TICKINT_Msk);
BspLpTimerStop();
rt_tick_set(rt_tick_get() + delta_tick);
rt_timer_check();
__enable_irq();
}
}
|
|