30#define DBG_TAG "kernel.timer"
31#define DBG_LVL DBG_INFO
34#ifndef RT_USING_TIMER_ALL_SOFT
40#ifdef RT_USING_TIMER_SOFT
42#ifndef RT_TIMER_THREAD_STACK_SIZE
43#define RT_TIMER_THREAD_STACK_SIZE 512
46#ifndef RT_TIMER_THREAD_PRIO
47#define RT_TIMER_THREAD_PRIO 0
56static rt_uint8_t _timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE];
59#if defined(RT_USING_HOOK) && defined(RT_HOOK_USING_FUNC_PTR)
60extern void (*rt_object_take_hook)(
struct rt_object *object);
61extern void (*rt_object_put_hook)(
struct rt_object *object);
62static void (*rt_timer_enter_hook)(
struct rt_timer *timer);
63static void (*rt_timer_exit_hook)(
struct rt_timer *timer);
79 rt_timer_enter_hook = hook;
90 rt_timer_exit_hook = hook;
98#ifdef RT_USING_TIMER_ALL_SOFT
101#ifdef RT_USING_TIMER_SOFT
104 return &_stimer_lock;
109 return &_htimer_lock;
132 void (*timeout)(
void *parameter),
139#ifdef RT_USING_TIMER_ALL_SOFT
201#if (DBG_LVL == DBG_LOG)
209static int _timer_count_height(
struct rt_timer *timer)
282 _timer_init(timer, timeout,
parameter, time, flag);
346 void (*timeout)(
void *parameter),
364 _timer_init(timer, timeout,
parameter, time, flag);
411 unsigned int row_lvl;
414 static unsigned int random_nr;
425 row_head[0] = &timer_list[0];
428 for (; row_head[row_lvl] != timer_list[row_lvl].
prev;
429 row_head[row_lvl] = row_head[row_lvl]->
next)
452 row_head[row_lvl + 1] = row_head[row_lvl] + 1;
547 _timer_start(timer_list, t);
565 int is_thread_timer = 0;
575#ifdef RT_USING_TIMER_ALL_SOFT
576 timer_list = _soft_timer_list;
577 spinlock = &_stimer_lock;
579#ifdef RT_USING_TIMER_SOFT
582 timer_list = _soft_timer_list;
583 spinlock = &_stimer_lock;
588 timer_list = _timer_list;
589 spinlock = &_htimer_lock;
606 err = _timer_start(timer_list, timer);
760#ifdef RT_USING_TIMER_SOFT
764 ret = _timer_list_next_timeout(_soft_timer_list, &next_timeout);
765 if ((ret == RT_EOK) && (next_timeout <=
rt_tick_get()))
770#ifndef RT_USING_TIMER_ALL_SOFT
771 _timer_check(_timer_list, &_htimer_lock);
785#ifndef RT_USING_TIMER_ALL_SOFT
787 _timer_list_next_timeout(_timer_list, &htimer_next_timeout);
791#ifdef RT_USING_TIMER_SOFT
793 _timer_list_next_timeout(_soft_timer_list, &stimer_next_timeout);
797 return htimer_next_timeout < stimer_next_timeout ? htimer_next_timeout : stimer_next_timeout;
800#ifdef RT_USING_TIMER_SOFT
806static void _timer_thread_entry(
void *parameter)
812 _timer_check(_soft_timer_list, &_stimer_lock);
825#ifndef RT_USING_TIMER_ALL_SOFT
828 for (i = 0; i <
sizeof(_timer_list) /
sizeof(_timer_list[0]); i++)
844#ifdef RT_USING_TIMER_SOFT
848 i <
sizeof(_soft_timer_list) /
sizeof(_soft_timer_list[0]);
861 &_timer_thread_stack[0],
862 sizeof(_timer_thread_stack),
863 RT_TIMER_THREAD_PRIO,
rt_err_t rt_timer_detach(rt_timer_t timer)
This function will detach a timer from timer management.
#define RT_TIMER_CTRL_GET_REMAIN_TIME
#define RT_TIMER_FLAG_SOFT_TIMER
rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg)
This function will get or set some options of the timer
#define RT_TIMER_FLAG_ACTIVATED
void rt_timer_exit_sethook(void(*hook)(struct rt_timer *timer))
#define RT_TIMER_CTRL_GET_TIME
#define RT_TIMER_CTRL_SET_PERIODIC
#define RT_TIMER_CTRL_GET_STATE
struct rt_timer * rt_timer_t
#define RT_TIMER_CTRL_SET_FUNC
void rt_timer_check(void)
This function will check timer list, if a timeout event happens, the corresponding timeout function w...
rt_err_t rt_timer_start(rt_timer_t timer)
This function will start the timer
#define RT_TIMER_CTRL_GET_PARM
#define RT_TIMER_CTRL_SET_ONESHOT
rt_tick_t rt_timer_next_timeout_tick(void)
This function will return the next timeout tick in the system.
#define RT_TIMER_FLAG_PERIODIC
void rt_timer_enter_sethook(void(*hook)(struct rt_timer *timer))
void rt_timer_init(rt_timer_t timer, const char *name, void(*timeout)(void *parameter), void *parameter, rt_tick_t time, rt_uint8_t flag)
This function will initialize a timer normally this function is used to initialize a static timer obj...
rt_tick_t rt_tick_get(void)
This function will return current tick from operating system startup.
#define RT_TIMER_CTRL_SET_TIME
rt_timer_t rt_timer_create(const char *name, void(*timeout)(void *parameter), void *parameter, rt_tick_t time, rt_uint8_t flag)
This function will create a timer
rt_err_t rt_timer_stop(rt_timer_t timer)
This function will stop the timer
#define RT_TIMER_CTRL_SET_PARM
#define RT_TIMER_CTRL_GET_FUNC
#define RT_TIMER_FLAG_THREAD_TIMER
#define RT_TIMER_SKIP_LIST_MASK
#define RT_TIMER_FLAG_DEACTIVATED
rt_err_t rt_timer_delete(rt_timer_t timer)
This function will delete a timer and release timer memory
#define RT_TIMER_SKIP_LIST_LEVEL
rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock)
This function will disable the local interrupt and then lock the spinlock, will lock the thread sched...
#define RT_WAITING_FOREVER
void rt_spin_lock_init(struct rt_spinlock *lock)
Initialize a static spinlock object.
#define RT_IPC_CMD_SET_VLIMIT
void rt_spin_unlock_irqrestore(struct rt_spinlock *lock, rt_base_t level)
This function will unlock the spinlock and then restore current cpu interrupt status,...
rt_weak rt_uint8_t rt_interrupt_get_nest(void)
This function will return the nest of interrupt.
void rt_object_delete(rt_object_t object)
This function will delete an object and release object memory.
void rt_object_init(struct rt_object *object, enum rt_object_class_type type, const char *name)
This function will initialize an object and add it to object system management.
rt_bool_t rt_object_is_systemobject(rt_object_t object)
This function will judge the object is system object or not.
#define RT_OBJECT_HOOK_CALL(func, argv)
rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name)
This function will allocate an object from object system.
rt_uint8_t rt_object_get_type(rt_object_t object)
This function will return the type of object without RT_Object_Class_Static flag.
void rt_object_detach(rt_object_t object)
This function will detach a static object from object system, and the memory of static object is not ...
rt_inline void rt_list_remove(rt_list_t *n)
remove node from list.
rt_inline int rt_list_isempty(const rt_list_t *l)
tests whether a list is empty
#define rt_list_entry(node, type, member)
get the struct for this entry
rt_inline void rt_list_init(rt_list_t *l)
initialize a list
rt_inline void rt_list_insert_after(rt_list_t *l, rt_list_t *n)
insert a node after a list
#define rt_container_of(ptr, type, member)
void rt_system_timer_init(void)
This function will initialize system timer
void rt_system_timer_thread_init(void)
This function will initialize system timer thread
rt_err_t rt_thread_startup(rt_thread_t thread)
This function will start a thread and put it to system ready queue.
rt_err_t rt_thread_init(struct rt_thread *thread, const char *name, void(*entry)(void *parameter), void *parameter, void *stack_start, rt_uint32_t stack_size, rt_uint8_t priority, rt_uint32_t tick)
This function will initialize a thread. It's used to initialize a static thread object.
struct rt_thread * rt_thread_t
rt_err_t rt_sem_init(rt_sem_t sem, const char *name, rt_uint32_t value, rt_uint8_t flag)
This function will initialize a static semaphore object.
rt_err_t rt_sem_control(rt_sem_t sem, int cmd, void *arg)
This function will set some extra attributions of a semaphore object.
rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time)
rt_err_t rt_sem_release(rt_sem_t sem)
This function will release a semaphore. If there is thread suspended on the semaphore,...
rt_align(RT_ALIGN_SIZE)
This function sets a hook function to idle thread loop. When the system performs idle loop,...
#define RTM_EXPORT(symbol)
rt_ubase_t rt_sched_lock_level_t
struct rt_list_node rt_list_t
rt_err_t rt_sched_thread_timer_start(struct rt_thread *thread)
rt_err_t rt_sched_lock(rt_sched_lock_level_t *plvl)
rt_err_t rt_sched_unlock(rt_sched_lock_level_t level)
struct rt_list_node * next
struct rt_list_node * prev
rt_timer_func_t timeout_func
rt_list_t row[RT_TIMER_SKIP_LIST_LEVEL]
rt_inline void _timer_remove(rt_timer_t timer)
Remove the timer
rt_inline struct rt_spinlock * _timerlock_idx(struct rt_timer *timer)
void rt_timer_dump(rt_list_t timer_heads[])
dump the all timer information