altos: Create macros to convert from/to radio RSSI representation
[fw/altos] / src / core / ao.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; 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_H_
19 #define _AO_H_
20
21 #include <stdint.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <stddef.h>
25 #include "ao_pins.h"
26 #include <ao_arch.h>
27
28 #define TRUE 1
29 #define FALSE 0
30
31 /* Convert a __data pointer into an __xdata pointer */
32 #ifndef DATA_TO_XDATA
33 #define DATA_TO_XDATA(a)        (a)
34 #endif
35 #ifndef PDATA_TO_XDATA
36 #define PDATA_TO_XDATA(a)       (a)
37 #endif
38 #ifndef CODE_TO_XDATA
39 #define CODE_TO_XDATA(a)        (a)
40 #endif
41
42 /* An AltOS task */
43 struct ao_task {
44         __xdata void *wchan;            /* current wait channel (NULL if running) */
45         uint16_t alarm;                 /* abort ao_sleep time */
46         ao_arch_task_members            /* any architecture-specific fields */
47         uint8_t task_id;                /* unique id */
48         __code char *name;              /* task name */
49         uint8_t stack[AO_STACK_SIZE];   /* saved stack */
50 };
51
52 extern __xdata struct ao_task *__data ao_cur_task;
53
54 #define AO_NUM_TASKS            16      /* maximum number of tasks */
55 #define AO_NO_TASK              0       /* no task id */
56
57 /*
58  ao_task.c
59  */
60
61 /* Suspend the current task until wchan is awoken.
62  * returns:
63  *  0 on normal wake
64  *  1 on alarm
65  */
66 uint8_t
67 ao_sleep(__xdata void *wchan);
68
69 /* Wake all tasks sleeping on wchan */
70 void
71 ao_wakeup(__xdata void *wchan);
72
73 /* set an alarm to go off in 'delay' ticks */
74 void
75 ao_alarm(uint16_t delay);
76
77 /* Clear any pending alarm */
78 void
79 ao_clear_alarm(void);
80
81 /* Yield the processor to another task */
82 void
83 ao_yield(void) ao_arch_naked_declare;
84
85 /* Add a task to the run queue */
86 void
87 ao_add_task(__xdata struct ao_task * task, void (*start)(void), __code char *name) __reentrant;
88
89 /* Terminate the current task */
90 void
91 ao_exit(void);
92
93 /* Dump task info to console */
94 void
95 ao_task_info(void);
96
97 /* Start the scheduler. This will not return */
98 void
99 ao_start_scheduler(void);
100
101 /*
102  * ao_panic.c
103  */
104
105 #define AO_PANIC_NO_TASK        1       /* AO_NUM_TASKS is not large enough */
106 #define AO_PANIC_DMA            2       /* Attempt to start DMA while active */
107 #define AO_PANIC_MUTEX          3       /* Mis-using mutex API */
108 #define AO_PANIC_EE             4       /* Mis-using eeprom API */
109 #define AO_PANIC_LOG            5       /* Failing to read/write log data */
110 #define AO_PANIC_CMD            6       /* Too many command sets registered */
111 #define AO_PANIC_STDIO          7       /* Too many stdio handlers registered */
112 #define AO_PANIC_REBOOT         8       /* Reboot failed */
113 #define AO_PANIC_FLASH          9       /* Invalid flash part (or wrong blocksize) */
114 #define AO_PANIC_USB            10      /* Trying to send USB packet while busy */
115 #define AO_PANIC_BT             11      /* Communications with bluetooth device failed */
116 #define AO_PANIC_STACK          12      /* Stack overflow */
117 #define AO_PANIC_SPI            13      /* SPI communication failure */
118 #define AO_PANIC_SELF_TEST      14      /* Self test failure */
119
120 /* Stop the operating system, beeping and blinking the reason */
121 void
122 ao_panic(uint8_t reason);
123
124 /*
125  * ao_timer.c
126  */
127
128 /* Our timer runs at 100Hz */
129 #define AO_HERTZ                100
130 #define AO_MS_TO_TICKS(ms)      ((ms) / (1000 / AO_HERTZ))
131 #define AO_SEC_TO_TICKS(s)      ((s) * AO_HERTZ)
132
133 /* Returns the current time in ticks */
134 uint16_t
135 ao_time(void);
136
137 /* Suspend the current task until ticks time has passed */
138 void
139 ao_delay(uint16_t ticks);
140
141 /* Set the ADC interval */
142 void
143 ao_timer_set_adc_interval(uint8_t interval) __critical;
144
145 /* Timer interrupt */
146 void
147 ao_timer_isr(void) ao_arch_interrupt(9);
148
149 /* Initialize the timer */
150 void
151 ao_timer_init(void);
152
153 /* Initialize the hardware clock. Must be called first */
154 void
155 ao_clock_init(void);
156
157 /*
158  * ao_mutex.c
159  */
160
161 void
162 ao_mutex_get(__xdata uint8_t *ao_mutex) __reentrant;
163
164 void
165 ao_mutex_put(__xdata uint8_t *ao_mutex) __reentrant;
166
167 /*
168  * ao_cmd.c
169  */
170
171 enum ao_cmd_status {
172         ao_cmd_success = 0,
173         ao_cmd_lex_error = 1,
174         ao_cmd_syntax_error = 2,
175 };
176
177 extern __pdata uint16_t ao_cmd_lex_i;
178 extern __pdata uint32_t ao_cmd_lex_u32;
179 extern __pdata char     ao_cmd_lex_c;
180 extern __pdata enum ao_cmd_status ao_cmd_status;
181
182 void
183 ao_cmd_lex(void);
184
185 void
186 ao_cmd_put8(uint8_t v);
187
188 void
189 ao_cmd_put16(uint16_t v);
190
191 uint8_t
192 ao_cmd_is_white(void);
193
194 void
195 ao_cmd_white(void);
196
197 int8_t
198 ao_cmd_hexchar(char c);
199
200 void
201 ao_cmd_hexbyte(void);
202
203 void
204 ao_cmd_hex(void);
205
206 void
207 ao_cmd_decimal(void);
208
209 uint8_t
210 ao_match_word(__code char *word);
211
212 struct ao_cmds {
213         void            (*func)(void);
214         __code char     *help;
215 };
216
217 void
218 ao_cmd_register(const __code struct ao_cmds *cmds);
219
220 void
221 ao_cmd_init(void);
222
223 #if HAS_CMD_FILTER
224 /*
225  * Provided by an external module to filter raw command lines
226  */
227 uint8_t
228 ao_cmd_filter(void);
229 #endif
230
231 /*
232  * Various drivers
233  */
234 #if HAS_ADC
235 #include <ao_adc.h>
236 #endif
237
238 #if HAS_BEEP
239 #include <ao_beep.h>
240 #endif
241
242 #if LEDS_AVAILABLE
243 #include <ao_led.h>
244 #endif
245
246 #if HAS_USB
247 #include <ao_usb.h>
248 #endif
249
250 #if HAS_EEPROM
251 #include <ao_storage.h>
252 #endif
253
254 #if HAS_LOG
255 #include <ao_log.h>
256 #endif
257
258 #if HAS_FLIGHT
259 #include <ao_flight.h>
260 #include <ao_sample.h>
261 #endif
262
263 /*
264  * ao_report.c
265  */
266
267 #define AO_RDF_INTERVAL_TICKS   AO_SEC_TO_TICKS(5)
268 #define AO_RDF_LENGTH_MS        500
269 #define AO_RDF_CONTINUITY_MS    32
270 #define AO_RDF_CONTINUITY_PAUSE 96
271 #define AO_RDF_CONTINUITY_TOTAL ((AO_RDF_CONTINUITY_PAUSE + AO_RDF_CONTINUITY_MS) * 3 + AO_RDF_CONTINUITY_PAUSE)
272
273 /* This assumes that we're generating a 1kHz tone, which
274  * modulates the carrier at 2kbps, or 250kBps
275  */
276 #define AO_MS_TO_RDF_LEN(ms) ((ms) / 4)
277
278 #define AO_RADIO_RDF_LEN        AO_MS_TO_RDF_LEN(AO_RDF_LENGTH_MS)
279 #define AO_RADIO_CONT_TONE_LEN  AO_MS_TO_RDF_LEN(AO_RDF_CONTINUITY_MS)
280 #define AO_RADIO_CONT_PAUSE_LEN AO_MS_TO_RDF_LEN(AO_RDF_CONTINUITY_PAUSE)
281 #define AO_RADIO_CONT_TOTAL_LEN AO_MS_TO_RDF_LEN(AO_RDF_CONTINUITY_TOTAL)
282
283 /* returns a value 0-3 to indicate igniter continuity */
284 uint8_t
285 ao_report_igniter(void);
286
287 void
288 ao_report_init(void);
289
290 /*
291  * ao_convert.c
292  *
293  * Given raw data, convert to SI units
294  */
295
296 /* pressure from the sensor to altitude in meters */
297 int16_t
298 ao_pres_to_altitude(int16_t pres) __reentrant;
299
300 int16_t
301 ao_altitude_to_pres(int16_t alt) __reentrant;
302
303 int16_t
304 ao_temp_to_dC(int16_t temp) __reentrant;
305
306 /*
307  * ao_convert_pa.c
308  *
309  * Convert between pressure in Pa and altitude in meters
310  */
311
312 int32_t
313 ao_pa_to_altitude(int32_t pa);
314
315 int32_t
316 ao_altitude_to_pa(int32_t alt);
317
318 #if HAS_DBG
319 #include <ao_dbg.h>
320 #endif
321
322 #if HAS_SERIAL_0 || HAS_SERIAL_1 || HAS_SERIAL_2 || HAS_SERIAL_3
323 #include <ao_serial.h>
324 #endif
325
326
327 /*
328  * ao_spi_slave.c
329  */
330
331 uint8_t
332 ao_spi_slave_recv(uint8_t *buf, uint8_t len);
333
334 void
335 ao_spi_slave_send(uint8_t *buf, uint8_t len);
336
337 void
338 ao_spi_slave_init(void);
339
340 /* This must be defined by the product; it will get called when chip
341  * select goes low, at which point it should use ao_spi_read and
342  * ao_spi_write to deal with the request
343  */
344
345 void
346 ao_spi_slave(void);
347
348 #include <ao_telemetry.h>
349 /*
350  * ao_gps.c
351  */
352
353 #define AO_GPS_NUM_SAT_MASK     (0xf << 0)
354 #define AO_GPS_NUM_SAT_SHIFT    (0)
355
356 #define AO_GPS_VALID            (1 << 4)
357 #define AO_GPS_RUNNING          (1 << 5)
358 #define AO_GPS_DATE_VALID       (1 << 6)
359 #define AO_GPS_COURSE_VALID     (1 << 7)
360
361 extern __pdata uint16_t ao_gps_tick;
362 extern __xdata uint8_t ao_gps_mutex;
363 extern __xdata struct ao_telemetry_location ao_gps_data;
364 extern __xdata struct ao_telemetry_satellite ao_gps_tracking_data;
365
366 struct ao_gps_orig {
367         uint8_t                 year;
368         uint8_t                 month;
369         uint8_t                 day;
370         uint8_t                 hour;
371         uint8_t                 minute;
372         uint8_t                 second;
373         uint8_t                 flags;
374         int32_t                 latitude;       /* degrees * 10⁷ */
375         int32_t                 longitude;      /* degrees * 10⁷ */
376         int16_t                 altitude;       /* m */
377         uint16_t                ground_speed;   /* cm/s */
378         uint8_t                 course;         /* degrees / 2 */
379         uint8_t                 hdop;           /* * 5 */
380         int16_t                 climb_rate;     /* cm/s */
381         uint16_t                h_error;        /* m */
382         uint16_t                v_error;        /* m */
383 };
384
385 struct ao_gps_sat_orig {
386         uint8_t         svid;
387         uint8_t         c_n_1;
388 };
389
390 #define AO_MAX_GPS_TRACKING     12
391
392 struct ao_gps_tracking_orig {
393         uint8_t                 channels;
394         struct ao_gps_sat_orig  sats[AO_MAX_GPS_TRACKING];
395 };
396
397 void
398 ao_gps(void);
399
400 void
401 ao_gps_print(__xdata struct ao_gps_orig *gps_data);
402
403 void
404 ao_gps_tracking_print(__xdata struct ao_gps_tracking_orig *gps_tracking_data);
405
406 void
407 ao_gps_init(void);
408
409 /*
410  * ao_gps_report.c
411  */
412
413 void
414 ao_gps_report(void);
415
416 void
417 ao_gps_report_init(void);
418
419 /*
420  * ao_gps_report_mega.c
421  */
422
423 void
424 ao_gps_report_mega(void);
425
426 void
427 ao_gps_report_mega_init(void);
428
429 /*
430  * ao_telemetry_orig.c
431  */
432
433 struct ao_adc_orig {
434         uint16_t        tick;           /* tick when the sample was read */
435         int16_t         accel;          /* accelerometer */
436         int16_t         pres;           /* pressure sensor */
437         int16_t         temp;           /* temperature sensor */
438         int16_t         v_batt;         /* battery voltage */
439         int16_t         sense_d;        /* drogue continuity sense */
440         int16_t         sense_m;        /* main continuity sense */
441 };
442
443 struct ao_telemetry_orig {
444         uint16_t                serial;
445         uint16_t                flight;
446         uint8_t                 flight_state;
447         int16_t                 accel;
448         int16_t                 ground_accel;
449         union {
450                 struct {
451                         int16_t                 speed;
452                         int16_t                 unused;
453                 } k;
454                 int32_t         flight_vel;
455         } u;
456         int16_t                 height;
457         int16_t                 ground_pres;
458         int16_t                 accel_plus_g;
459         int16_t                 accel_minus_g;
460         struct ao_adc_orig      adc;
461         struct ao_gps_orig      gps;
462         char                    callsign[AO_MAX_CALLSIGN];
463         struct ao_gps_tracking_orig     gps_tracking;
464 };
465
466 struct ao_telemetry_tiny {
467         uint16_t                serial;
468         uint16_t                flight;
469         uint8_t                 flight_state;
470         int16_t                 height;         /* AGL in meters */
471         int16_t                 speed;          /* in m/s * 16 */
472         int16_t                 accel;          /* in m/s² * 16 */
473         int16_t                 ground_pres;    /* sensor units */
474         struct ao_adc           adc;            /* raw ADC readings */
475         char                    callsign[AO_MAX_CALLSIGN];
476 };
477
478 struct ao_telemetry_orig_recv {
479         struct ao_telemetry_orig        telemetry_orig;
480         int8_t                          rssi;
481         uint8_t                         status;
482 };
483
484 struct ao_telemetry_tiny_recv {
485         struct ao_telemetry_tiny        telemetry_tiny;
486         int8_t                          rssi;
487         uint8_t                         status;
488 };
489
490 /* Unfortunately, we've exposed the CC1111 rssi units as the 'usual' method
491  * for reporting RSSI. So, now we use these values everywhere
492  */
493 #define AO_RSSI_FROM_RADIO(radio)       ((int16_t) ((int8_t) (radio) >> 1) - 74)
494 #define AO_RADIO_FROM_RSSI(rssi)        (((int8_t) (rssi) + 74) << 1)
495
496 /*
497  * ao_radio_recv tacks on rssi and status bytes
498  */
499
500 struct ao_telemetry_raw_recv {
501         uint8_t                 packet[AO_MAX_TELEMETRY + 2];
502 };
503
504 /* Set delay between telemetry reports (0 to disable) */
505
506 #ifdef AO_SEND_ALL_BARO
507 #define AO_TELEMETRY_INTERVAL_PAD       AO_MS_TO_TICKS(100)
508 #define AO_TELEMETRY_INTERVAL_FLIGHT    AO_MS_TO_TICKS(100)
509 #define AO_TELEMETRY_INTERVAL_RECOVER   AO_MS_TO_TICKS(100)
510 #else
511 #define AO_TELEMETRY_INTERVAL_PAD       AO_MS_TO_TICKS(1000)
512 #define AO_TELEMETRY_INTERVAL_FLIGHT    AO_MS_TO_TICKS(100)
513 #define AO_TELEMETRY_INTERVAL_RECOVER   AO_MS_TO_TICKS(1000)
514 #endif
515
516 void
517 ao_telemetry_set_interval(uint16_t interval);
518
519 void
520 ao_rdf_set(uint8_t rdf);
521
522 void
523 ao_telemetry_init(void);
524
525 void
526 ao_telemetry_orig_init(void);
527
528 void
529 ao_telemetry_tiny_init(void);
530
531 /*
532  * ao_radio.c
533  */
534
535 extern __xdata uint8_t  ao_radio_dma;
536 extern __xdata uint8_t ao_radio_dma_done;
537 extern __xdata uint8_t ao_radio_done;
538 extern __xdata uint8_t ao_radio_mutex;
539
540 #ifdef PKT_APPEND_STATUS_1_CRC_OK
541 #define AO_RADIO_STATUS_CRC_OK  PKT_APPEND_STATUS_1_CRC_OK
542 #else
543 #include <ao_fec.h>
544 #define AO_RADIO_STATUS_CRC_OK  AO_FEC_DECODE_CRC_OK
545 #endif
546
547 void
548 ao_radio_general_isr(void) ao_arch_interrupt(16);
549
550 void
551 ao_radio_send(const __xdata void *d, uint8_t size) __reentrant;
552
553 uint8_t
554 ao_radio_recv(__xdata void *d, uint8_t size) __reentrant;
555
556 void
557 ao_radio_recv_abort(void);
558
559 /*
560  * Compute the packet length as follows:
561  *
562  * 2000 bps (for a 1kHz tone)
563  * so, for 'ms' milliseconds, we need
564  * 2 * ms bits, or ms / 4 bytes
565  */
566
567 void
568 ao_radio_rdf(void);
569
570 void
571 ao_radio_continuity(uint8_t c);
572
573 void
574 ao_radio_rdf_abort(void);
575
576 void
577 ao_radio_init(void);
578
579 /*
580  * ao_monitor.c
581  */
582
583 extern const char const * const ao_state_names[];
584
585 #define AO_MONITOR_RING 8
586
587 union ao_monitor {
588         struct ao_telemetry_raw_recv    raw;
589         struct ao_telemetry_all_recv    all;
590         struct ao_telemetry_orig_recv   orig;
591         struct ao_telemetry_tiny_recv   tiny;
592 };
593
594 extern __xdata union ao_monitor ao_monitor_ring[AO_MONITOR_RING];
595
596 #define ao_monitor_ring_next(n) (((n) + 1) & (AO_MONITOR_RING - 1))
597
598 extern __data uint8_t ao_monitoring;
599 extern __data uint8_t ao_monitor_head;
600
601 void
602 ao_monitor(void);
603
604 #define AO_MONITORING_OFF       0
605 #define AO_MONITORING_ORIG      1
606
607 void
608 ao_monitor_set(uint8_t monitoring);
609
610 void
611 ao_monitor_disable(void);
612
613 void
614 ao_monitor_enable(void);
615
616 void
617 ao_monitor_init(void) __reentrant;
618
619 /*
620  * ao_stdio.c
621  */
622
623 #define AO_READ_AGAIN   ((char) -1)
624
625 struct ao_stdio {
626         char    (*pollchar)(void);
627         void    (*putchar)(char c) __reentrant;
628         void    (*flush)(void);
629         uint8_t echo;
630 };
631
632 extern __xdata struct ao_stdio ao_stdios[];
633 extern __pdata int8_t ao_cur_stdio;
634 extern __pdata int8_t ao_num_stdios;
635
636 void
637 flush(void);
638
639 extern __xdata uint8_t ao_stdin_ready;
640
641 uint8_t
642 ao_echo(void);
643
644 int8_t
645 ao_add_stdio(char (*pollchar)(void),
646              void (*putchar)(char) __reentrant,
647              void (*flush)(void)) __reentrant;
648
649 /*
650  * ao_ignite.c
651  */
652
653 enum ao_igniter {
654         ao_igniter_drogue = 0,
655         ao_igniter_main = 1
656 };
657
658 void
659 ao_ignite(enum ao_igniter igniter);
660
661 enum ao_igniter_status {
662         ao_igniter_unknown,     /* unknown status (ambiguous voltage) */
663         ao_igniter_ready,       /* continuity detected */
664         ao_igniter_active,      /* igniter firing */
665         ao_igniter_open,        /* open circuit detected */
666 };
667
668 struct ao_ignition {
669         uint8_t request;
670         uint8_t fired;
671         uint8_t firing;
672 };
673
674 extern __xdata struct ao_ignition ao_ignition[2];
675
676 enum ao_igniter_status
677 ao_igniter_status(enum ao_igniter igniter);
678
679 extern __pdata uint8_t ao_igniter_present;
680
681 void
682 ao_ignite_set_pins(void);
683
684 void
685 ao_igniter_init(void);
686
687 /*
688  * ao_config.c
689  */
690
691 #if HAS_FORCE_FREQ
692 /*
693  * Set this to force the frequency to 434.550MHz
694  */
695 extern __xdata uint8_t ao_force_freq;
696 #endif
697
698 #define AO_CONFIG_MAJOR 1
699 #define AO_CONFIG_MINOR 11
700
701 #define AO_AES_LEN 16
702
703 struct ao_config {
704         uint8_t         major;
705         uint8_t         minor;
706         uint16_t        main_deploy;
707         int16_t         accel_plus_g;           /* changed for minor version 2 */
708         uint8_t         _legacy_radio_channel;
709         char            callsign[AO_MAX_CALLSIGN + 1];
710         uint8_t         apogee_delay;           /* minor version 1 */
711         int16_t         accel_minus_g;          /* minor version 2 */
712         uint32_t        radio_cal;              /* minor version 3 */
713         uint32_t        flight_log_max;         /* minor version 4 */
714         uint8_t         ignite_mode;            /* minor version 5 */
715         uint8_t         pad_orientation;        /* minor version 6 */
716         uint32_t        radio_setting;          /* minor version 7 */
717         uint8_t         radio_enable;           /* minor version 8 */
718         uint8_t         aes_key[AO_AES_LEN];    /* minor version 9 */
719         uint32_t        frequency;              /* minor version 10 */
720         uint16_t        apogee_lockout;         /* minor version 11 */
721 };
722
723 #define AO_IGNITE_MODE_DUAL             0
724 #define AO_IGNITE_MODE_APOGEE           1
725 #define AO_IGNITE_MODE_MAIN             2
726
727 #define AO_PAD_ORIENTATION_ANTENNA_UP   0
728 #define AO_PAD_ORIENTATION_ANTENNA_DOWN 1
729
730 extern __xdata struct ao_config ao_config;
731
732 #define AO_CONFIG_MAX_SIZE      128
733
734 void
735 ao_config_get(void);
736
737 void
738 ao_config_put(void);
739
740 void
741 ao_config_set_radio(void);
742
743 void
744 ao_config_init(void);
745
746 /*
747  * ao_rssi.c
748  */
749
750 void
751 ao_rssi_set(int rssi_value);
752
753 void
754 ao_rssi_init(uint8_t rssi_led);
755
756 /*
757  * ao_product.c
758  *
759  * values which need to be defined for
760  * each instance of a product
761  */
762
763 extern const char ao_version[];
764 extern const char ao_manufacturer[];
765 extern const char ao_product[];
766
767 /*
768  * Fifos
769  */
770
771 #define AO_FIFO_SIZE    32
772
773 struct ao_fifo {
774         uint8_t insert;
775         uint8_t remove;
776         char    fifo[AO_FIFO_SIZE];
777 };
778
779 #define ao_fifo_insert(f,c) do { \
780         (f).fifo[(f).insert] = (c); \
781         (f).insert = ((f).insert + 1) & (AO_FIFO_SIZE-1); \
782 } while(0)
783
784 #define ao_fifo_remove(f,c) do {\
785         c = (f).fifo[(f).remove]; \
786         (f).remove = ((f).remove + 1) & (AO_FIFO_SIZE-1); \
787 } while(0)
788
789 #define ao_fifo_full(f)         ((((f).insert + 1) & (AO_FIFO_SIZE-1)) == (f).remove)
790 #define ao_fifo_empty(f)        ((f).insert == (f).remove)
791
792 #if PACKET_HAS_MASTER || PACKET_HAS_SLAVE
793 #include <ao_packet.h>
794 #endif
795
796 #if HAS_BTM
797 #include <ao_btm.h>
798 #endif
799
800 #if HAS_COMPANION
801 #include <ao_companion.h>
802 #endif
803
804 #if HAS_LCD
805 #include <ao_lcd.h>
806 #endif
807
808 #if HAS_AES
809 #include <ao_aes.h>
810 #endif
811
812 /* ao_launch.c */
813
814 struct ao_launch_command {
815         uint16_t        tick;
816         uint16_t        serial;
817         uint8_t         cmd;
818         uint8_t         channel;
819         uint16_t        unused;
820 };
821
822 #define AO_LAUNCH_QUERY         1
823
824 struct ao_launch_query {
825         uint16_t        tick;
826         uint16_t        serial;
827         uint8_t         channel;
828         uint8_t         valid;
829         uint8_t         arm_status;
830         uint8_t         igniter_status;
831 };
832
833 #define AO_LAUNCH_ARM           2
834 #define AO_LAUNCH_FIRE          3
835
836 void
837 ao_launch_init(void);
838
839 /*
840  * ao_log_single.c
841  */
842
843 #define AO_LOG_TELESCIENCE_START        ((uint8_t) 's')
844 #define AO_LOG_TELESCIENCE_DATA         ((uint8_t) 'd')
845
846 #define AO_LOG_TELESCIENCE_NUM_ADC      12
847
848 struct ao_log_telescience {
849         uint8_t         type;
850         uint8_t         csum;
851         uint16_t        tick;
852         uint16_t        tm_tick;
853         uint8_t         tm_state;
854         uint8_t         unused;
855         uint16_t        adc[AO_LOG_TELESCIENCE_NUM_ADC];
856 };
857
858 #define AO_LOG_SINGLE_SIZE              32
859
860 union ao_log_single {
861         struct ao_log_telescience       telescience;
862         union ao_telemetry_all          telemetry;
863         uint8_t                         bytes[AO_LOG_SINGLE_SIZE];
864 };
865
866 extern __xdata union ao_log_single      ao_log_single_write_data;
867 extern __xdata union ao_log_single      ao_log_single_read_data;
868
869 void
870 ao_log_single_extra_query(void);
871
872 void
873 ao_log_single_list(void);
874
875 void
876 ao_log_single_main(void);
877
878 uint8_t
879 ao_log_single_write(void);
880
881 uint8_t
882 ao_log_single_read(uint32_t pos);
883
884 void
885 ao_log_single_start(void);
886
887 void
888 ao_log_single_stop(void);
889
890 void
891 ao_log_single_restart(void);
892
893 void
894 ao_log_single_set(void);
895
896 void
897 ao_log_single_delete(void);
898
899 void
900 ao_log_single_init(void);
901
902 void
903 ao_log_single(void);
904
905 /*
906  * ao_pyro_slave.c
907  */
908
909 #define AO_TELEPYRO_NUM_ADC     9
910
911 #ifndef ao_xmemcpy
912 #define ao_xmemcpy(d,s,c) memcpy(d,s,c)
913 #define ao_xmemset(d,v,c) memset(d,v,c)
914 #define ao_xmemcmp(d,s,c) memcmp(d,s,c)
915 #endif
916
917 /*
918  * ao_terraui.c
919  */
920
921 void
922 ao_terraui_init(void);
923
924 /*
925  * ao_battery.c
926  */
927
928 #ifdef BATTERY_PIN
929 void
930 ao_battery_isr(void) ao_arch_interrupt(1);
931
932 uint16_t
933 ao_battery_get(void);
934
935 void
936 ao_battery_init(void);
937 #endif /* BATTERY_PIN */
938
939 /*
940  * ao_sqrt.c
941  */
942
943 uint32_t
944 ao_sqrt(uint32_t op);
945
946 /*
947  * ao_freq.c
948  */
949
950 int32_t ao_freq_to_set(int32_t freq, int32_t cal) __reentrant;
951
952 #include <ao_arch_funcs.h>
953
954 /*
955  * ao_ms5607.c
956  */
957
958 void ao_ms5607_init(void);
959
960 #endif /* _AO_H_ */