Skip to content

Commit

Permalink
Merge pull request RIOT-OS#12142 from fabian18/drivers/at86rf2xx_do_n…
Browse files Browse the repository at this point in the history
…ot_hang_on_no_dev

drivers/at86rf2xx: do not hang on no dev
  • Loading branch information
benpicco authored Sep 2, 2019
2 parents 3901740 + 2edf153 commit f74381c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
17 changes: 13 additions & 4 deletions drivers/at86rf2xx/at86rf2xx_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,24 @@ static int _init(netdev_t *netdev)
gpio_set(dev->params.reset_pin);
gpio_init_int(dev->params.int_pin, GPIO_IN, GPIO_RISING, _irq_handler, dev);

/* reset device to default values and put it into RX state */
at86rf2xx_reset(dev);
/* Intentionally check if bus can be acquired,
since getbus() drops the return value */
if (spi_acquire(dev->params.spi, dev->params.cs_pin, SPI_MODE_0,
dev->params.spi_clk) < 0) {
DEBUG("[at86rf2xx] error: unable to acquire SPI bus\n");
return -EIO;
}
spi_release(dev->params.spi);

/* test if the SPI is set up correctly and the device is responding */
/* test if 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;
return -ENOTSUP;
}

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

return 0;
}

Expand Down
11 changes: 10 additions & 1 deletion tests/driver_at86rf2xx/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ int main(void)
puts("AT86RF2xx device driver test");
xtimer_init();

unsigned dev_success = 0;
for (unsigned i = 0; i < AT86RF2XX_NUM; i++) {
netopt_enable_t en = NETOPT_ENABLE;
const at86rf2xx_params_t *p = &at86rf2xx_params[i];
Expand All @@ -98,8 +99,16 @@ int main(void)
printf("Initializing AT86RF2xx radio at SPI_%d\n", p->spi);
at86rf2xx_setup(&devs[i], p);
dev->event_callback = _event_cb;
dev->driver->init(dev);
if (dev->driver->init(dev) < 0) {
continue;
}
dev->driver->set(dev, NETOPT_RX_END_IRQ, &en, sizeof(en));
dev_success++;
}

if (!dev_success) {
puts("No device could be initialized");
return 1;
}

_recv_pid = thread_create(stack, sizeof(stack), THREAD_PRIORITY_MAIN - 1,
Expand Down

0 comments on commit f74381c

Please sign in to comment.