From 1d4d1942b8b1e3d5410f7bf1231e16885806b460 Mon Sep 17 00:00:00 2001 From: Levi Oliver Date: Tue, 9 Aug 2016 15:55:50 -0700 Subject: btle: Improved stability of ble_tx function ble_tx now resets values that could prevent its functioning. Since there is no NRF51 shortcut from TX->RX, it also blocks until packet is transmitted. This prevents calling RX before TX is completed, specifically in advertising state. Also added timeouts to prevent possibility of freezing in case of unexpected state. TEST=Used function before and after CL in a more fully implemented stack. This improved reliability. BUG=None BRANCH=None Change-Id: I6a5b0b6f36e37ac0102d254bbdc9dfcd29694bb8 Signed-off-by: Levi Oliver Reviewed-on: https://chromium-review.googlesource.com/370597 Reviewed-by: Aseda Aboagye --- chip/nrf51/bluetooth_le.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'chip/nrf51') diff --git a/chip/nrf51/bluetooth_le.c b/chip/nrf51/bluetooth_le.c index 39a10d48d0..4b9adc4e60 100644 --- a/chip/nrf51/bluetooth_le.c +++ b/chip/nrf51/bluetooth_le.c @@ -107,11 +107,32 @@ static uint32_t tx_end, rsp_end; void ble_tx(struct ble_pdu *pdu) { + uint32_t timeout_time; + ble2nrf_packet(pdu, &tx_packet); NRF51_RADIO_PACKETPTR = (uint32_t)&tx_packet; NRF51_RADIO_END = NRF51_RADIO_PAYLOAD = NRF51_RADIO_ADDRESS = 0; + NRF51_RADIO_RXEN = 0; NRF51_RADIO_TXEN = 1; + + timeout_time = get_time().val + RADIO_SETUP_TIMEOUT; + while (!NRF51_RADIO_READY) { + if (get_time().val > timeout_time) { + CPRINTF("ERROR DURING RADIO TX SETUP. TRY AGAIN.\n"); + return; + } + } + + timeout_time = get_time().val + RADIO_SETUP_TIMEOUT; + while (!NRF51_RADIO_END) { + if (get_time().val > timeout_time) { + CPRINTF("RADIO DID NOT SHUT DOWN AFTER TX. " + "RECOMMEND REBOOT.\n"); + return; + } + } + NRF51_RADIO_DISABLE = 1; } static struct nrf51_ble_packet_t rx_packet; -- cgit v1.2.1