RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
Clock and Timer Management
+ Clock and Timer Management 的协作图:

结构体

struct  rt_timer
 

宏定义

#define _update_process_times(tick)
 
#define RT_TIMER_FLAG_DEACTIVATED   0x0
 
#define RT_TIMER_FLAG_ACTIVATED   0x1
 
#define RT_TIMER_FLAG_ONE_SHOT   0x0
 
#define RT_TIMER_FLAG_PERIODIC   0x2
 
#define RT_TIMER_FLAG_HARD_TIMER   0x0
 
#define RT_TIMER_FLAG_SOFT_TIMER   0x4
 
#define RT_TIMER_FLAG_THREAD_TIMER    (0x8 | RT_TIMER_FLAG_HARD_TIMER)
 
#define RT_TIMER_CTRL_SET_TIME   0x0
 
#define RT_TIMER_CTRL_GET_TIME   0x1
 
#define RT_TIMER_CTRL_SET_ONESHOT   0x2
 
#define RT_TIMER_CTRL_SET_PERIODIC   0x3
 
#define RT_TIMER_CTRL_GET_STATE   0x4
 
#define RT_TIMER_CTRL_GET_REMAIN_TIME   0x5
 
#define RT_TIMER_CTRL_GET_FUNC   0x6
 
#define RT_TIMER_CTRL_SET_FUNC   0x7
 
#define RT_TIMER_CTRL_GET_PARM   0x8
 
#define RT_TIMER_CTRL_SET_PARM   0x9
 
#define RT_TIMER_SKIP_LIST_LEVEL   1
 
#define RT_TIMER_SKIP_LIST_MASK   0x3
 

类型定义

typedef void(* rt_timer_func_t) (void *parameter)
 
typedef struct rt_timerrt_timer_t
 

函数

rt_tick_t rt_tick_get (void)
 
 RTM_EXPORT (rt_tick_get)
 
void rt_tick_set (rt_tick_t tick)
 
void rt_tick_increase (void)
 
void rt_tick_increase_tick (rt_tick_t tick)
 
rt_tick_t rt_tick_from_millisecond (rt_int32_t ms)
 
 RTM_EXPORT (rt_tick_from_millisecond)
 
rt_weak rt_tick_t rt_tick_get_millisecond (void)
 
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)
 
 RTM_EXPORT (rt_timer_init)
 
rt_err_t rt_timer_detach (rt_timer_t timer)
 
 RTM_EXPORT (rt_timer_detach)
 
rt_timer_t rt_timer_create (const char *name, void(*timeout)(void *parameter), void *parameter, rt_tick_t time, rt_uint8_t flag)
 
 RTM_EXPORT (rt_timer_create)
 
rt_err_t rt_timer_delete (rt_timer_t timer)
 
 RTM_EXPORT (rt_timer_delete)
 
rt_err_t rt_timer_start (rt_timer_t timer)
 
 RTM_EXPORT (rt_timer_start)
 
rt_err_t rt_timer_stop (rt_timer_t timer)
 
 RTM_EXPORT (rt_timer_stop)
 
rt_err_t rt_timer_control (rt_timer_t timer, int cmd, void *arg)
 
 RTM_EXPORT (rt_timer_control)
 
void rt_timer_check (void)
 
rt_tick_t rt_timer_next_timeout_tick (void)
 
void rt_tick_sethook (void(*hook)(void))
 
void rt_system_timer_init (void)
 
void rt_system_timer_thread_init (void)
 
void rt_timer_enter_sethook (void(*hook)(struct rt_timer *timer))
 
void rt_timer_exit_sethook (void(*hook)(struct rt_timer *timer))
 

详细描述

clock and system timer management

RT-Thread uses clock tick to implement shared time-slice scheduling.

The timing sensitivity of thread is implemented by timers. The timer can be set as one-shot or periodic timeout.

宏定义说明

◆ _update_process_times

#define _update_process_times ( tick)

在文件 clock.c113 行定义.

◆ RT_TIMER_FLAG_DEACTIVATED

#define RT_TIMER_FLAG_DEACTIVATED   0x0

clock & timer macros timer is deactive

