Example of an interrupt which passes its job as a thread using signals. "With an RTOS application it is best to design the interrupt service code as a thread within the RTOS and assign it a high priority. While it is possible to run C code in an interrupt service routine (ISR), this is not desirable within an RTOS if the interrupt code is going to run for more than a short period of time. This delays the timer tick and disrupts the RTOS kernel. " - “The Designers Guide to the Cortex-M ProcessorFamily” by Trevor Martin
RTOS Example of an RTOS Interrupt as Thread (using signals)
Diff: main.cpp
- Revision:
- 0:f28b116a2be0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Mar 05 12:16:33 2019 +0000
@@ -0,0 +1,41 @@
+#include "mbed.h"
+
+InterruptIn button(p14);
+
+Thread ISRthread(osPriorityAboveNormal);
+osThreadId ISRthreadId;
+
+DigitalOut myled(LED1);
+DigitalOut myled3(LED3);
+
+void newInput();
+void ISR_thread();
+
+int main() {
+
+ ISRthread.start(callback(ISR_thread));
+ button.rise(&newInput); //interrupt to catch input
+
+ while(1) {
+ myled = 1;
+ osDelay(1000);
+ myled = 0;
+ osDelay(1000);
+ }
+}
+
+
+void newInput() {
+ osSignalSet(ISRthreadId,0x01);
+}
+
+
+void ISR_thread() {
+ ISRthreadId = osThreadGetId();
+ for(;;) {
+ osSignalWait(0x01, osWaitForever);
+ myled3 = 1;
+ osDelay(500);
+ myled3 = 0;
+ }
+}
\ No newline at end of file