Skip to content

Latest commit

 

History

History
38 lines (32 loc) · 1016 Bytes

File metadata and controls

38 lines (32 loc) · 1016 Bytes

Simple state machine (Enhanced)

This is an enhanced version of simple state machine demo simple state machine

This demo uses macro to enumerate the list of states and to initialize the state_t in process.c

#define ALL_PROCESS_STATE \
 ADD_STATE(IDLE_STATE, idle_handler, idle_entry_handler, idle_exit_handler)  \
 ADD_STATE(ACTIVE_STATE, active_handler, active_entry_handler, active_exit_handler)  \
 ADD_STATE(PAUSE_STATE, paused_handler, paused_entry_handler, paused_exit_handler)
//! List of states in the process state machine
#define ADD_STATE(name, ...)  name,
typedef enum
{
  ALL_PROCESS_STATE
}process_state_t;
#undef ADD_STATE
#define ADD_STATE(name, state_handler, entry_handler, exit_handler) \
[name].Handler = state_handler, \
[name].Entry   = entry_handler, \
[name].Exit    = exit_handler,  \
[name].Id      = name,

static const state_t Process_States[] =
{
  ALL_PROCESS_STATE
};

#undef ADD_STATE