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.
Revision 1:5438da9e6654, committed 2019-03-07
- Comitter:
- Ritzerk
- Date:
- Thu Mar 07 16:29:56 2019 +0000
- Parent:
- 0:f28b116a2be0
- Child:
- 2:65ff74ea1476
- Commit message:
- RTOS interrupt as thread
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed-os.lib | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Mar 05 12:16:33 2019 +0000
+++ b/main.cpp Thu Mar 07 16:29:56 2019 +0000
@@ -1,12 +1,13 @@
#include "mbed.h"
-InterruptIn button(p14);
-
Thread ISRthread(osPriorityAboveNormal);
osThreadId ISRthreadId;
+RawSerial pc(USBTX, USBRX);
+Mutex serial_mutex;
+
DigitalOut myled(LED1);
-DigitalOut myled3(LED3);
+DigitalOut myled4(LED4);
void newInput();
void ISR_thread();
@@ -14,18 +15,16 @@
int main() {
ISRthread.start(callback(ISR_thread));
- button.rise(&newInput); //interrupt to catch input
+ pc.attach(&newInput); //interrupt to catch input
while(1) {
- myled = 1;
- osDelay(1000);
- myled = 0;
- osDelay(1000);
+ myled4 = 1;
}
}
void newInput() {
+ pc.attach(NULL); //deatch the ISR to prevent recursive calls
osSignalSet(ISRthreadId,0x01);
}
@@ -34,8 +33,13 @@
ISRthreadId = osThreadGetId();
for(;;) {
osSignalWait(0x01, osWaitForever);
- myled3 = 1;
- osDelay(500);
- myled3 = 0;
+
+ while (pc.readable()) {
+ pc.putc(pc.getc());
+ }
+ myled = 1;
+ osDelay(50);
+ myled = 0;
+ pc.attach(&newInput); //re-attach the ISR
}
}
\ No newline at end of file
--- a/mbed-os.lib Tue Mar 05 12:16:33 2019 +0000 +++ b/mbed-os.lib Thu Mar 07 16:29:56 2019 +0000 @@ -1,1 +1,1 @@ -https://github.com/armmbed/mbed-os/#ecb3c8c837162c73537bd0f3592c6e2a42994045 +https://github.com/armmbed/mbed-os/#51d55508e8400b60af467005646c4e2164738d48