FSM Lecture 41: Exercise-004 State table approach for implementation of an FSM part-2

  • Post author:
  • Post category:Blog

 

Exercise-004 State table approach for implementation of an FSM part-2

 

 

Now the addresses of the event handlers should be stored in the State table. That’s why you have to share the name of Event handler functions with the main.cpp, where we will implement the State table.

You create prototypes of all Event handler functions and include it in ‘main.h’. In the main.h, you have to include the prototypes. Prototypes of event handlers are shown below.

//prototypes of event handlers 
event_status_t IDLE_Inc_time(protimer_t *const mobj, event_t const *const e);
event_status_t IDLE_Time_tick(protimer_t *const mobj, event_t const *const e);
event_status_t IDLE_Start_pause(protimer_t *const mobj, event_t const *const e);
event_status_t IDLE_Entry(protimer_t *const mobj, event_t const *const e);
event_status_t IDLE_Exit(protimer_t *const mobj, event_t const *const e);

event_status_t COUNTDOWN_Start_pause(protimer_t *const mobj, event_t const *const e);
event_status_t COUNTDOWN_abrt(protimer_t *const mobj, event_t const *const e);
event_status_t COUNTDOWN_Exit(protimer_t *const mobj, event_t const *const e);
event_status_t COUNTDOWN_Time_tick(protimer_t *const mobj, event_t const *const e);

event_status_t PAUSE_Inc_time(protimer_t *const mobj, event_t const *const e);
event_status_t PAUSE_Dec_time(protimer_t *const mobj, event_t const *const e);
event_status_t PAUSE_Start_pause(protimer_t *const mobj, event_t const *const e);
event_status_t PAUSE_abrt(protimer_t *const mobj, event_t const *const e);
event_status_t PAUSE_Entry(protimer_t *const mobj, event_t const *const e);
event_status_t PAUSE_Exit(protimer_t *const mobj, event_t const *const e);

event_status_t TIME_SET_Inc_time(protimer_t *const mobj, event_t const *const e);
event_status_t TIME_SET_Dec_time(protimer_t *const mobj, event_t const *const e);
event_status_t TIME_SET_Start_pause(protimer_t *const mobj, event_t const *const e);
event_status_t TIME_SET_abrt(protimer_t *const mobj, event_t const *const e);
event_status_t TIME_SET_Entry(protimer_t *const mobj, event_t const *const e);
event_status_t TIME_SET_Exit(protimer_t *const mobj, event_t const *const e);

event_status_t STAT_Time_tick(protimer_t *const mobj, event_t const *const e);
event_status_t STAT_Time_tick(protimer_t *const mobj, event_t const *const e);
event_status_t STAT_Entry(protimer_t *const mobj, event_t const *const e);
event_status_t STAT_Exit(protimer_t *const mobj, event_t const *const e);

Prototypes of event handlers

 

State table approach
Figure 1. State table

 

And after that, in the table, you have to mention two important details. First of all, which event handler will we call, and what is the next state when that event happens. So, that you need to mention. After that, we have to convert this state table into a two-dimensional array.

The following article covers what a two-dimensional array is, how to access the different elements of a two-dimensional array, and how the memory organization looks like for the two-dimensional array.

 

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.