Solaris Software
Toggle main menu visibility
Loading...
Searching...
No Matches
fsm.h
Go to the documentation of this file.
1
/**
2
* @file fsm.h
3
* @brief Finite State Machine (FSM) module for the SPP core.
4
*/
5
6
#ifndef SPP_CORE_FSM_H
7
#define SPP_CORE_FSM_H
8
9
#include "
spp/core/returnTypes.h
"
10
#include "
spp/core/types.h
"
11
12
/* ----------------------------------------------------------------
13
* DEFINES
14
* ---------------------------------------------------------------- */
15
#define K_FSM_TIMEOUT_MS 10000U
// Only executed once, np with stops
16
#define K_FSM_MAX_TABLE_SIZE 10U
/*<Only allow 10 rows per FSM table */
17
#define K_FSM_MAX_TABLES 4U
/*<Maximum number of registered tables */
18
19
20
/* ----------------------------------------------------------------
21
* STRUCTS
22
* ---------------------------------------------------------------- */
23
24
/**
25
* @brief Top-level FSM states.
26
*/
27
typedef
enum
28
{
29
FSM_STATE_INIT
= 0,
30
FSM_STATE_READY
,
31
FSM_STATE_FLIGHT
,
32
FSM_STATE_LANDED
,
33
}
FSM_State_t
;
34
35
/**
36
* @brief FSM sub-states. Use FSM_SUBSTATE_NONE for states with no sub-state.
37
*/
38
typedef
enum
39
{
40
FSM_SUBSTATE_NONE
= 0,
41
FSM_SUBSTATE_FLIGHT_ASCENDING
,
42
FSM_SUBSTATE_FLIGHT_DESCENDING
,
43
FSM_SUBSTATE_FLIGHT_PARACHUTE_DEPLOYED
,
44
}
FSM_SubState_t
;
45
46
/**
47
* @brief A single row in the FSM transition table.
48
*/
49
typedef
struct
50
{
51
FSM_State_t
fromState
;
52
FSM_SubState_t
fromSubState
;
53
FSM_State_t
toState
;
54
FSM_SubState_t
toSubState
;
55
spp_bool_t
(*
guard
)(void);
56
void (*
action
)(void);
57
void (*
stateFunction
)(void);
58
}
FSM_Transition_t
;
59
60
/**
61
* @brief FSM handle — holds the current and previous state of the machine.
62
*/
63
typedef
struct
64
{
65
FSM_State_t
state
;
66
FSM_SubState_t
subState
;
67
FSM_State_t
prevState
;
68
FSM_SubState_t
prevSubState
;
69
}
FSM_Handle_t
;
70
71
/* ----------------------------------------------------------------
72
* PUBLIC FUNCTIONS
73
* ---------------------------------------------------------------- */
74
/**
75
* @brief Get the pointer to the FSM errors bit.
76
* @return Pointer to the FSM errors bit.
77
*/
78
spp_uint16_t
*
SPP_CORE_FSM_getErrorsBit
(
void
);
79
/**
80
* @brief Initialise the FSM with the internal service table.
81
* The service table runs the PUBSUB produce/consume cycle in the
82
* active states. Use @ref FSM_addTable to append application rows.
83
* @return K_SPP_OK on success.
84
*/
85
SPP_RetVal_t
FSM_init
(
void
);
86
87
/**
88
* @brief Append a transition table to the FSM.
89
* @param p_transitionTable Pointer to the table to append.
90
* @param tableSize Number of rows in the table.
91
* @return K_SPP_OK on success.
92
*/
93
SPP_RetVal_t
FSM_addTable
(
const
FSM_Transition_t
*p_transitionTable,
const
spp_uint8_t
tableSize);
94
/**
95
* @brief Evaluate the transition table and advance the FSM if a guard passes.
96
* Call this once per superloop tick.
97
*/
98
void
FSM_tick
(
void
);
99
100
101
#endif
/* SPP_CORE_FSM_H */
FSM_init
SPP_RetVal_t FSM_init(void)
Initialise the FSM with the internal service table. The service table runs the PUBSUB produce/consume...
Definition
fsm.c:122
SPP_CORE_FSM_getErrorsBit
spp_uint16_t * SPP_CORE_FSM_getErrorsBit(void)
Get the pointer to the FSM errors bit.
Definition
fsm.c:117
FSM_addTable
SPP_RetVal_t FSM_addTable(const FSM_Transition_t *p_transitionTable, const spp_uint8_t tableSize)
Append a transition table to the FSM.
Definition
fsm.c:135
FSM_tick
void FSM_tick(void)
Evaluate the transition table and advance the FSM if a guard passes. Call this once per superloop tic...
Definition
fsm.c:159
FSM_State_t
FSM_State_t
Top-level FSM states.
Definition
fsm.h:28
FSM_STATE_LANDED
@ FSM_STATE_LANDED
Definition
fsm.h:32
FSM_STATE_FLIGHT
@ FSM_STATE_FLIGHT
Definition
fsm.h:31
FSM_STATE_READY
@ FSM_STATE_READY
Definition
fsm.h:30
FSM_STATE_INIT
@ FSM_STATE_INIT
Definition
fsm.h:29
FSM_SubState_t
FSM_SubState_t
FSM sub-states. Use FSM_SUBSTATE_NONE for states with no sub-state.
Definition
fsm.h:39
FSM_SUBSTATE_FLIGHT_ASCENDING
@ FSM_SUBSTATE_FLIGHT_ASCENDING
Definition
fsm.h:41
FSM_SUBSTATE_FLIGHT_PARACHUTE_DEPLOYED
@ FSM_SUBSTATE_FLIGHT_PARACHUTE_DEPLOYED
Definition
fsm.h:43
FSM_SUBSTATE_NONE
@ FSM_SUBSTATE_NONE
Definition
fsm.h:40
FSM_SUBSTATE_FLIGHT_DESCENDING
@ FSM_SUBSTATE_FLIGHT_DESCENDING
Definition
fsm.h:42
returnTypes.h
Standard return-value type used across all SPP modules.
SPP_RetVal_t
SPP_RetVal_t
Unified return type for all SPP API functions.
Definition
returnTypes.h:24
FSM_Handle_t
FSM handle — holds the current and previous state of the machine.
Definition
fsm.h:64
FSM_Handle_t::prevSubState
FSM_SubState_t prevSubState
Definition
fsm.h:68
FSM_Handle_t::prevState
FSM_State_t prevState
Definition
fsm.h:67
FSM_Handle_t::state
FSM_State_t state
Definition
fsm.h:65
FSM_Handle_t::subState
FSM_SubState_t subState
Definition
fsm.h:66
FSM_Transition_t
A single row in the FSM transition table.
Definition
fsm.h:50
FSM_Transition_t::fromSubState
FSM_SubState_t fromSubState
Definition
fsm.h:52
FSM_Transition_t::guard
spp_bool_t(*) guard(void)
Definition
fsm.h:55
FSM_Transition_t::stateFunction
void(*) stateFunction(void)
Definition
fsm.h:57
FSM_Transition_t::fromState
FSM_State_t fromState
Definition
fsm.h:51
FSM_Transition_t::toState
FSM_State_t toState
Definition
fsm.h:53
FSM_Transition_t::action
void(*) action(void)
Definition
fsm.h:56
FSM_Transition_t::toSubState
FSM_SubState_t toSubState
Definition
fsm.h:54
types.h
Portable integer types and SPI/storage configuration types for SPP.
spp_uint16_t
uint16_t spp_uint16_t
Definition
types.h:29
spp_uint8_t
uint8_t spp_uint8_t
Definition
types.h:27
spp_bool_t
bool spp_bool_t
Definition
types.h:36
solaris-v2
spp
services
fsm
fsm.h
Generated by
1.18.0