Midnight Sun Firmware
Loading...
Searching...
No Matches
fsm.h
1#pragma once
2
3/************************************************************************************************
4 * @file fsm.h
5 *
6 * @brief Finite State Machine Library
7 *
8 * @date 2024-10-27
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include "stdint.h"
14
15/* Inter-component Headers */
16#include "FreeRTOS.h"
17#include "semphr.h"
18
19/* Intra-component Headers */
20#include "status.h"
21#include "tasks.h"
22
29#define MAX_STATES 10
30#define MAX_TRANSITIONS 5
31
32typedef void (*StateAction)(void *context);
33typedef uint8_t StateId;
34
35typedef struct {
36 StateId id;
37 StateAction entry_func;
38 StateAction state_action;
39} State;
40
41typedef struct {
42 State *states;
43 uint8_t *transition_table;
44 void *context;
45 StateId curr_state;
46 SemaphoreHandle_t fsm_sem;
47 StaticSemaphore_t sem_buf;
48 uint8_t num_states;
49} Fsm;
50
55#define STATE(state_id, entry, state_func) [state_id] = { .entry_func = entry, .state_action = state_func }
56
Definition: fsm.h:41
Definition: fsm.h:35