Skip to content

Commit

Permalink
AP_HAL_ChibiOS: get the last time when the tx write buffer got emptied
Browse files Browse the repository at this point in the history
  • Loading branch information
amilcarlucas committed Feb 13, 2024
1 parent ea4617b commit 252d6cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libraries/AP_HAL_ChibiOS/UARTDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ void UARTDriver::uart_thread()
if (_tx_initialised && ((mask & EVT_TRANSMIT_DATA_READY) || need_tick || (hd_tx_active && (mask & EVT_TRANSMIT_END)))) {
_tx_timer_tick();
}

// record the time when a half-duplex TX buffer got emptied
if (_tx_initialised && hd_tx_active && (mask & EVT_TRANSMIT_END) && _writebuf.is_empty()) {
_last_write_completed_us = now;
}
}
}
#pragma GCC diagnostic pop
Expand Down
7 changes: 7 additions & 0 deletions libraries/AP_HAL_ChibiOS/UARTDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ class ChibiOS::UARTDriver : public AP_HAL::UARTDriver {
*/
bool is_dma_enabled() const override { return rx_dma_enabled && tx_dma_enabled; }

// get the last time when the tx write buffer got emptied
#if CH_CFG_USE_EVENTS == TRUE
uint32_t get_last_tx_empty_us() const override { return ((tx_dma_enabled || half_duplex) && _writebuf.is_empty()) ? _last_write_completed_us : 0; }
#else
uint32_t get_last_tx_empty_us() const override { return (tx_dma_enabled && _writebuf.is_empty()) ? _last_write_completed_us : 0; }
#endif

private:
const SerialDef &sdef;
bool rx_dma_enabled;
Expand Down

0 comments on commit 252d6cc

Please sign in to comment.