RT-Thread RTOS  1.0.0
An open source embedded real-time operating system
Clock and Timer Management

Data Structures

struct  rt_timer

Defines

#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_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

Functions

rt_tick_t rt_tick_get (void)
void rt_tick_set (rt_tick_t tick)
void rt_tick_increase (void)
rt_tick_t rt_tick_from_millisecond (rt_uint32_t ms)
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, rt_uint8_t cmd, void *arg)
void rt_timer_check (void)
void rt_system_tick_init (void)
void rt_system_timer_init (void)
void rt_system_timer_thread_init (void)
void rt_timer_timeout_sethook (void(*hook)(struct rt_timer *timer))

Detailed Description

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


Define Documentation

#define RT_TIMER_FLAG_DEACTIVATED   0x0

clock & timer macros timer is deactive

#define RT_TIMER_FLAG_ACTIVATED   0x1

timer is active

#define RT_TIMER_FLAG_ONE_SHOT   0x0

one shot timer

#define RT_TIMER_FLAG_PERIODIC   0x2

periodic timer

#define RT_TIMER_FLAG_HARD_TIMER   0x0

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

#define RT_TIMER_FLAG_SOFT_TIMER   0x4

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

#define RT_TIMER_CTRL_SET_TIME   0x0

set timer control command

#define RT_TIMER_CTRL_GET_TIME   0x1

get timer control command

#define RT_TIMER_CTRL_SET_ONESHOT   0x2

change timer to one shot

#define RT_TIMER_CTRL_SET_PERIODIC   0x3

change timer to periodic


Function Documentation

rt_tick_t rt_tick_get ( void  )

This function will return current tick from operating system startup

Returns:
current tick
void rt_tick_set ( rt_tick_t  tick)

This function will set current tick

void rt_tick_increase ( void  )

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

This function will calculate the tick from millisecond.

Parameters:
msthe specified millisecond
Returns:
the calculated tick
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:
timerthe static timer object
namethe name of timer
timeoutthe timeout function
parameterthe parameter of timeout function
timethe tick of timer
flagthe flag of timer

This function will detach a timer from timer management.

Parameters:
timerthe static timer object
Returns:
the operation status, RT_EOK on OK; RT_ERROR on error
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:
namethe name of timer
timeoutthe timeout function
parameterthe parameter of timeout function
timethe tick of timer
flagthe flag of timer
Returns:
the created timer object

This function will delete a timer and release timer memory

Parameters:
timerthe timer to be deleted
Returns:
the operation status, RT_EOK on OK; RT_ERROR on error

This function will start the timer

Parameters:
timerthe timer to be started
Returns:
the operation status, RT_EOK on OK, -RT_ERROR on error

This function will stop the timer

Parameters:
timerthe timer to be stopped
Returns:
the operation status, RT_EOK on OK, -RT_ERROR on error
rt_err_t rt_timer_control ( rt_timer_t  timer,
rt_uint8_t  cmd,
void *  arg 
)

This function will get or set some options of the timer

Parameters:
timerthe timer to be get or set
cmdthe control command
argthe argument
Returns:
RT_EOK
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.
void rt_system_tick_init ( void  )

This function will init system tick and set it to zero.

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

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

This function will set a hook function, which will be invoked when timer is timeout.

Parameters:
hookthe hook function
 All Data Structures Variables