-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathinit_state_machine.h
More file actions
62 lines (51 loc) · 1.8 KB
/
Copy pathinit_state_machine.h
File metadata and controls
62 lines (51 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// init_state_machine.h - Initialization State Machine
#ifndef INIT_STATE_MACHINE_H
#define INIT_STATE_MACHINE_H
#include <stdint.h>
#include <stdbool.h>
//--------------------------------------------------------------------+
// Initialization States
//--------------------------------------------------------------------+
typedef enum {
INIT_STATE_POWER_STABILIZATION,
INIT_STATE_SYSTEM_SETUP,
INIT_STATE_USB_DEVICE_INIT,
INIT_STATE_CORE1_STARTUP,
INIT_STATE_WAITING_CORE1,
INIT_STATE_WATCHDOG_START,
INIT_STATE_POWER_ENABLE,
INIT_STATE_FINAL_CHECKS,
INIT_STATE_COMPLETE,
INIT_STATE_ERROR,
INIT_STATE_RETRY
} init_state_t;
typedef enum {
INIT_EVENT_TIMER_EXPIRED,
INIT_EVENT_SUCCESS,
INIT_EVENT_FAILURE,
INIT_EVENT_RETRY_LIMIT_REACHED,
INIT_EVENT_CORE1_READY,
INIT_EVENT_RESET_REQUEST
} init_event_t;
//--------------------------------------------------------------------+
// State Machine Context
//--------------------------------------------------------------------+
typedef struct {
init_state_t current_state;
init_state_t previous_state;
uint32_t state_entry_time;
uint32_t state_timeout_ms;
int retry_count;
int max_retries;
bool error_occurred;
char error_message[64];
} init_state_machine_t;
//--------------------------------------------------------------------+
// State Machine Functions
//--------------------------------------------------------------------+
void init_state_machine_init(init_state_machine_t* sm);
bool init_state_machine_process(init_state_machine_t* sm, init_event_t event);
const char* init_state_to_string(init_state_t state);
bool init_state_machine_is_complete(const init_state_machine_t* sm);
bool init_state_machine_has_error(const init_state_machine_t* sm);
#endif // INIT_STATE_MACHINE_H