Lee Shen / FTHR_USB_serial_qSPI
Embed: (wiki syntax)

« Back to documentation index

RtosTimer Class Reference

RtosTimer Class Reference
[Rtos]

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

#include <RtosTimer.h>

Inherits NonCopyable< RtosTimer >.

Public Member Functions

 MBED_DEPRECATED_SINCE ("mbed-os-5.1","Replaced with RtosTimer(Callback<void()>, os_timer_type)") MBED_DEPRECATED_SINCE("mbed-os-5.2"
 Create timer.
 MBED_DEPRECATED_SINCE ("mbed-os-5.2","The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details") RtosTimer(mbed
 Create timer.
template<typename T , typename M >
 MBED_DEPRECATED_SINCE ("mbed-os-5.1","The RtosTimer constructor does not support cv-qualifiers. Replaced by ""RtosTimer(callback(obj, method), os_timer_type).") MBED_DEPRECATED_SINCE("mbed-os-5.2"
 Create timer.
osStatus stop (void)
 Stop the timer.
osStatus start (uint32_t millisec)
 Start or restart the timer.

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.

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 83 of file RtosTimer.h.


Member Function Documentation

MBED_DEPRECATED_SINCE ( "mbed-os-5.1"  ,
"Replaced with RtosTimer(Callback<void()>, os_timer_type)"   
)

Create timer.

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