Skip to content

Commit

Permalink
Merge pull request #15012 from benpicco/driver/cc2420-register
Browse files Browse the repository at this point in the history
drivers/cc2420: register with netdev
  • Loading branch information
benpicco committed Apr 27, 2021
2 parents 52314ce + d611a26 commit 494ef67
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
1 change: 0 additions & 1 deletion drivers/cc2420/Makefile.dep
@@ -1,5 +1,4 @@
USEMODULE += xtimer
USEMODULE += luid
USEMODULE += ieee802154
USEMODULE += netdev_ieee802154
FEATURES_REQUIRED += periph_gpio
Expand Down
22 changes: 9 additions & 13 deletions drivers/cc2420/cc2420.c
Expand Up @@ -20,7 +20,6 @@
* @}
*/

#include "luid.h"
#include "byteorder.h"
#include "net/ieee802154.h"
#include "net/gnrc.h"
Expand All @@ -32,32 +31,30 @@
#define ENABLE_DEBUG 0
#include "debug.h"


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)
{
netdev_t *netdev = &dev->netdev.netdev;

/* set pointer to the devices netdev functions */
dev->netdev.netdev.driver = &cc2420_driver;
netdev->driver = &cc2420_driver;
/* pull in device configuration parameters */
dev->params = *params;
dev->state = CC2420_STATE_IDLE;
/* reset device descriptor fields */
dev->options = 0;

netdev_register(netdev, NETDEV_CC2420, index);
netdev_ieee802154_setup(&dev->netdev);
}

int cc2420_init(cc2420_t *dev)
{
uint16_t reg;
uint8_t addr[8];

netdev_ieee802154_reset(&dev->netdev);

/* set default address, channel, PAN ID, and TX power */
luid_get(addr, sizeof(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_addr_short(dev, dev->netdev.short_addr);
cc2420_set_addr_long(dev, dev->netdev.long_addr);
cc2420_set_chan(dev, CC2420_CHAN_DEFAULT);
cc2420_set_txpower(dev, CC2420_TXPOWER_DEFAULT);

Expand Down Expand Up @@ -92,7 +89,6 @@ int cc2420_init(cc2420_t *dev)
return 0;
}


bool cc2420_cca(cc2420_t *dev)
{
while (!(cc2420_status(dev) & CC2420_STATUS_RSSI_VALID)) {}
Expand Down
4 changes: 3 additions & 1 deletion drivers/include/cc2420.h
Expand Up @@ -101,11 +101,13 @@ typedef struct {
*
* @param[out] dev device descriptor
* @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 -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
Expand Down
1 change: 1 addition & 0 deletions drivers/include/net/netdev.h
Expand Up @@ -319,6 +319,7 @@ typedef enum {
NETDEV_NRF24L01P_NG,
NETDEV_SOCKET_ZEP,
NETDEV_SX126X,
NETDEV_CC2420,
/* add more if needed */
} netdev_type_t;
/** @} */
Expand Down
2 changes: 1 addition & 1 deletion sys/net/gnrc/netif/init_devs/auto_init_cc2420.c
Expand Up @@ -57,7 +57,7 @@ void auto_init_cc2420(void)
for (unsigned i = 0; i < CC2420_NUMOF; 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,
CC2420_MAC_PRIO, "cc2420",
(netdev_t *)&cc2420_devs[i]);
Expand Down

0 comments on commit 494ef67

Please sign in to comment.