在文件 rtdef.h524 行定义.

◆ RT_TIMER_FLAG_ACTIVATED

#define RT_TIMER_FLAG_ACTIVATED   0x1

timer is active

在文件 rtdef.h525 行定义.

◆ RT_TIMER_FLAG_ONE_SHOT

#define RT_TIMER_FLAG_ONE_SHOT   0x0

one shot timer

在文件 rtdef.h526 行定义.

◆ RT_TIMER_FLAG_PERIODIC

#define RT_TIMER_FLAG_PERIODIC   0x2

periodic timer

在文件 rtdef.h527 行定义.

◆ RT_TIMER_FLAG_HARD_TIMER

#define RT_TIMER_FLAG_HARD_TIMER   0x0

hard timer,the timer's callback function will be called in tick isr.

在文件 rtdef.h529 行定义.

◆ RT_TIMER_FLAG_SOFT_TIMER

#define RT_TIMER_FLAG_SOFT_TIMER   0x4

soft timer,the timer's callback function will be called in timer thread.

在文件 rtdef.h530 行定义.

◆ RT_TIMER_FLAG_THREAD_TIMER

#define RT_TIMER_FLAG_THREAD_TIMER    (0x8 | RT_TIMER_FLAG_HARD_TIMER)

thread timer that cooperates with scheduler directly

在文件 rtdef.h531 行定义.

531#define RT_TIMER_FLAG_THREAD_TIMER \
532 (0x8 | RT_TIMER_FLAG_HARD_TIMER)

◆ RT_TIMER_CTRL_SET_TIME

#define RT_TIMER_CTRL_SET_TIME   0x0

set timer control command

在文件 rtdef.h534 行定义.

◆ RT_TIMER_CTRL_GET_TIME

#define RT_TIMER_CTRL_GET_TIME   0x1

get timer control command

在文件 rtdef.h535 行定义.

◆ RT_TIMER_CTRL_SET_ONESHOT

#define RT_TIMER_CTRL_SET_ONESHOT   0x2

change timer to one shot

在文件 rtdef.h536 行定义.

◆ RT_TIMER_CTRL_SET_PERIODIC

#define RT_TIMER_CTRL_SET_PERIODIC   0x3

change timer to periodic

在文件 rtdef.h537 行定义.

◆ RT_TIMER_CTRL_GET_STATE

#define RT_TIMER_CTRL_GET_STATE   0x4

get timer run state active or deactive

在文件 rtdef.h538 行定义.

◆ RT_TIMER_CTRL_GET_REMAIN_TIME

#define RT_TIMER_CTRL_GET_REMAIN_TIME   0x5

get the remaining hang time

在文件 rtdef.h539 行定义.

◆ RT_TIMER_CTRL_GET_FUNC

#define RT_TIMER_CTRL_GET_FUNC   0x6

get timer timeout func

在文件 rtdef.h540 行定义.

◆ RT_TIMER_CTRL_SET_FUNC

#define RT_TIMER_CTRL_SET_FUNC   0x7

set timer timeout func

在文件 rtdef.h541 行定义.

◆ RT_TIMER_CTRL_GET_PARM

#define RT_TIMER_CTRL_GET_PARM   0x8

get timer parameter

在文件 rtdef.h542 行定义.

◆ RT_TIMER_CTRL_SET_PARM

#define RT_TIMER_CTRL_SET_PARM   0x9

get timer parameter

在文件 rtdef.h543 行定义.

◆ RT_TIMER_SKIP_LIST_LEVEL

#define RT_TIMER_SKIP_LIST_LEVEL   1

在文件 rtdef.h546 行定义.

◆ RT_TIMER_SKIP_LIST_MASK

#define RT_TIMER_SKIP_LIST_MASK   0x3

Timer skips the list mask

在文件 rtdef.h551 行定义.

类型定义说明

◆ rt_timer_func_t

typedef void(* rt_timer_func_t) (void *parameter)

timeout handler of rt_timer

在文件 rtdef.h557 行定义.

◆ rt_timer_t

typedef struct rt_timer* rt_timer_t

在文件 rtdef.h574 行定义.

