struct Timer {
uintptr_t end_time;
};
void HAL_Timer_countdown_ms(Timer *timer, unsigned int timeout_ms)
{
timer->end_time = 获取当前时间
timer->end_time += timeout_ms;
}
int HAL_Timer_expired(Timer *timer)
{
uint32_t now_ts;
now_ts = 获取当前时间;
return (now_ts > timer->end_time) ? TRUE : FALSE;
}
int function(unsigned int timeout_ms)
{
int ret = 0 ;
Timer timer;
HAL_Timer_countdown_ms(&timer,timeout_ms)
do
{
//具体实现
} while (!HAL_Timer_expired(&timer));
if (HAL_Timer_expired(&timer))
{
ret = 错误值;
}
return ret;
}