This post describes the initial values of static variables during state transitions.
Initial values of static variables in embedded software are usually set at Power On Reset. However, in an embedded system, when the hardware or software state transitions as shown in the figure below, it may be required to set initial values according to each state.
Initial values of static variables in C language are set at E1 (S1) in the figure below, and E2 to E10 are often set at each component of the application layer. Judging and executing state transitions on a component-by-component basis tends to complicate components and can lead to the creation of bugs. It is recommended that state transition judgments, initialization of static variables at state transitions, and component execution for each state be created as quasi-RTOS services.
Initial values of static variables in C language are set at the timing of E1 (S1) in the figure below. On the other hand, in E2 to E10, initial values are likely to be set in each component of the application layer in many cases. If state transitions are judged and executed on a component-by-component basis, components tend to become more complex, which may cause bugs. Therefore, it is recommended that the determination of state transitions, initialization of static variables at the time of transition, and component execution for each state be implemented as quasi-RTOS services.