1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-15 04:15:44 +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
parent 93d0902319
commit d8dfd14dfc

View file

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