File syn_fsm.c¶
FileList > src > syntropic > util > syn_fsm.c
Go to the source code of this file
Finite state machine implementation.
#include "../log/syn_log.h"#include "syn_assert.h"#include "syn_fsm.h"#include <string.h>
Public Functions¶
| Type | Name |
|---|---|
| bool | syn_fsm_dispatch (SYN_FSM * fsm, SYN_FSM_Event event) Dispatch an event. |
| void | syn_fsm_init (SYN_FSM * fsm, const SYN_FSM_Transition * transitions, SYN_FSM_State initial, const char * tag) Initialize the FSM. |
| void | syn_fsm_set_context (SYN_FSM * fsm, void * ctx) Set the user context pointer passed to guards and actions. |
| void | syn_fsm_set_state (SYN_FSM * fsm, SYN_FSM_State state) Force-set the FSM to a specific state. |
| void | syn_fsm_set_state_descs (SYN_FSM * fsm, const SYN_FSM_StateDesc * descs) Set optional state descriptors (entry/exit actions). |
| void | syn_fsm_set_state_names (SYN_FSM * fsm, const char *const * names) Set optional state name strings for debug/logging. |
Public Static Functions¶
| Type | Name |
|---|---|
| const SYN_FSM_StateDesc * | find_state_desc (const SYN_FSM * fsm, SYN_FSM_State state) Find the state descriptor for a given state. |
| void | fire_enter (const SYN_FSM * fsm, SYN_FSM_State state) Invoke the on_enter callback for a state. |
| void | fire_exit (const SYN_FSM * fsm, SYN_FSM_State state) Invoke the on_exit callback for a state. |
Public Functions Documentation¶
function syn_fsm_dispatch¶
Dispatch an event.
Scans the transition table for a matching (current_state, event) pair. If a guard exists and returns false, the transition is skipped and the next matching row is tried. On a successful match: * Exit action for the current state (if state_descs set) * Transition action * State change * Entry action for the new state (if state_descs set)
Parameters:
fsmFSM instance.eventEvent to dispatch.
Returns:
true if a transition was taken, false if no match found.
function syn_fsm_init¶
Initialize the FSM.
void syn_fsm_init (
SYN_FSM * fsm,
const SYN_FSM_Transition * transitions,
SYN_FSM_State initial,
const char * tag
)
Parameters:
fsmFSM instance.transitionsTransition table (terminated by SYN_FSM_END).initialInitial state.tagLog tag for transition logging (e.g., "motor").
function syn_fsm_set_context¶
Set the user context pointer passed to guards and actions.
Parameters:
fsmFSM instance.ctxUser context.
function syn_fsm_set_state¶
Force-set the FSM to a specific state.
Fires exit action for the old state and entry action for the new state (if state_descs are set). No transition action is called.
Parameters:
fsmFSM instance.stateNew state.
function syn_fsm_set_state_descs¶
Set optional state descriptors (entry/exit actions).
Parameters:
fsmFSM instance.descsState descriptor table (terminated by SYN_FSM_STATE_END).
function syn_fsm_set_state_names¶
Set optional state name strings for debug/logging.
Parameters:
fsmFSM instance.namesArray of state name strings, indexed by state value. Must cover all state values used in the transition table.
Public Static Functions Documentation¶
function find_state_desc¶
Find the state descriptor for a given state.
Parameters:
fsmFSM instance.stateState to look up.
Returns:
Descriptor, or NULL if not found.
function fire_enter¶
Invoke the on_enter callback for a state.
Parameters:
fsmFSM instance.stateState being entered.
function fire_exit¶
Invoke the on_exit callback for a state.
Parameters:
fsmFSM instance.stateState being exited.
The documentation for this class was generated from the following file src/syntropic/util/syn_fsm.c