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

SD_EVT_IRQHandler hit before m_softdevice_task created

Running into a weird issue with my development.  I'm getting a freeRTOS assert because the SD_EVT_IRQHandler is getting hit before m_softdevice_task creation is complete.  How/why would this occur?  The Assert is trigger because the SD_EVT_IRQHandler is trigger, which hits the vTaskNotifyGiveFromISR in nrf_sdh_freertos.c.   HOWEVER, if I restart the debugger a couple times, this doesn't occur.  This indicates a close race-condition.   I'd update nrf_sdh_freertos.c as per other posts on here.  Any ideas as to why this IRQ would trigger before the task creation is complete?  This is the first thread to be created in my application.  Its repeatable that if I clear the flash, program the SD, then the program the application this occurs.  After restarting/running a couple times this issue goes away.....?  I'm using SDK 15.2 with this patch: https://devzone.nordicsemi.com/f/nordic-q-a/39459/observer-under-freertos-events-stop-coming-after-a-few-minutes

void SD_EVT_IRQHandler(void)
{
BaseType_t xYieldRequired;

//xYieldRequired = xTaskResumeFromISR( m_softdevice_task );
vTaskNotifyGiveFromISR(m_softdevice_task, &xYieldRequired);

if( xYieldRequired == pdTRUE )
{
portYIELD_FROM_ISR(xYieldRequired);
}
}


/* This function gets events from the SoftDevice and processes them. */
static void softdevice_task(void * pvParameter)
{
NRF_LOG_DEBUG("Enter softdevice_task.");

if (m_task_hook != NULL)
{
m_task_hook(pvParameter);
}

while (true)
{
nrf_sdh_evts_poll(); // Let the handlers run first, in case the EVENT occured before creating this task.
//vTaskSuspend(NULL);

(void) ulTaskNotifyTake(pdTRUE, /* Clear the notification value before exiting (equivalent to the binary semaphore). */
portMAX_DELAY); /* Block indefinitely (INCLUDE_vTaskSuspend has to be enabled).*/
}
}

Parents Reply
  • seems like you are starting the softdevice activity way before starting the scheduler. I think the trigger to softdevice activity (advertising/scanning) should be clubbed close together due to the missing check in SD_EVT_IRQhandler to see if the softdevice task has started or not.

    You patch is nice eliminating the need to club the softdevice event triggers to be close to vTaskStartScheduler but is an unnecessary overhead everytime after the task has been created. which is more optimal, i am not sure.

Children
No Data
Related