mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
nrf802154: unify auto_init for HAL and netdev
This commit is contained in:
parent
c1a9d352f3
commit
46600adf22
@ -36,7 +36,12 @@
|
||||
#ifndef NRF802154_H
|
||||
#define NRF802154_H
|
||||
|
||||
#if !IS_USED(MODULE_IEEE802154_RADIO_HAL)
|
||||
#if IS_USED(MODULE_IEEE802154_RADIO_HAL)
|
||||
#include "net/ieee802154/radio.h"
|
||||
#if IS_USED(MODULE_NETDEV_IEEE802154_SUBMAC)
|
||||
#include "net/netdev/ieee802154_submac.h"
|
||||
#endif
|
||||
#else
|
||||
#include "net/netdev/ieee802154.h"
|
||||
#endif
|
||||
|
||||
@ -44,6 +49,20 @@
|
||||
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 */
|
||||
#elif !IS_USED(MODULE_IEEE802154_RADIO_HAL)
|
||||
netdev_ieee802154_t netdev; /**< ieee802154 device descriptor */
|
||||
#endif
|
||||
} nrf802154_t;
|
||||
|
||||
/**
|
||||
* @defgroup drivers_nrf52_802154_conf nrf802154 driver compile configuration
|
||||
* @ingroup drivers_nrf52_802154
|
||||
@ -61,13 +80,6 @@ extern "C" {
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
#if !IS_USED(MODULE_IEEE802154_RADIO_HAL)
|
||||
/**
|
||||
* @brief Export the netdev device descriptor
|
||||
*/
|
||||
extern netdev_ieee802154_t nrf802154_dev;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief IEEE 802.15.4 radio timer configuration
|
||||
*
|
||||
@ -86,5 +98,12 @@ extern netdev_ieee802154_t nrf802154_dev;
|
||||
*/
|
||||
int nrf802154_init(void);
|
||||
|
||||
/**
|
||||
* @brief Setup a NRF802154 radio device for use with netdev
|
||||
*
|
||||
* @param[out] dev Device descriptor
|
||||
*/
|
||||
void nrf802154_setup(nrf802154_t *dev);
|
||||
|
||||
#endif /* NRF802154_H */
|
||||
/** @} */
|
||||
|
@ -37,28 +37,9 @@
|
||||
|
||||
static const netdev_driver_t nrf802154_netdev_driver;
|
||||
|
||||
netdev_ieee802154_t nrf802154_dev = {
|
||||
{
|
||||
.driver = &nrf802154_netdev_driver,
|
||||
.event_callback = NULL,
|
||||
.context = NULL,
|
||||
},
|
||||
#ifdef MODULE_GNRC
|
||||
#ifdef MODULE_GNRC_SIXLOWPAN
|
||||
.proto = GNRC_NETTYPE_SIXLOWPAN,
|
||||
#else
|
||||
.proto = GNRC_NETTYPE_UNDEF,
|
||||
#endif
|
||||
#endif
|
||||
.pan = CONFIG_IEEE802154_DEFAULT_PANID,
|
||||
.short_addr = { 0, 0 },
|
||||
.long_addr = { 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
.chan = CONFIG_IEEE802154_DEFAULT_CHANNEL,
|
||||
.flags = 0
|
||||
};
|
||||
|
||||
static uint8_t rxbuf[IEEE802154_FRAME_LEN_MAX + 3]; /* len PHR + PSDU + LQI */
|
||||
static uint8_t txbuf[IEEE802154_FRAME_LEN_MAX + 3]; /* len PHR + PSDU + LQI */
|
||||
static netdev_ieee802154_t *nrf802154_dev;
|
||||
|
||||
#define ED_RSSISCALE (4U)
|
||||
#define ED_RSSIOFFS (-92)
|
||||
@ -197,7 +178,7 @@ static void _set_chan(uint16_t chan)
|
||||
/* Channel map between 2400 MHZ ... 2500 MHz
|
||||
* -> Frequency = 2400 + FREQUENCY (MHz) */
|
||||
NRF_RADIO->FREQUENCY = (chan - 10) * 5;
|
||||
nrf802154_dev.chan = chan;
|
||||
nrf802154_dev->chan = chan;
|
||||
}
|
||||
|
||||
static int16_t _get_txpower(void)
|
||||
@ -252,7 +233,7 @@ static int _init(netdev_t *dev)
|
||||
{
|
||||
(void)dev;
|
||||
|
||||
netdev_register(&nrf802154_dev.netdev, NETDEV_NRF802154, 0);
|
||||
netdev_register(&nrf802154_dev->netdev, NETDEV_NRF802154, 0);
|
||||
|
||||
int result = timer_init(NRF802154_TIMER, TIMER_FREQ, _timer_cb, NULL);
|
||||
assert(result >= 0);
|
||||
@ -295,10 +276,11 @@ static int _init(netdev_t *dev)
|
||||
NRF_RADIO->MODECNF0 |= RADIO_MODECNF0_RU_Msk;
|
||||
|
||||
/* assign default addresses */
|
||||
netdev_ieee802154_setup(&nrf802154_dev);
|
||||
netdev_ieee802154_setup(nrf802154_dev);
|
||||
|
||||
nrf802154_dev->chan = CONFIG_IEEE802154_DEFAULT_CHANNEL;
|
||||
/* set default channel */
|
||||
_set_chan(nrf802154_dev.chan);
|
||||
_set_chan(nrf802154_dev->chan);
|
||||
|
||||
/* set default CCA threshold */
|
||||
_set_cca_thresh(CONFIG_NRF802154_CCA_THRESH_DEFAULT);
|
||||
@ -411,14 +393,14 @@ static int _recv(netdev_t *dev, void *buf, size_t len, void *info)
|
||||
|
||||
static void _isr(netdev_t *dev)
|
||||
{
|
||||
if (!nrf802154_dev.netdev.event_callback) {
|
||||
if (!nrf802154_dev->netdev.event_callback) {
|
||||
return;
|
||||
}
|
||||
if (_state & RX_COMPLETE) {
|
||||
nrf802154_dev.netdev.event_callback(dev, NETDEV_EVENT_RX_COMPLETE);
|
||||
nrf802154_dev->netdev.event_callback(dev, NETDEV_EVENT_RX_COMPLETE);
|
||||
}
|
||||
if (_state & TX_COMPLETE) {
|
||||
nrf802154_dev.netdev.event_callback(dev, NETDEV_EVENT_TX_COMPLETE);
|
||||
nrf802154_dev->netdev.event_callback(dev, NETDEV_EVENT_TX_COMPLETE);
|
||||
_state &= ~TX_COMPLETE;
|
||||
}
|
||||
}
|
||||
@ -436,7 +418,7 @@ static int _get(netdev_t *dev, netopt_t opt, void *value, size_t max_len)
|
||||
switch (opt) {
|
||||
case NETOPT_CHANNEL:
|
||||
assert(max_len >= sizeof(uint16_t));
|
||||
*((uint16_t *)value) = nrf802154_dev.chan;
|
||||
*((uint16_t *)value) = nrf802154_dev->chan;
|
||||
return sizeof(uint16_t);
|
||||
case NETOPT_TX_POWER:
|
||||
assert(max_len >= sizeof(int16_t));
|
||||
@ -503,9 +485,9 @@ void isr_radio(void)
|
||||
switch(state) {
|
||||
case RADIO_STATE_STATE_RxIdle:
|
||||
/* only process packet if event callback is set and CRC is valid */
|
||||
if ((nrf802154_dev.netdev.event_callback) &&
|
||||
if ((nrf802154_dev->netdev.event_callback) &&
|
||||
(NRF_RADIO->CRCSTATUS == 1) &&
|
||||
(netdev_ieee802154_dst_filter(&nrf802154_dev,
|
||||
(netdev_ieee802154_dst_filter(nrf802154_dev,
|
||||
&rxbuf[1]) == 0)) {
|
||||
_state |= RX_COMPLETE;
|
||||
}
|
||||
@ -525,7 +507,7 @@ void isr_radio(void)
|
||||
DEBUG("[nrf802154] Unhandled state: %x\n", (uint8_t)NRF_RADIO->STATE);
|
||||
}
|
||||
if (_state) {
|
||||
netdev_trigger_event_isr(&nrf802154_dev.netdev);
|
||||
netdev_trigger_event_isr(&nrf802154_dev->netdev);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -535,6 +517,17 @@ void isr_radio(void)
|
||||
cortexm_isr_end();
|
||||
}
|
||||
|
||||
void nrf802154_setup(nrf802154_t *dev)
|
||||
{
|
||||
netdev_t *netdev = (netdev_t*) dev;
|
||||
netdev_ieee802154_t *netdev_ieee802154 = (netdev_ieee802154_t*) dev;
|
||||
nrf802154_dev = netdev_ieee802154;
|
||||
|
||||
netdev->driver = &nrf802154_netdev_driver;
|
||||
netdev_register(netdev, NETDEV_NRF802154, 0);
|
||||
netdev_ieee802154_reset(netdev_ieee802154);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Export of the netdev interface
|
||||
*/
|
||||
|
@ -714,6 +714,15 @@ static int _set_csma_params(ieee802154_dev_t *dev, const ieee802154_csma_be_t *b
|
||||
return 0;
|
||||
}
|
||||
|
||||
void nrf802154_setup(nrf802154_t *dev)
|
||||
{
|
||||
(void) dev;
|
||||
#if IS_USED(MODULE_NETDEV_IEEE802154_SUBMAC)
|
||||
netdev_ieee802154_submac_init(&dev->netdev, &nrf802154_hal_dev);
|
||||
#endif
|
||||
nrf802154_init();
|
||||
}
|
||||
|
||||
static const ieee802154_radio_ops_t nrf802154_ops = {
|
||||
.write = _write,
|
||||
.read = _read,
|
||||
|
@ -22,9 +22,6 @@
|
||||
#include "nrf802154.h"
|
||||
#include "net/gnrc/netif/ieee802154.h"
|
||||
|
||||
#include "net/ieee802154/radio.h"
|
||||
#include "net/netdev/ieee802154_submac.h"
|
||||
|
||||
/**
|
||||
* @brief Define stack parameters for the MAC layer thread
|
||||
* @{
|
||||
@ -40,27 +37,16 @@
|
||||
static char _stack[NRF802154_MAC_STACKSIZE];
|
||||
static gnrc_netif_t _netif;
|
||||
|
||||
#if IS_USED(MODULE_IEEE802154_RADIO_HAL)
|
||||
extern ieee802154_dev_t nrf802154_hal_dev;
|
||||
static netdev_ieee802154_submac_t nrf802154_submac;
|
||||
#endif
|
||||
static nrf802154_t nrf802154_dev;
|
||||
|
||||
void auto_init_nrf802154(void)
|
||||
{
|
||||
LOG_DEBUG("[auto_init_netif] initializing nrf802154\n");
|
||||
|
||||
netdev_t *netdev;
|
||||
#if IS_USED(MODULE_IEEE802154_RADIO_HAL)
|
||||
netdev_ieee802154_submac_init(&nrf802154_submac, &nrf802154_hal_dev);
|
||||
netdev = (netdev_t*) &nrf802154_submac;
|
||||
nrf802154_init();
|
||||
#else
|
||||
netdev = (netdev_t*) &nrf802154_dev;
|
||||
#endif
|
||||
|
||||
nrf802154_setup(&nrf802154_dev);
|
||||
gnrc_netif_ieee802154_create(&_netif, _stack,
|
||||
NRF802154_MAC_STACKSIZE,
|
||||
NRF802154_MAC_PRIO, "nrf802154",
|
||||
netdev);
|
||||
(netdev_t *)&nrf802154_dev);
|
||||
}
|
||||
/** @} */
|
||||
|
Loading…
Reference in New Issue
Block a user