??? 01/11/08 00:39 Read: times |
#149289 - I have a doubt about that KEIL code. Responding to: ???'s previous message |
Just for curiosity - and also because I'm a tad interested on this.
The code: /*------------------------------------------------ Received data interrupt. ------------------------------------------------*/ if (RI != 0) { RI = 0; if (((r_in - r_out) & ~(RBUF_SIZE-1)) == 0) { rbuf [r_in & (RBUF_SIZE-1)] = SBUF; r_in++; } } Looks quite normal but what happens if the receive buffer gets full and the data is not read from the SBUF? Will the thing stop generating RX interrupts because the data was not read? According the "Bible" The thing will go back looking for another character and next interrupt will occur whether or not the data in SBUF was read. It is just replaced. However - and I may be a tad paranoid here - it IS a good practise to tickle the hardware the same way every time when the interrupt arrives. So I would rewrite the code as: if (RI != 0) { RI = 0; rbuf [r_in & (RBUF_SIZE-1)] = SBUF; if (((r_in - r_out) & ~(RBUF_SIZE-1)) == 0) { r_in++; } } |