-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·112 lines (98 loc) · 3.4 KB
/
main.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "main.h"
#include <main.h>
#include <source/drivers/flash.h>
#include <source/drivers/hal.h>
#include <source/drivers/lithium.h>
#include <source/drivers/payload.h>
#include <source/drivers/ring_buffer.h>
#include <source/drivers/umbilical.h>
#include <source/globals.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <ti/devices/msp432e4/driverlib/driverlib.h>
#include "source/drivers/lithium.h"
#include "source/drivers/payload.h"
#include "source/drivers/umbilical.h"
#include "source/updater/updater.h"
uint8_t SYSTEM_FLAGS;
int main(void) {
init_clock();
init_gpio();
init_hibernate();
bool hibernate_on_boot;
should_hibernate_on_boot(&hibernate_on_boot);
if (hibernate_on_boot) {
GPIOPinWrite(sys_reset_port, low_power_trigger_pin,
low_power_trigger_pin);
GPIOPinWrite(sys_reset_port, sys_reset_pin, 0x00);
MAP_HibernateRTCMatchSet(0, (MAP_HibernateRTCGet() + hibernate_time_s));
MAP_HibernateRequest();
while (1) {
}
}
SysCtlDelay(5 * system_clock_hz); // 1 second wait before bringing up the sys MCU
GPIOPinWrite(sys_reset_port, sys_reset_pin, sys_reset_pin);
init_system_uart();
init_lithium_uart();
init_umbilical_uart();
init_flash_spi();
init_crc();
MAP_IntMasterEnable();
SYSTEM_FLAGS = 0;
uint8_t payload_buffer_len = 0;
uint8_t payload_buffer[payload_buffer_max_len] = {0};
static uint32_t payloads_received = 0;
static uint32_t payload_errors = 0;
SystemState state = SYSTEM_IDLE_STATE;
while (1) {
switch (state) {
case SYSTEM_IDLE_STATE: {
// If something of interest in a buffer, call the packet handler
uint8_t n_bytes_available = 0;
umbilicalBytesAvailable(&n_bytes_available);
if (n_bytes_available > 5) {
state = SYSTEM_HANDLE_UMBILICAL_PACKET;
break;
}
lithiumBytesAvailable(&n_bytes_available);
if (n_bytes_available > 5) {
state = SYSTEM_HANDLE_LITHIUM_PACKET;
break;
}
state = SYSTEM_IDLE_STATE;
break;
}
case SYSTEM_HANDLE_UMBILICAL_PACKET: {
err_t read_successful =
umbilicalReadPacket(payload_buffer, &payload_buffer_len);
if (read_successful != UMB_NO_ERROR) {
state = SYSTEM_IDLE_STATE;
break;
}
state = SYSTEM_HANDLE_PAYLOAD;
break;
}
case SYSTEM_HANDLE_LITHIUM_PACKET: {
err_t read_successful =
lithiumReadPacket(payload_buffer, &payload_buffer_len);
if (read_successful != LITHIUM_NO_ERROR) {
state = SYSTEM_IDLE_STATE;
break;
}
state = SYSTEM_HANDLE_PAYLOAD;
break;
}
case SYSTEM_HANDLE_PAYLOAD: {
payloads_received++;
err_t err =
handlePayload(payload_buffer, (uint8_t)payload_buffer_len);
if (err != 0) {
payload_errors++;
}
state = SYSTEM_IDLE_STATE;
break;
}
}
}
}