1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 12:55:19 +03:00

Fix a bug that caused uartTotalRxBytesWaiting() to return a grossly incorrect

value when DMA was used.  For example, if one byte was waiting, the function
returned one less than the size of the buffer.

The reason the bug didn't cause serious problems is that almost all
calls to this function check only whether the returned value is zero or not.
(The only exceptions I found were in "src/main/telemetry/hott.c".  Perhaps
that code was tested on a target that did not use DMA.)  The case of zero
bytes waiting was the only case in which the correct result was returned.
This commit is contained in:
John Polstra 2020-08-19 11:30:29 -07:00
parent 08a87b72fc
commit d184e581d8

View file

@ -156,10 +156,12 @@ static uint32_t uartTotalRxBytesWaiting(const serialPort_t *instance)
uint32_t rxDMAHead = xDMA_GetCurrDataCounter(s->rxDMAResource);
#endif
if (rxDMAHead >= s->rxDMAPos) {
return rxDMAHead - s->rxDMAPos;
// s->rxDMAPos and rxDMAHead represent distances from the end
// of the buffer. They count DOWN as they advance.
if (s->rxDMAPos >= rxDMAHead) {
return s->rxDMAPos - rxDMAHead;
} else {
return s->port.rxBufferSize + rxDMAHead - s->rxDMAPos;
return s->port.rxBufferSize + s->rxDMAPos - rxDMAHead;
}
}
#endif