Philipp Kundegraber
/
TINF_PE_20190328_Events
Übungen zu Events im MbedOS https://os.mbed.com/users/fpucher/code/HIM0Board/wiki/Events
Diff: main.cpp
- Revision:
- 0:0e8dbc229b3a
diff -r 000000000000 -r 0e8dbc229b3a main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 28 17:12:15 2019 +0000 @@ -0,0 +1,29 @@ +#include "mbed.h" + +DigitalOut led(LED1); +InterruptIn btn(p15); + +Semaphore updates(1); + +void fall_handler() { + // release the semaphore + updates.release(); +} + +int main() { + btn.fall(&fall_handler); // The 'fall' handler will execute in IRQ context + printf("Starting in context %p\r\n", Thread::gettid()); + + while(1){ + int32_t v = updates.wait(); // wait for the semaphore to be released from the ISR + + if (v == 1) { // now this runs on the main thread, and is safe + led = !led; + printf("fall_handler in context %p\r\n",Thread::gettid()); + } + + } + + + wait(osWaitForever); +}