Are user events safe in ISR?

Is it safe to call the user event logging from an ISR? Something like this for example where I have an encoder interrupt, I want to log the encoder value immediately and then notify the task to execute afterwards.

void encoder_isr(void *handle)
{
    //read the encoder count and log it to trace
    u32 enc_count = read_encoder();
    xTracePrintF(isr_channel, "EncoderCount = %d", enc_count);

    TaskHandle_t *task_handle= (TaskHandle_t *)handle;
    if (task_handle != NULL && *task_handle != NULL) {
        //notify the task to execute
        BaseType_t xHigherPriorityTaskWoken = pdFALSE;
        vTaskNotifyGiveFromISR(*task_handle, &xHigherPriorityTaskWoken);
        portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
    }
}

I looked through the percepio documentation but couldn’t find a specific answer.

In ISRs that are allowed to use FreeRTOS functions, it is always safe to use TraceRecorder. It is designed to allow this.

On Arm Cortex-M devices it is safe to use in any ISR, also high-priority ISRs that runs independently of FreeRTOS. (For such ISRs on other processor types, it depends on how the TraceRecorder critical section macros are defined in trcHardwarePort.h or trcKernelPort.h. It must only be used from ISRs that are masked by TraceRecorder’s critical section.)

1 Like

Great, thanks for the quick answer. I am using the ARM Cortex A9 port, and the ISR priority low enough to be able to call FreeRTOS functions.

You are welcome. Good luck with your project.