FSM Lecture 14: Exercise-003 Defining states Entry and Exit actions

  • Post author:
  • Post category:Blog

 

Exercise-003 Defining states Entry and Exit actions

 

 

To reduce the clutter on the diagram, you will use short names instead of full variable names. Like c_time, e_time, and p_time.

 

Entry Actions:

As per the demo(figure 1), the LCD should display a ‘Set time.’ Whenever you give power to the application, the time component shows 0 (0 seconds, 0 minutes).

That’s why, whenever the application comes to the IDLE state, it should display something. That’s why we will now define the Entry activity for the IDLE state.

Just click on IDLE state, and at the left-hand side, you can see Entry/Do/Exit(Figure 2).

Figure 1. IDLE state
Figure 1. IDLE state

 

Entry and Exit actions
Figure 2. Entry action for IDLE state

Let’s define the Entry action.

One Entry action could display the time on the LCD; I will call disp_time.

Display time is a helper action; it’s a helper action or just an action that displays the time. But initially, whenever the application is in the IDLE state, it should display 0. That’s why the argument I send is just 0. The display time function displays as per the argument being passed. So, the argument being passed disp_time(0).

And as you can see in the demo(Figure 2), it also shows one message to the user, “Set time’’; display message, that is another action function.  disp_msg(“Set time”). These are the 2 Entry actions.

 

Figure 3. Entry action for IDLE state
Figure 3. Entry action for IDLE state

We should also make a mobj->curr_time=0; and also, mobj->elaspsed_time=0;because it’s in the IDLE state.  mobj->current_time =0; elapsed_time=0; and display  time as 0; and display the message as “Set time”. These are the Entry actions.

And since we are already doing c_time=0, e_time=0, here it is not required, I will just make p_time =0 here. That’s our Entry action for this. 

 

Entry and Exit actions
Figure 4. TIME_SET state

Let’s discuss the TIME_SET state.

Whenever the application comes to the TIME_SET state, it should display the current time.

Let’s define one Entry action for this. Entry action for TIME_SET state is disp_time; And you have to display their current time (c_time). So, whenever an application comes to the TIME_SET state, it displays the time.

 

Entry and Exit actions
Figure 5. PAUSE state

Let’s write the Entry action for PAUSE state. Whenever you press the PAUSE button, the COUNTDOWN stops and shows the message “paused.” 

The Entry action for this would be disp_msg(“paused”), and it doesn’t respect the COUNTDOWN. But whenever the application comes to PAUSE state, it should send the message “paused.”

 

Entry and Exit actions
Figure 6. COUNTDOWN state

For the COUNTDOWN, it should COUNTDOWN every one second. Whenever this state receives the TICK event, there will be counting down process. That’s why I have no idea whether this requires the Entry action or not; if you don’t have any idea, then you leave it. But I don’t want to define any Entry action for COUNTDOWN.

 

Entry and Exit actions
Figure 7. STAT state

 

Let’s go to the statistics state(STAT state).

As you can see in the demo, whenever you press the START or PAUSE button, it shows the productive time and displays the message “Productive time.”

The demo should show the productive time in the first line of the display and send a message at the second line. That means we have two actions here. disp_time(mobj->p_time), and disp_msg( “productive time”).

You end each action with a semicolon whenever you have two or more actions to do. That looks nice.

 

EXIT Actions:

Entry and Exit actions
Figure 8. Exit action for IDLE state

 

Let’s define some Exit actions.

Let’s start with  IDLE. The IDLE state during the Entry it has displayed something. And when the application receives some events it goes to some other state, and it may display something else. So, while exiting that state, it has to clear whatever message it has displayed. That’s why I would define the exit action; for this state, the exit action is ‘disp_clr.’

And for the STAT state also the exit action would be disp_clr.

For the TIME_SET state, it may be required; I’m not going to define any exit action for the time being.

For the PAUSE, also it had displayed “paused.” So, it should clear it up. I would define an exit action for PAUSE state as ‘disp_clr.’

And for the COUNTDOWN, I’m not sure whether I have to define any exit action or not. Let’s see later.

 

FastBit Embedded Brain Academy Courses

click here:https://fastbitlab.com/course1

 

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.

Leave a Reply