函数说明

◆ rt_tick_get()

rt_tick_t rt_tick_get ( void )

This function will return current tick from operating system startup.

返回
Return current tick.

在文件 clock.c69 行定义.

70{
71 /* return the global tick */
72 return (rt_tick_t)rt_atomic_load(&(rt_tick));
73}
#define rt_atomic_load(ptr)
rt_uint32_t rt_tick_t

引用了 rt_atomic_load.

+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [1/9]

RTM_EXPORT ( rt_tick_get )

引用了 rt_tick_get().

+ 函数调用图:

◆ rt_tick_set()

void rt_tick_set ( rt_tick_t tick)

This function will set current tick.

参数
tickis the value that you will set.

在文件 clock.c81 行定义.

82{
83 rt_atomic_store(&(rt_tick), tick);
84}
#define rt_atomic_store(ptr, v)

引用了 rt_atomic_store.

◆ rt_tick_increase()

void rt_tick_increase ( void )

This function will notify kernel there is one tick passed. Normally, this function is invoked by clock ISR.

在文件 clock.c120 行定义.

121{
123
124 RT_OBJECT_HOOK_CALL(rt_tick_hook, ());
125
126 /* tracing cpu usage */
128
129 /* increase the global tick */
130#ifdef RT_USING_SMP
131 /* get percpu and increase the tick */
132 rt_atomic_add(&(rt_cpu_self()->tick), 1);
133#else
134 rt_atomic_add(&(rt_tick), 1);
135#endif /* RT_USING_SMP */
136
137 /* check time slice */
139
140 /* check timer */
141#ifdef RT_USING_SMP
142 if (rt_cpu_get_id() != 0)
143 {
144 return;
145 }
146#endif
148}
struct rt_cpu * rt_cpu_self(void)
This fucntion will return current cpu object.
void rt_timer_check(void)
This function will check timer list, if a timeout event happens, the corresponding timeout function w...
#define _update_process_times(tick)
rt_weak rt_uint8_t rt_interrupt_get_nest(void)
This function will return the nest of interrupt.
定义 irq.c:136
#define RT_OBJECT_HOOK_CALL(func, argv)
#define RT_ASSERT(EX)
#define rt_atomic_add(ptr, v)
#define rt_cpu_get_id()
rt_err_t rt_sched_tick_increase(rt_tick_t tick)

引用了 _update_process_times, RT_ASSERT, rt_atomic_add, rt_cpu_get_id, rt_cpu_self(), rt_interrupt_get_nest(), RT_OBJECT_HOOK_CALL, rt_sched_tick_increase() , 以及 rt_timer_check().

+ 函数调用图:

◆ rt_tick_increase_tick()

void rt_tick_increase_tick ( rt_tick_t tick)

This function will notify kernel there is n tick passed. Normally, this function is invoked by clock ISR.

在文件 clock.c154 行定义.

155{
157
158 RT_OBJECT_HOOK_CALL(rt_tick_hook, ());
159
160 /* tracing cpu usage */
162
163 /* increase the global tick */
164#ifdef RT_USING_SMP
165 /* get percpu and increase the tick */
166 rt_atomic_add(&(rt_cpu_self()->tick), tick);
167#else
168 rt_atomic_add(&(rt_tick), tick);
169#endif /* RT_USING_SMP */
170
171 /* check time slice */
173
174 /* check timer */
175#ifdef RT_USING_SMP
176 if (rt_cpu_get_id() != 0)
177 {
178 return;
179 }
180#endif
182
183#ifdef RT_USING_VDSO
184 rt_vdso_update_glob_time();
185#endif
186}

引用了 _update_process_times, RT_ASSERT, rt_atomic_add, rt_cpu_get_id, rt_cpu_self(), rt_interrupt_get_nest(), RT_OBJECT_HOOK_CALL, rt_sched_tick_increase() , 以及 rt_timer_check().

+ 函数调用图:

◆ rt_tick_from_millisecond()

rt_tick_t rt_tick_from_millisecond ( rt_int32_t ms)

This function will calculate the tick from millisecond.

