altos: Add Mosaic GPS support to TeleMega v3+
[fw/altos] / src / kernel / ao_host.h
1 /*
2  * Copyright © 2009 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 #define _GNU_SOURCE
20
21 #include <stddef.h>
22 #include <stdint.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stdbool.h>
27
28 #define AO_TICK_TYPE uint32_t
29 #define AO_ADC_RING     64
30 #define ao_adc_ring_next(n)     (((n) + 1) & (AO_ADC_RING - 1))
31 #define ao_adc_ring_prev(n)     (((n) - 1) & (AO_ADC_RING - 1))
32
33 /*
34  * One set of samples read from the A/D converter
35  */
36 struct ao_adc {
37         AO_TICK_TYPE    tick;           /* tick when the sample was read */
38         int16_t         accel;          /* accelerometer */
39         int16_t         pres;           /* pressure sensor */
40         int16_t         temp;           /* temperature sensor */
41         int16_t         v_batt;         /* battery voltage */
42         int16_t         sense_d;        /* drogue continuity sense */
43         int16_t         sense_m;        /* main continuity sense */
44 };
45
46 enum ao_flight_state {
47         ao_flight_startup = 0,
48         ao_flight_idle = 1,
49         ao_flight_pad = 2,
50         ao_flight_boost = 3,
51         ao_flight_fast = 4,
52         ao_flight_coast = 5,
53         ao_flight_drogue = 6,
54         ao_flight_main = 7,
55         ao_flight_landed = 8,
56         ao_flight_invalid = 9
57 };
58
59 struct ao_adc ao_adc_ring[AO_ADC_RING];
60 uint8_t ao_adc_head;
61 AO_TICK_TYPE ao_tick_count;
62
63 #define ao_led_on(l)
64 #define ao_led_off(l)
65 #define ao_timer_set_adc_interval(i)
66 #define ao_wakeup(wchan) ao_dump_state(wchan)
67 #define ao_cmd_register(c)
68 #define ao_usb_disable()
69 #define ao_telemetry_set_interval(x)
70 #define ao_delay(x)
71
72 enum ao_igniter {
73         ao_igniter_drogue = 0,
74         ao_igniter_main = 1
75 };
76
77 void
78 ao_ignite(enum ao_igniter igniter)
79 {
80         printf ("ignite %s\n", igniter == ao_igniter_drogue ? "drogue" : "main");
81 }
82
83 struct ao_task {
84         int dummy;
85 };
86
87 #define ao_add_task(t,f,n)
88
89 #define ao_log_start()
90 #define ao_log_stop()
91
92 #ifndef AO_HERTZ
93 #define AO_HERTZ                100
94 #endif
95 #define AO_MS_TO_TICKS(ms)      ((ms) / (1000 / AO_HERTZ))
96 #define AO_SEC_TO_TICKS(s)      ((AO_TICK_TYPE) (s) * AO_HERTZ)
97 #define AO_NS_TO_TICKS(ns)      ((ns) / (1000000000L / AO_HERTZ))
98
99 #define AO_FLIGHT_TEST
100
101 struct ao_adc ao_adc_static;
102
103 FILE *emulator_in;
104
105 void
106 ao_dump_state(void *wchan);
107
108 void
109 ao_sleep(void *wchan);
110
111 const char * const ao_state_names[] = {
112         "startup", "idle", "pad", "boost", "fast",
113         "coast", "drogue", "main", "landed", "invalid"
114 };
115
116 struct ao_cmds {
117         void            (*func)(void);
118         const char      *help;
119 };
120
121
122 struct ao_config {
123         uint16_t        main_deploy;
124         int16_t         accel_zero_g;
125 #ifdef HAS_MOSAIC
126         uint8_t         gps_mosaic;
127 #endif
128 };
129
130 #define ao_config_get()
131
132 struct ao_config ao_config = { 250, 16000 };
133
134 #define memcpy(d,s,c) memcpy(d,s,c)
135 #define memset(d,v,c) memset(d,v,c)
136 #define memcmp(d,s,c) memcmp(d,s,c)
137
138 #define flush() fflush(stdout)