From 3399a6476af1203d7ed7dc9f6c2e475b71a5049e Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 23 Aug 2021 13:26:34 +0200 Subject: [PATCH] drivers/dose: calculate timeout based on symbol rate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A fixed timeout is either too long for high symbol rates or too short for low symbol rates. To fix this, calculate the timeout based on the symbol rate. For this, the old 5ms timeout is equivalent to 58 bytes being transmitted at 115200 baud (8 data bit + start & stop bit). I rounded this to 50 bytes which should yield 4340 µs. --- drivers/dose/Kconfig | 8 ++++---- drivers/dose/dose.c | 3 ++- drivers/include/dose.h | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/dose/Kconfig b/drivers/dose/Kconfig index feb2a42f3b..5eb1c8cbdb 100644 --- a/drivers/dose/Kconfig +++ b/drivers/dose/Kconfig @@ -13,11 +13,11 @@ menuconfig KCONFIG_USEMODULE_DOSE if KCONFIG_USEMODULE_DOSE -config DOSE_TIMEOUT_USEC - int "Transaction timeout in microseconds [us]" - default 5000 +config DOSE_TIMEOUT_BYTES + int "Transaction timeout in bytes" + default 50 help - Timeout, in microseconds, to bring the driver back into idle state if + Timeout, in bytes at the set baudrate, to bring the driver back into idle state if the remote side died within a transaction. endif # KCONFIG_USEMODULE_DOSE diff --git a/drivers/dose/dose.c b/drivers/dose/dose.c index 6bf97a0ad7..0e82e1b4be 100644 --- a/drivers/dose/dose.c +++ b/drivers/dose/dose.c @@ -599,10 +599,11 @@ void dose_setup(dose_t *ctx, const dose_params_t *params, uint8_t index) * We have to ensure it is above the XTIMER_BACKOFF. Otherwise state * transitions are triggered from another state transition setting up the * timeout. */ - ctx->timeout_base = CONFIG_DOSE_TIMEOUT_USEC; + ctx->timeout_base = CONFIG_DOSE_TIMEOUT_BYTES * 10UL * US_PER_SEC / params->baudrate; if (ctx->timeout_base < xtimer_usec_from_ticks(min_timeout)) { ctx->timeout_base = xtimer_usec_from_ticks(min_timeout); } + DEBUG("dose timeout set to %" PRIu32 " µs\n", ctx->timeout_base); ctx->timeout.callback = _isr_xtimer; ctx->timeout.arg = ctx; } diff --git a/drivers/include/dose.h b/drivers/include/dose.h index 50052fafdb..2b7bcc0e27 100644 --- a/drivers/include/dose.h +++ b/drivers/include/dose.h @@ -128,12 +128,12 @@ typedef enum { * @{ */ /** - * @brief Timeout that brings the driver back into idle state. + * @brief Timeout that brings the driver back into idle state expressed as bytes. * * Fallback to idle if the remote side died within a transaction. */ -#ifndef CONFIG_DOSE_TIMEOUT_USEC -#define CONFIG_DOSE_TIMEOUT_USEC (5000) +#ifndef CONFIG_DOSE_TIMEOUT_BYTES +#define CONFIG_DOSE_TIMEOUT_BYTES (50) #endif /** @} */