Hello,
I'm using nRF52840 devboards and am running the NUS-examples on two devboards (peripheral and central) with SoftDevice S140 (SDK 17.0.2).
I want to synchronize my application code (sending on the peripheral side) with the radio to enhance data throughput and further implement a FreeRTOS sending task.
My idea is:
- Configure Radio Notifications on active radio event with a distance of 800 us before the actual event
- Give a FreeRTOS task notification in the radio-event-ISR to the sending task to indicate that the radio is going the be active soon
- Implement a sending task which accesses the data-to-send in a queue and pends on that task notification given by the active radio event ISR
The code is something like that:
BLE_HANDLING_ERROR_CODE radioNotificationInit()
{
sd_nvic_ClearPendingIRQ(SWI1_IRQn);
sd_nvic_SetPriority(SWI1_IRQn, 3);
sd_nvic_EnableIRQ(SWI1_IRQn);
/* Configure the radio notification event */
sd_radio_notification_cfg_set(NRF_RADIO_NOTIFICATION_TYPE_INT_ON_ACTIVE, NRF_RADIO_NOTIFICATION_DISTANCE_800US);
}
void SWI1_IRQHandler(bool radio_active)
{
vTaskNotifyGiveFromISR(xbleCommTaskHandle, NULL);
}
void vbleCommunicationTask(void * pvParameters)
{
while(1)
{
if(ulTaskNotifyTake(pdTRUE, portMAX_DELAY))
{
/* Send data now */
do
{
returnValue = ble_nus_data_send(&m_nus, sendDataArray, &sendIndex, m_conn_handle);
if ((returnValue != NRF_ERROR_INVALID_STATE) &&
(returnValue != NRF_ERROR_RESOURCES) &&
(returnValue != NRF_ERROR_NOT_FOUND))
{
// Something went clearly wrong here
}
} while (returnValue == NRF_ERROR_RESOURCES);
}
}
}
}
The data array is something like that:
#define BLE_NUS_MAX_DATA_LEN (NRF_SDH_BLE_GATT_MAX_MTU_SIZE - OPCODE_LENGTH - HANDLE_LENGTH) static uint8_t sendDataArray[BLE_NUS_MAX_DATA_LEN]; ///< This is for testing purposes only since it is NOT THREADSAFE!
The define NRF_SDH_BLE_GATT_MAX_MTU_SIZE is set to the maximum size of 247.
So the basic idea behind this is, each time the radio becomes active, the application can send all the pending data and no ressources are wasted. The actual communication and the radio notifications are working properly with my configuration.
Now my problem: The throughput is completely inconsistent with this approach. Sometimes data is send properly; sometimes nothing is sent and after a few seconds the communication starts to send properly again. I tried to change the notification distance but it doesn't help.
Is there anything wrong with this approach in principle? What's the way to go to synchronize sending with radio notifications?
Best Regards,
Dominik