Skip to content
Merged
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
20 changes: 10 additions & 10 deletions cpu/cc2538/include/cc2538_rf.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
#include "kernel_defines.h"

#include "net/ieee802154/radio.h"
#if IS_USED(MODULE_NETDEV_IEEE802154_SUBMAC)
#include "net/netdev/ieee802154_submac.h"
#endif

#include "net/netopt.h"

Expand Down Expand Up @@ -285,17 +282,20 @@ enum {

/**
* @brief Device descriptor for CC2538 transceiver
*
* @extends netdev_ieee802154_t if using legacy radio
* @extends netdev_ieee802154_submac_t if using radio HAL
*/
typedef struct {
#if IS_USED(MODULE_NETDEV_IEEE802154_SUBMAC)
netdev_ieee802154_submac_t netdev; /**< netdev parent struct */
#endif
uint8_t state; /**< current state of the radio */
} cc2538_rf_t;

/**
* @brief Setup CC2538 in order to be used with the IEEE 802.15.4 Radio HAL
*
* @note This functions MUST be called before @ref cc2538_init.
*
* @param[in] hal pointer to the HAL descriptor associated to the device.
*/
void cc2538_rf_hal_setup(ieee802154_dev_t *hal);

/**
* @brief IRQ handler for RF events
*
Expand Down Expand Up @@ -380,7 +380,7 @@ void cc2538_off(void);
bool cc2538_on(void);

/**
* @brief Setup a CC2538 radio device for use with netdev
* @brief Setup a CC2538 radio device
*
* @param[out] dev Device descriptor
*/
Expand Down
39 changes: 0 additions & 39 deletions cpu/cc2538/include/cc2538_rf_netdev.h

This file was deleted.

6 changes: 0 additions & 6 deletions cpu/cc2538/radio/cc2538_rf.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "periph_conf.h"

#include "cc2538_rf.h"
#include "cc2538_rf_netdev.h"

#define ENABLE_DEBUG 0
#include "debug.h"
Expand Down Expand Up @@ -211,10 +210,5 @@ bool cc2538_on(void)
void cc2538_setup(cc2538_rf_t *dev)
{
(void) dev;
#if IS_USED(MODULE_NETDEV_IEEE802154_SUBMAC)
extern ieee802154_dev_t cc2538_rf_dev;
netdev_register(&dev->netdev.dev.netdev, NETDEV_CC2538, 0);
netdev_ieee802154_submac_init(&dev->netdev, &cc2538_rf_dev);
#endif
cc2538_init();
}
1 change: 0 additions & 1 deletion cpu/cc2538/radio/cc2538_rf_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "cpu.h"
#include "cc2538.h"
#include "cc2538_rf.h"
#include "cc2538_rf_netdev.h"
#include "cc2538_rf_internal.h"

#define ENABLE_DEBUG 0
Expand Down
27 changes: 17 additions & 10 deletions cpu/cc2538/radio/cc2538_rf_radio_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@

static const ieee802154_radio_ops_t cc2538_rf_ops;

ieee802154_dev_t cc2538_rf_dev = {
.driver = &cc2538_rf_ops,
};
static ieee802154_dev_t *cc2538_rf_hal;

static bool cc2538_tx_busy; /**< used to indicate TX chain is busy */
static bool cc2538_rx_busy; /**< used to indicate RX chain is busy */
Expand Down Expand Up @@ -332,21 +330,21 @@ void cc2538_irq_handler(void)
if ((flags_f0 & SFD)) {
/* If the radio already transmitted, this SFD is the TX_START event */
if (cc2538_tx_busy) {
cc2538_rf_dev.cb(&cc2538_rf_dev, IEEE802154_RADIO_INDICATION_TX_START);
cc2538_rf_hal->cb(cc2538_rf_hal, IEEE802154_RADIO_INDICATION_TX_START);
}
/* If the RX chain was not busy, the detected SFD corresponds to a new
* incoming frame. Note the automatic ACK frame also triggers this event.
* Therefore, we use this variable to distinguish them. */
else if (!cc2538_rx_busy){
cc2538_rx_busy = true;
cc2538_rf_dev.cb(&cc2538_rf_dev, IEEE802154_RADIO_INDICATION_RX_START);
cc2538_rf_hal->cb(cc2538_rf_hal, IEEE802154_RADIO_INDICATION_RX_START);
}
}

if (flags_f1 & TXDONE) {
/* TXDONE marks the end of the TX chain. The radio is not busy anymore */
cc2538_tx_busy = false;
cc2538_rf_dev.cb(&cc2538_rf_dev, IEEE802154_RADIO_CONFIRM_TX_DONE);
cc2538_rf_hal->cb(cc2538_rf_hal, IEEE802154_RADIO_CONFIRM_TX_DONE);
}

if (flags_f0 & RXPKTDONE) {
Expand All @@ -363,14 +361,14 @@ void cc2538_irq_handler(void)
*/
cc2538_rx_busy = false;
}
cc2538_rf_dev.cb(&cc2538_rf_dev, IEEE802154_RADIO_INDICATION_RX_DONE);
cc2538_rf_hal->cb(cc2538_rf_hal, IEEE802154_RADIO_INDICATION_RX_DONE);
}
else {
/* Disable RX while the frame has not been processed */
RFCORE_XREG_RXMASKCLR = 0xFF;
/* CRC failed; discard packet. The RX chain is not busy anymore */
cc2538_rx_busy = false;
cc2538_rf_dev.cb(&cc2538_rf_dev, IEEE802154_RADIO_INDICATION_CRC_ERROR);
cc2538_rf_hal->cb(cc2538_rf_hal, IEEE802154_RADIO_INDICATION_CRC_ERROR);
}
}

