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 16, 2016
1 parent 81aa6fe commit 274318b
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 478 deletions.
52 changes: 9 additions & 43 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)
int 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 @@ -219,28 +185,27 @@ 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);
Expand All @@ -252,6 +217,7 @@ void at86rf2xx_tx_exec(at86rf2xx_t *dev)
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 274318b

Please sign in to comment.