I have a task that starts up all of the other tasks depending upon a mode byte that is stored in EEPROM. These tasks call the init functions for all of the hardware modules they use. Several tasks use the same hardware, however, with I2C as an example.
These init functions create FreeRTOS objects and I do protect against them from being created more than once, such as in the code snippet below. My concern is that my Startup Task is creating all of these other tasks at once and the OS might be causing a task to call the init function when another task had already called it, particularly in between checking for the NULL value and actually creating the FreeRTOS object. Is this a valid concern for which I should change my design.
void I2C_Control_Init(void) {
for(int i2c_control = 0; i2c_control < I2C_CONTROL_NUM; i2c_control++) {
if (NULL == i2c_control_mutex[i2c_control]) {
i2c_control_mutex[i2c_control] = xSemaphoreCreateMutex();
configASSERT(i2c_control_mutex[i2c_control]); // Do not continue with null pointer.
}
}
return;
}