[En-Nut-Discussion] Proposal: Extending the USART(AVR) driver to support DMA-style read functionality

Clemens Kirchgatterer c.kirchgatterer at amatic.com
Tue Apr 13 07:23:50 CEST 2004


Matthias Ringwald <mringwal at inf.ethz.ch> wrote:

> 	// read first two bytes
> 	read( uart, buffer, 1);
> 	read( uart, buffer+1, 1);
> 	
> 	length = buffer[0] + buffer[1] << 8;
> 
> 	// now length is known, read all data
> 	while ( length > 0) {
> 		rc = read(uart, ptr, length);
> 		length -= rc;
> 		ptr += rc;
> 	}

> ok. the interesting part is the while loop.
> what happens, if the load on the processor is low
> (or the thread has a high priority)?
> 
> for every received byte, the thread would wake up,
> get its one byte, figure out that the packet is not finished
> call read and be put to sleep again.
> 
> it should be clear that this is not very efficient... :)

you will only receive just one byte under low load and then it just does
not matter if there are some cycles wasted fo each iteration. this is
the way it is under posix also. sounds like "premature optimization" to
me. ;-)

just my 2c. ...
clemens



More information about the En-Nut-Discussion mailing list