forked from WPI-HPRC/AvionicsComputer22
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystemManager.cpp
More file actions
90 lines (62 loc) · 2.52 KB
/
SystemManager.cpp
File metadata and controls
90 lines (62 loc) · 2.52 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
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
/*
* SystemManager.cpp
* Created on: Sep 17, 2021
* Author: Peter Dentch
*/
#include "SystemManager.h"
/*
* Constructor for this object SystemManager, should only be one instance running
*/
SystemManager::SystemManager(){};
/*
* Setup function for the system manager
*
* When main system is instantiated, subsystems are fields which get defined but initialized in this function
* Main system has SPI/I2C/Serial objects which are defined and passed to their subsystems
* Subsystems have init functions, pin bindings/config of peripherals happen there, not in any class constructor
*/
void SystemManager::mainSetup(){
Wire.begin(); // initialize I2C bus
Wire.setClock(I2C_FREQ); // set its frequency
SPI.begin(); // initialize SPI bus
// Test with setting different higher freq SPI
#ifdef USE_SERIAL
// "Serial.begin() is optional on Teensy. USB hardware initialization is performed before setup() runs.
// The baud rate input is ignored, and only used for Arduino compatibility."
Serial.begin(BAUD); // initialize USB port serial, gotta debug somehow
Serial.println(F("Serial initialized"));
#endif
//#ifdef USE_ROBOT_SYSTEM
// robot->systemInit(); // initializing system object
// robot->registerAllLoops(looper); // and registering its system/subsystem loops
//#endif
//Individual Boards
//sensorBoard->systemInit(); //Initializing Sensor Board Object
//sensorBoard->registerAllLoops(looper); //Registering the sensorBoard loops
telemetryBoard->systemInit();
telemetryBoard->registerAllLoops(looper);
}
/*
* Main loop function of the system manager which is constantly iterated by the Arduino/Teensy loop()
* This runs the highest level state machine of the computer, handles looper functionality,
* calling to run the system loops when their setup is successfully and it is safe to do so
*/
void SystemManager::mainLoop(){
// Main system state machine
switch(state){
// Startup state, for starting loops, which should run system/subsystem initialization code that
// doesn't need to run in setup() unlike hardware peripheral instances
case Startup:
// Don't attempt to run loops if they failed to start, stuck in this state
if(looper->startLoops()){ // start all loops, call all onStart() methods
state = Running;
Serial.println("Now in Running Mode");
}
break;
case Running:
looper->runLoops(); // run all loops, call all onLoop() methods
break;
default:
break;
}
}