Mistake on this page?
Report an issue in GitHub or email us


Deprecated: The EventQueue has superseded the RtosTimer. 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.

RtosTimer class hierarchy

Use the RtosTimer class to create and control timer functions in the system. A timer function is called when a time period expires, so both one-shot and periodic timers are possible. You can start, restart or stop a timer.

The thread osTimerThread handles timers. Callback functions run under the control of this thread and may use underlying RTOS API calls.

RtosTimer class reference

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

RtosTimer example

Control the timing of four LEDs.

#include "mbed.h"
#include "rtos.h"

DigitalOut LEDs[4] = {
    DigitalOut(LED1), DigitalOut(LED2), DigitalOut(LED3), DigitalOut(LED4)

void blink(void const *n) {
    LEDs[(int)n] = !LEDs[(int)n];

int main(void) {
    RtosTimer led_1_timer(blink, osTimerPeriodic, (void *)0);
    RtosTimer led_2_timer(blink, osTimerPeriodic, (void *)1);
    RtosTimer led_3_timer(blink, osTimerPeriodic, (void *)2);
    RtosTimer led_4_timer(blink, osTimerPeriodic, (void *)3);

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.