diff options
-rw-r--r-- | chip/nrf51/bluetooth_le.c | 9 | ||||
-rw-r--r-- | include/bluetooth_le.h | 8 |
2 files changed, 15 insertions, 2 deletions
diff --git a/chip/nrf51/bluetooth_le.c b/chip/nrf51/bluetooth_le.c index 08a4a26b5f..1f681a3e30 100644 --- a/chip/nrf51/bluetooth_le.c +++ b/chip/nrf51/bluetooth_le.c @@ -119,16 +119,18 @@ static struct nrf51_ble_packet_t rx_packet; int ble_rx(struct ble_pdu *pdu, int timeout, int adv) { uint32_t done; + uint32_t timeout_time; NRF51_RADIO_PACKETPTR = (uint32_t)&rx_packet; NRF51_RADIO_END = NRF51_RADIO_PAYLOAD = NRF51_RADIO_ADDRESS = 0; NRF51_RADIO_SHORTS = NRF51_RADIO_SHORTS_READY_START | NRF51_RADIO_SHORTS_END_DISABLE; NRF51_RADIO_RXEN = 1; + timeout_time = get_time().val + timeout; do { - if (timeout-- <= 0) { - radio_disable(); + if (get_time().val >= timeout_time) { + NRF51_RADIO_DISABLE = 1; return EC_ERROR_TIMEOUT; } done = NRF51_RADIO_END; @@ -138,6 +140,9 @@ int ble_rx(struct ble_pdu *pdu, int timeout, int adv) nrf2ble_packet(pdu, &rx_packet, adv); + if (NRF51_RADIO_DISABLED != 1) + return EC_ERROR_UNKNOWN; + return EC_SUCCESS; } diff --git a/include/bluetooth_le.h b/include/bluetooth_le.h index 07a0dde5df..8e0422c3a7 100644 --- a/include/bluetooth_le.h +++ b/include/bluetooth_le.h @@ -352,6 +352,14 @@ void fill_remapping_table(struct remapping_table *rt, uint8_t map[5], void ble_tx(struct ble_pdu *pdu); +/** + * Receive a packet into pdu if one comes before the timeout + * + * @param pdu Where the received data is to be stored + * @param timeout Number of microseconds allowed before timeout + * @param adv Set to 1 if receiving in advertising state; else set to 0 + * @returns EC_SUCCESS on packet reception, else returns error + */ int ble_rx(struct ble_pdu *pdu, int timeout, int adv); int ble_radio_init(uint32_t access_address, uint32_t crc_init_val); |