BLE NUS concurrency, collisions


I'm new to BLE and have a general question about concurrency and collisions. Sorry if a repeat question. I'm developing for nRF52832 using SDK 15.3 and S112 v6.1.1. I'm using three nRF52 Dev Kits for testing.

My application is based on ble_app_uart example, using NUS, with UART removed.

Generally, once connected to a central (iOS device):

- PPI and GPIOTE are used to sense toggle of a pin and call ble_nus_data_send() to send a few bytes of data to the central. These events occur randomly, separated by at least a few seconds.

- From time to time, the connected BLE central will send a message to the peripheral (by writing value for the appropriate characteristic) which results in a call to nus_data_handler(). For testing, this happens every 5 seconds. This, in turn, causes a message to be sent back to the central by calling ble_nus_data_send().

What happens if the application calls ble_nus_data_send() while the Softdevice is receiving a message from the central? Will the call to sd_ble_gatts_hvx() fail with NRF_ERROR_BUSY or NRF_ERROR_INVALID_STATE? Or will the Softdevice manage the collision?

What happens if the application issues call to ble_nus_data_send() while the Softdevice is processing a previously issued call to ble_nus_data_send()? Same as above?

Does the peripheral application have to manage this? Can it be managed safely by simply enclosing calls to ble_nus_data_send() within a while loop like this:

uint32_t err_code;
do {
     err_code = ble_nus_data_send(&m_nus, message, &length, m_conn_handle);
} while (err_code == NRF_ERROR_INVALID_STATE || err_code == NRF_ERROR_BUSY || err_code == NRF_ERROR_NOT_FOUND)

Many thanks,