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:
parent
93d0902319
commit
d8dfd14dfc
1 changed files with 5 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue