Solaris Software
Loading...
Searching...
No Matches
app.c
Go to the documentation of this file.
1/**
2 * @file app.c
3 * @brief Solaris application initialization and execution.
4 *
5 * Initializes the hardware abstraction layer and the FSM,
6 * registers application-specific transitions, and runs the
7 * main execution loop. Handles fatal boot errors.
8 */
9
10/* ----------------------------------------------------------------
11 * INCLUDES
12 * ---------------------------------------------------------------- */
13#include "app.h"
16#include "custom.h"
17
18#include <stdio.h>
19
20/* ----------------------------------------------------------------
21 * STATIC FUNCTIONS
22 * ---------------------------------------------------------------- */
23/**
24 * @brief Boot error handler.
25 */
26static inline void BootError();
27
28/* ----------------------------------------------------------------
29 * PUBLIC FUNCTIONS
30 * ---------------------------------------------------------------- */
31void APP_initHal(void)
32{
33 // Get HAL port
34 const SPP_HalPort_t *p_halPorts = SPP_PORTS_ESP32S3_getHalPorts();
35
36 // HAL init
37 SPP_RetVal_t ret = SPP_HAL_init((void *)p_halPorts);
38 if (ret != K_SPP_OK)
39 {
40 printf("BOOT FAIL: HAL ret=%d\n", (int)ret);
41 BootError();
42 }
43}
44
45void APP_initFsm(void)
46{
47 // Get the custom FSM table
48 const FSM_Transition_t *p_fsmTable = CUSTOM_getFsmTable();
49
50 // Init the FSM with the internal service table
51 SPP_RetVal_t ret = FSM_init();
52 if (ret != K_SPP_OK)
53 {
54 printf("BOOT FAIL: FSM init ret=%d\n", (int)ret);
55 BootError();
56 }
57
58 // Add the application transition table
59 ret = FSM_addTable(p_fsmTable, K_CUSTOM_FSM_TABLE_SIZE);
60 if (ret != K_SPP_OK)
61 {
62 printf("BOOT FAIL: FSM addTable ret=%d\n", (int)ret);
63 BootError();
64 }
65}
66
67void APP_fsmLoop(void)
68{
69 // FSM loop
70 while (1)
71 {
72 FSM_tick();
73 }
74}
75
76/* ----------------------------------------------------------------
77 * STATIC FUNCTIONS IMPLEMENTATIONS
78 * ---------------------------------------------------------------- */
79static inline void BootError()
80{
81 while (1)
82 {
83 // Update Watchdog (future expansion)
84 // Send error bit to ground station (future expansion)
85 }
86}
void APP_fsmLoop(void)
Main loop for the FSM (executes the state machine indefinitely).
Definition app.c:67
static void BootError()
Boot error handler.
Definition app.c:79
void APP_initFsm(void)
Initialize the FSM (Finite State Machine).
Definition app.c:45
void APP_initHal(void)
Initialize the HAL (Hardware Abstraction Layer).
Definition app.c:31
const FSM_Transition_t * CUSTOM_getFsmTable(void)
Returns the application-specific FSM transition table.
Definition custom.c:53
Application-specific FSM configuration and error tracking.
#define K_CUSTOM_FSM_TABLE_SIZE
Definition custom.h:17
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_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
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
Finite State Machine (FSM) module for the SPP core.
const SPP_HalPort_t * SPP_PORTS_ESP32S3_getHalPorts(void)
Returns a pointer to the ESP32-S3 HAL port descriptor.
Definition halEsp32.c:74
ESP32-S3 HAL port descriptor for SPP.
SPP_RetVal_t SPP_HAL_init(void *p_halPorts)
This functions initializes the ports struct and initializes all the peripherals.
Definition hal.c:26
SPP_RetVal_t
Unified return type for all SPP API functions.
Definition returnTypes.h:24
@ K_SPP_OK
Definition returnTypes.h:25
A single row in the FSM transition table.
Definition fsm.h:50
Ports struct that contains all the pointers to the Ports functions.
Definition hal.h:234