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
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 }
Generated on Thu Jul 21 2022 01:14:25 by
1.7.2