[En-Nut-Discussion] Bugs in Uart.c

Moritz Struebe morty at gmx.net
Tue Mar 25 20:39:32 CET 2008


Hi there,

it's me again. I found some bugs. The reason was a stupid bug of mine 
but suspecting some problem with the usart I had a closer look at the 
usart.c. Here are some things I think should be changed:

1: UsartRead
if (NutEventWait(&rbf->rbf_que, dcb->dcb_rtimeout)) {
should be
if (NutEventWait(&rbf->rbf_que, dcb->dcb_rtimeout) == -1) {

As NutEventWait returns 0 or -1 the if-statement will always be false. 
(I think this bug is at some other places, too. (A quick search for 
"if?(NutEventWait(" found 38 matches - only three or four were ok!!! - 
That's over 30 bugs on one afternoon! :-) )

2: Still UsartRead:
rc should be unsiged int. The is no reason to make it size_t as it will 
never become bigger then size. The disadvantage is, that for the avr 
size_t is an unsigned long, which costs performance.

3: The Cooked mode isn't very nice. If \r\n are the last chars in your 
buffer and you read them character wise you first get \n and then 
-1/EOF. I think the cooked mode should be either moved to the 
interrupt-routine filling the buffer or to the wait statement waiting 
for "at least one character".

4: Once again the return types are often much bigger then needed. This 
costs registers and performance.

If I didn't get anything wrong I'll provide a diff.

Cheers
Morty






More information about the En-Nut-Discussion mailing list