As far as I understand TIMERTICK event will be always processed in one of the substates first so it can’t be used by superstate S1. What is the way to deal with this situation?
There are three ways of dealing with this situation:
The timing generator posts two messages
TimerTick2. The substates react only to
TimerTick1, and "burn" the message when they react to it. The superstate reacts only to
The timing generator will always be posting duplicate timing message, because it shouldn't "know" the exact state configuration.
The timing generator posts one message
TimerTick1. When a substate reacts to the
TimerTick1 messages, it "burns" that message, it also post a different message
TimerTick2. The superstate reacts only to
[I use this method frequently.]
This approach somewhat increases the coupling between the substates and their superstate. The substates "know" that that there is a superstate and they have to post a certain message for it.
Relax the rule that the substate has to "burn" the message
It's a design choice whether or not the substate necessarily burns the message after acting on the message. If you don't burn the message, you can pass it on to the superstate.
You will need to watch out that the superstate doesn't spoil the work of each of its substates. In other words, this can increase coupling between substates and their superstate.
Here's the purest example of such coupling. As a reaction to a message, a substate determines that the HSM needs to change state to S42. As a reaction to that same message, the superstate determines that the HSM needs to change state to S24. Should substate or superstate win? Were will this be arbitrated?