altos/test: Adjust CRC error rate after FEC fix
[fw/altos] / src / kernel / ao_config.h
1 /*
2  * Copyright © 2013 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #ifndef _AO_CONFIG_H_
20 #define _AO_CONFIG_H_
21
22 #include <ao_pyro.h>
23
24 #ifndef USE_STORAGE_CONFIG
25 #define USE_STORAGE_CONFIG 1
26 #endif
27
28 #ifndef USE_EEPROM_CONFIG
29 #define USE_EEPROM_CONFIG 0
30 #endif
31
32 #ifndef FLIGHT_LOG_APPEND
33 #define FLIGHT_LOG_APPEND 0
34 #endif
35
36 #if USE_STORAGE_CONFIG
37
38 #include <ao_storage.h>
39
40 #define ao_config_setup()               ao_storage_setup()
41 #define ao_config_erase()               ao_storage_erase(ao_storage_config, ao_storage_block)
42 #define ao_config_write(pos,bytes, len) ao_storage_write(ao_storage_config+(pos), bytes, len)
43 #define ao_config_read(pos,bytes, len)  ao_storage_read(ao_storage_config+(pos), bytes, len)
44 #define ao_config_flush()               ao_storage_flush()
45
46 #endif
47
48 #if USE_EEPROM_CONFIG
49
50 #include <ao_eeprom.h>
51
52 #define ao_config_setup()
53 #define ao_config_erase()
54 #define ao_config_write(pos,bytes, len) ao_eeprom_write(pos, bytes, len)
55 #define ao_config_read(pos,bytes, len)  ao_eeprom_read(pos, bytes, len)
56 #define ao_config_flush()
57
58 #endif
59
60 #define AO_CONFIG_MAJOR 1
61 #define AO_CONFIG_MINOR 26
62
63 /* All cc1200 devices support limiting TX power to 10mW */
64 #if !defined(HAS_RADIO_10MW) && defined(AO_CC1200_SPI)
65 #define HAS_RADIO_10MW 1
66 #endif
67
68 #define AO_AES_LEN 16
69
70 extern uint8_t ao_config_aes_seq;
71
72 struct ao_config {
73         uint8_t         major;
74         uint8_t         minor;
75         uint16_t        main_deploy;
76         int16_t         accel_plus_g;           /* changed for minor version 2 */
77         uint8_t         _legacy_radio_channel;
78         char            callsign[AO_MAX_CALLSIGN + 1];
79         uint8_t         apogee_delay;           /* minor version 1 */
80         int16_t         accel_minus_g;          /* minor version 2 */
81         uint32_t        radio_cal;              /* minor version 3 */
82         uint32_t        flight_log_max;         /* minor version 4 */
83         uint8_t         ignite_mode;            /* minor version 5 */
84         uint8_t         pad_orientation;        /* minor version 6 */
85         uint32_t        radio_setting;          /* minor version 7 */
86         uint8_t         radio_enable;           /* minor version 8 */
87         uint8_t         aes_key[AO_AES_LEN];    /* minor version 9 */
88         uint32_t        frequency;              /* minor version 10 */
89         uint16_t        apogee_lockout;         /* minor version 11 */
90 #if AO_PYRO_NUM
91         struct ao_pyro  pyro[AO_PYRO_NUM];      /* minor version 12 */
92 #endif
93         uint16_t        aprs_interval;          /* minor version 13 */
94 #if HAS_RADIO_POWER
95         uint8_t         radio_power;            /* minor version 14 */
96 #endif
97 #if HAS_RADIO_AMP
98         uint8_t         radio_amp;              /* minor version 14 */
99 #endif
100 #if HAS_IMU
101         int16_t         accel_zero_along;       /* minor version 15 */
102         int16_t         accel_zero_across;      /* minor version 15 */
103         int16_t         accel_zero_through;     /* minor version 15 */
104 #endif
105 #if HAS_BEEP
106         uint8_t         mid_beep;               /* minor version 16 */
107 #endif
108 #if HAS_TRACKER
109         uint16_t        tracker_motion;         /* minor version 17 */
110         uint8_t         tracker_interval;       /* minor version 17 */
111 #endif
112 #if AO_PYRO_NUM
113         uint16_t        pyro_time;              /* minor version 18 */
114 #endif
115 #if HAS_APRS
116         uint8_t         aprs_ssid;              /* minor version 19 */
117 #endif
118 #if HAS_RADIO_RATE
119         uint8_t         radio_rate;             /* minor version 20 */
120 #endif
121 #if HAS_RADIO_FORWARD
122         uint32_t        send_frequency;         /* minor version 21 */
123 #endif
124 #if HAS_APRS
125         uint8_t         aprs_format;            /* minor version 22 */
126 #endif
127 #if HAS_FIXED_PAD_BOX
128         uint8_t         pad_box;                /* minor version 22 */
129         uint8_t         pad_idle;               /* minor version 23 */
130 #endif
131 #if HAS_APRS
132         uint8_t         aprs_offset;            /* minor version 24 */
133 #endif
134 #if HAS_RADIO_10MW
135         uint8_t         radio_10mw;             /* minor version 25 */
136 #endif
137         uint8_t         report_feet;            /* minor version 26 */
138 };
139
140 struct ao_config_1_24 {
141         uint8_t         major;
142         uint8_t         minor;
143         uint16_t        main_deploy;
144         int16_t         accel_plus_g;           /* changed for minor version 2 */
145         uint8_t         _legacy_radio_channel;
146         char            callsign[AO_MAX_CALLSIGN + 1];
147         uint8_t         apogee_delay;           /* minor version 1 */
148         int16_t         accel_minus_g;          /* minor version 2 */
149         uint32_t        radio_cal;              /* minor version 3 */
150         uint32_t        flight_log_max;         /* minor version 4 */
151         uint8_t         ignite_mode;            /* minor version 5 */
152         uint8_t         pad_orientation;        /* minor version 6 */
153         uint32_t        radio_setting;          /* minor version 7 */
154         uint8_t         radio_enable;           /* minor version 8 */
155         uint8_t         aes_key[AO_AES_LEN];    /* minor version 9 */
156         uint32_t        frequency;              /* minor version 10 */
157         uint16_t        apogee_lockout;         /* minor version 11 */
158 #if AO_PYRO_NUM
159         struct ao_pyro_1_24     pyro[AO_PYRO_NUM];      /* minor version 12 */
160 #endif
161         uint16_t        aprs_interval;          /* minor version 13 */
162 #if HAS_RADIO_POWER
163         uint8_t         radio_power;            /* minor version 14 */
164 #endif
165 #if HAS_RADIO_AMP
166         uint8_t         radio_amp;              /* minor version 14 */
167 #endif
168 #if HAS_IMU
169         int16_t         accel_zero_along;       /* minor version 15 */
170         int16_t         accel_zero_across;      /* minor version 15 */
171         int16_t         accel_zero_through;     /* minor version 15 */
172 #endif
173 #if HAS_BEEP
174         uint8_t         mid_beep;               /* minor version 16 */
175 #endif
176 #if HAS_TRACKER
177         uint16_t        tracker_motion;         /* minor version 17 */
178         uint8_t         tracker_interval;       /* minor version 17 */
179 #endif
180 #if AO_PYRO_NUM
181         uint16_t        pyro_time;              /* minor version 18 */
182 #endif
183 #if HAS_APRS
184         uint8_t         aprs_ssid;              /* minor version 19 */
185 #endif
186 #if HAS_RADIO_RATE
187         uint8_t         radio_rate;             /* minor version 20 */
188 #endif
189 #if HAS_RADIO_FORWARD
190         uint32_t        send_frequency;         /* minor version 21 */
191 #endif
192 #if HAS_APRS
193         uint8_t         aprs_format;            /* minor version 22 */
194 #endif
195 #if HAS_FIXED_PAD_BOX
196         uint8_t         pad_box;                /* minor version 22 */
197         uint8_t         pad_idle;               /* minor version 23 */
198 #endif
199 #if HAS_APRS
200         uint8_t         aprs_offset;            /* minor version 24 */
201 #endif
202 };
203
204 #define AO_APRS_FORMAT_COMPRESSED       0
205 #define AO_APRS_FORMAT_UNCOMPRESSED     1
206 #define AO_CONFIG_DEFAULT_APRS_FORMAT   AO_APRS_FORMAT_COMPRESSED
207
208 #if HAS_RADIO_FORWARD
209 extern uint32_t ao_send_radio_setting;
210 #endif
211
212 #define AO_IGNITE_MODE_DUAL             0
213 #define AO_IGNITE_MODE_APOGEE           1
214 #define AO_IGNITE_MODE_MAIN             2
215 #define AO_IGNITE_MODE_BOOSTER          3
216
217 #define AO_RADIO_ENABLE_CORE            1
218 #define AO_RADIO_DISABLE_TELEMETRY      2
219 #define AO_RADIO_DISABLE_RDF            4
220
221 #define AO_PAD_ORIENTATION_ANTENNA_UP   0
222 #define AO_PAD_ORIENTATION_ANTENNA_DOWN 1
223
224 #ifndef AO_CONFIG_MAX_SIZE
225 #define AO_CONFIG_MAX_SIZE      128
226 #endif
227
228 /* Make sure AO_CONFIG_MAX_SIZE is big enough */
229 typedef uint8_t config_check_space[(int) (AO_CONFIG_MAX_SIZE - sizeof (struct ao_config))];
230
231 extern struct ao_config ao_config;
232 extern uint8_t ao_config_loaded;
233
234 void
235 _ao_config_edit_start(void);
236
237 void
238 _ao_config_edit_finish(void);
239
240 void
241 ao_config_get(void);
242
243 void
244 ao_config_put(void);
245
246 void
247 ao_config_set_radio(void);
248
249 void
250 ao_config_log_fix_append(void);
251
252 void
253 ao_config_init(void);
254
255 #endif /* _AO_CONFIG_H_ */