参数
msis the specified millisecond.
  • Negative Number wait forever
  • Zero not wait
  • Max 0x7fffffff
返回
Return the calculated tick.

在文件 clock.c198 行定义.

199{
200 rt_tick_t tick;
201
202 if (ms < 0)
203 {
205 }
206 else
207 {
208#if RT_TICK_PER_SECOND == 1000u
209 tick = ms;
210#else
211 tick = RT_TICK_PER_SECOND * (ms / 1000);
212 tick += (RT_TICK_PER_SECOND * (ms % 1000) + 999) / 1000;
213#endif /* RT_TICK_PER_SECOND == 1000u */
214 }
215
216 /* return the calculated tick */
217 return tick;
218}
#define RT_WAITING_FOREVER

引用了 RT_WAITING_FOREVER.

+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [2/9]

RTM_EXPORT ( rt_tick_from_millisecond )

引用了 rt_tick_from_millisecond().

+ 函数调用图:

◆ rt_tick_get_millisecond()

rt_tick_t rt_tick_get_millisecond ( void )

This function will return the passed millisecond from boot.

注解
if the value of RT_TICK_PER_SECOND is lower than 1000 or is not an integral multiple of 1000, this function will not provide the correct 1ms-based tick.
返回
Return passed millisecond from boot.

在文件 clock.c230 行定义.

231{
232#if RT_TICK_PER_SECOND == 0 /* make cppcheck happy*/
233#error "RT_TICK_PER_SECOND must be greater than zero"
234#endif
235
236#if 1000 % RT_TICK_PER_SECOND == 0u
237 return rt_tick_get() * (1000u / RT_TICK_PER_SECOND);
238#else
239 #warning "rt-thread cannot provide a correct 1ms-based tick any longer,\
240 please redefine this function in another file by using a high-precision hard-timer."
241 return 0;
242#endif /* 1000 % RT_TICK_PER_SECOND == 0u */
243}
rt_tick_t rt_tick_get(void)
This function will return current tick from operating system startup.
定义 clock.c:69

引用了 rt_tick_get().

+ 函数调用图:

◆ rt_timer_init()

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 object.

参数
timeris the point of timer
nameis a pointer to the name of the timer
timeoutis the callback of timer
parameteris the param of the callback
timeis timeout ticks of timer
        NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1).
flagis the flag of timer

在文件 timer.c267 行定义.

273{
274 /* parameter check */
275 RT_ASSERT(timer != RT_NULL);
276 RT_ASSERT(timeout != RT_NULL);
277 RT_ASSERT(time < RT_TICK_MAX / 2);
278
279 /* timer object initialization */
281
282 _timer_init(timer, timeout, parameter, time, flag);
283}
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_Object_Class_Timer
#define RT_TICK_MAX
#define RT_NULL
struct rt_object parent

引用了 rt_timer::parameter, rt_timer::parent, RT_ASSERT, RT_NULL, RT_Object_Class_Timer, rt_object_init() , 以及 RT_TICK_MAX.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [3/9]

RTM_EXPORT ( rt_timer_init )

引用了 rt_timer_init().

+ 函数调用图:

◆ rt_timer_detach()

rt_err_t rt_timer_detach ( rt_timer_t timer)

This function will detach a timer from timer management.

参数
timeris the timer to be detached
返回
the status of detach

在文件 timer.c293 行定义.

294{
295 rt_base_t level;
296 struct rt_spinlock *spinlock;
297
298 /* parameter check */
299 RT_ASSERT(timer != RT_NULL);
302
303 spinlock = _timerlock_idx(timer);
304 level = rt_spin_lock_irqsave(spinlock);
305
306 _timer_remove(timer);
307 /* stop timer */
309
310 rt_spin_unlock_irqrestore(spinlock, level);
311 rt_object_detach(&(timer->parent));
312
313 return RT_EOK;
314}
#define RT_TIMER_FLAG_ACTIVATED
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...
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_bool_t rt_object_is_systemobject(rt_object_t object)
This function will judge the object is system object or not.
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_int32_t rt_base_t
rt_uint8_t flag
rt_inline void _timer_remove(rt_timer_t timer)
Remove the timer
rt_inline struct rt_spinlock * _timerlock_idx(struct rt_timer *timer)
定义 timer.c:96