Expand All @@ -392,13 +390,13 @@ void cc2538_irq_handler(void)
else {
/* In case of CCA failure the TX chain is not busy anymore */
cc2538_tx_busy = false;
cc2538_rf_dev.cb(&cc2538_rf_dev, IEEE802154_RADIO_CONFIRM_TX_DONE);
cc2538_rf_hal->cb(cc2538_rf_hal, IEEE802154_RADIO_CONFIRM_TX_DONE);
}
}
else {
cc2538_cca_status = BOOLEAN(RFCORE->XREG_FSMSTAT1bits.CCA)
&& RFCORE->XREG_RSSISTATbits.RSSI_VALID;
cc2538_rf_dev.cb(&cc2538_rf_dev, IEEE802154_RADIO_CONFIRM_CCA);
cc2538_rf_hal->cb(cc2538_rf_hal, IEEE802154_RADIO_CONFIRM_CCA);
}
}
}
Expand Down Expand Up @@ -536,6 +534,15 @@ static int _set_frame_filter_mode(ieee802154_dev_t *dev, ieee802154_filter_mode_
return 0;

}

void cc2538_rf_hal_setup(ieee802154_dev_t *hal)
{
/* We don't set hal->priv because the context of this device is global */
/* We need to store a reference to the HAL descriptor though for the ISR */
hal->driver = &cc2538_rf_ops;
cc2538_rf_hal = hal;
}

