Tool/software: TI-RTOS
Hello,
In my application there are 3 levels of initialization:
- MCU peripherals (SPI, I2C, UART etc.) driver initialization - occurs inside main() by calling Board_Init<module>() BEFORE BIOS_start()
- External peripherals initialization (Switches, ADCs, other sensors) - has two constraints:
- Has to be called AFTER MCU peripheral (SPI, UART) initializtion
- Has to be called within Task context as it uses TI-RTOS drivers API (I2C_transfer() etc.)
- Tasks (app level) initialization and while(1) loop. These tasks count on prior external peripheral initialization
Now, the problem starts with 2b above -
As the (e.g.) analog switch has to be initialized over I2C, within a task context (per 2b above), it is called within Task A when it start running (lets assume highest priority).
Since I2C_transfer() is a blocking call, Task A blocks and Task B, C & D start to execute.
However, Task B/C/D uses the external peripheral that is still being initialized by Task A.
I hope I succeeded to convey the problem...
One way to overcome this synchronization-ordering problem would be to use a 'non resetting Semaphore' (similar to .NET ManualResetEvent object) that is being set by Task A after the external peripheral completed its initialization and let Tasks B/C/D pend on it.
I looked for poor man's implementation of this concept by setting a counting semaphore count value to (e.g.) 100 (and pending Tasks B/C/D on it) but couldn't find and Semaphore_setCount() API for this.
Another way Is to use an Event and have Task A set all the event's bits after peripheral initialization and pend Tasks B/C/D on each bit of the Event.
This also fails since only one task can pend on Event at a time...
3rd approach would be to have only Task A running, and let it launch Tasks B/C/D only after initialization is done.
As Tasks B/C/D are created statically, I couldn't find a way to keep them from running
Are there any design patterns/sync objects that deal with this scenario ?
Any advice is highly appreciated.