RealtimeCompLab2
Dependencies: mbed
Fork of PPP-Blinky by
Diff: main.cpp
- Revision:
- 22:00df34cd4d7e
- Parent:
- 21:66459cb32ce0
- Child:
- 23:af88d429bed1
--- a/main.cpp Mon Jan 02 17:38:08 2017 +0000 +++ b/main.cpp Mon Jan 02 17:45:55 2017 +0000 @@ -69,17 +69,20 @@ led1 = ledState; } -int pc_readable() // check if buffer has data +int rxbufNotEmpty() // check if rx buffer has data { - return (ppp.rx.head==ppp.rx.tail) ? 0 : 1 ; + __disable_irq(); // critical section start + int notEmpty = (ppp.rx.head==ppp.rx.tail) ? 0 : 1 ; + __enable_irq(); // critical section end + return notEmpty; } int pc_getBuf() // get one character from the buffer { - if (ppp.rx.head!=ppp.rx.tail) { + if ( rxbufNotEmpty() ) { int x = ppp.rx.buf[ ppp.rx.tail ]; __disable_irq(); // critical section start - ppp.rx.tail=(ppp.rx.tail+1)&(BUFLEN-1); // atomic operation + ppp.rx.tail=(ppp.rx.tail+1)&(BUFLEN-1); __enable_irq(); // critical section end return x; } else return -1; @@ -380,7 +383,7 @@ while(1) { if ( ppp.online==0 ) scanForConnectString(); // try to connect - while ( pc_readable() ) { + while ( rxbufNotEmpty() ) { int rx = pc_getBuf(); if (frameBusy) { if (rx==FRAME_7E) {