From c382d5819e003fea7f394868472f8a606e26343b Mon Sep 17 00:00:00 2001 From: GUVWAF Date: Mon, 9 Oct 2023 19:14:16 +0200 Subject: [PATCH] Wait for `SX126X_IRQ_CAD_DONE` flag before Tx --- drivers/include/sx126x.h | 4 ++-- drivers/sx126x/sx126x_radio_hal.c | 20 +++++++++++++++----- tests/ieee802154_hal/Makefile | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/include/sx126x.h b/drivers/include/sx126x.h index c40aa1e5268a..0bfe13c96209 100644 --- a/drivers/include/sx126x.h +++ b/drivers/include/sx126x.h @@ -89,8 +89,7 @@ typedef enum { STATE_TX, STATE_ACK, STATE_RX, - STATE_CCA_CLEAR, - STATE_CCA_BUSY, + STATE_CCA, } sx126x_state_t; /** @@ -127,6 +126,7 @@ struct sx126x { bool radio_sleep; /**< Radio sleep status */ sx126x_cad_params_t cad_params; /**< Radio Channel Activity Detection parametres */ bool cad_detected; /**< Channel Activity Detected Flag*/ + bool cad_done; /**< Channel Activity Detection Done Flag*/ bool ifs : 1; /**< if true, the device is currently inside the IFS period */ bool cca_send : 1; /**< whether the next transmission uses CCA or not */ diff --git a/drivers/sx126x/sx126x_radio_hal.c b/drivers/sx126x/sx126x_radio_hal.c index 32c960f392a8..1a4f73744d96 100644 --- a/drivers/sx126x/sx126x_radio_hal.c +++ b/drivers/sx126x/sx126x_radio_hal.c @@ -20,7 +20,7 @@ #include #include -#define ENABLE_DEBUG 0 +#define ENABLE_DEBUG 1 #include "debug.h" #include "net/ieee802154/radio.h" @@ -205,6 +205,12 @@ static int _set_state(sx126x_t *dev, sx126x_state_t state) sx126x_set_tx(dev, 0); break; + case STATE_CCA: + DEBUG("[sx126x] netdev: set STATE_CCA\n"); + dev->cad_done = false; + sx126x_set_cad(dev); + break; + default: return -ENOTSUP; } @@ -336,10 +342,10 @@ void sx126x_hal_task_handler(ieee802154_dev_t *hal) if (irq_mask & SX126X_IRQ_CAD_DETECTED){ DEBUG("[sx126x] netdev: SX126X_IRQ_CAD_DETECTED \n"); dev->cad_detected = true; + hal->cb(hal, IEEE802154_RADIO_CONFIRM_TX_DONE); } DEBUG("[sx126x] netdev: SX126X_IRQ_CAD_DONE\n"); - hal->cb(hal, IEEE802154_RADIO_CONFIRM_CCA); - _set_state(dev, STATE_RX); + dev->cad_done = true; } else if (irq_mask & SX126X_IRQ_TIMEOUT) { @@ -413,7 +419,7 @@ static int _request_op(ieee802154_dev_t *hal, ieee802154_hal_op_t op, void *ctx) DEBUG("[sx126x] netdev: HAL_OP_CCA (CAD Detection state)\n"); dev->cad_detected = 0; _set_state(dev, STATE_IDLE); - sx126x_set_cad(dev); + _set_state(dev, STATE_CCA); break; @@ -437,7 +443,7 @@ static int _confirm_op(ieee802154_dev_t *hal, ieee802154_hal_op_t op, void *ctx) switch (op){ case IEEE802154_HAL_OP_TRANSMIT: - if (info) { + if (info) { info->status = (dev->cad_detected) ? TX_STATUS_MEDIUM_BUSY : TX_STATUS_SUCCESS; } @@ -454,7 +460,11 @@ switch (op){ break; case IEEE802154_HAL_OP_CCA: + if (!dev->cad_done) + eagain = true; + else { *((bool*) ctx) = !dev->cad_detected; + } break; default: diff --git a/tests/ieee802154_hal/Makefile b/tests/ieee802154_hal/Makefile index 86771e5ce60c..78c5aa303c4a 100644 --- a/tests/ieee802154_hal/Makefile +++ b/tests/ieee802154_hal/Makefile @@ -19,6 +19,7 @@ BOARD_WHITELIST := \ pba-d-01-kw2x \ rak3172 \ lora2w \ + lora-e5-dev \ # DISABLE_MODULE += auto_init_at86rf2xx auto_init_nrf802154 auto_init_sx126x