|
rt_tick_t | rt_tick_get (void) |
|
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) |
|
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) |
|
rt_err_t | rt_timer_detach (rt_timer_t timer) |
|
rt_timer_t | rt_timer_create (const char *name, void(*timeout)(void *parameter), void *parameter, rt_tick_t time, rt_uint8_t flag) |
|
rt_err_t | rt_timer_delete (rt_timer_t timer) |
|
rt_err_t | rt_timer_start (rt_timer_t timer) |
|
rt_err_t | rt_timer_stop (rt_timer_t timer) |
|
rt_err_t | rt_timer_control (rt_timer_t timer, int cmd, void *arg) |
|
void | rt_timer_check (void) |
|
rt_tick_t | rt_timer_next_timeout_tick (void) |
|
void | rt_system_timer_init (void) |
|
void | rt_system_timer_thread_init (void) |
|
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.
◆ RT_TIMER_FLAG_DEACTIVATED
#define RT_TIMER_FLAG_DEACTIVATED 0x0 |
clock & timer macros timer is deactive
◆ RT_TIMER_FLAG_ACTIVATED
#define RT_TIMER_FLAG_ACTIVATED 0x1 |
◆ RT_TIMER_FLAG_ONE_SHOT
#define RT_TIMER_FLAG_ONE_SHOT 0x0 |
◆ RT_TIMER_FLAG_PERIODIC
#define RT_TIMER_FLAG_PERIODIC 0x2 |
◆ 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.
◆ 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.
◆ RT_TIMER_FLAG_THREAD_TIMER
thread timer that cooperates with scheduler directly
◆ RT_TIMER_CTRL_SET_TIME
#define RT_TIMER_CTRL_SET_TIME 0x0 |
set timer control command
◆ RT_TIMER_CTRL_GET_TIME
#define RT_TIMER_CTRL_GET_TIME 0x1 |
get timer control command
◆ RT_TIMER_CTRL_SET_ONESHOT
#define RT_TIMER_CTRL_SET_ONESHOT 0x2 |
◆ RT_TIMER_CTRL_SET_PERIODIC
#define RT_TIMER_CTRL_SET_PERIODIC 0x3 |
◆ RT_TIMER_CTRL_GET_STATE
#define RT_TIMER_CTRL_GET_STATE 0x4 |
get timer run state active or deactive
◆ RT_TIMER_CTRL_GET_REMAIN_TIME
#define RT_TIMER_CTRL_GET_REMAIN_TIME 0x5 |
get the remaining hang time
◆ RT_TIMER_CTRL_GET_FUNC
#define RT_TIMER_CTRL_GET_FUNC 0x6 |
◆ RT_TIMER_CTRL_SET_FUNC
#define RT_TIMER_CTRL_SET_FUNC 0x7 |
◆ RT_TIMER_CTRL_GET_PARM
#define RT_TIMER_CTRL_GET_PARM 0x8 |
◆ RT_TIMER_CTRL_SET_PARM
#define RT_TIMER_CTRL_SET_PARM 0x9 |
◆ RT_TIMER_SKIP_LIST_MASK
#define RT_TIMER_SKIP_LIST_MASK 0x3 |
Timer skips the list mask
◆ rt_timer_func_t
typedef void(* rt_timer_func_t) (void *parameter) |
◆ rt_tick_get()
rt_tick_t rt_tick_get |
( |
void |
| ) |
|
This function will return current tick from operating system startup.
- Returns
- Return current tick.
◆ rt_tick_set()
void rt_tick_set |
( |
rt_tick_t |
tick | ) |
|
This function will set current tick.
- Parameters
-
tick | is the value that you will set. |
◆ 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.
◆ 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.
◆ rt_tick_from_millisecond()
rt_tick_t rt_tick_from_millisecond |
( |
rt_int32_t |
ms | ) |
|
This function will calculate the tick from millisecond.
- Parameters
-
ms | is the specified millisecond.
- Negative Number wait forever
- Zero not wait
- Max 0x7fffffff
|
- Returns
- Return the calculated tick.
◆ rt_tick_get_millisecond()
rt_tick_t rt_tick_get_millisecond |
( |
void |
| ) |
|
This function will return the passed millisecond from boot.
- Note
- 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.
- Returns
- Return passed millisecond from boot.
◆ rt_timer_init()
void rt_timer_init |
( |
rt_timer_t |
timer, |
|
|
const char * |
name, |
|
|
void(*)(void *parameter) |
timeout, |
|
|
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.
- Parameters
-
timer | is the point of timer |
name | is a pointer to the name of the timer |
timeout | is the callback of timer |
parameter | is the param of the callback |
time | is timeout ticks of timer NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1).
|
flag | is the flag of timer |
◆ rt_timer_detach()
This function will detach a timer from timer management.
- Parameters
-
timer | is the timer to be detached |
- Returns
- the status of detach
◆ rt_timer_create()
rt_timer_t rt_timer_create |
( |
const char * |
name, |
|
|
void(*)(void *parameter) |
timeout, |
|
|
void * |
parameter, |
|
|
rt_tick_t |
time, |
|
|
rt_uint8_t |
flag |
|
) |
| |
This function will create a timer.
- Parameters
-
name | is the name of timer |
timeout | is the timeout function |
parameter | is the parameter of timeout function |
time | is timeout ticks of the timer NOTE: The max timeout tick should be no more than (RT_TICK_MAX/2 - 1).
|
flag | is 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.
|
- Returns
- the created timer object
◆ rt_timer_delete()
This function will delete a timer and release timer memory.
- Parameters
-
timer | the timer to be deleted |
- Returns
- the operation status, RT_EOK on OK; -RT_ERROR on error
◆ rt_timer_start()
This function will start the timer.
- Parameters
-
timer | the timer to be started |
- Returns
- the operation status, RT_EOK on OK, -RT_ERROR on error
◆ rt_timer_stop()
This function will stop the timer.
- Parameters
-
timer | the timer to be stopped |
- Returns
- the operation status, RT_EOK on OK, -RT_ERROR on error
◆ 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.
- Parameters
-
timer | the timer to be get or set |
cmd | the control command |
arg | the argument |
- Returns
- the statu of 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.
- Note
- This function shall be invoked in operating system timer interrupt.
◆ 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.
- Returns
- the next timeout tick in the system
◆ rt_system_timer_init()
void rt_system_timer_init |
( |
void |
| ) |
|
This function will initialize system timer.
◆ rt_system_timer_thread_init()
void rt_system_timer_thread_init |
( |
void |
| ) |
|
This function will initialize system timer thread.