引用了 _timer_remove(), _timerlock_idx(), rt_object::flag, rt_timer::parent, RT_ASSERT, RT_NULL, RT_Object_Class_Timer, rt_object_detach(), rt_object_get_type(), rt_object_is_systemobject(), rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore() , 以及 RT_TIMER_FLAG_ACTIVATED.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [4/9]

RTM_EXPORT ( rt_timer_detach )

引用了 rt_timer_detach().

+ 函数调用图:

◆ rt_timer_create()

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

参数
nameis the name of timer
timeoutis the timeout function
parameteris the parameter of timeout function
timeis timeout ticks of the timer
   NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1).
flagis the flag of timer. Timer will invoke the timeout function according to the selected values of flag, if one or more of the following flags is set.
     RT_TIMER_FLAG_ONE_SHOT          One shot timing
     RT_TIMER_FLAG_PERIODIC          Periodic timing

     RT_TIMER_FLAG_HARD_TIMER        Hardware timer
     RT_TIMER_FLAG_SOFT_TIMER        Software timer
     RT_TIMER_FLAG_THREAD_TIMER      Thread timer

   NOTE:
   You can use multiple values with "|" logical operator.  By default, system will use the RT_TIME_FLAG_HARD_TIMER.
返回
the created timer object

在文件 timer.c345 行定义.

350{
351 struct rt_timer *timer;
352
353 /* parameter check */
354 RT_ASSERT(timeout != RT_NULL);
355 RT_ASSERT(time < RT_TICK_MAX / 2);
356
357 /* allocate a object */
358 timer = (struct rt_timer *)rt_object_allocate(RT_Object_Class_Timer, name);
359 if (timer == RT_NULL)
360 {
361 return RT_NULL;
362 }
363
364 _timer_init(timer, timeout, parameter, time, flag);
365
366 return timer;
367}
rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name)
This function will allocate an object from object system.
void * parameter

引用了 rt_timer::parameter, RT_ASSERT, RT_NULL, rt_object_allocate(), RT_Object_Class_Timer , 以及 RT_TICK_MAX.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [5/9]

RTM_EXPORT ( rt_timer_create )

引用了 rt_timer_create().

+ 函数调用图:

◆ rt_timer_delete()

rt_err_t rt_timer_delete ( rt_timer_t timer)

This function will delete a timer and release timer memory

参数
timerthe timer to be deleted
返回
the operation status, RT_EOK on OK; -RT_ERROR on error

在文件 timer.c377 行定义.

378{
379 rt_base_t level;
380 struct rt_spinlock *spinlock;
381
382 /* parameter check */
383 RT_ASSERT(timer != RT_NULL);
386
387 spinlock = _timerlock_idx(timer);
388
389 level = rt_spin_lock_irqsave(spinlock);
390
391 _timer_remove(timer);
392 /* stop timer */
394 rt_spin_unlock_irqrestore(spinlock, level);
395 rt_object_delete(&(timer->parent));
396
397 return RT_EOK;
398}
void rt_object_delete(rt_object_t object)
This function will delete an object and release object memory.
#define RT_FALSE

引用了 _timer_remove(), _timerlock_idx(), rt_object::flag, rt_timer::parent, RT_ASSERT, RT_FALSE, RT_NULL, RT_Object_Class_Timer, rt_object_delete(), rt_object_get_type(), rt_object_is_systemobject(), rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore() , 以及 RT_TIMER_FLAG_ACTIVATED.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [6/9]

RTM_EXPORT ( rt_timer_delete )

◆ rt_timer_start()

rt_err_t rt_timer_start ( rt_timer_t timer)

This function will start the timer

参数
timerthe timer to be started
返回
the operation status, RT_EOK on OK, -RT_ERROR on error

在文件 timer.c562 行定义.

