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>
This commit is contained in:
Levi Oliver
2016-08-12 09:08:23 -07:00
committed by chrome-bot
parent f1951ce3a7
commit 31f297da0b
2 changed files with 15 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -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);