kernel: Widen pyro time values to 32 bits
[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 25
62
63 #define AO_AES_LEN 16
64
65 extern uint8_t ao_config_aes_seq;
66
67 struct ao_config {
68         uint8_t         major;
69         uint8_t         minor;
70         uint16_t        main_deploy;
71         int16_t         accel_plus_g;           /* changed for minor version 2 */
72         uint8_t         _legacy_radio_channel;
73         char            callsign[AO_MAX_CALLSIGN + 1];
74         uint8_t         apogee_delay;           /* minor version 1 */
75         int16_t         accel_minus_g;          /* minor version 2 */
76         uint32_t        radio_cal;              /* minor version 3 */
77         uint32_t        flight_log_max;         /* minor version 4 */
78         uint8_t         ignite_mode;            /* minor version 5 */
79         uint8_t         pad_orientation;        /* minor version 6 */
80         uint32_t        radio_setting;          /* minor version 7 */
81         uint8_t         radio_enable;           /* minor version 8 */
82         uint8_t         aes_key[AO_AES_LEN];    /* minor version 9 */
83         uint32_t        frequency;              /* minor version 10 */
84         uint16_t        apogee_lockout;         /* minor version 11 */
85 #if AO_PYRO_NUM
86         struct ao_pyro  pyro[AO_PYRO_NUM];      /* minor version 12 */
87 #endif
88         uint16_t        aprs_interval;          /* minor version 13 */
89 #if HAS_RADIO_POWER
90         uint8_t         radio_power;            /* minor version 14 */
91 #endif
92 #if HAS_RADIO_AMP
93         uint8_t         radio_amp;              /* minor version 14 */
94 #endif
95 #if HAS_IMU
96         int16_t         accel_zero_along;       /* minor version 15 */
97         int16_t         accel_zero_across;      /* minor version 15 */
98         int16_t         accel_zero_through;     /* minor version 15 */
99 #endif
100 #if HAS_BEEP
101         uint8_t         mid_beep;               /* minor version 16 */
102 #endif
103 #if HAS_TRACKER
104         uint16_t        tracker_motion;         /* minor version 17 */
105         uint8_t         tracker_interval;       /* minor version 17 */
106 #endif
107 #if AO_PYRO_NUM
108         uint16_t        pyro_time;              /* minor version 18 */
109 #endif
110 #if HAS_APRS
111         uint8_t         aprs_ssid;              /* minor version 19 */
112 #endif
113 #if HAS_RADIO_RATE
114         uint8_t         radio_rate;             /* minor version 20 */
115 #endif
116 #if HAS_RADIO_FORWARD
117         uint32_t        send_frequency;         /* minor version 21 */
118 #endif
119 #if HAS_APRS
120         uint8_t         aprs_format;            /* minor version 22 */
121 #endif
122 #if HAS_FIXED_PAD_BOX
123         uint8_t         pad_box;                /* minor version 22 */
124         uint8_t         pad_idle;               /* minor version 23 */
125 #endif
126 #if HAS_APRS
127         uint8_t         aprs_offset;            /* minor version 24 */
128 #endif
129 };
130
131 #define AO_APRS_FORMAT_COMPRESSED       0
132 #define AO_APRS_FORMAT_UNCOMPRESSED     1
133 #define AO_CONFIG_DEFAULT_APRS_FORMAT   AO_APRS_FORMAT_COMPRESSED
134
135 #if HAS_RADIO_FORWARD
136 extern uint32_t ao_send_radio_setting;
137 #endif
138
139 #define AO_IGNITE_MODE_DUAL             0
140 #define AO_IGNITE_MODE_APOGEE           1
141 #define AO_IGNITE_MODE_MAIN             2
142 #define AO_IGNITE_MODE_BOOSTER          3
143
144 #define AO_RADIO_ENABLE_CORE            1
145 #define AO_RADIO_DISABLE_TELEMETRY      2
146 #define AO_RADIO_DISABLE_RDF            4
147
148 #define AO_PAD_ORIENTATION_ANTENNA_UP   0
149 #define AO_PAD_ORIENTATION_ANTENNA_DOWN 1
150
151 #ifndef AO_CONFIG_MAX_SIZE
152 #define AO_CONFIG_MAX_SIZE      128
153 #endif
154
155 /* Make sure AO_CONFIG_MAX_SIZE is big enough */
156 typedef uint8_t config_check_space[(int) (AO_CONFIG_MAX_SIZE - sizeof (struct ao_config))];
157
158 extern struct ao_config ao_config;
159 extern uint8_t ao_config_loaded;
160
161 void
162 _ao_config_edit_start(void);
163
164 void
165 _ao_config_edit_finish(void);
166
167 void
168 ao_config_get(void);
169
170 void
171 ao_config_put(void);
172
173 void
174 ao_config_set_radio(void);
175
176 void
177 ao_config_log_fix_append(void);
178
179 void
180 ao_config_init(void);
181
182 #endif /* _AO_CONFIG_H_ */