Instead of using an interrupt to read a serial message, a thread is created within the interrupt that reads serial data coming in. Original project for LPC1768.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 Thread ISRthread(osPriorityAboveNormal);
00004 osThreadId ISRthreadId;
00005 
00006 RawSerial pc(USBTX, USBRX);
00007 
00008 DigitalOut myled(LED1);
00009 DigitalOut myled4(LED4);
00010 
00011 void newInput();
00012 void ISR_thread();
00013 
00014 int main() {
00015     
00016    ISRthread.start(callback(ISR_thread));
00017    pc.attach(&newInput);                                      //interrupt to catch input
00018    
00019     while(1) {
00020         myled4 = 1;
00021     }
00022 }
00023 
00024 
00025 void newInput() {
00026     pc.attach(NULL);                                           //deatch the ISR to prevent recursive calls
00027     osSignalSet(ISRthreadId,0x01);
00028 }
00029 
00030 
00031 void ISR_thread() {
00032     ISRthreadId = osThreadGetId();
00033     for(;;) {
00034         osSignalWait(0x01, osWaitForever);
00035         
00036         while (pc.readable()) {
00037             pc.putc(pc.getc());
00038         }
00039         myled = 1;
00040         osDelay(50);
00041         myled = 0;
00042         pc.attach(&newInput);                                     //re-attach the ISR
00043     }
00044 }