Skip to content

Commit

Permalink
at86rf2xx: port to netdev2
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Jan 24, 2016
1 parent 8d93a54 commit 21b8558
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 471 deletions.
4 changes: 4 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ ifneq (,$(filter nhdp,$(USEMODULE)))
USEMODULE += oonf_rfc5444
endif

ifneq (,$(filter at86rf2%,$(USEMODULE)))
USEMODULE += netdev2_ieee802154
endif

ifneq (,$(filter netdev2_ieee802154,$(USEMODULE)))
USEMODULE += ieee802154
endif
Expand Down
2 changes: 1 addition & 1 deletion boards/fox/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ifneq (,$(filter gnrc_netif_default,$(USEMODULE)))
USEMODULE += at86rf231
USEMODULE += gnrc_nomac
USEMODULE += gnrc_netdev2
endif

ifneq (,$(filter saul_default,$(USEMODULE)))
Expand Down
2 changes: 1 addition & 1 deletion boards/iotlab-m3/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ifneq (,$(filter gnrc_netif_default,$(USEMODULE)))
USEMODULE += at86rf231
USEMODULE += gnrc_nomac
USEMODULE += gnrc_netdev2
endif

ifneq (,$(filter saul_default,$(USEMODULE)))
Expand Down
2 changes: 1 addition & 1 deletion boards/mulle/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ifneq (,$(filter gnrc_netif_default,$(USEMODULE)))
USEMODULE += at86rf212b
USEMODULE += gnrc_nomac
USEMODULE += gnrc_netdev2
endif

# The RTT clock drives the core clock in the default configuration
Expand Down
2 changes: 1 addition & 1 deletion boards/samr21-xpro/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ifneq (,$(filter gnrc_netif_default,$(USEMODULE)))
USEMODULE += at86rf233
USEMODULE += gnrc_nomac
USEMODULE += gnrc_netdev2
endif

ifneq (,$(filter saul_default,$(USEMODULE)))
Expand Down
58 changes: 12 additions & 46 deletions drivers/at86rf2xx/at86rf2xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,9 @@
#include "debug.h"


static void _irq_handler(void *arg)
{
msg_t msg;
at86rf2xx_t *dev = (at86rf2xx_t *) arg;

/* tell driver thread about the interrupt */
msg.type = GNRC_NETDEV_MSG_TYPE_EVENT;
msg_send(&msg, dev->mac_pid);
}

int at86rf2xx_init(at86rf2xx_t *dev, spi_t spi, spi_speed_t spi_speed,
gpio_t cs_pin, gpio_t int_pin,
gpio_t sleep_pin, gpio_t reset_pin)
void at86rf2xx_setup(at86rf2xx_t *dev, spi_t spi, spi_speed_t spi_speed,
gpio_t cs_pin, gpio_t int_pin, gpio_t sleep_pin,
gpio_t reset_pin)
{
dev->driver = &at86rf2xx_driver;

Expand All @@ -59,32 +49,8 @@ int at86rf2xx_init(at86rf2xx_t *dev, spi_t spi, spi_speed_t spi_speed,
dev->reset_pin = reset_pin;
dev->idle_state = AT86RF2XX_STATE_TRX_OFF;
dev->state = AT86RF2XX_STATE_SLEEP;

/* initialise SPI */
spi_init_master(dev->spi, SPI_CONF_FIRST_RISING, spi_speed);
/* initialise GPIOs */
gpio_init(dev->cs_pin, GPIO_DIR_OUT, GPIO_NOPULL);
gpio_set(dev->cs_pin);
gpio_init(dev->sleep_pin, GPIO_DIR_OUT, GPIO_NOPULL);
gpio_clear(dev->sleep_pin);
gpio_init(dev->reset_pin, GPIO_DIR_OUT, GPIO_NOPULL);
gpio_set(dev->reset_pin);
gpio_init_int(dev->int_pin, GPIO_NOPULL, GPIO_RISING, _irq_handler, dev);

/* make sure device is not sleeping, so we can query part number */
at86rf2xx_assert_awake(dev);

/* test if the SPI is set up correctly and the device is responding */
if (at86rf2xx_reg_read(dev, AT86RF2XX_REG__PART_NUM) !=
AT86RF2XX_PARTNUM) {
DEBUG("[at86rf2xx] error: unable to read correct part number\n");
return -1;
}

/* reset device to default values and put it into RX state */
at86rf2xx_reset(dev);

return 0;
}

void at86rf2xx_reset(at86rf2xx_t *dev)
Expand Down Expand Up @@ -141,7 +107,7 @@ void at86rf2xx_reset(at86rf2xx_t *dev)
/* set default protocol */
#ifdef MODULE_GNRC_SIXLOWPAN
dev->proto = GNRC_NETTYPE_SIXLOWPAN;
#else
#elif MODULE_GNRC
dev->proto = GNRC_NETTYPE_UNDEF;
#endif
/* enable safe mode (protect RX FIFO until reading data starts) */
Expand Down Expand Up @@ -219,39 +185,39 @@ void at86rf2xx_tx_prepare(at86rf2xx_t *dev)
/* make sure ongoing transmissions are finished */
do {
state = at86rf2xx_get_status(dev);
}
while (state == AT86RF2XX_STATE_BUSY_RX_AACK ||
state == AT86RF2XX_STATE_BUSY_TX_ARET);
} while (state == AT86RF2XX_STATE_BUSY_RX_AACK ||
state == AT86RF2XX_STATE_BUSY_TX_ARET);
if (state != AT86RF2XX_STATE_TX_ARET_ON) {
dev->idle_state = state;
}
at86rf2xx_set_state(dev, AT86RF2XX_STATE_TX_ARET_ON);
dev->frame_len = IEEE802154_FCS_LEN;
dev->tx_frame_len = IEEE802154_FCS_LEN;
}

size_t at86rf2xx_tx_load(at86rf2xx_t *dev, uint8_t *data,
size_t len, size_t offset)
{
dev->frame_len += (uint8_t)len;
dev->tx_frame_len += (uint8_t)len;
at86rf2xx_sram_write(dev, offset + 1, data, len);
return offset + len;
}

void at86rf2xx_tx_exec(at86rf2xx_t *dev)
{
/* write frame length field in FIFO */
at86rf2xx_sram_write(dev, 0, &(dev->frame_len), 1);
at86rf2xx_sram_write(dev, 0, &(dev->tx_frame_len), 1);
/* trigger sending of pre-loaded frame */
at86rf2xx_reg_write(dev, AT86RF2XX_REG__TRX_STATE,
AT86RF2XX_TRX_STATE__TX_START);
if (dev->event_cb && (dev->options & AT86RF2XX_OPT_TELL_TX_START)) {
dev->event_cb(NETDEV_EVENT_TX_STARTED, NULL);
if (dev->event_callback && (dev->options & AT86RF2XX_OPT_TELL_TX_START)) {
dev->event_callback((netdev2_t *)dev, NETDEV_EVENT_TX_STARTED, NULL);
}
}

size_t at86rf2xx_rx_len(at86rf2xx_t *dev)
{
uint8_t phr;

at86rf2xx_fb_read(dev, &phr, 1);

/* ignore MSB (refer p.80) and substract length of FCS field */
Expand Down
Loading

0 comments on commit 21b8558

Please sign in to comment.