mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/cc2420: register with netdev
This commit is contained in:
parent
52314cece8
commit
d611a264fd
@ -1,5 +1,4 @@
|
||||
USEMODULE += xtimer
|
||||
USEMODULE += luid
|
||||
USEMODULE += ieee802154
|
||||
USEMODULE += netdev_ieee802154
|
||||
FEATURES_REQUIRED += periph_gpio
|
||||
|
@ -20,7 +20,6 @@
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "luid.h"
|
||||
#include "byteorder.h"
|
||||
#include "net/ieee802154.h"
|
||||
#include "net/gnrc.h"
|
||||
@ -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);
|
||||
|
||||
@ -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)) {}
|
||||
|
@ -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
|
||||
|
@ -319,6 +319,7 @@ typedef enum {
|
||||
NETDEV_NRF24L01P_NG,
|
||||
NETDEV_SOCKET_ZEP,
|
||||
NETDEV_SX126X,
|
||||
NETDEV_CC2420,
|
||||
/* add more if needed */
|
||||
} netdev_type_t;
|
||||
/** @} */
|
||||
|
@ -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]);
|
||||
|
Loading…
Reference in New Issue
Block a user