When reading a portion of the packet that is not divisible by 4 and not equal to rxbcnt the count could get off, since 4 bytes are read from the fifo in the last step but rxbcnt was only updated by the number of bytes the caller requested. We fix this by always subtracting four bytes (the number of bytes read from the fifo) when we read a word from the fifo. Care has to be taken in the last step so that rxbcnt doesn't underflow (it is an unsigned number). Note that reading in several small chunks not divisible by 4 doesn't work as the extra bytes read in the last step are always discarded.
11 KiB
11 KiB