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.h>
23
24 #if AO_PYRO_NUM
25 #include <ao_pyro.h>
26 #endif
27
28 #ifndef USE_STORAGE_CONFIG
29 #define USE_STORAGE_CONFIG 1
30 #endif
31
32 #ifndef USE_EEPROM_CONFIG
33 #define USE_EEPROM_CONFIG 0
34 #endif
35
36 #ifndef FLIGHT_LOG_APPEND
37 #define FLIGHT_LOG_APPEND 0
38 #endif
39
40 #if USE_STORAGE_CONFIG
41
42 #include <ao_storage.h>
43
44 #define ao_config_setup()               ao_storage_setup()
45 #define ao_config_erase()               ao_storage_erase(ao_storage_config, ao_storage_block)
46 #define ao_config_write(pos,bytes, len) ao_storage_write(ao_storage_config+(pos), bytes, len)
47 #define ao_config_read(pos,bytes, len)  ao_storage_read(ao_storage_config+(pos), bytes, len)
48 #define ao_config_flush()               ao_storage_flush()
49
50 #endif
51
52 #if USE_EEPROM_CONFIG
53
54 #include <ao_eeprom.h>
55
56 #define ao_config_setup()
57 #define ao_config_erase()
58 #define ao_config_write(pos,bytes, len) ao_eeprom_write(pos, bytes, len)
59 #define ao_config_read(pos,bytes, len)  ao_eeprom_read(pos, bytes, len)
60 #define ao_config_flush()
61
62 #endif
63
64 #define AO_CONFIG_MAJOR 1
65 #define AO_CONFIG_MINOR 26
66
67 /* All cc1200 devices support limiting TX power to 10mW */
68 #if !defined(HAS_RADIO_10MW) && defined(AO_CC1200_SPI)
69 #define HAS_RADIO_10MW 1
70 #endif
71
72 #define AO_AES_LEN 16
73
74 extern uint8_t ao_config_aes_seq;
75
76 struct ao_config {
77         uint8_t         major;
78         uint8_t         minor;
79         uint16_t        main_deploy;
80         int16_t         accel_plus_g;           /* changed for minor version 2 */
81         uint8_t         _legacy_radio_channel;
82         char            callsign[AO_MAX_CALLSIGN + 1];
83         uint8_t         apogee_delay;           /* minor version 1 */
84         int16_t         accel_minus_g;          /* minor version 2 */
85         uint32_t        radio_cal;              /* minor version 3 */
86         uint32_t        flight_log_max;         /* minor version 4 */
87         uint8_t         ignite_mode;            /* minor version 5 */
88         uint8_t         pad_orientation;        /* minor version 6 */
89         uint32_t        radio_setting;          /* minor version 7 */
90         uint8_t         radio_enable;           /* minor version 8 */
91         uint8_t         aes_key[AO_AES_LEN];    /* minor version 9 */
92         uint32_t        frequency;              /* minor version 10 */
93         uint16_t        apogee_lockout;         /* minor version 11 */
94 #if AO_PYRO_NUM
95         struct ao_pyro  pyro[AO_PYRO_NUM];      /* minor version 12 */
96 #endif
97         uint16_t        aprs_interval;          /* minor version 13 */
98 #if HAS_RADIO_POWER
99         uint8_t         radio_power;            /* minor version 14 */
100 #endif
101 #if HAS_RADIO_AMP
102         uint8_t         radio_amp;              /* minor version 14 */
103 #endif
104 #if HAS_IMU
105         int16_t         accel_zero_along;       /* minor version 15 */
106         int16_t         accel_zero_across;      /* minor version 15 */
107         int16_t         accel_zero_through;     /* minor version 15 */
108 #endif
109 #if HAS_BEEP
110         uint8_t         mid_beep;               /* minor version 16 */
111 #endif
112 #if HAS_TRACKER
113         uint16_t        tracker_motion;         /* minor version 17 */
114         uint8_t         tracker_interval;       /* minor version 17 */
115 #endif
116 #if AO_PYRO_NUM
117         uint16_t        pyro_time;              /* minor version 18 */
118 #endif
119 #if HAS_APRS
120         uint8_t         aprs_ssid;              /* minor version 19 */
121 #endif
122 #if HAS_RADIO_RATE
123         uint8_t         radio_rate;             /* minor version 20 */
124 #endif
125 #if HAS_RADIO_FORWARD
126         uint32_t        send_frequency;         /* minor version 21 */
127 #endif
128 #if HAS_APRS
129         uint8_t         aprs_format;            /* minor version 22 */
130 #endif
131 #if HAS_FIXED_PAD_BOX
132         uint8_t         pad_box;                /* minor version 22 */
133         uint8_t         pad_idle;               /* minor version 23 */
134 #endif
135 #if HAS_APRS
136         uint8_t         aprs_offset;            /* minor version 24 */
137 #endif
138 #if HAS_RADIO_10MW
139         uint8_t         radio_10mw;             /* minor version 25 */
140 #endif
141         uint8_t         report_feet;            /* minor version 26 */
142 };
143
144 struct ao_config_1_24 {
145         uint8_t         major;
146         uint8_t         minor;
147         uint16_t        main_deploy;
148         int16_t         accel_plus_g;           /* changed for minor version 2 */
149         uint8_t         _legacy_radio_channel;
150         char            callsign[AO_MAX_CALLSIGN + 1];
151         uint8_t         apogee_delay;           /* minor version 1 */
152         int16_t         accel_minus_g;          /* minor version 2 */
153         uint32_t        radio_cal;              /* minor version 3 */
154         uint32_t        flight_log_max;         /* minor version 4 */
155         uint8_t         ignite_mode;            /* minor version 5 */
156         uint8_t         pad_orientation;        /* minor version 6 */
157         uint32_t        radio_setting;          /* minor version 7 */
158         uint8_t         radio_enable;           /* minor version 8 */
159         uint8_t         aes_key[AO_AES_LEN];    /* minor version 9 */
160         uint32_t        frequency;              /* minor version 10 */
161         uint16_t        apogee_lockout;         /* minor version 11 */
162 #if AO_PYRO_NUM
163         struct ao_pyro_1_24     pyro[AO_PYRO_NUM];      /* minor version 12 */
164 #endif
165         uint16_t        aprs_interval;          /* minor version 13 */
166 #if HAS_RADIO_POWER
167         uint8_t         radio_power;            /* minor version 14 */
168 #endif
169 #if HAS_RADIO_AMP
170         uint8_t         radio_amp;              /* minor version 14 */
171 #endif
172 #if HAS_IMU
173         int16_t         accel_zero_along;       /* minor version 15 */
174         int16_t         accel_zero_across;      /* minor version 15 */
175         int16_t         accel_zero_through;     /* minor version 15 */
176 #endif
177 #if HAS_BEEP
178         uint8_t         mid_beep;               /* minor version 16 */
179 #endif
180 #if HAS_TRACKER
181         uint16_t        tracker_motion;         /* minor version 17 */
182         uint8_t         tracker_interval;       /* minor version 17 */
183 #endif
184 #if AO_PYRO_NUM
185         uint16_t        pyro_time;              /* minor version 18 */
186 #endif
187 #if HAS_APRS
188         uint8_t         aprs_ssid;              /* minor version 19 */
189 #endif
190 #if HAS_RADIO_RATE
191         uint8_t         radio_rate;             /* minor version 20 */
192 #endif
193 #if HAS_RADIO_FORWARD
194         uint32_t        send_frequency;         /* minor version 21 */
195 #endif
196 #if HAS_APRS
197         uint8_t         aprs_format;            /* minor version 22 */
198 #endif
199 #if HAS_FIXED_PAD_BOX
200         uint8_t         pad_box;                /* minor version 22 */
201         uint8_t         pad_idle;               /* minor version 23 */
202 #endif
203 #if HAS_APRS
204         uint8_t         aprs_offset;            /* minor version 24 */
205 #endif
206 };
207
208 #define AO_APRS_FORMAT_COMPRESSED       0
209 #define AO_APRS_FORMAT_UNCOMPRESSED     1
210 #define AO_CONFIG_DEFAULT_APRS_FORMAT   AO_APRS_FORMAT_COMPRESSED
211
212 #if HAS_RADIO_FORWARD
213 extern uint32_t ao_send_radio_setting;
214 #endif
215
216 #define AO_IGNITE_MODE_DUAL             0
217 #define AO_IGNITE_MODE_APOGEE           1
218 #define AO_IGNITE_MODE_MAIN             2
219 #define AO_IGNITE_MODE_BOOSTER          3
220
221 #define AO_RADIO_ENABLE_CORE            1
222 #define AO_RADIO_DISABLE_TELEMETRY      2
223 #define AO_RADIO_DISABLE_RDF            4
224
225 #define AO_PAD_ORIENTATION_ANTENNA_UP   0
226 #define AO_PAD_ORIENTATION_ANTENNA_DOWN 1
227
228 #ifndef AO_CONFIG_MAX_SIZE
229 #define AO_CONFIG_MAX_SIZE      128
230 #endif
231
232 /* Make sure AO_CONFIG_MAX_SIZE is big enough */
233 typedef uint8_t config_check_space[(int) (AO_CONFIG_MAX_SIZE - sizeof (struct ao_config))];
234
235 extern struct ao_config ao_config;
236 extern uint8_t ao_config_loaded;
237
238 void
239 _ao_config_edit_start(void);
240
241 void
242 _ao_config_edit_finish(void);
243
244 void
245 ao_config_get(void);
246
247 void
248 ao_config_put(void);
249
250 void
251 ao_config_set_radio(void);
252
253 void
254 ao_config_log_fix_append(void);
255
256 void
257 ao_config_init(void);
258
259 #endif /* _AO_CONFIG_H_ */