static const ieee802154_radio_ops_t cc2538_rf_ops = {
.caps = IEEE802154_CAP_24_GHZ
| IEEE802154_CAP_AUTO_CSMA
Expand Down
23 changes: 11 additions & 12 deletions cpu/nrf52/include/nrf802154.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,15 @@
#define NRF802154_H

#include "net/ieee802154/radio.h"
#if IS_USED(MODULE_NETDEV_IEEE802154_SUBMAC)
#include "net/netdev/ieee802154_submac.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Device descriptor for NRF802154 transceiver
*
* @extends netdev_ieee802154_t if using legacy radio
* @extends netdev_ieee802154_submac_t if using radio HAL
*/
typedef struct {
#if IS_USED(MODULE_NETDEV_IEEE802154_SUBMAC)
netdev_ieee802154_submac_t netdev; /**< netdev SubMAC descriptor */
#endif
} nrf802154_t;
typedef struct nrf802154 nrf802154_t;

/**
* @defgroup drivers_nrf52_802154_conf nrf802154 driver compile configuration
Expand Down Expand Up @@ -84,6 +74,15 @@ typedef struct {
#define NRF802154_TIMER TIMER_DEV(1)
#endif

/**
* @brief Setup NRF802154 in order to be used with the IEEE 802.15.4 Radio HAL
*
* @note This functions MUST be called before @ref nrf802154_init.
*
* @param[in] hal pointer to the HAL descriptor associated to the device.
*/
void nrf802154_hal_setup(ieee802154_dev_t *hal);

/**
* @brief Initialize the NRF52840 radio.
*
Expand All @@ -93,7 +92,7 @@ typedef struct {
int nrf802154_init(void);

/**
* @brief Setup a NRF802154 radio device for use with netdev
* @brief Setup a NRF802154 radio device
*
* @param[out] dev Device descriptor
*/
Expand Down
25 changes: 11 additions & 14 deletions cpu/nrf52/radio/nrf802154/nrf802154_radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ static struct {
};

static const ieee802154_radio_ops_t nrf802154_ops;

ieee802154_dev_t nrf802154_hal_dev = {
.driver = &nrf802154_ops,
};
static ieee802154_dev_t *nrf802154_hal_dev;

static void _power_on(void)
{
Expand Down Expand Up @@ -428,7 +425,7 @@ static int _request_set_trx_state(ieee802154_dev_t *dev, ieee802154_trx_state_t
static void _timer_cb(void *arg, int chan)
{
(void)arg;
ieee802154_dev_t *dev = &nrf802154_hal_dev;
ieee802154_dev_t *dev = nrf802154_hal_dev;

if (chan == MAC_TIMER_CHAN_ACK) {
/* Copy sqn */
Expand Down Expand Up @@ -477,7 +474,7 @@ int nrf802154_init(void)

void isr_radio(void)
{
ieee802154_dev_t *dev = &nrf802154_hal_dev;
ieee802154_dev_t *dev = nrf802154_hal_dev;

if (NRF_RADIO->EVENTS_FRAMESTART) {
NRF_RADIO->EVENTS_FRAMESTART = 0;
Expand Down Expand Up @@ -783,17 +780,17 @@ static int _set_csma_params(ieee802154_dev_t *dev, const ieee802154_csma_be_t *b
void nrf802154_setup(nrf802154_t *dev)
{
(void) dev;
#if IS_USED(MODULE_NETDEV_IEEE802154_SUBMAC)
netdev_ieee802154_submac_t *netdev_submac = &dev->netdev;
netdev_ieee802154_t *netdev_ieee802154 = &netdev_submac->dev;
netdev_t *netdev = &netdev_ieee802154->netdev;
netdev_register(netdev, NETDEV_NRF802154, 0);
DEBUG("[nrf802154] init submac.\n")
netdev_ieee802154_submac_init(&dev->netdev, &nrf802154_hal_dev);
#endif
nrf802154_init();
}

void nrf802154_hal_setup(ieee802154_dev_t *hal)
{
/* We don't set hal->priv because the context of this device is global */
/* We need to store a reference to the HAL descriptor though for the ISR */
hal->driver = &nrf802154_ops;
nrf802154_hal_dev = hal;
}

static const ieee802154_radio_ops_t nrf802154_ops = {
.caps = IEEE802154_CAP_24_GHZ
| IEEE802154_CAP_IRQ_CRC_ERROR
Expand Down
5 changes: 2 additions & 3 deletions drivers/include/net/netdev/ieee802154_submac.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@ typedef struct {
* @brief Init the IEEE 802.15.4 SubMAC netdev adoption.
*
* @param[in] netdev_submac pointer to the netdev submac descriptor.
* @param[in] dev pointer to the device associated to @p netdev_submac.
*
* @return 0 on success.
* @return negative errno on failure.
*/
int netdev_ieee802154_submac_init(netdev_ieee802154_submac_t *netdev_submac,
ieee802154_dev_t *dev);
int netdev_ieee802154_submac_init(netdev_ieee802154_submac_t *netdev_submac);

#ifdef __cplusplus
}
#endif
Expand Down
9 changes: 3 additions & 6 deletions drivers/netdev_ieee802154_submac/netdev_ieee802154_submac.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ static const ieee802154_submac_cb_t _cb = {
/* Event Notification callback */
static void _hal_radio_cb(ieee802154_dev_t *dev, ieee802154_trx_ev_t status)
{
ieee802154_submac_t *submac = dev->ctx;
ieee802154_submac_t *submac = container_of(dev, ieee802154_submac_t, dev);
netdev_ieee802154_submac_t *netdev_submac = container_of(submac,
netdev_ieee802154_submac_t,
submac);
Expand Down Expand Up @@ -329,20 +329,17 @@ static int _init(netdev_t *netdev)
return 0;
}

int netdev_ieee802154_submac_init(netdev_ieee802154_submac_t *netdev_submac,
ieee802154_dev_t *dev)
int netdev_ieee802154_submac_init(netdev_ieee802154_submac_t *netdev_submac)
{
netdev_t *netdev = &netdev_submac->dev.netdev;

netdev->driver = &netdev_submac_driver;
ieee802154_submac_t *submac = &netdev_submac->submac;

submac->dev = dev;
submac->cb = &_cb;
submac->dev->ctx = submac;

/* Set the Event Notification */
submac->dev->cb = _hal_radio_cb;
submac->dev.cb = _hal_radio_cb;

netdev_submac->ack_timer.callback = _ack_timeout;
netdev_submac->ack_timer.arg = netdev_submac;
Expand Down
14 changes: 11 additions & 3 deletions pkg/lwip/contrib/lwip.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
#include "nrf802154.h"
#endif

#if IS_USED(MODULE_NETDEV_IEEE802154_SUBMAC)
#include "net/netdev/ieee802154_submac.h"
#endif

#include "lwip.h"

#define ENABLE_DEBUG 0
Expand Down Expand Up @@ -170,7 +174,7 @@ extern void stm32_eth_netdev_setup(netdev_t *netdev);
#endif

#ifdef MODULE_NRF802154
static nrf802154_t nrf802154_dev;
static netdev_ieee802154_submac_t nrf802154_netdev;
#endif

void lwip_bootstrap(void)
Expand Down Expand Up @@ -263,8 +267,12 @@ void lwip_bootstrap(void)
return;
}
#elif defined(MODULE_NRF802154)
nrf802154_setup(&nrf802154_dev);
if (netif_add_noaddr(&netif[0], &nrf802154_dev.netdev.dev.netdev, lwip_netdev_init,
netdev_register(&nrf802154_netdev.dev.netdev, NETDEV_NRF802154, 0);
netdev_ieee802154_submac_init(&nrf802154_netdev);

nrf802154_hal_setup(&nrf802154_netdev.submac.dev);
nrf802154_init();
if (netif_add_noaddr(&netif[0], &nrf802154_netdev.dev.netdev, lwip_netdev_init,
tcpip_6lowpan_input) == NULL) {
DEBUG("Could not add nrf802154 device\n");
return;
Expand Down
Loading