Mistake on this page?
Report an issue in GitHub or email us
Public Member Functions
RtosTimer Class Reference

The RtosTimer class allow creating and and controlling of timer functions in the system. More...

#include <RtosTimer.h>

Inheritance diagram for RtosTimer:
NonCopyable< RtosTimer >

Public Member Functions

 RtosTimer (void(*func)(void const *argument), os_timer_type type=osTimerPeriodic, void *argument=NULL)
 Create timer. More...
 
 RtosTimer (mbed::Callback< void()> func, os_timer_type type=osTimerPeriodic)
 Create timer. More...
 
template<typename T , typename M >
 RtosTimer (T *obj, M method, os_timer_type type=osTimerPeriodic)
 Create timer. More...
 
osStatus stop (void)
 Stop the timer. More...
 
osStatus start (uint32_t millisec)
 Start or restart the timer. More...
 
 ~RtosTimer ()
 RtosTimer destructor. More...
 

Detailed Description

The RtosTimer class allow creating and and controlling of timer functions in the system.

A timer function is called when a time period expires whereby both on-shot and periodic timers are possible. A timer can be started, restarted, or stopped.

Timers are handled in the thread osTimerThread. Callback functions run under control of this thread and may use CMSIS-RTOS API calls.

Deprecated:
The RtosTimer has been superseded by the EventQueue. The RtosTimer and EventQueue duplicate the functionality of timing events outside of interrupt context, however the EventQueue has additional features to handle deferring other events to multiple contexts.

For an example, the following code shows a simple use of the RtosTimer:

DigitalOut led(LED1);
void blink() {
led = !led;
}
RtosTimer timer(&blink);
int main() {
timer.start(1000); // call blink every 1s
wait_ms(5000);
timer.stop(); // stop after 5s
}

This is the above example rewritten to use the EventQueue:

DigitalOut led(LED1);
void blink() {
led = !led;
}
EventQueue queue(4*EVENTS_EVENT_SIZE);
int main() {
int blink_id = queue.call_every(1000, &blink); // call blink every 1s
queue.dispatch(5000);
queue.cancel(blink_id); // stop after 5s
}
Note
Memory considerations: The timer control structures will be created on current thread's stack, both for the mbed OS and underlying RTOS objects (static or dynamic RTOS memory pools are not being used).

Definition at line 87 of file RtosTimer.h.

Constructor & Destructor Documentation

RtosTimer ( void(*)(void const *argument)  func,
os_timer_type  type = osTimerPeriodic,
void *  argument = NULL 
)

Create timer.

Parameters
funcfunction to be executed by this timer.
typeosTimerOnce for one-shot or osTimerPeriodic for periodic behavior. (default: osTimerPeriodic)
argumentargument to the timer call back function. (default: NULL)
Deprecated:

Replaced with RtosTimer(Callback<void()>, os_timer_type)

The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details

Note
You cannot call this function from ISR context.

Definition at line 103 of file RtosTimer.h.

RtosTimer ( mbed::Callback< void()>  func,
os_timer_type  type = osTimerPeriodic 
)

Create timer.

Parameters
funcfunction to be executed by this timer.
typeosTimerOnce for one-shot or osTimerPeriodic for periodic behavior. (default: osTimerPeriodic)
Deprecated:
The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details
Note
You cannot call this function from ISR context.

Definition at line 118 of file RtosTimer.h.

RtosTimer ( T *  obj,
method,
os_timer_type  type = osTimerPeriodic 
)

Create timer.

Parameters
objpointer to the object to call the member function on.
methodmember function to be executed by this timer.
typeosTimerOnce for one-shot or osTimerPeriodic for periodic behavior. (default: osTimerPeriodic)
Deprecated:

The RtosTimer constructor does not support cv-qualifiers. Replaced by RtosTimer(callback(obj, method), os_timer_type).

The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details

Note
You cannot call this function from ISR context.

Definition at line 141 of file RtosTimer.h.

~RtosTimer ( )

RtosTimer destructor.

Note
You cannot call this function from ISR context.

Member Function Documentation

osStatus start ( uint32_t  millisec)

Start or restart the timer.

Parameters
millisecnon-zero value of the timer.
Returns
status code that indicates the execution status of the function: osOK the timer has been started or restarted. osErrorISR start cannot be called from interrupt service routines. osErrorParameter internal error or incorrect parameter value. osErrorResource internal error (the timer is in an invalid timer state).
Note
You cannot call this function from ISR context.
osStatus stop ( void  )

Stop the timer.

Returns
status code that indicates the execution status of the function: osOK the timer has been stopped. osErrorISR stop cannot be called from interrupt service routines. osErrorParameter internal error. osErrorResource the timer is not running.
Note
You cannot call this function from ISR context.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.