0
votes

I'm using an ARM Cortex-M4 microcontroller to develop an application with FreeRTOS.

For exact timing, I want use an interrupt based timer. The interrupt has an appropriate priority so it should be able to call the FreeRTOS API. The ISR is called periodically and should wake up a task as in the given code:

/* This function is executed by the task I'd like to resume */
void hello_task() {
    while (1) {
        vTaskSuspend(task);
        printf("Tick\n");
    }
}

/* The ISR is called by an interrupt about 200 times per second */
void Timer_IRQHandler() {
    CLEAR_INTERRUPT_FLAG();
    xTaskResumeFromISR(task);
}

The ISR is executed correctly but the task doesn't resume afterwards. Does anyone have an explaination for this behavior?

Thank you!

1
The documentation says that xTaskResumeFromISR will actually not perform a context switch directly, but needs a portYIELD_FROM_ISR() at the end of the ISR to make it happen. - tofro
As far as I see, the example in link only yields when xTaskResumeFromISR returns pdTRUE. In my case pdFALSE is returned therefore this should not be the problem. - eeucalyptus
Well that exactly could be the problem - I guess you want it to yield? - tofro

1 Answers

1
votes

Read the documentation for xTaskResumeFromISR(). It tells you not to do what you are doing.

Direct to task notifications offer the best (most light weight and efficient) method of doing what you describe. There is a worked example on the following page: http://www.freertos.org/RTOS_Task_Notification_As_Counting_Semaphore.html