altos: Add config support for 2400 and 9600 baud telemetry rates
[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 #if USE_STORAGE_CONFIG
32
33 #include <ao_storage.h>
34
35 #define ao_config_setup()               ao_storage_setup()
36 #define ao_config_erase()               ao_storage_erase(ao_storage_config)
37 #define ao_config_write(pos,bytes, len) ao_storage_write(ao_storage_config+(pos), bytes, len)
38 #define ao_config_read(pos,bytes, len)  ao_storage_read(ao_storage_config+(pos), bytes, len)
39 #define ao_config_flush()               ao_storage_flush()
40
41 #endif
42
43 #if USE_EEPROM_CONFIG
44
45 #include <ao_eeprom.h>
46
47 #define ao_config_setup()
48 #define ao_config_erase()
49 #define ao_config_write(pos,bytes, len) ao_eeprom_write(pos, bytes, len)
50 #define ao_config_read(pos,bytes, len)  ao_eeprom_read(pos, bytes, len)
51 #define ao_config_flush()
52
53 #endif
54
55 #define AO_CONFIG_MAJOR 1
56 #define AO_CONFIG_MINOR 20
57
58 #define AO_AES_LEN 16
59
60 extern __xdata uint8_t ao_config_aes_seq;
61
62 struct ao_config {
63         uint8_t         major;
64         uint8_t         minor;
65         uint16_t        main_deploy;
66         int16_t         accel_plus_g;           /* changed for minor version 2 */
67         uint8_t         _legacy_radio_channel;
68         char            callsign[AO_MAX_CALLSIGN + 1];
69         uint8_t         apogee_delay;           /* minor version 1 */
70         int16_t         accel_minus_g;          /* minor version 2 */
71         uint32_t        radio_cal;              /* minor version 3 */
72         uint32_t        flight_log_max;         /* minor version 4 */
73         uint8_t         ignite_mode;            /* minor version 5 */
74         uint8_t         pad_orientation;        /* minor version 6 */
75         uint32_t        radio_setting;          /* minor version 7 */
76         uint8_t         radio_enable;           /* minor version 8 */
77         uint8_t         aes_key[AO_AES_LEN];    /* minor version 9 */
78         uint32_t        frequency;              /* minor version 10 */
79         uint16_t        apogee_lockout;         /* minor version 11 */
80 #if AO_PYRO_NUM
81         struct ao_pyro  pyro[AO_PYRO_NUM];      /* minor version 12 */
82 #endif
83         uint16_t        aprs_interval;          /* minor version 13 */
84 #if HAS_RADIO_POWER
85         uint8_t         radio_power;            /* minor version 14 */
86 #endif
87 #if HAS_RADIO_AMP
88         uint8_t         radio_amp;              /* minor version 14 */
89 #endif
90 #if HAS_GYRO
91         int16_t         accel_zero_along;       /* minor version 15 */
92         int16_t         accel_zero_across;      /* minor version 15 */
93         int16_t         accel_zero_through;     /* minor version 15 */
94 #endif
95 #if HAS_BEEP
96         uint8_t         mid_beep;               /* minor version 16 */
97 #endif
98 #if HAS_TRACKER
99         uint16_t        tracker_motion;         /* minor version 17 */
100         uint8_t         tracker_interval;       /* minor version 17 */
101 #endif
102 #if AO_PYRO_NUM
103         uint16_t        pyro_time;              /* minor version 18 */
104 #endif
105 #if HAS_APRS
106         uint8_t         aprs_ssid;              /* minor version 19 */
107 #endif
108 #if HAS_RADIO_RATE
109         uint8_t         radio_rate;             /* minor version 20 */
110 #endif
111 };
112
113 #define AO_IGNITE_MODE_DUAL             0
114 #define AO_IGNITE_MODE_APOGEE           1
115 #define AO_IGNITE_MODE_MAIN             2
116
117 #define AO_RADIO_ENABLE_CORE            1
118 #define AO_RADIO_DISABLE_TELEMETRY      2
119 #define AO_RADIO_DISABLE_RDF            4
120
121 #define AO_PAD_ORIENTATION_ANTENNA_UP   0
122 #define AO_PAD_ORIENTATION_ANTENNA_DOWN 1
123
124 #ifndef AO_CONFIG_MAX_SIZE
125 #define AO_CONFIG_MAX_SIZE      128
126 #endif
127
128 /* Make sure AO_CONFIG_MAX_SIZE is big enough */
129 typedef uint8_t config_check_space[(int) (AO_CONFIG_MAX_SIZE - sizeof (struct ao_config))];
130
131 extern __xdata struct ao_config ao_config;
132 extern __pdata uint8_t ao_config_loaded;
133
134 void
135 _ao_config_edit_start(void);
136
137 void
138 _ao_config_edit_finish(void);
139
140 void
141 ao_config_get(void);
142
143 void
144 ao_config_put(void);
145
146 void
147 ao_config_set_radio(void);
148
149 void
150 ao_config_init(void);
151
152 #endif /* _AO_CONFIG_H_ */