diff options
author | Levi Oliver <levio@google.com> | 2016-08-12 09:08:23 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-08-12 20:49:45 -0700 |
commit | 31f297da0b9cb3b4e6fb1cc2f044f71df1c830c2 (patch) | |
tree | e2ee09fd2bd8c1d30cb5d1b930748ea43d46b9c8 | |
parent | f1951ce3a76781f2c3a311342651dc827828d722 (diff) | |
download | chrome-ec-31f297da0b9cb3b4e6fb1cc2f044f71df1c830c2.tar.gz |
btle: Timeout of ble_rx now based on chip time
Previously, timeout meant the number of attempts taken to receive. Now,
it means the number of microseconds before timing out.
TEST=printouts displaying time before and after rx attempt. Not included
in CL.
BUG=None
BRANCH=None
Change-Id: I00ccfc4bbf15f77c2777f35c911dceacaff98e4f
Signed-off-by: Levi Oliver <levio@google.com>
Reviewed-on: https://chromium-review.googlesource.com/368471
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-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); |