563{
565 int is_thread_timer = 0;
566 struct rt_spinlock *spinlock;
567 rt_list_t *timer_list;
568 rt_base_t level;
569 rt_err_t err;
570
571 /* parameter check */
572 RT_ASSERT(timer != RT_NULL);
574
575#ifdef RT_USING_TIMER_ALL_SOFT
576 timer_list = _soft_timer_list;
577 spinlock = &_stimer_lock;
578#else
579#ifdef RT_USING_TIMER_SOFT
581 {
582 timer_list = _soft_timer_list;
583 spinlock = &_stimer_lock;
584 }
585 else
586#endif /* RT_USING_TIMER_SOFT */
587 {
588 timer_list = _timer_list;
589 spinlock = &_htimer_lock;
590 }
591#endif
592
594 {
595 rt_thread_t thread;
596 is_thread_timer = 1;
597 rt_sched_lock(&slvl);
598
599 thread = rt_container_of(timer, struct rt_thread, thread_timer);
602 }
603
604 level = rt_spin_lock_irqsave(spinlock);
605
606 err = _timer_start(timer_list, timer);
607
608 rt_spin_unlock_irqrestore(spinlock, level);
609
610 if (is_thread_timer)
611 {
612 rt_sched_unlock(slvl);
613 }
614
615 return err;
616}
#define RT_TIMER_FLAG_SOFT_TIMER
#define RT_TIMER_FLAG_THREAD_TIMER
@ RT_Object_Class_Thread
#define rt_container_of(ptr, type, member)
struct rt_thread * rt_thread_t
rt_ubase_t rt_sched_lock_level_t
rt_base_t rt_err_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_object parent

引用了 rt_object::flag, rt_thread::parent, rt_timer::parent, RT_ASSERT, rt_container_of, RT_NULL, RT_Object_Class_Thread, RT_Object_Class_Timer, rt_object_get_type(), rt_sched_lock(), rt_sched_thread_timer_start(), rt_sched_unlock(), rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore(), RT_TIMER_FLAG_SOFT_TIMER , 以及 RT_TIMER_FLAG_THREAD_TIMER.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [7/9]

RTM_EXPORT ( rt_timer_start )

引用了 rt_timer_start().

+ 函数调用图:

◆ rt_timer_stop()

rt_err_t rt_timer_stop ( rt_timer_t timer)

This function will stop the timer

参数
timerthe timer to be stopped
返回
the operation status, RT_EOK on OK, -RT_ERROR on error

在文件 timer.c626 行定义.

627{
628 rt_base_t level;
629 struct rt_spinlock *spinlock;
630
631 /* timer check */
632 RT_ASSERT(timer != RT_NULL);
634
635 spinlock = _timerlock_idx(timer);
636
637 level = rt_spin_lock_irqsave(spinlock);
638
639 if (!(timer->parent.flag & RT_TIMER_FLAG_ACTIVATED))
640 {
641 rt_spin_unlock_irqrestore(spinlock, level);
642 return -RT_ERROR;
643 }
644 RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(timer->parent)));
645
646 _timer_remove(timer);
647 /* change status */
649
650 rt_spin_unlock_irqrestore(spinlock, level);
651
652 return RT_EOK;
653}

引用了 _timer_remove(), _timerlock_idx(), rt_object::flag, rt_timer::parent, RT_ASSERT, RT_NULL, RT_Object_Class_Timer, rt_object_get_type(), RT_OBJECT_HOOK_CALL, rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore() , 以及 RT_TIMER_FLAG_ACTIVATED.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [8/9]

RTM_EXPORT ( rt_timer_stop )

引用了 rt_timer_stop().

+ 函数调用图:

◆ rt_timer_control()

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

参数
timerthe timer to be get or set
cmdthe control command
argthe argument
返回
the statu of control

在文件 timer.c665 行定义.

