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 on the FSM table */
17
18
19
/* ----------------------------------------------------------------
20
* STRUCTS
21
* ---------------------------------------------------------------- */
22
23
/**
24
* @brief Top-level FSM states.
25
*/
26
typedef
enum
27
{
28
FSM_STATE_INIT
= 0,
29
FSM_STATE_READY
,
30
FSM_STATE_FLIGHT
,
31
FSM_STATE_LANDED
,
32
}
FSM_State_t
;
33
34
/**
35
* @brief FSM sub-states. Use FSM_SUBSTATE_NONE for states with no sub-state.
36
*/
37
typedef
enum
38
{
39
FSM_SUBSTATE_NONE
= 0,
40
FSM_SUBSTATE_FLIGHT_ASCENDING
,
41
FSM_SUBSTATE_FLIGHT_DESCENDING
,
42
FSM_SUBSTATE_FLIGHT_PARACHUTE_DEPLOYED
,
43
}
FSM_SubState_t
;
44
45
/**
46
* @brief A single row in the FSM transition table.
47
*/
48
typedef
struct
49
{
50
FSM_State_t
fromState
;
51
FSM_SubState_t
fromSubState
;
52
FSM_State_t
toState
;
53
FSM_SubState_t
toSubState
;
54
spp_bool_t
(*
guard
)(void);
55
void (*
action
)(void);
56
void (*
stateFunction
)(void);
57
}
FSM_Transition_t
;
58
59
/**
60
* @brief FSM handle — holds the current and previous state of the machine.
61
*/
62
typedef
struct
63
{
64
FSM_State_t
state
;
65
FSM_SubState_t
subState
;
66
FSM_State_t
prevState
;
67
FSM_SubState_t
prevSubState
;
68
}
FSM_Handle_t
;
69
70
/* ----------------------------------------------------------------
71
* PUBLIC FUNCTIONS
72
* ---------------------------------------------------------------- */
73
/**
74
* @brief Get the pointer to the FSM errors bit.
75
* @return Pointer to the FSM errors bit.
76
*/
77
spp_uint16_t
*
SPP_CORE_FSM_getErrorsBit
(
void
);
78
/**
79
* @brief Initialize the FSM.
80
* @param p_halPorts Pointer to the HAL ports.
81
* @param p_transitiontable Pointer to the FSM table for operation.
82
* @param tableSize Size of the table.
83
*/
84
SPP_RetVal_t
FSM_init
(
const
FSM_Transition_t
*p_transitionTable,
const
spp_uint8_t
tableSize);
85
/**
86
* @brief Evaluate the transition table and advance the FSM if a guard passes.
87
* Call this once per superloop tick.
88
*/
89
void
FSM_tick
(
void
);
90
91
92
#endif
/* SPP_CORE_FSM_H */
FSM_init
SPP_RetVal_t FSM_init(const FSM_Transition_t *p_transitionTable, const spp_uint8_t tableSize)
Initialize the FSM.
Definition
fsm.c:38
SPP_CORE_FSM_getErrorsBit
spp_uint16_t * SPP_CORE_FSM_getErrorsBit(void)
Get the pointer to the FSM errors bit.
Definition
fsm.c:33
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:58
FSM_State_t
FSM_State_t
Top-level FSM states.
Definition
fsm.h:27
FSM_STATE_LANDED
@ FSM_STATE_LANDED
Definition
fsm.h:31
FSM_STATE_FLIGHT
@ FSM_STATE_FLIGHT
Definition
fsm.h:30
FSM_STATE_READY
@ FSM_STATE_READY
Definition
fsm.h:29
FSM_STATE_INIT
@ FSM_STATE_INIT
Definition
fsm.h:28
FSM_SubState_t
FSM_SubState_t
FSM sub-states. Use FSM_SUBSTATE_NONE for states with no sub-state.
Definition
fsm.h:38
FSM_SUBSTATE_FLIGHT_ASCENDING
@ FSM_SUBSTATE_FLIGHT_ASCENDING
Definition
fsm.h:40
FSM_SUBSTATE_FLIGHT_PARACHUTE_DEPLOYED
@ FSM_SUBSTATE_FLIGHT_PARACHUTE_DEPLOYED
Definition
fsm.h:42
FSM_SUBSTATE_NONE
@ FSM_SUBSTATE_NONE
Definition
fsm.h:39
FSM_SUBSTATE_FLIGHT_DESCENDING
@ FSM_SUBSTATE_FLIGHT_DESCENDING
Definition
fsm.h:41
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:63
FSM_Handle_t::prevSubState
FSM_SubState_t prevSubState
Definition
fsm.h:67
FSM_Handle_t::prevState
FSM_State_t prevState
Definition
fsm.h:66
FSM_Handle_t::state
FSM_State_t state
Definition
fsm.h:64
FSM_Handle_t::subState
FSM_SubState_t subState
Definition
fsm.h:65
FSM_Transition_t
A single row in the FSM transition table.
Definition
fsm.h:49
FSM_Transition_t::fromSubState
FSM_SubState_t fromSubState
Definition
fsm.h:51
FSM_Transition_t::guard
spp_bool_t(*) guard(void)
Definition
fsm.h:54
FSM_Transition_t::stateFunction
void(*) stateFunction(void)
Definition
fsm.h:56
FSM_Transition_t::fromState
FSM_State_t fromState
Definition
fsm.h:50
FSM_Transition_t::toState
FSM_State_t toState
Definition
fsm.h:52
FSM_Transition_t::action
void(*) action(void)
Definition
fsm.h:55
FSM_Transition_t::toSubState
FSM_SubState_t toSubState
Definition
fsm.h:53
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