![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
IRQ Demo
main.cpp@0:96fb278b654f, 2019-05-23 (annotated)
- Committer:
- gmoertl
- Date:
- Thu May 23 06:25:18 2019 +0000
- Revision:
- 0:96fb278b654f
IRQ Demo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gmoertl | 0:96fb278b654f | 1 | #include "mbed.h" |
gmoertl | 0:96fb278b654f | 2 | |
gmoertl | 0:96fb278b654f | 3 | InterruptIn fireIrq(p14); |
gmoertl | 0:96fb278b654f | 4 | Timeout timeoutIrq; |
gmoertl | 0:96fb278b654f | 5 | |
gmoertl | 0:96fb278b654f | 6 | DigitalOut led1(LED1); |
gmoertl | 0:96fb278b654f | 7 | DigitalOut led2(LED2); |
gmoertl | 0:96fb278b654f | 8 | |
gmoertl | 0:96fb278b654f | 9 | Serial pc(USBTX, USBRX); |
gmoertl | 0:96fb278b654f | 10 | |
gmoertl | 0:96fb278b654f | 11 | |
gmoertl | 0:96fb278b654f | 12 | // funktion runs in interrupt-context |
gmoertl | 0:96fb278b654f | 13 | void fireIrqHandler( void ) |
gmoertl | 0:96fb278b654f | 14 | { |
gmoertl | 0:96fb278b654f | 15 | led1 = !led1; |
gmoertl | 0:96fb278b654f | 16 | pc.printf("Starting up...\n\r"); |
gmoertl | 0:96fb278b654f | 17 | } |
gmoertl | 0:96fb278b654f | 18 | |
gmoertl | 0:96fb278b654f | 19 | // runs in irq-context |
gmoertl | 0:96fb278b654f | 20 | void timeoutIrqHandler( void ) |
gmoertl | 0:96fb278b654f | 21 | { |
gmoertl | 0:96fb278b654f | 22 | led2 = 0; |
gmoertl | 0:96fb278b654f | 23 | } |
gmoertl | 0:96fb278b654f | 24 | |
gmoertl | 0:96fb278b654f | 25 | int main() |
gmoertl | 0:96fb278b654f | 26 | { |
gmoertl | 0:96fb278b654f | 27 | pc.printf("Starting up...\n\r"); |
gmoertl | 0:96fb278b654f | 28 | |
gmoertl | 0:96fb278b654f | 29 | fireIrq.fall( &fireIrqHandler ); |
gmoertl | 0:96fb278b654f | 30 | fireIrq.rise( &fireIrqHandler ); |
gmoertl | 0:96fb278b654f | 31 | |
gmoertl | 0:96fb278b654f | 32 | led2 = 1; |
gmoertl | 0:96fb278b654f | 33 | timeoutIrq.attach( &timeoutIrqHandler, 3 ); |
gmoertl | 0:96fb278b654f | 34 | |
gmoertl | 0:96fb278b654f | 35 | while(1) { |
gmoertl | 0:96fb278b654f | 36 | wait(5); |
gmoertl | 0:96fb278b654f | 37 | } |
gmoertl | 0:96fb278b654f | 38 | } |