666{
667 struct rt_spinlock *spinlock;
668 rt_base_t level;
669
670 /* parameter check */
671 RT_ASSERT(timer != RT_NULL);
673
674 spinlock = _timerlock_idx(timer);
675
676 level = rt_spin_lock_irqsave(spinlock);
677 switch (cmd)
678 {
680 *(rt_tick_t *)arg = timer->init_tick;
681 break;
682
684 RT_ASSERT((*(rt_tick_t *)arg) < RT_TICK_MAX / 2);
686 {
687 _timer_remove(timer);
689 }
690 timer->init_tick = *(rt_tick_t *)arg;
691 break;
692
695 break;
696
699 break;
700
703 {
704 /*timer is start and run*/
706 }
707 else
708 {
709 /*timer is stop*/
711 }
712 break;
713
715 *(rt_tick_t *)arg = timer->timeout_tick;
716 break;
718 *(void **)arg = (void *)timer->timeout_func;
719 break;
720
722 timer->timeout_func = (void (*)(void*))arg;
723 break;
724
726 *(void **)arg = timer->parameter;
727 break;
728
730 timer->parameter = arg;
731 break;
732
733 default:
734 break;
735 }
736 rt_spin_unlock_irqrestore(spinlock, level);
737
738 return RT_EOK;
739}
#define RT_TIMER_CTRL_GET_REMAIN_TIME
#define RT_TIMER_CTRL_GET_TIME
#define RT_TIMER_CTRL_SET_PERIODIC
#define RT_TIMER_CTRL_GET_STATE
#define RT_TIMER_CTRL_SET_FUNC
#define RT_TIMER_CTRL_GET_PARM
#define RT_TIMER_CTRL_SET_ONESHOT
#define RT_TIMER_FLAG_PERIODIC
#define RT_TIMER_CTRL_SET_TIME
#define RT_TIMER_CTRL_SET_PARM
#define RT_TIMER_CTRL_GET_FUNC
#define RT_TIMER_FLAG_DEACTIVATED
unsigned int rt_uint32_t
rt_timer_func_t timeout_func
rt_tick_t init_tick
rt_tick_t timeout_tick

引用了 _timer_remove(), _timerlock_idx(), rt_object::flag, rt_timer::init_tick, rt_timer::parameter, rt_timer::parent, RT_ASSERT, RT_NULL, RT_Object_Class_Timer, rt_object_get_type(), rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore(), RT_TICK_MAX, RT_TIMER_CTRL_GET_FUNC, RT_TIMER_CTRL_GET_PARM, RT_TIMER_CTRL_GET_REMAIN_TIME, RT_TIMER_CTRL_GET_STATE, RT_TIMER_CTRL_GET_TIME, RT_TIMER_CTRL_SET_FUNC, RT_TIMER_CTRL_SET_ONESHOT, RT_TIMER_CTRL_SET_PARM, RT_TIMER_CTRL_SET_PERIODIC, RT_TIMER_CTRL_SET_TIME, RT_TIMER_FLAG_ACTIVATED, RT_TIMER_FLAG_DEACTIVATED, RT_TIMER_FLAG_PERIODIC, rt_timer::timeout_func , 以及 rt_timer::timeout_tick.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [9/9]

RTM_EXPORT ( rt_timer_control )

引用了 rt_timer_control().

+ 函数调用图:

◆ rt_timer_check()

void rt_timer_check ( void )

This function will check timer list, if a timeout event happens, the corresponding timeout function will be invoked.

注解
This function shall be invoked in operating system timer interrupt.

在文件 timer.c748 行定义.

749{
751
752#ifdef RT_USING_SMP
753 /* Running on core 0 only */
754 if (rt_cpu_get_id() != 0)
755 {
756 return;
757 }
758#endif
759
760#ifdef RT_USING_TIMER_SOFT
761 rt_err_t ret = RT_ERROR;
762 rt_tick_t next_timeout;
763
764 ret = _timer_list_next_timeout(_soft_timer_list, &next_timeout);
765 if ((ret == RT_EOK) && (next_timeout <= rt_tick_get()))
766 {
767 rt_sem_release(&_soft_timer_sem);
768 }
769#endif
770#ifndef RT_USING_TIMER_ALL_SOFT
771 _timer_check(_timer_list, &_htimer_lock);
772#endif
773}
rt_err_t rt_sem_release(rt_sem_t sem)
This function will release a semaphore. If there is thread suspended on the semaphore,...
定义 ipc.c:695

