Skip to content
Open
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
4 changes: 2 additions & 2 deletions drivers/include/sx126x.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ typedef enum {
STATE_TX,
STATE_ACK,
STATE_RX,
STATE_CCA_CLEAR,
STATE_CCA_BUSY,
STATE_CCA,
} sx126x_state_t;

/**
Expand Down Expand Up @@ -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 */
Expand Down
20 changes: 15 additions & 5 deletions drivers/sx126x/sx126x_radio_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <errno.h>
#include <stdio.h>

#define ENABLE_DEBUG 0
#define ENABLE_DEBUG 1
#include "debug.h"

#include "net/ieee802154/radio.h"
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}

Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tests/ieee802154_hal/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down