i am writting problem to receive data from a interrupt-driven serial port, and i think my code will always have change of lossing data.
in the receving ISR, i get a byte from a register and put it into a buffer,
static unsigned char buff[ BUFF_SIZE ]; static buff_len = 0;
__interrupt on_byte_in( void ) { if ( buffer_len < sizeof( buff ) ) buffer[ buffer_len++ ] = the_byte_in_the_register; }
another function used to fetch the buffer data,
flush_receiving_buff( void ) { for ( size_t i = 0; i < buff_len; ++i ) { process the buff[ i ]; buff_len = 0; ------------- (a) }
my question is that, during the execution of statement (a), one or more new bytes might come in and code above will lost them. if you folks see the problem, can you please suggest me a solution? i believe the question is very basic and must have been well resolved.
thanks in advance.
-- woody