Files
RTOS/Kernel/SingleCore/os_timer.h
T

60 lines
1.5 KiB
C
Raw Normal View History

2026-05-19 11:49:22 +08:00
#ifndef INCLUDED_OS_TIMER_H
#define INCLUDED_OS_TIMER_H
#ifndef INCLUDED_OS_LIST_H
#include <os_list.h>
#endif /*INCLUDED_OS_LIST_H*/
#ifndef INCLUDED_OS_COMPILER_H
#include <os_compiler.h>
#endif /*INCLUDED_OS_COMPILER_H*/
/* -------------------------------------------------------------------------------------------------------------- */
/* */
#define OS_TIMER_FLAG_ONCE (1<<0)
#define OS_TIMER_FLAG_REPEAT (1<<1)
/* -------------------------------------------------------------------------------------------------------------- */
/* */
typedef struct os_timer_t os_timer_t;
typedef void (*os_timer_function_t)(os_timer_t* timer);
struct os_timer_t {
os_list_node_t node;
os_timer_function_t function;
void* userdata;
os_tick_t ticks;
os_tick_t expire_tick;
int flag;
};
/* -------------------------------------------------------------------------------------------------------------- */
/* */
OS_STATIC_FORCE_INLINE
void os_timer_init(os_timer_t* timer, os_timer_function_t fn, void* userdata, os_tick_t ticks, int flag) {
timer->function = fn;
timer->userdata = userdata;
timer->ticks = ticks;
timer->expire_tick = 0;
timer->flag = flag;
os_list_init(&timer->node);
}
OS_STATIC_FORCE_INLINE
void os_timer_remove(os_timer_t* self){
os_list_remove(&self->node);
}
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
#define OS_Timer_Init os_timer_init
#endif /*INCLUDED_OS_TIMER_H*/