Basic example showing the Signals API

Dependencies:   mbed-rtos mbed

mbed 2 and mbed OS 5

This is an mbed 2 example. mbed OS 5 has intergrated the mbed library with mbed-rtos. For an mbed-os example, please see:

Import programrtos_signals

signals example

Committer:
mbed_official
Date:
Wed Feb 15 13:51:51 2017 -0600
Revision:
6:8359b29626dc
Parent:
5:476186ff82cf
Revert update to mbed-os.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:6a8fcc666593 1 #include "mbed.h"
mbed_official 6:8359b29626dc 2 #include "rtos.h"
emilmont 1:6a8fcc666593 3
emilmont 1:6a8fcc666593 4 DigitalOut led(LED1);
emilmont 1:6a8fcc666593 5
Bartek Szatkowski 4:fc60c5b6c104 6 void led_thread() {
emilmont 1:6a8fcc666593 7 while (true) {
emilmont 1:6a8fcc666593 8 // Signal flags that are reported as event are automatically cleared.
emilmont 1:6a8fcc666593 9 Thread::signal_wait(0x1);
emilmont 1:6a8fcc666593 10 led = !led;
emilmont 1:6a8fcc666593 11 }
emilmont 1:6a8fcc666593 12 }
emilmont 1:6a8fcc666593 13
emilmont 1:6a8fcc666593 14 int main (void) {
mbed_official 6:8359b29626dc 15 Thread thread;
mbed_official 6:8359b29626dc 16
Bartek Szatkowski 4:fc60c5b6c104 17 thread.start(callback(led_thread));
Bartek Szatkowski 4:fc60c5b6c104 18
emilmont 1:6a8fcc666593 19 while (true) {
mbed_official 6:8359b29626dc 20 Thread::wait(1000);
emilmont 1:6a8fcc666593 21 thread.signal_set(0x1);
emilmont 1:6a8fcc666593 22 }
emilmont 1:6a8fcc666593 23 }