[En-Nut-Discussion] UARTAVR driver, was: Serious bug in Realtek driver

Pavel Chromy chromy at asix.cz
Tue Apr 20 15:06:54 CEST 2004


In contrast to the realtek driver, uartavr.c driver is more careful than necessary
when dealing with interrupts.

This note:

/*
 * Handle AVR UART receive complete.
 *
 * Note, that this function modifies the receive index in 
 * interrupt context. This requires, that any non atomic 
 * access of this index requires interrupts being disabled. 
 * Thanks to Mike Cornelius, who pointed this out.
 */

is theroretically right, but also notice that the receive index is modified
in the interrupt only, and only read in the rest of the code, see what I mean?
Yes! Reading of a single memory location _is_always_ an atomic operation,
and the producer/consumer model each modifying distinct memory locations
without usage of any other synchronization is commonly used.

That is - dealing with interrupts by calls to NutEnterCritical() and NutExitCritical()
in UartAvrInput() just increases the overhead with with no real effect.

Note: interrupt disabling in such case is necessary only when there are two or more
consequent read operations which count on there is no asynchronous change meanwhile,
which is certainly a wrong approach and can be avoided.


-- 
#define QUESTION ((bb)||!(bb))

Mgr. Pavel Chromy
ASIX s.r.o.
Staropramenna 4
150 00 Praha 5



More information about the En-Nut-Discussion mailing list