1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-19 14:25:20 +03:00

Merge pull request #10118 from SJChannel/serialRxBytesWaiting-fix

Fix bug that causes uartTotalRxBytesWaiting() to return incorrect value when DMA is used
This commit is contained in:
Michael Keller 2020-08-23 15:57:12 +12:00 committed by GitHub
commit da9bb85843
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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