summaryrefslogtreecommitdiff
path: root/chip/nrf51
diff options
context:
space:
mode:
authorLevi Oliver <levio@google.com>2016-08-09 15:55:50 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-08-17 12:49:22 -0700
commit1d4d1942b8b1e3d5410f7bf1231e16885806b460 (patch)
tree34e408a3d677cdab1e6a2d649ccdb79b6c013ac5 /chip/nrf51
parent7317e1f165fa16fee437c8969cefbd73f42de7e6 (diff)
downloadchrome-ec-1d4d1942b8b1e3d5410f7bf1231e16885806b460.tar.gz
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 <levio@google.com> Reviewed-on: https://chromium-review.googlesource.com/370597 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'chip/nrf51')
-rw-r--r--chip/nrf51/bluetooth_le.c21
1 files changed, 21 insertions, 0 deletions
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;