Loading...
Searching...
No Matches
state.c
1/***********************************************************************************
2 * @file state.c *
3 * @author Matt Ricci *
4 * @addtogroup State *
5 * *
6 * @{ *
7 ***********************************************************************************/
8
9#include "state.h"
10
11#define AVG_BUFF_SIZE 15
12#define MEM_BUFF_SIZE 20992
13#define FLASH_PAGE_SIZE 256
14
15float avgPressBuff[AVG_BUFF_SIZE];
16float avgVelBuff[AVG_BUFF_SIZE];
17uint8_t buff[MEM_BUFF_SIZE];
18
19// TODO:
20// Move state pointer getter to private interface only accessible to core
21// and implement public interface that returns copy of struct.
22//
23// Australis Core should be the only source codebase that has access to
24// modify the contents of the system state variables. Updating state is
25// not an atomic operation, however with only a single writing task
26// per variable, and no possiblity for re-entrance, this will not pose
27// an issue to thread safety.
28//
29// This behaviour should be documented with an extremely clear warning
30// for internal development to avoid adding more tasks that may write
31// to state variables with already assigned ownership.
32
33static State state = {
34};
35
36/* =============================================================================== */
45void State_init() {
46 state.flightState = PRELAUNCH;
47 state.flightTimeMs = 0;
48 state.tilt = 0.0f;
49 state.cosine = 0.0f;
50 state.altitude = 0.0f;
51 state.velocity = 0.0f;
52 state.rotation = Quaternion_new();
53 state.avgVel = SlidingWindow_new(avgVelBuff, AVG_BUFF_SIZE);
54 state.avgPress = SlidingWindow_new(avgVelBuff, AVG_BUFF_SIZE);
55 state.mem = MemBuff_new(buff, MEM_BUFF_SIZE, FLASH_PAGE_SIZE);
56 memcpy(state.attitude, (float[]){0, 0, 1}, sizeof(state.attitude));
57 memcpy(state.launchAngle, (float[]){0, 0, 1}, sizeof(state.launchAngle));
58}
59
60/* =============================================================================== */
70 return &state;
71}
void State_init()
Definition state.c:45
State * State_getState()
Definition state.c:69
@ PRELAUNCH
Initial boot condition.
Definition state.h:25
State variable struct.
Definition state.h:36