引用了 RT_ASSERT, rt_cpu_get_id, rt_interrupt_get_nest(), rt_sem_release() , 以及 rt_tick_get().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ rt_timer_next_timeout_tick()

rt_tick_t rt_timer_next_timeout_tick ( void )

This function will return the next timeout tick in the system.

返回
the next timeout tick in the system

在文件 timer.c780 行定义.

781{
782 rt_base_t level;
783 rt_tick_t htimer_next_timeout = RT_TICK_MAX, stimer_next_timeout = RT_TICK_MAX;
784
785#ifndef RT_USING_TIMER_ALL_SOFT
786 level = rt_spin_lock_irqsave(&_htimer_lock);
787 _timer_list_next_timeout(_timer_list, &htimer_next_timeout);
788 rt_spin_unlock_irqrestore(&_htimer_lock, level);
789#endif
790
791#ifdef RT_USING_TIMER_SOFT
792 level = rt_spin_lock_irqsave(&_stimer_lock);
793 _timer_list_next_timeout(_soft_timer_list, &stimer_next_timeout);
794 rt_spin_unlock_irqrestore(&_stimer_lock, level);
795#endif
796
797 return htimer_next_timeout < stimer_next_timeout ? htimer_next_timeout : stimer_next_timeout;
798}

引用了 rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore() , 以及 RT_TICK_MAX.

+ 函数调用图:

◆ rt_tick_sethook()

void rt_tick_sethook ( void(* hook )(void))

◆ rt_system_timer_init()

void rt_system_timer_init ( void )

This function will initialize system timer

在文件 timer.c823 行定义.

824{
825#ifndef RT_USING_TIMER_ALL_SOFT
826 rt_size_t i;
827
828 for (i = 0; i < sizeof(_timer_list) / sizeof(_timer_list[0]); i++)
829 {
830 rt_list_init(_timer_list + i);
831 }
832
833 rt_spin_lock_init(&_htimer_lock);
834#endif
835}
void rt_spin_lock_init(struct rt_spinlock *lock)
Initialize a static spinlock object.
rt_inline void rt_list_init(rt_list_t *l)
initialize a list
rt_ubase_t rt_size_t

引用了 rt_list_init() , 以及 rt_spin_lock_init().

+ 函数调用图:

◆ rt_system_timer_thread_init()

void rt_system_timer_thread_init ( void )

This function will initialize system timer thread

在文件 timer.c842 行定义.

843{
844#ifdef RT_USING_TIMER_SOFT
845 int i;
846
847 for (i = 0;
848 i < sizeof(_soft_timer_list) / sizeof(_soft_timer_list[0]);
849 i++)
850 {
851 rt_list_init(_soft_timer_list + i);
852 }
853 rt_spin_lock_init(&_stimer_lock);
854 rt_sem_init(&_soft_timer_sem, "stimer", 0, RT_IPC_FLAG_PRIO);
855 rt_sem_control(&_soft_timer_sem, RT_IPC_CMD_SET_VLIMIT, (void*)1);
856 /* start software timer thread */
857 rt_thread_init(&_timer_thread,
858 "timer",
859 _timer_thread_entry,
860 RT_NULL,
861 &_timer_thread_stack[0],
862 sizeof(_timer_thread_stack),
863 RT_TIMER_THREAD_PRIO,
864 10);
865
866 /* startup */
867 rt_thread_startup(&_timer_thread);
868#endif /* RT_USING_TIMER_SOFT */
869}
#define RT_IPC_FLAG_PRIO
#define RT_IPC_CMD_SET_VLIMIT
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.
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.
定义 ipc.c:376
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.
定义 ipc.c:759

引用了 RT_IPC_CMD_SET_VLIMIT, RT_IPC_FLAG_PRIO, rt_list_init(), RT_NULL, rt_sem_control(), rt_sem_init(), rt_spin_lock_init(), rt_thread_init() , 以及 rt_thread_startup().

+ 函数调用图:

◆ rt_timer_enter_sethook()

void rt_timer_enter_sethook ( void(* hook )(struct rt_timer *timer))

◆ rt_timer_exit_sethook()

void rt_timer_exit_sethook ( void(* hook )(struct rt_timer *timer))