L B / Mbed OS RTOS Example: RTOS Interrupt as Thread (using signals)
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 InterruptIn button(p14);
00004 
00005 Thread ISRthread(osPriorityAboveNormal);
00006 osThreadId ISRthreadId;
00007 
00008 DigitalOut myled(LED1);
00009 DigitalOut myled3(LED3);
00010 
00011 void newInput();
00012 void ISR_thread();
00013 
00014 int main() {
00015     
00016    ISRthread.start(callback(ISR_thread));
00017    button.rise(&newInput);          //interrupt to catch input
00018    
00019     while(1) {
00020         myled = 1;
00021         osDelay(1000);
00022         myled = 0;
00023         osDelay(1000);
00024     }
00025 }
00026 
00027 
00028 void newInput() {
00029     osSignalSet(ISRthreadId,0x01);
00030 }
00031 
00032 
00033 void ISR_thread() {
00034     ISRthreadId = osThreadGetId();
00035     for(;;) {
00036         osSignalWait(0x01, osWaitForever);
00037         myled3 = 1;
00038         osDelay(500);
00039         myled3 = 0;
00040     }
00041 }