Interrupts calling API before Scheduler start

fabiensf wrote on Thursday, August 16, 2012:

Hi all,

I’m still working on my first FreeRTOS project and I would like to have some advices on Interrupts management.

I have enable my interrupts at the beginning of my code, before calling vTaskStartScheduler(). I have some troubles and I think this happen when an interrupts is calling FreeRTOS API before my Scheduler is running. In order to avoid this, I find 2 ways:

1 - Check for each interrupts the State of Scheduler by using xTaskGetSchedulerState. I will call FreeRTOS API (FromISR) Only if Scheduler is running (taskSCHEDULER_RUNNING)

2 - Enable my interrupts in one Task, In order to be sure that Scheduler is running.

Do you think that one way is better? Or if you know a cleanest way to do this, don’t hesitate to explain it to me.

Thanks for your help,
Best regards,
Fabien

rtel wrote on Thursday, August 16, 2012:

If you call FreeRTOS API functions before the scheduler is started (which you must do, to create at least one task, if nothing else), then the kernel will leave interrupts disabled for this very reason.  It also makes no sense to try and unblock a task, or access a kernel primitive, etc. from an interrupt is the task or primitive does not exist or the scheduler is not running.

Method 1 could work depending on the port, but note that only API functions that end in “FromISR” are guaranteed to be interrupt safe, so by doing this you are outside the stated scope of use.  Also, you don’t really want to be making an extra function call on every interrupt once the scheduler is running.

Method 2 is the preferred method.  You can enable peripheral interrupts before the scheduler has started, if you leave global interrupts disabled.  The RTOS kernel will enable global interrupts automatically when the first task starts running.

Regards.

fabiensf wrote on Thursday, August 16, 2012:

Hi Richard

Thanks a lot for your (very fast) answer.

Method 1: Thanks for your explantion. I forget that only function with “FromISR” is  guaranteed inside interrupt.

I will implement the second method.

Best regards,
Fabien