Alex Whittemore
/
threadinterrupt
Simple program that demonstrates how one might send signals to arbitrary threads from an ISR.
main.cpp@0:32a3e697c11f, 2012-04-10 (annotated)
- Committer:
- alexwhittemore
- Date:
- Tue Apr 10 13:26:44 2012 +0000
- Revision:
- 0:32a3e697c11f
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alexwhittemore | 0:32a3e697c11f | 1 | #include "mbed.h" |
alexwhittemore | 0:32a3e697c11f | 2 | #include "rtos.h" |
alexwhittemore | 0:32a3e697c11f | 3 | |
alexwhittemore | 0:32a3e697c11f | 4 | DigitalOut led1(LED1); |
alexwhittemore | 0:32a3e697c11f | 5 | DigitalOut led2(LED2); |
alexwhittemore | 0:32a3e697c11f | 6 | DigitalOut led3(LED3); |
alexwhittemore | 0:32a3e697c11f | 7 | Serial pc(USBTX,USBRX); |
alexwhittemore | 0:32a3e697c11f | 8 | |
alexwhittemore | 0:32a3e697c11f | 9 | Thread *LED_THREAD_POINTER; |
alexwhittemore | 0:32a3e697c11f | 10 | |
alexwhittemore | 0:32a3e697c11f | 11 | uint32_t UART_0_RBR; |
alexwhittemore | 0:32a3e697c11f | 12 | |
alexwhittemore | 0:32a3e697c11f | 13 | void UART0_ISR(){ |
alexwhittemore | 0:32a3e697c11f | 14 | UART_0_RBR = LPC_UART0->RBR; // Clear the RBR flag to make sure the interrupt doesn't loop |
alexwhittemore | 0:32a3e697c11f | 15 | led3=!led3; |
alexwhittemore | 0:32a3e697c11f | 16 | (*LED_THREAD_POINTER).signal_set(0x1); // Dereference the LED_THREAD_POINTER then set the signal 0x1 flag of the thread it points to |
alexwhittemore | 0:32a3e697c11f | 17 | } |
alexwhittemore | 0:32a3e697c11f | 18 | |
alexwhittemore | 0:32a3e697c11f | 19 | void led3blinker(void const *argument){ |
alexwhittemore | 0:32a3e697c11f | 20 | while(true){ |
alexwhittemore | 0:32a3e697c11f | 21 | Thread::signal_wait(0x1); |
alexwhittemore | 0:32a3e697c11f | 22 | led2=!led2; |
alexwhittemore | 0:32a3e697c11f | 23 | //Thread::wait(233); |
alexwhittemore | 0:32a3e697c11f | 24 | } |
alexwhittemore | 0:32a3e697c11f | 25 | } |
alexwhittemore | 0:32a3e697c11f | 26 | |
alexwhittemore | 0:32a3e697c11f | 27 | int main() { |
alexwhittemore | 0:32a3e697c11f | 28 | Thread led3blinkerthread(led3blinker); |
alexwhittemore | 0:32a3e697c11f | 29 | pc.attach(&UART0_ISR); |
alexwhittemore | 0:32a3e697c11f | 30 | LED_THREAD_POINTER = &led3blinkerthread; // Set the globally-accessible thread pointer |
alexwhittemore | 0:32a3e697c11f | 31 | |
alexwhittemore | 0:32a3e697c11f | 32 | while(true){ |
alexwhittemore | 0:32a3e697c11f | 33 | led1=!led1; |
alexwhittemore | 0:32a3e697c11f | 34 | Thread::wait(1000); |
alexwhittemore | 0:32a3e697c11f | 35 | led3blinkerthread.signal_set(0x1); |
alexwhittemore | 0:32a3e697c11f | 36 | } |
alexwhittemore | 0:32a3e697c11f | 37 | } |