24 #ifndef Q_FSM_MAX_NEST_DEPTH
25 #define Q_FSM_MAX_NEST_DEPTH ( 5 )
28 #ifndef Q_FSM_MAX_TIMEOUTS
29 #define Q_FSM_MAX_TIMEOUTS ( 3 )
32 #ifndef Q_FSM_PS_SIGNALS_MAX
33 #define Q_FSM_PS_SIGNALS_MAX ( 0 )
36 #ifndef Q_FSM_PS_SUB_PER_SIGNAL_MAX
37 #define Q_FSM_PS_SUB_PER_SIGNAL_MAX ( 0 )
40 #if ( Q_FSM_MAX_NEST_DEPTH < 1 )
41 #error Q_FSM_MAX_NEST_DEPTH must be defined to be greater than or equal to 1.
44 #if ( ( Q_FSM_MAX_TIMEOUTS < 1 ) || ( Q_FSM_MAX_TIMEOUTS > 32 ) )
45 #error Q_FSM_MAX_TIMEOUTS must be defined with a value between 1 to 32.
57 #define QSM_STATE_TOP ( NULL )
60 #define QSM_TSOPT_MASK ( (qSM_TimeoutSpecOptions_t)0x00FFFFFFUL )
70 #define QSM_SIGNAL_START ( (qSM_SigId_t)0xFFFFFFFFUL )
76 #define QSM_SIGNAL_EXIT ( (qSM_SigId_t)0xFFFFFFFEUL )
82 #define QSM_SIGNAL_ENTRY ( (qSM_SigId_t)0xFFFFFFFDUL )
86 #define QSM_SIGNAL_NONE ( (qSM_SigId_t)0xFFFFFFFCUL )
91 #define QSM_SIGNAL_TIMEOUT(index) \
92 ( (qSM_SigId_t)0xFFFFFFFBUL - (qSM_SigId_t)( Q_FSM_MAX_TIMEOUTS - 1 ) \
93 + (qSM_SigId_t)(index) ) \
100 #define QSM_TSOPT_INDEX(index) \
101 ( ( QSM_TSOPT_MASK & (qSM_TimeoutSpecOptions_t)(index) ) ) \
108 #define QSM_TSOPT_SET_ENTRY ( (qSM_TimeoutSpecOptions_t)0x01000000UL )
114 #define QSM_TSOPT_RST_ENTRY ( (qSM_TimeoutSpecOptions_t)0x02000000UL )
120 #define QSM_TSOPT_SET_EXIT ( (qSM_TimeoutSpecOptions_t)0x04000000UL )
126 #define QSM_TSOPT_RST_EXIT ( (qSM_TimeoutSpecOptions_t)0x08000000UL )
132 #define QSM_TSOPT_KEEP_IF_SET ( (qSM_TimeoutSpecOptions_t)0x10000000UL )
138 #define QSM_TSOPT_PERIODIC ( (qSM_TimeoutSpecOptions_t)0x20000000UL )
143 #define QSM_SIGNAL_RANGE_MIN ( (qSM_SigId_t)0U )
147 #define QSM_SIGNAL_RANGE_MAX \
148 ( (qSM_SigId_t)( 0xFFFFFFFBUL - (qSM_SigId_t)Q_FSM_MAX_TIMEOUTS ) ) \
150 #define QSM_SIGNAL_TM_MAX ( (qSM_SigId_t)0xFFFFFFFBUL )
151 #define QSM_SIGNAL_TM_MIN QSM_SIGNAL_TIMEOUT(0)
156 #define QSM_SIGNAL_USER ( QSM_SIGNAL_RANGE_MIN )
166 typedef struct _qSM_Signal_s {
198 #define _qSM_HANDLER_FIELDS( pAttrib ) \
201 pAttrib void *machine; \
202 pAttrib void *state; \
203 pAttrib void *Data; \
204 pAttrib void *StateData; \
205 pAttrib void *SignalData; \
206 pAttrib qSM_SigId_t Signal; \
207 pAttrib qSM_Status_t Status; \
208 qSM_TransitionHistoryMode_t TransitionHistory \
212 typedef struct _qSM_uPublicData_s {
213 _qSM_HANDLER_FIELDS( Q_NONE );
215 _qSM_UnprotectedPublicData_t;
216 typedef struct _qSM_pPublicData_s {
217 _qSM_HANDLER_FIELDS(
const );
219 _qSM_ProtectedPublicData_t;
220 typedef _qSM_UnprotectedPublicData_t* qSM_UnprotectedHandler_t;
319 typedef struct _qSM_TimeoutStateDefinition_s {
346 typedef struct _qSM_State_s {
348 struct _qSM_State_Private_s {
349 struct _qSM_State_s *parent;
350 struct _qSM_State_s *lastRunningChild;
351 struct _qSM_State_s *initState;
368 typedef struct _qSM_TimeoutSpec_s {
371 qSTimer_t builtin_timeout[ Q_FSM_MAX_TIMEOUTS ];
387 typedef struct _qSM_s {
389 struct _qSM_Private_s {
394 #if ( Q_QUEUES == 1 )
400 _qSM_UnprotectedPublicData_t handler;
413 typedef struct _qSM_Transition_s {
qFloat32_t qTime_t
The typedef that specified an time quantity, usually expressed in seconds.
Definition qclock.h:33
void * qStateMachine_Get_State(const qSM_State_t *const s, const qSM_Attribute_t a)
Get attributes from the provided state object.
Definition qfsm.c:910
qBool_t qStateMachine_Run(qSM_t *const m, qSM_Signal_t sig)
Execute the Finite State Machine (FSM).
Definition qfsm.c:486
qBool_t qStateMachine_Set_MachineSurrounding(qSM_t *const m, qSM_SurroundingCallback_t sFcn)
Set/Change the FSM surrounding callback in run-time.
Definition qfsm.c:954
qUINT32_t qSM_TimeoutSpecOptions_t
A typedef to hold the timeout specification options.
Definition qfsm.h:312
qSM_Attribute_t
This enumeration defines the attributes that can be acquired for a FSM or a state.
Definition qfsm.h:425
qUINT32_t qSM_SigId_t
The type for signal ID.
Definition qfsm.h:161
qBool_t qStateMachine_TimeoutStop(qSM_t *const m, const qIndex_t xTimeout)
Stop the time count for the selected built-in timeout.
Definition qfsm.c:848
qBool_t qStateMachine_InstallSignalQueue(qSM_t *const m, qQueue_t *q)
Install a signal queue to the provided Finite State Machine (FSM).
Definition qfsm.c:607
qBool_t qStateMachine_Set_StateTransitions(qSM_State_t *const s, qSM_Transition_t *const table, const size_t n)
Installs a table with the outgoing transitions for the supplied state.
Definition qfsm.c:592
qBool_t qStateMachine_UnsubscribeFromSignal(const qSM_t *const m, qSM_SigId_t s)
Unsubscribe state machine from a particular signal.
Definition qfsm.c:162
qBool_t qStateMachine_SubscribeToSignal(qSM_t *const m, qSM_SigId_t s)
Subscribe state machine to a particular signal.
Definition qfsm.c:130
qBool_t qStateMachine_TimeoutSet(qSM_t *const m, const qIndex_t xTimeout, const qTime_t t)
Set the time for the selected built-in timeout inside the target FSM.
Definition qfsm.c:833
qBool_t qStateMachine_StateSubscribe(qSM_t *const m, qSM_State_t *const s, qSM_State_t *const parent, qSM_StateCallback_t sFcn, qSM_State_t *const init, void *pData)
This function subscribes the FSM instance to a specific state with an associated callback function.
Definition qfsm.c:565
qBool_t qStateMachine_InstallTimeoutSpec(qSM_t *const m, qSM_TimeoutSpec_t *const ts)
Install the Timeout-specification object to target FSM to allow timed signals within states ( See the...
Definition qfsm.c:799
qSM_Status_t(* qSM_StateCallback_t)(qSM_Handler_t h)
Pointer to a function that represents a state callback.
Definition qfsm.h:268
void(* qSM_SurroundingCallback_t)(qSM_Handler_t h)
Pointer to a function that represents a surrounding callback.
Definition qfsm.h:288
qSM_TransitionHistoryMode_t
This enumeration defines the possible modes to perform a transition to history.
Definition qfsm.h:188
void * qStateMachine_Get_Machine(qSM_t *const m, const qSM_Attribute_t a)
Get attributes from the provided Finite State Machine object.
Definition qfsm.c:877
qBool_t qStateMachine_SendSignal(qSM_t *const m, qSM_SigId_t sig, void *sData, const qBool_t isUrgent)
Sends a signal to a specific state machine or to all its subscribers (if available).
Definition qfsm.c:693
qBool_t qStateMachine_Setup(qSM_t *const m, qSM_StateCallback_t topFcn, qSM_State_t *const init, qSM_SurroundingCallback_t sFcn, void *pData)
Initializes a Finite State Machine (FSM).
Definition qfsm.c:525
qBool_t qStateMachine_Set_StateCallback(qSM_State_t *const state, qSM_StateCallback_t sFcn)
Set/Change the state callback in run-time.
Definition qfsm.c:941
qBool_t(* qSM_SignalAction_t)(qSM_Handler_t h)
Pointer to a function that represents a signal guard/action.
Definition qfsm.h:307
qBool_t qStateMachine_Set_StateTimeouts(qSM_State_t *const s, qSM_TimeoutStateDefinition_t *tdef, const size_t n)
Setup fixed timeouts for the specified state using a lookup-table.
Definition qfsm.c:818
qSM_Status_t
This enumeration defines the built-in state-execution status values that can be used as return value ...
Definition qfsm.h:175
@ qSM_ATTRIB_STATE_CURRENT
Definition qfsm.h:427
@ qSM_ATTRIB_DATA
Definition qfsm.h:431
@ qSM_ATTRIB_TRANSITION_TABLE
Definition qfsm.h:430
@ qSM_ATTRIB_COMPOSITE_LASTSTATE
Definition qfsm.h:433
@ qSM_ATTRIB_SIGNAL_QUEUE
Definition qfsm.h:428
@ qSM_ATTRIB_STATE_TOP
Definition qfsm.h:426
@ qSM_ATTRIB_COMPOSITE_PARENT
Definition qfsm.h:434
@ qSM_ATTRIB_TIMESPEC
Definition qfsm.h:429
@ qSM_ATTRIB_COMPOSITE_INITSTATE
Definition qfsm.h:432
@ qSM_TRANSITION_DEEP_HISTORY
Definition qfsm.h:191
@ qSM_TRANSITION_SHALLOW_HISTORY
Definition qfsm.h:190
@ qSM_TRANSITION_NO_HISTORY
Definition qfsm.h:189
@ qSM_STATUS_NULL
Definition qfsm.h:177
@ qSM_STATUS_BEFORE_ANY
Definition qfsm.h:176
@ qSM_STATUS_EXIT_FAILURE
Definition qfsm.h:178
@ qSM_STATUS_EXIT_SUCCESS
Definition qfsm.h:179
@ qSM_STATUS_SIGNAL_HANDLED
Definition qfsm.h:180
qUINT8_t qBool_t
A type to instantiate an OS boolean variable.
Definition qtypes.h:139
size_t qIndex_t
A type to instantiate an OS index variable. Can store the maximum size of a theoretically possible ob...
Definition qtypes.h:146
uint32_t qUINT32_t
Unsigned integer type with width of exactly 32 bits respectively.
Definition qtypes.h:48
A Queue object.
Definition qqueues.h:53
The callback argument to handle the state-machine dynamics and provide execution information....
Definition qfsm.h:232
void * StartState
Definition qfsm.h:233
const qSM_SigId_t Signal
Definition qfsm.h:240
const void * StateData
Definition qfsm.h:238
const void * state
Definition qfsm.h:236
void * NextState
Definition qfsm.h:234
const void * SignalData
Definition qfsm.h:239
const qSM_Status_t Status
Definition qfsm.h:241
qSM_TransitionHistoryMode_t TransitionHistory
Definition qfsm.h:242
const void * machine
Definition qfsm.h:235
const void * Data
Definition qfsm.h:237
The type to be used as a container variable for a signal.
Definition qfsm.h:166
void * sigData
Definition qfsm.h:168
qSM_SigId_t id
Definition qfsm.h:167
A state object.
Definition qfsm.h:346
A FSM Timeout-specification object.
Definition qfsm.h:368
This structure should be used to define an item for a timeout-specification table.
Definition qfsm.h:319
qSM_TimeoutSpecOptions_t options
Definition qfsm.h:321
qTime_t xTimeout
Definition qfsm.h:320
This structure should be used to define an item for a state transition table.
Definition qfsm.h:413
void * signalData
Definition qfsm.h:418
qSM_SignalAction_t guard
Definition qfsm.h:415
qSM_State_t * nextState
Definition qfsm.h:416
qSM_SigId_t xSignal
Definition qfsm.h:414
qSM_TransitionHistoryMode_t historyMode
Definition qfsm.h:417
A FSM(Finite State Machine) object.
Definition qfsm.h:387
A STimer(Software Timer) object.
Definition qstimers.h:32