代码拉取完成,页面将自动刷新
同步操作将从 vtor3478/vtor_elec_module 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "vtor_timer.h"
#ifdef __VTOR_TIMER__
// 一直指向所有任务的头,不可更改
VtorTimer* vtorTimerHeader = NULL;
static uint32_t VtorTimerTick = 0;
static uint32_t VtorTimerCnt = 0;
void VtorTimer_VoidFun()
{
}
void VtorTimer_Schedule(void)
{
VtorTimer* timer = vtorTimerHeader;
VtorTimerCnt++;
while (timer && NULL != timer->fun)
{
if (VtorTimer_VoidFun != timer->fun)
{
if(VTOR_TIMER_STATE_READY == timer->state)
{
uint32_t endTime = 0;
uint32_t startTime = VtorTimer_GetTick();
timer->state = VTOR_TIMER_STATE_RUNNING;
timer->fun();
if(VTOR_TIMER_STATE_RUNNING == timer->state)
{
timer->state = VTOR_TIMER_STATE_WAITING;
}
timer->runCnt++;
endTime = VtorTimer_GetTick();
timer->runTime = endTime - startTime;
}
}
timer++;
}
}
void VtorTimer_IncTick(uint32_t tick)
{
VtorTimer* timer = vtorTimerHeader;
VtorTimerTick += tick;
while (timer && NULL != timer->fun)
{
if (VtorTimer_VoidFun != timer->fun)
{
if(VTOR_TIMER_STATE_WAITING == timer->state)
{
timer->curTime += tick;
if (timer->curTime >= timer->interval)
{
timer->curTime = 0;
timer->state = VTOR_TIMER_STATE_READY;
}
}
}
timer++;
}
}
uint32_t VtorTimer_GetTick(void)
{
return VtorTimerTick;
}
uint32_t VtorTimer_GetCnt(void)
{
return VtorTimerCnt;
}
VtorTimer* VtorTimer_GetRunningTimer()
{
VtorTimer* timer = vtorTimerHeader;
while (NULL != timer->fun)
{
if(VTOR_TIMER_STATE_RUNNING == timer->state)
{
return timer;
}
timer++;
}
return NULL;
}
VtorTimer* VtorTimer_GetTimerByFun(VtorTimerFun fun)
{
VtorTimer* timer = vtorTimerHeader;
if (NULL == fun)
{
return NULL;
}
while(NULL != timer->fun)
{
if (fun == timer->fun)
{
return timer;
}
timer++;
}
return NULL;
}
VtorTimer* VtorTimer_Restart(VtorTimerFun fun, uint32_t interval)
{
VtorTimer* timer = NULL;
if (NULL == fun)
{
return NULL;
}
timer = VtorTimer_GetTimerByFun(fun);
if(NULL == timer)
{
timer = VtorTimer_GetTimerByFun(VtorTimer_VoidFun);
if(NULL == timer)
{
return NULL;
}
timer->fun = fun;
timer->state = VTOR_TIMER_STATE_STOP;
}
//if(VTOR_TIMER_STATE_STOP == timer->state)
{
VtorTimer_StartCallback(timer->fun);
timer->curTime = 0;
timer->state = VTOR_TIMER_STATE_WAITING;
}
timer->interval = interval;
return timer;
}
VtorTimer* VtorTimer_Start(VtorTimerFun fun, uint32_t interval)
{
VtorTimer* timer = NULL;
if (NULL == fun)
{
return NULL;
}
timer = VtorTimer_GetTimerByFun(fun);
if(NULL == timer)
{
timer = VtorTimer_GetTimerByFun(VtorTimer_VoidFun);
if(NULL == timer)
{
return NULL;
}
timer->fun = fun;
timer->state = VTOR_TIMER_STATE_STOP;
}
if(VTOR_TIMER_STATE_STOP == timer->state)
{
VtorTimer_StartCallback(timer->fun);
timer->curTime = 0;
timer->state = VTOR_TIMER_STATE_WAITING;
}
timer->interval = interval;
return timer;
}
void VtorTimer_RunNow(VtorTimerFun fun)
{
VtorTimer* timer = NULL;
timer = VtorTimer_GetTimerByFun(fun);
if(NULL != timer)
{
if(fun == timer->fun)
{
timer->state = VTOR_TIMER_STATE_READY;
timer->curTime = 0;
}
}
}
void VtorTimer_Delete(VtorTimerFun fun)
{
VtorTimer* timer = NULL;
timer = VtorTimer_GetTimerByFun(fun);
if(NULL != timer)
{
if (VTOR_TIMER_STATE_STOP != timer->state)
{
VtorTimer_StopCallback(fun);
timer->state = VTOR_TIMER_STATE_STOP;
timer->fun = VtorTimer_VoidFun;
}
timer->runCnt = 0;
timer->curTime = 0;
}
}
void VtorTimer_Stop(VtorTimerFun fun)
{
VtorTimer* timer = NULL;
if (NULL == fun)
{
return ;
}
timer = VtorTimer_GetTimerByFun(fun);
if(NULL != timer)
{
if (VTOR_TIMER_STATE_STOP != timer->state)
{
VtorTimer_StopCallback(fun);
timer->state = VTOR_TIMER_STATE_STOP;
}
timer->curTime = 0;
}
}
#endif // __VTOR_TIMER__
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。