drivers/cc2420: register with netdev

This commit is contained in:
Benjamin Valentin 2020-09-11 16:16:50 +02:00 committed by Benjamin Valentin
parent 52314cece8
commit d611a264fd
5 changed files with 14 additions and 16 deletions

View File

@ -1,5 +1,4 @@
USEMODULE += xtimer USEMODULE += xtimer
USEMODULE += luid
USEMODULE += ieee802154 USEMODULE += ieee802154
USEMODULE += netdev_ieee802154 USEMODULE += netdev_ieee802154
FEATURES_REQUIRED += periph_gpio FEATURES_REQUIRED += periph_gpio

View File

@ -20,7 +20,6 @@
* @} * @}
*/ */
#include "luid.h"
#include "byteorder.h" #include "byteorder.h"
#include "net/ieee802154.h" #include "net/ieee802154.h"
#include "net/gnrc.h" #include "net/gnrc.h"
@ -32,32 +31,30 @@
#define ENABLE_DEBUG 0 #define ENABLE_DEBUG 0
#include "debug.h" #include "debug.h"
void cc2420_setup(cc2420_t * dev, const cc2420_params_t *params, uint8_t index)
void cc2420_setup(cc2420_t * dev, const cc2420_params_t *params)
{ {
netdev_t *netdev = &dev->netdev.netdev;
/* set pointer to the devices netdev functions */ /* set pointer to the devices netdev functions */
dev->netdev.netdev.driver = &cc2420_driver; netdev->driver = &cc2420_driver;
/* pull in device configuration parameters */ /* pull in device configuration parameters */
dev->params = *params; dev->params = *params;
dev->state = CC2420_STATE_IDLE; dev->state = CC2420_STATE_IDLE;
/* reset device descriptor fields */ /* reset device descriptor fields */
dev->options = 0; dev->options = 0;
netdev_register(netdev, NETDEV_CC2420, index);
netdev_ieee802154_setup(&dev->netdev);
} }
int cc2420_init(cc2420_t *dev) int cc2420_init(cc2420_t *dev)
{ {
uint16_t reg; uint16_t reg;
uint8_t addr[8];
netdev_ieee802154_reset(&dev->netdev); netdev_ieee802154_reset(&dev->netdev);
/* set default address, channel, PAN ID, and TX power */ cc2420_set_addr_short(dev, dev->netdev.short_addr);
luid_get(addr, sizeof(addr)); cc2420_set_addr_long(dev, dev->netdev.long_addr);
/* make sure we mark the address as non-multicast and not globally unique */
addr[0] &= ~(0x01);
addr[0] |= 0x02;
cc2420_set_addr_short(dev, &addr[6]);
cc2420_set_addr_long(dev, addr);
cc2420_set_chan(dev, CC2420_CHAN_DEFAULT); cc2420_set_chan(dev, CC2420_CHAN_DEFAULT);
cc2420_set_txpower(dev, CC2420_TXPOWER_DEFAULT); cc2420_set_txpower(dev, CC2420_TXPOWER_DEFAULT);
@ -92,7 +89,6 @@ int cc2420_init(cc2420_t *dev)
return 0; return 0;
} }
bool cc2420_cca(cc2420_t *dev) bool cc2420_cca(cc2420_t *dev)
{ {
while (!(cc2420_status(dev) & CC2420_STATUS_RSSI_VALID)) {} while (!(cc2420_status(dev) & CC2420_STATUS_RSSI_VALID)) {}

View File

@ -101,11 +101,13 @@ typedef struct {
* *
* @param[out] dev device descriptor * @param[out] dev device descriptor
* @param[in] params device parameters * @param[in] params device parameters
* @param[in] index index of @p params in a global parameter struct array.
* If initialized manually, pass a unique identifier instead.
* *
* @return 0 on success * @return 0 on success
* @return -1 on error * @return -1 on error
*/ */
void cc2420_setup(cc2420_t *dev, const cc2420_params_t *params); void cc2420_setup(cc2420_t *dev, const cc2420_params_t *params, uint8_t index);
/** /**
* @brief Initialize a given CC2420 device * @brief Initialize a given CC2420 device

View File

@ -319,6 +319,7 @@ typedef enum {
NETDEV_NRF24L01P_NG, NETDEV_NRF24L01P_NG,
NETDEV_SOCKET_ZEP, NETDEV_SOCKET_ZEP,
NETDEV_SX126X, NETDEV_SX126X,
NETDEV_CC2420,
/* add more if needed */ /* add more if needed */
} netdev_type_t; } netdev_type_t;
/** @} */ /** @} */

View File

@ -57,7 +57,7 @@ void auto_init_cc2420(void)
for (unsigned i = 0; i < CC2420_NUMOF; i++) { for (unsigned i = 0; i < CC2420_NUMOF; i++) {
LOG_DEBUG("[auto_init_netif] initializing cc2420 #%u\n", i); LOG_DEBUG("[auto_init_netif] initializing cc2420 #%u\n", i);
cc2420_setup(&cc2420_devs[i], &cc2420_params[i]); cc2420_setup(&cc2420_devs[i], &cc2420_params[i], i);
gnrc_netif_ieee802154_create(&_netif[i], _cc2420_stacks[i], CC2420_MAC_STACKSIZE, gnrc_netif_ieee802154_create(&_netif[i], _cc2420_stacks[i], CC2420_MAC_STACKSIZE,
CC2420_MAC_PRIO, "cc2420", CC2420_MAC_PRIO, "cc2420",
(netdev_t *)&cc2420_devs[i]); (netdev_t *)&cc2420_devs[i]);