48 lines
1.4 KiB
C
48 lines
1.4 KiB
C
#include <os_timewheel.h>
|
|
#include <os_macros.h>
|
|
|
|
|
|
/* -------------------------------------------------------------------------------------------------------------- */
|
|
/* */
|
|
|
|
os_list_t os_timewheel__R[TWR_SIZE];
|
|
os_list_t os_timewheel__N0[TWN_SIZE];
|
|
os_list_t os_timewheel__N1[TWN_SIZE];
|
|
os_list_t os_timewheel__N2[TWN_SIZE];
|
|
os_list_t os_timewheel__N3[TWN_SIZE];
|
|
volatile os_tick_t os_timewheel__tick;
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------------------------------------------------- */
|
|
/* */
|
|
|
|
|
|
|
|
|
|
os_err_t os_timewheel_tick(void) {
|
|
os_tick_t current_tick = os_timewheel__tick++;
|
|
os_list_node_t* node=0;
|
|
os_timer_t* timer_p=0;
|
|
os_err_t err = OS_TIMEWHEEL_TICK_OK;
|
|
const os_list_t* wheel = os_timewheel_find(current_tick);
|
|
for (node = os_list_next(wheel); node!=wheel;) {
|
|
timer_p = os_list_member_of(node, os_timer_t, node);
|
|
node = os_list_next(node);
|
|
if (timer_p->expire_tick <= current_tick) {
|
|
os_list_remove(&(timer_p->node));
|
|
timer_p->function(timer_p);
|
|
if (OS_BIT_GET(timer_p->flag, OS_TIMER_FLAG_REPEAT)) {
|
|
timer_p->expire_tick = current_tick + timer_p->ticks;
|
|
os_list_t* slot = os_timewheel_find(timer_p->expire_tick);
|
|
os_list_insert_before(slot, &timer_p->node);
|
|
}
|
|
err = OS_TIMEWHEEL_TICK_NEED_SCHEDULE;
|
|
}
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
|