drivers/at86rf2xx: do not hang on no dev
This commit is contained in:
parent
d991883c5b
commit
2edf153cf8
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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];
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user