This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Can you not call sd_ble_gatts_hvx() in a loop?

I basically need clarification on the last point of this question, which seems to imply that: the first time you call sd_ble_gatts_hvx() while the SoftDevice's transmit buffer is full, it reliably returns NRF_ERROR_RESOURCES, but you should not call it in a loop that checks for NRF_SUCCESS. You must wait for BLE_GATTS_EVT_HVN_TX_COMPLETE. Is this correct?

If so, why? Wouldn't that imply that there is a race condition in the SoftDevice, i.e. the possibility that the application could call sd_ble_gatts_hvx() at just the wrong time, which is what the loop forces?

Indeed, I'm looking into this because I think the SoftDevice was sending some packets in an unexpected order because I was being lazy and using a loop instead of an event handler. If the race condition exists, then I need to spend the time to make sure that the peer is robust to receiving packets out of order.

Related