-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOBC.mega2560.ino
176 lines (137 loc) · 3.1 KB
/
OBC.mega2560.ino
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include <SPI.h>
#include <SdFat.h>
#include <stdio.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <mcp_can.h>
#include "service_mode.h"
#include "task_mngr.h"
#include "sdcard.h"
#include "time.h"
#include "gps.h"
#include "task_init.h"
#include "temperature.h"
#include "timer.h"
#include "radio.h"
#include "sw_timer.h"
#include "bus.h"
#include "get_hk.h"
#include "operation_modes.h"
#include "can.h"
/*
* Timing macros
*/
#define GETGPS 1 // activate GPS read every GETGPS)*5s (0-> never, 1-> every 5second)
#define GETTEMP 15 // activate Temperature measurement every GETTEMP)*5s (0-> never, 1-> every 5second)
#define GETISD_CS 2 // activate ISD_CS capture every GETISD_CS)*5s (0-> never, 1-> every 5second)
#define RADIO 3 // activate telemetry downlink every RADIO*5s (0-> never, 1-> every 5second)
//#define TERMINATION cut_down_alt
/*
* PIN macros
*/
#define BUZZ 5 //BUZZER
#define FTU 4 //FLIGHT TERMINATION ENABLE
#define GPS_RX 17 //GPS TO OBC
#define GPS_TX 16 //OBC TO GPS
#define SDA 18 //I2C SDA
#define SCL 19 //I2C SCL
//EXTERNAL CAMERA
#define MENU 6
#define SHTR 7
/*
* Radio variables
*/
//char radio_handshake[65];
/*
* Timing variables
*/
time_t obc_time;
can_ltm_t ltm_msg;
can_com_hk_t can_com_hk_msg;
unsigned long now;
//bool is_FTU_on=false;
int ledon = 1;
void task_toggle_led()
{
if(ledon == 0)
{
digitalWrite(7, LOW);
ledon = 1;
}
else
{
digitalWrite(7, HIGH);
ledon = 0;
}
}
void setup()
{
// put your setup code here, to run once:
set_operation_mode(OP_MODE_INIT);
sub_module_state = 0;
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
sw_timer_init();
//UART port for COM module
bus_init();
// DEBUG.begin(DEBUG_BAUD); // TODO: UNCOMMENT THIS FOR RELEASE
DEBUG.println(F("[OBC] startup"));
// ecam_init();
// ecam_ON();
time_init(&obc_time);
can_init();
DEBUG.println(F("[OBC] init COM..."));
//SICL.listen();
radio_init();
//wait for COM startup or timeout
DEBUG.print(F("[OBC] init GPS..."));
int32_t gps_error;
gps_error = gps_init();
switch(gps_error)
{
case 0 :
{
DEBUG.println(F("OK"));
break;
}
case -1 :
{
DEBUG.println(F("ERROR!: Airborne mode"));
break;
}
default :
{
DEBUG.println(F("ERROR!"));
break;
}
}
delay(500);
//SICL.listen();
//Pin configurations
pinMode(BUZZ, OUTPUT);
pinMode(FTU, OUTPUT);
digitalWrite(FTU, LOW);
delay(500);
//Test Buzzer
buzzerTest();
//Debug FTU
/* digitalWrite(FTU, HIGH);
delay(1000);
digitalWrite(FTU, LOW);
while(1);
*/
//SD CARD init
sdcard_init();
task_init();
//send startup msg
DEBUG.println(F("[OBC] Init done"));
set_operation_mode(OP_MODE_SAFE);
wake_up_task(SAFE_MODE_TASK);
start_scheduler();
}
void loop()
{
// put your main code here, to run repeatedly:
DEBUG.println(F("[OBC] TASK MANAGER ERROR"));
while(1);
}