
main.cpp@0:90e9a34552d3, 2010-02-20 (annotated)
- Committer:
- mbed714
- Date:
- Sat Feb 20 11:26:16 2010 +0000
- Revision:
- 0:90e9a34552d3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed714 | 0:90e9a34552d3 | 1 | #include "mbed.h" |
mbed714 | 0:90e9a34552d3 | 2 | |
mbed714 | 0:90e9a34552d3 | 3 | // Test app to cause program to suddently terminate when using serial interrupt... |
mbed714 | 0:90e9a34552d3 | 4 | // Line 24 seems to be the important bit, but I don't really understand why? |
mbed714 | 0:90e9a34552d3 | 5 | // Is it perhaps the putc is peroperly clearing the interrupt flag instead of the getc? |
mbed714 | 0:90e9a34552d3 | 6 | |
mbed714 | 0:90e9a34552d3 | 7 | |
mbed714 | 0:90e9a34552d3 | 8 | // usb serial device defaults to 9600 baud, 8N1 on /dev/ttyACM0 (in Linux!) |
mbed714 | 0:90e9a34552d3 | 9 | Serial pc(USBTX, USBRX); // tx, rx |
mbed714 | 0:90e9a34552d3 | 10 | |
mbed714 | 0:90e9a34552d3 | 11 | // debugging LEDs |
mbed714 | 0:90e9a34552d3 | 12 | DigitalOut interrupt(LED1); |
mbed714 | 0:90e9a34552d3 | 13 | DigitalOut tx(LED4); |
mbed714 | 0:90e9a34552d3 | 14 | |
mbed714 | 0:90e9a34552d3 | 15 | // one byte receive buffer |
mbed714 | 0:90e9a34552d3 | 16 | char rx_byte; |
mbed714 | 0:90e9a34552d3 | 17 | |
mbed714 | 0:90e9a34552d3 | 18 | void handle() |
mbed714 | 0:90e9a34552d3 | 19 | { |
mbed714 | 0:90e9a34552d3 | 20 | interrupt = 1; |
mbed714 | 0:90e9a34552d3 | 21 | //if(pc.readable()) // <--- this line doesn't matter either way... |
mbed714 | 0:90e9a34552d3 | 22 | { |
mbed714 | 0:90e9a34552d3 | 23 | rx_byte = pc.getc(); |
mbed714 | 0:90e9a34552d3 | 24 | //pc.putc(rx_byte); // <--- WITHOUT THIS LINE, THE APPLICATION WILL HANG IF IT RECEIVES WHILE SENDING! |
mbed714 | 0:90e9a34552d3 | 25 | } |
mbed714 | 0:90e9a34552d3 | 26 | interrupt = 0; |
mbed714 | 0:90e9a34552d3 | 27 | return; |
mbed714 | 0:90e9a34552d3 | 28 | } |
mbed714 | 0:90e9a34552d3 | 29 | |
mbed714 | 0:90e9a34552d3 | 30 | int main() |
mbed714 | 0:90e9a34552d3 | 31 | { |
mbed714 | 0:90e9a34552d3 | 32 | interrupt = 0; |
mbed714 | 0:90e9a34552d3 | 33 | tx = 0; |
mbed714 | 0:90e9a34552d3 | 34 | pc.attach(handle); |
mbed714 | 0:90e9a34552d3 | 35 | |
mbed714 | 0:90e9a34552d3 | 36 | while(1) |
mbed714 | 0:90e9a34552d3 | 37 | { |
mbed714 | 0:90e9a34552d3 | 38 | // send a long string of bytes |
mbed714 | 0:90e9a34552d3 | 39 | tx = 1; |
mbed714 | 0:90e9a34552d3 | 40 | for(int i=0;i<20;i++) |
mbed714 | 0:90e9a34552d3 | 41 | { |
mbed714 | 0:90e9a34552d3 | 42 | NVIC_DisableIRQ(UART0_IRQn); |
mbed714 | 0:90e9a34552d3 | 43 | pc.printf("If I receive while transmitting this I *won't* crash...\r\n"); |
mbed714 | 0:90e9a34552d3 | 44 | NVIC_EnableIRQ(UART0_IRQn); |
mbed714 | 0:90e9a34552d3 | 45 | } |
mbed714 | 0:90e9a34552d3 | 46 | tx = 0; |
mbed714 | 0:90e9a34552d3 | 47 | |
mbed714 | 0:90e9a34552d3 | 48 | wait(1.0); |
mbed714 | 0:90e9a34552d3 | 49 | } |
mbed714 | 0:90e9a34552d3 | 50 | } |