On STM32F4 application, I need to synchronize access to a resource (SPI/Flash).
So, I am going to use a mutex.
However, before starting the scheduler, I need to access the resource to get some data.
The synchronization code is there [xSemaphoreTake( h,10 ) / xSemaphoreGive( h )]
At the beginning (before scheduler starts) all accesses are serial.
Will this work as I use ticks in the call to take function?
There is little point using the mutex before the scheduler has started,
so I assume the reason you are doing it is because the same code runs
both before and after the scheduler is running.
I THINK that, as long as you have a block time of 0, then you SHOULD be
ok, but am going from memory of the source code and haven’t actually
tried it. Note that calling [nearly] any FreeRTOS API function before
the scheduler has started will [deliberately] leave interrupts disabled.
I thought that the ticks are effective if there is another task using the resurce (already took the mutex) and ticks used are to give the the calling code a chance to wait.
Since scheduler has not started, and access is serial, the tick has no effect since no other code is taking the mutex.
Note that calling [nearly] any FreeRTOS API function before
the scheduler has started will [deliberately] leave interrupts disabled.
I do have initialization code enables other interrupts.
Does that mean if I use an API function before scheduler starts, I have to re-enable those IRQs?
Interrupts up to configMAX_SYSCALL_INTERRUPT_PRIORITY will be left
disabled. You can renable them by calling portENABLE_INTERRUPTS()
(again, I think that is the case, didn’t actually check the source code).
Note calling portEXIT_CRITICAL() will NOT re-enable them.
To avoid all this complexity, do you recommend to create an initialization task and start scheduler.
Then the initialization task initializes all resources, then delete itself?