avnish aggarwal / Mbed 2 deprecated rtos_signals

Dependencies:   mbed-rtos mbed

Fork of rtos_signals by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "rtos.h"
00003 
00004 void        proxy_thread(void const *argument);
00005 DigitalOut  led1(LED1);
00006 DigitalOut  led2(LED2);
00007 InterruptIn fire(p14);
00008 Thread      *proxy_ptr;
00009 
00010 /*
00011  * PROXY thread that works with and is triggered by the ISR
00012  */
00013 
00014 void proxy_thread(void const *argument) {
00015     while (true) { 
00016         printf("proxy - waiting for  signal \n\r");    
00017         Thread::signal_wait(0x1, osWaitForever);
00018         printf("proxy - got signal \n\r");
00019         led1 = !led1;
00020     }
00021 }
00022 
00023 
00024 /*
00025  * ISR - does minimal work and passes the buck to PROXY thread
00026  */
00027 
00028 void ISR1() {
00029     led2 = !led2;
00030     proxy_ptr->signal_set(0x1);
00031 }
00032 
00033 
00034 
00035 
00036 int main (void) {
00037     
00038     fire.rise(&ISR1);
00039     Thread thread(proxy_thread);
00040     proxy_ptr = &thread;  
00041     
00042     printf("main ... testing signals\n\r");
00043     while (true) {
00044         Thread::wait(1000);
00045         printf("main ... wait loop\n\r");
00046     }
00047 }