telegps-v1.0: Provide one log and append to it
[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; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #ifndef _AO_CONFIG_H_
19 #define _AO_CONFIG_H_
20
21 #include <ao_pyro.h>
22
23 #ifndef USE_STORAGE_CONFIG
24 #define USE_STORAGE_CONFIG 1
25 #endif
26
27 #ifndef USE_EEPROM_CONFIG
28 #define USE_EEPROM_CONFIG 0
29 #endif
30
31 #ifndef FLIGHT_LOG_APPEND
32 #define FLIGHT_LOG_APPEND 0
33 #endif
34
35 #if USE_STORAGE_CONFIG
36
37 #include <ao_storage.h>
38
39 #define ao_config_setup()               ao_storage_setup()
40 #define ao_config_erase()               ao_storage_erase(ao_storage_config)
41 #define ao_config_write(pos,bytes, len) ao_storage_write(ao_storage_config+(pos), bytes, len)
42 #define ao_config_read(pos,bytes, len)  ao_storage_read(ao_storage_config+(pos), bytes, len)
43 #define ao_config_flush()               ao_storage_flush()
44
45 #endif
46
47 #if USE_EEPROM_CONFIG
48
49 #include <ao_eeprom.h>
50
51 #define ao_config_setup()
52 #define ao_config_erase()
53 #define ao_config_write(pos,bytes, len) ao_eeprom_write(pos, bytes, len)
54 #define ao_config_read(pos,bytes, len)  ao_eeprom_read(pos, bytes, len)
55 #define ao_config_flush()
56
57 #endif
58
59 #define AO_CONFIG_MAJOR 1
60 #define AO_CONFIG_MINOR 20
61
62 #define AO_AES_LEN 16
63
64 extern __xdata uint8_t ao_config_aes_seq;
65
66 struct ao_config {
67         uint8_t         major;
68         uint8_t         minor;
69         uint16_t        main_deploy;
70         int16_t         accel_plus_g;           /* changed for minor version 2 */
71         uint8_t         _legacy_radio_channel;
72         char            callsign[AO_MAX_CALLSIGN + 1];
73         uint8_t         apogee_delay;           /* minor version 1 */
74         int16_t         accel_minus_g;          /* minor version 2 */
75         uint32_t        radio_cal;              /* minor version 3 */
76         uint32_t        flight_log_max;         /* minor version 4 */
77         uint8_t         ignite_mode;            /* minor version 5 */
78         uint8_t         pad_orientation;        /* minor version 6 */
79         uint32_t        radio_setting;          /* minor version 7 */
80         uint8_t         radio_enable;           /* minor version 8 */
81         uint8_t         aes_key[AO_AES_LEN];    /* minor version 9 */
82         uint32_t        frequency;              /* minor version 10 */
83         uint16_t        apogee_lockout;         /* minor version 11 */
84 #if AO_PYRO_NUM
85         struct ao_pyro  pyro[AO_PYRO_NUM];      /* minor version 12 */
86 #endif
87         uint16_t        aprs_interval;          /* minor version 13 */
88 #if HAS_RADIO_POWER
89         uint8_t         radio_power;            /* minor version 14 */
90 #endif
91 #if HAS_RADIO_AMP
92         uint8_t         radio_amp;              /* minor version 14 */
93 #endif
94 #if HAS_GYRO
95         int16_t         accel_zero_along;       /* minor version 15 */
96         int16_t         accel_zero_across;      /* minor version 15 */
97         int16_t         accel_zero_through;     /* minor version 15 */
98 #endif
99 #if HAS_BEEP
100         uint8_t         mid_beep;               /* minor version 16 */
101 #endif
102 #if HAS_TRACKER
103         uint16_t        tracker_motion;         /* minor version 17 */
104         uint8_t         tracker_interval;       /* minor version 17 */
105 #endif
106 #if AO_PYRO_NUM
107         uint16_t        pyro_time;              /* minor version 18 */
108 #endif
109 #if HAS_APRS
110         uint8_t         aprs_ssid;              /* minor version 19 */
111 #endif
112 #if HAS_RADIO_RATE
113         uint8_t         radio_rate;             /* minor version 20 */
114 #endif
115 };
116
117 #define AO_IGNITE_MODE_DUAL             0
118 #define AO_IGNITE_MODE_APOGEE           1
119 #define AO_IGNITE_MODE_MAIN             2
120
121 #define AO_RADIO_ENABLE_CORE            1
122 #define AO_RADIO_DISABLE_TELEMETRY      2
123 #define AO_RADIO_DISABLE_RDF            4
124
125 #define AO_PAD_ORIENTATION_ANTENNA_UP   0
126 #define AO_PAD_ORIENTATION_ANTENNA_DOWN 1
127
128 #ifndef AO_CONFIG_MAX_SIZE
129 #define AO_CONFIG_MAX_SIZE      128
130 #endif
131
132 /* Make sure AO_CONFIG_MAX_SIZE is big enough */
133 typedef uint8_t config_check_space[(int) (AO_CONFIG_MAX_SIZE - sizeof (struct ao_config))];
134
135 extern __xdata struct ao_config ao_config;
136 extern __pdata uint8_t ao_config_loaded;
137
138 void
139 _ao_config_edit_start(void);
140
141 void
142 _ao_config_edit_finish(void);
143
144 void
145 ao_config_get(void);
146
147 void
148 ao_config_put(void);
149
150 void
151 ao_config_set_radio(void);
152
153 void
154 ao_config_log_fix_append(void);
155
156 void
157 ao_config_init(void);
158
159 #endif /* _AO_CONFIG_H_ */