Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the last time when the tx write buffer got emptied #17978

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libraries/AP_HAL/UARTDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class AP_HAL::UARTDriver : public AP_HAL::BetterStream {
*/
virtual bool is_dma_enabled() const { return false; }

virtual uint32_t get_last_tx_empty_us() const { return 0; }

#if HAL_UART_STATS_ENABLED
// request information on uart I/O for this uart, for @SYS/uarts.txt
virtual void uart_info(ExpandingString &str) {}
Expand Down
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; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this depends on DMA config ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the _last_write_completed_us only gets written to if tx_dma_enabled == true

#endif

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