drivers: net: ppp: improve CONFIG_NET_PPP_ASYNC_UART_TX_TIMEOUT

Its default value (100 ms) resulted in PDUs big enough to never make it
through on a slow enough UART (e.g. ~1152-byte PDUs on a UART@115200).
The UART TXs were silently aborted.

A no-timeout value is now allowed and made the default.
Additional warnings are logged when it is likely that a UART TX
was aborted due to a too low timeout for the used baud rate.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
This commit is contained in:
Tomi Fontanilles 2023-12-14 11:58:55 +02:00 committed by Carles Cufí
parent 9b78b4e894
commit 490a02fda7
2 changed files with 30 additions and 11 deletions

View File

@ -94,11 +94,12 @@ config PPP_NET_IF_NO_AUTO_START
if NET_PPP_ASYNC_UART
config NET_PPP_ASYNC_UART_TX_BUF_LEN
int "Buffer length from where the write to async UART is done"
int "Length of the UART TX buffer to which data is written."
default 2048
help
This options sets the size of the UART TX buffer where data
is being written from to UART.
config NET_PPP_ASYNC_UART_TX_TIMEOUT
int "The timeout for UART transfers in milliseconds, or 0 for no timeout."
default 0
config NET_PPP_ASYNC_UART_RX_RECOVERY_TIMEOUT
int "UART RX recovery timeout in milliseconds"
@ -111,10 +112,6 @@ config NET_PPP_ASYNC_UART_RX_ENABLE_TIMEOUT
int "A timeout for uart_rx_enable() in milliseconds"
default 100
config NET_PPP_ASYNC_UART_TX_TIMEOUT
int "A timeout for uart_tx() in milliseconds"
default 100
endif # NET_PPP_ASYNC_UART
module = NET_PPP

View File

@ -126,9 +126,29 @@ static void uart_callback(const struct device *dev,
break;
case UART_TX_ABORTED:
LOG_DBG("Tx aborted");
{
k_sem_give(&uarte_tx_finished);
if (CONFIG_NET_PPP_ASYNC_UART_TX_TIMEOUT == 0) {
LOG_WRN("UART TX aborted.");
break;
}
struct uart_config uart_conf;
err = uart_config_get(dev, &uart_conf);
if (err) {
LOG_ERR("uart_config_get() err: %d", err);
} else if (uart_conf.baudrate / 10 * CONFIG_NET_PPP_ASYNC_UART_TX_TIMEOUT
/ MSEC_PER_SEC > evt->data.tx.len * 2) {
/* The abort likely did not happen because of missing bandwidth. */
LOG_DBG("UART_TX_ABORTED");
} else {
LOG_WRN("UART TX aborted: Only %zu bytes were sent. You may want"
" to change either CONFIG_NET_PPP_ASYNC_UART_TX_TIMEOUT"
" (%d ms) or the UART baud rate (%u).", evt->data.tx.len,
CONFIG_NET_PPP_ASYNC_UART_TX_TIMEOUT, uart_conf.baudrate);
}
break;
}
case UART_RX_RDY:
len = evt->data.rx.len;
@ -368,11 +388,13 @@ static int ppp_send_flush(struct ppp_driver_context *ppp, int off)
} else if (IS_ENABLED(CONFIG_NET_PPP_ASYNC_UART)) {
#if defined(CONFIG_NET_PPP_ASYNC_UART)
int ret;
const int32_t timeout = CONFIG_NET_PPP_ASYNC_UART_TX_TIMEOUT
? CONFIG_NET_PPP_ASYNC_UART_TX_TIMEOUT * USEC_PER_MSEC
: SYS_FOREVER_US;
k_sem_take(&uarte_tx_finished, K_FOREVER);
ret = uart_tx(ppp->dev, buf, off,
CONFIG_NET_PPP_ASYNC_UART_TX_TIMEOUT * USEC_PER_MSEC);
ret = uart_tx(ppp->dev, buf, off, timeout);
if (ret) {
LOG_ERR("uart_tx() failed, err %d", ret);
k_sem_give(&uarte_tx_finished);