Skip to content

Commit

Permalink
at86rf215: gracefully handle non-attached module
Browse files Browse the repository at this point in the history
also tweak reset values - too low values don't reset module.
  • Loading branch information
benpicco committed Sep 4, 2019
1 parent a37d768 commit 369990b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
9 changes: 8 additions & 1 deletion drivers/at86rf215/at86rf215_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ static inline uint8_t _get_rf_state_with_lock(at86rf215_t *dev)
return spi_transfer_byte(SPIDEV, CSPIN, false, 0) & STATE_STATE_MASK;
}

void at86rf215_hardware_reset(at86rf215_t *dev)
int at86rf215_hardware_reset(at86rf215_t *dev)
{
/* bail out if no module is connected */
if (at86rf215_reg_read(dev, RG_RF_PN) == 0) {
return -ENODEV;
}

/* prevent access during reset */
getbus(dev);

Expand All @@ -55,6 +60,8 @@ void at86rf215_hardware_reset(at86rf215_t *dev)

while (_get_rf_state_with_lock(dev) != RF_STATE_TRXOFF) {}
spi_release(SPIDEV);

return 0;
}

void at86rf215_reg_write(const at86rf215_t *dev, uint16_t reg, uint8_t value)
Expand Down
22 changes: 8 additions & 14 deletions drivers/at86rf215/at86rf215_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ static void _irq_handler(void *arg)

static int _init(netdev_t *netdev)
{
int res;
at86rf215_t *dev = (at86rf215_t *)netdev;

/* don't call HW init for both radios */
Expand All @@ -88,23 +89,16 @@ static int _init(netdev_t *netdev)
gpio_init_int(dev->params.int_pin, GPIO_IN, GPIO_RISING, _irq_handler, dev);

/* reset the entire chip */
at86rf215_hardware_reset(dev);
}

/* test if the SPI is set up correctly and the device is responding */
uint8_t tries = 5;
while (tries--) {
uint8_t pn = at86rf215_reg_read(dev, RG_RF_PN);
if ((pn == AT86RF215_PN) || (pn == AT86RF215M_PN)) {
break;
if ((res = at86rf215_hardware_reset(dev))) {
gpio_irq_disable(dev->params.int_pin);
return res;
}

xtimer_usleep(1000);
}

if (tries == 0) {
DEBUG("[at86rf215] error: unable to read correct part number\n");
return -1;
res = at86rf215_reg_read(dev, RG_RF_PN);
if ((res != AT86RF215_PN) && (res != AT86RF215M_PN)) {
DEBUG("[at86rf215] error: unable to read correct part number: %x\n", res);
return -ENOTSUP;;
}

/* reset device to default values and put it into RX state */
Expand Down
11 changes: 5 additions & 6 deletions drivers/at86rf215/include/at86rf215_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@
extern "C" {
#endif

#define AT86RF215_WAKEUP_DELAY (306U)
/* Minimum reset pulse width (tRST) - 625ns */
#define AT86RF215_RESET_PULSE_WIDTH (1U)
/* The typical transition time to TRX_OFF after reset pulse is 1 µs (tPOWERON) */
#define AT86RF215_RESET_DELAY (1U)
/* Minimum reset pulse width (tRST) */
#define AT86RF215_RESET_PULSE_WIDTH (16U)
/* The typical transition time to TRX_OFF after reset (tPOWERON) */
#define AT86RF215_RESET_DELAY (16U)

/* This is used to calculate the ACK timeout based on the bitrate.
* AT86RF233 uses an ACK timeout of 54 symbol periods, or 864 µs @ 250 kbit/s
Expand All @@ -50,7 +49,7 @@ extern "C" {

extern const uint8_t at86rf215_fsk_srate_10kHz[];

void at86rf215_hardware_reset(at86rf215_t *dev);
int at86rf215_hardware_reset(at86rf215_t *dev);

void at86rf215_reg_write(const at86rf215_t *dev, uint16_t reg, uint8_t val);

Expand Down

0 comments on commit 369990b

Please sign in to comment.