Fix clock initialization to not try to use 32kHz xtal on P2_3/P2_4
[fw/altos] / src / 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 "cc1111.h"
25
26 #define TRUE 1
27 #define FALSE 0
28
29 /* Convert a __data pointer into an __xdata pointer */
30 #define DATA_TO_XDATA(a)        ((void __xdata *) ((uint8_t) (a) | 0xff00))
31
32 /* Stack runs from above the allocated __data space to 0xfe, which avoids
33  * writing to 0xff as that triggers the stack overflow indicator
34  */
35 #define AO_STACK_START  0x80
36 #define AO_STACK_END    0xfe
37 #define AO_STACK_SIZE   (AO_STACK_END - AO_STACK_START + 1)
38
39 /* An AltOS task */
40 struct ao_task {
41         __xdata void *wchan;            /* current wait channel (NULL if running) */
42         uint8_t stack_count;            /* amount of saved stack */
43         uint8_t task_id;                /* index in the task array */
44         __code char *name;              /* task name */
45         uint8_t stack[AO_STACK_SIZE];   /* saved stack */
46 };
47
48 extern __xdata struct ao_task *__data ao_cur_task;
49
50 #define AO_NUM_TASKS            16      /* maximum number of tasks */
51 #define AO_NO_TASK              0       /* no task id */
52
53 /*
54  ao_task.c
55  */
56
57 /* Suspend the current task until wchan is awoken */
58 void
59 ao_sleep(__xdata void *wchan);
60
61 /* Wake all tasks sleeping on wchan */
62 void
63 ao_wakeup(__xdata void *wchan);
64
65 /* Yield the processor to another task */
66 void
67 ao_yield(void) _naked;
68
69 /* Add a task to the run queue */
70 void
71 ao_add_task(__xdata struct ao_task * task, void (*start)(void), __code char *name) __reentrant;
72
73 /* Dump task info to console */
74 void
75 ao_task_info(void);
76
77 /* Start the scheduler. This will not return */
78 void
79 ao_start_scheduler(void);
80
81 /*
82  * ao_panic.c
83  */
84
85 #define AO_PANIC_NO_TASK        1       /* AO_NUM_TASKS is not large enough */
86 #define AO_PANIC_DMA            2       /* Attempt to start DMA while active */
87 #define AO_PANIC_MUTEX          3       /* Mis-using mutex API */
88 #define AO_PANIC_EE             4       /* Mis-using eeprom API */
89 #define AO_PANIC_LOG            5       /* Failing to read/write log data */
90 #define AO_PANIC_CMD            6       /* Too many command sets registered */
91
92 /* Stop the operating system, beeping and blinking the reason */
93 void
94 ao_panic(uint8_t reason);
95
96 /*
97  * ao_timer.c
98  */
99
100 /* Our timer runs at 100Hz */
101 #define AO_MS_TO_TICKS(ms)      ((ms) / 10)
102 #define AO_SEC_TO_TICKS(s)      ((s) * 100)
103
104 /* Returns the current time in ticks */
105 uint16_t
106 ao_time(void);
107
108 /* Suspend the current task until ticks time has passed */
109 void
110 ao_delay(uint16_t ticks);
111
112 /* Set the ADC interval */
113 void
114 ao_timer_set_adc_interval(uint8_t interval) __critical;
115
116 /* Timer interrupt */
117 void
118 ao_timer_isr(void) interrupt 9;
119
120 /* Initialize the timer */
121 void
122 ao_timer_init(void);
123
124 /* Initialize the hardware clock. Must be called first */
125 void
126 ao_clock_init(void);
127
128 /*
129  * ao_adc.c
130  */
131
132 #define AO_ADC_RING     64
133 #define ao_adc_ring_next(n)     (((n) + 1) & (AO_ADC_RING - 1))
134 #define ao_adc_ring_prev(n)     (((n) - 1) & (AO_ADC_RING - 1))
135
136 /*
137  * One set of samples read from the A/D converter
138  */
139 struct ao_adc {
140         uint16_t        tick;           /* tick when the sample was read */
141         int16_t         accel;          /* accelerometer */
142         int16_t         pres;           /* pressure sensor */
143         int16_t         temp;           /* temperature sensor */
144         int16_t         v_batt;         /* battery voltage */
145         int16_t         sense_d;        /* drogue continuity sense */
146         int16_t         sense_m;        /* main continuity sense */
147 };
148
149 /*
150  * A/D data is stored in a ring, with the next sample to be written
151  * at ao_adc_head
152  */
153 extern volatile __xdata struct ao_adc   ao_adc_ring[AO_ADC_RING];
154 extern volatile __data uint8_t          ao_adc_head;
155
156 /* Trigger a conversion sequence (called from the timer interrupt) */
157 void
158 ao_adc_poll(void);
159
160 /* Suspend the current task until another A/D sample is converted */
161 void
162 ao_adc_sleep(void);
163
164 /* Get a copy of the last complete A/D sample set */
165 void
166 ao_adc_get(__xdata struct ao_adc *packet);
167
168 /* The A/D interrupt handler */
169 #if !AO_NO_ADC_ISR
170 void
171 ao_adc_isr(void) interrupt 1;
172 #endif
173
174 /* Initialize the A/D converter */
175 void
176 ao_adc_init(void);
177
178 /*
179  * ao_beep.c
180  */
181
182 /*
183  * Various pre-defined beep frequencies
184  *
185  * frequency = 1/2 (24e6/32) / beep
186  */
187
188 #define AO_BEEP_LOW     150     /* 2500Hz */
189 #define AO_BEEP_MID     94      /* 3989Hz */
190 #define AO_BEEP_HIGH    75      /* 5000Hz */
191 #define AO_BEEP_OFF     0       /* off */
192
193 #define AO_BEEP_g       240     /* 1562.5Hz */
194 #define AO_BEEP_gs      227     /* 1652Hz (1655Hz) */
195 #define AO_BEEP_aa      214     /* 1752Hz (1754Hz) */
196 #define AO_BEEP_bbf     202     /* 1856Hz (1858Hz) */
197 #define AO_BEEP_bb      190     /* 1974Hz (1969Hz) */
198 #define AO_BEEP_cc      180     /* 2083Hz (2086Hz) */
199 #define AO_BEEP_ccs     170     /* 2205Hz (2210Hz) */
200 #define AO_BEEP_dd      160     /* 2344Hz (2341Hz) */
201 #define AO_BEEP_eef     151     /* 2483Hz (2480Hz) */
202 #define AO_BEEP_ee      143     /* 2622Hz (2628Hz) */
203 #define AO_BEEP_ff      135     /* 2778Hz (2784Hz) */
204 #define AO_BEEP_ffs     127     /* 2953Hz (2950Hz) */
205 #define AO_BEEP_gg      120     /* 3125Hz */
206 #define AO_BEEP_ggs     113     /* 3319Hz (3311Hz) */
207 #define AO_BEEP_aaa     107     /* 3504Hz (3508Hz) */
208 #define AO_BEEP_bbbf    101     /* 3713Hz (3716Hz) */
209 #define AO_BEEP_bbb     95      /* 3947Hz (3937Hz) */
210 #define AO_BEEP_ccc     90      /* 4167Hz (4171Hz) */
211 #define AO_BEEP_cccs    85      /* 4412Hz (4419Hz) */
212 #define AO_BEEP_ddd     80      /* 4688Hz (4682Hz) */
213 #define AO_BEEP_eeef    76      /* 4934Hz (4961Hz) */
214 #define AO_BEEP_eee     71      /* 5282Hz (5256Hz) */
215 #define AO_BEEP_fff     67      /* 5597Hz (5568Hz) */
216 #define AO_BEEP_fffs    64      /* 5859Hz (5899Hz) */
217 #define AO_BEEP_ggg     60      /* 6250Hz */
218
219 /* Set the beeper to the specified tone */
220 void
221 ao_beep(uint8_t beep);
222
223 /* Turn on the beeper for the specified time */
224 void
225 ao_beep_for(uint8_t beep, uint16_t ticks) __reentrant;
226
227 /* Initialize the beeper */
228 void
229 ao_beep_init(void);
230
231 /*
232  * ao_led.c
233  */
234
235 #define AO_LED_NONE     0
236 #define AO_LED_GREEN    1
237 #define AO_LED_RED      2
238
239 /* Turn on the specified LEDs */
240 void
241 ao_led_on(uint8_t colors);
242
243 /* Turn off the specified LEDs */
244 void
245 ao_led_off(uint8_t colors);
246
247 /* Set all of the LEDs to the specified state */
248 void
249 ao_led_set(uint8_t colors);
250
251 /* Toggle the specified LEDs */
252 void
253 ao_led_toggle(uint8_t colors);
254
255 /* Turn on the specified LEDs for the indicated interval */
256 void
257 ao_led_for(uint8_t colors, uint16_t ticks) __reentrant;
258
259 /* Initialize the LEDs */
260 void
261 ao_led_init(uint8_t enable);
262
263 /*
264  * ao_usb.c
265  */
266
267 /* Put one character to the USB output queue */
268 void
269 ao_usb_putchar(char c);
270
271 /* Get one character from the USB input queue */
272 char
273 ao_usb_getchar(void);
274
275 /* Flush the USB output queue */
276 void
277 ao_usb_flush(void);
278
279 /* USB interrupt handler */
280 void
281 ao_usb_isr(void) interrupt 6;
282
283 /* Enable the USB controller */
284 void
285 ao_usb_enable(void);
286
287 /* Disable the USB controller */
288 void
289 ao_usb_disable(void);
290
291 /* Initialize the USB system */
292 void
293 ao_usb_init(void);
294
295 /*
296  * ao_cmd.c
297  */
298
299 enum ao_cmd_status {
300         ao_cmd_success = 0,
301         ao_cmd_lex_error = 1,
302         ao_cmd_syntax_error = 2,
303 };
304
305 extern __xdata uint16_t ao_cmd_lex_i;
306 extern __xdata char     ao_cmd_lex_c;
307 extern __xdata enum ao_cmd_status ao_cmd_status;
308
309 void
310 ao_cmd_lex(void);
311
312 void
313 ao_cmd_put8(uint8_t v);
314
315 void
316 ao_cmd_put16(uint16_t v);
317
318 void
319 ao_cmd_white(void);
320
321 void
322 ao_cmd_hex(void);
323
324 void
325 ao_cmd_decimal(void);
326
327 struct ao_cmds {
328         char            cmd;
329         void            (*func)(void);
330         const char      *help;
331 };
332
333 void
334 ao_cmd_register(__code struct ao_cmds *cmds);
335
336 void
337 ao_cmd_init(void);
338
339 /*
340  * ao_dma.c
341  */
342
343 /* Allocate a DMA channel. the 'done' parameter will be set to 1
344  * when the dma is finished and will be used to wakeup any waiters
345  */
346 uint8_t
347 ao_dma_alloc(__xdata uint8_t * done);
348
349 /* Setup a DMA channel */
350 void
351 ao_dma_set_transfer(uint8_t id,
352                     void __xdata *srcaddr,
353                     void __xdata *dstaddr,
354                     uint16_t count,
355                     uint8_t cfg0,
356                     uint8_t cfg1);
357
358 /* Start a DMA channel */
359 void
360 ao_dma_start(uint8_t id);
361
362 /* Manually trigger a DMA channel */
363 void
364 ao_dma_trigger(uint8_t id);
365
366 /* Abort a running DMA transfer */
367 void
368 ao_dma_abort(uint8_t id);
369
370 /* DMA interrupt routine */
371 void
372 ao_dma_isr(void) interrupt 8;
373
374 /*
375  * ao_mutex.c
376  */
377
378 void
379 ao_mutex_get(__xdata uint8_t *ao_mutex) __reentrant;
380
381 void
382 ao_mutex_put(__xdata uint8_t *ao_mutex) __reentrant;
383
384 /*
385  * ao_ee.c
386  */
387
388 /*
389  * We reserve the last block on the device for
390  * configuration space. Writes and reads in this
391  * area return errors.
392  */
393
394 #define AO_EE_BLOCK_SIZE        ((uint16_t) (256))
395 #define AO_EE_DEVICE_SIZE       ((uint32_t) 128 * (uint32_t) 1024)
396 #define AO_EE_DATA_SIZE         (AO_EE_DEVICE_SIZE - (uint32_t) AO_EE_BLOCK_SIZE)
397 #define AO_EE_CONFIG_BLOCK      ((uint16_t) (AO_EE_DATA_SIZE / AO_EE_BLOCK_SIZE))
398
399 void
400 ao_ee_flush(void) __reentrant;
401
402 /* Write to the eeprom */
403 uint8_t
404 ao_ee_write(uint32_t pos, uint8_t *buf, uint16_t len) __reentrant;
405
406 /* Read from the eeprom */
407 uint8_t
408 ao_ee_read(uint32_t pos, uint8_t *buf, uint16_t len) __reentrant;
409
410 /* Write the config block (at the end of the eeprom) */
411 uint8_t
412 ao_ee_write_config(uint8_t *buf, uint16_t len) __reentrant;
413
414 /* Read the config block (at the end of the eeprom) */
415 uint8_t
416 ao_ee_read_config(uint8_t *buf, uint16_t len) __reentrant;
417
418 /* Initialize the EEPROM code */
419 void
420 ao_ee_init(void);
421
422 /*
423  * ao_log.c
424  */
425
426 /* Structure containing GPS position, either lat or lon */
427
428 struct ao_gps_pos {
429         uint8_t degrees;
430         uint8_t minutes;
431         uint16_t minutes_fraction;      /* in units of 1/10000 minutes */
432 };
433
434 /*
435  * The data log is recorded in the eeprom as a sequence
436  * of data packets.
437  *
438  * Each packet starts with a 4-byte header that has the
439  * packet type, the packet checksum and the tick count. Then
440  * they all contain 2 16 bit values which hold packet-specific
441  * data.
442  *
443  * For each flight, the first packet
444  * is FLIGHT packet, indicating the serial number of the
445  * device and a unique number marking the number of flights
446  * recorded by this device.
447  *
448  * During flight, data from the accelerometer and barometer
449  * are recorded in SENSOR packets, using the raw 16-bit values
450  * read from the A/D converter.
451  *
452  * Also during flight, but at a lower rate, the deployment
453  * sensors are recorded in DEPLOY packets. The goal here is to
454  * detect failure in the deployment circuits.
455  *
456  * STATE packets hold state transitions as the flight computer
457  * transitions through different stages of the flight.
458  */
459 #define AO_LOG_FLIGHT           'F'
460 #define AO_LOG_SENSOR           'A'
461 #define AO_LOG_TEMP_VOLT        'T'
462 #define AO_LOG_DEPLOY           'D'
463 #define AO_LOG_STATE            'S'
464 #define AO_LOG_GPS_TIME         'G'
465 #define AO_LOG_GPS_LAT          'N'
466 #define AO_LOG_GPS_LON          'W'
467 #define AO_LOG_GPS_ALT          'H'
468
469 #define AO_LOG_POS_NONE         (~0UL)
470
471 struct ao_log_record {
472         char                    type;
473         uint8_t                 csum;
474         uint16_t                tick;
475         union {
476                 struct {
477                         int16_t         ground_accel;
478                         uint16_t        flight;
479                 } flight;
480                 struct {
481                         int16_t         accel;
482                         int16_t         pres;
483                 } sensor;
484                 struct {
485                         int16_t         temp;
486                         int16_t         v_batt;
487                 } temp_volt;
488                 struct {
489                         int16_t         drogue;
490                         int16_t         main;
491                 } deploy;
492                 struct {
493                         uint16_t        state;
494                         uint16_t        reason;
495                 } state;
496                 struct {
497                         uint8_t         hour;
498                         uint8_t         minute;
499                         uint8_t         second;
500                         uint8_t         flags;
501                 } gps_time;
502                 struct ao_gps_pos gps_latitude;
503                 struct ao_gps_pos gps_longitude;
504                 struct {
505                         int16_t         altitude;
506                         uint16_t        unused;
507                 } gps_altitude;
508                 struct {
509                         uint16_t        d0;
510                         uint16_t        d1;
511                 } anon;
512         } u;
513 };
514
515 /* Write a record to the eeprom log */
516 void
517 ao_log_data(struct ao_log_record *log);
518
519 /* Flush the log */
520 void
521 ao_log_flush(void);
522
523 /* Log dumping API:
524  * ao_log_dump_first() - get first log record
525  * ao_log_dump_next()  - get next log record
526  */
527 extern __xdata struct ao_log_record ao_log_dump;
528
529 /* Retrieve first log record for the current flight */
530 uint8_t
531 ao_log_dump_first(void);
532
533 /* return next log record for the current flight */
534 uint8_t
535 ao_log_dump_next(void);
536
537 /* Logging thread main routine */
538 void
539 ao_log(void);
540
541 /* Start logging to eeprom */
542 void
543 ao_log_start(void);
544
545 /* Stop logging */
546 void
547 ao_log_stop(void);
548
549 /* Initialize the logging system */
550 void
551 ao_log_init(void);
552
553 /*
554  * ao_flight.c
555  */
556
557 enum ao_flight_state {
558         ao_flight_startup = 0,
559         ao_flight_idle = 1,
560         ao_flight_pad = 2,
561         ao_flight_boost = 3,
562         ao_flight_fast = 4,
563         ao_flight_coast = 5,
564         ao_flight_drogue = 6,
565         ao_flight_main = 7,
566         ao_flight_landed = 8,
567         ao_flight_invalid = 9
568 };
569
570 extern __xdata struct ao_adc            ao_flight_data;
571 extern __pdata enum ao_flight_state     ao_flight_state;
572 extern __pdata uint16_t                 ao_flight_tick;
573 extern __pdata int16_t                  ao_flight_accel;
574 extern __pdata int16_t                  ao_flight_pres;
575 extern __pdata int32_t                  ao_flight_vel;
576 extern __pdata int16_t                  ao_ground_pres;
577 extern __pdata int16_t                  ao_ground_accel;
578 extern __pdata int16_t                  ao_min_pres;
579 extern __pdata uint16_t                 ao_launch_time;
580
581 /* Flight thread */
582 void
583 ao_flight(void);
584
585 /* Initialize flight thread */
586 void
587 ao_flight_init(void);
588
589 /*
590  * ao_report.c
591  */
592
593 void
594 ao_report_init(void);
595
596 /*
597  * ao_convert.c
598  *
599  * Given raw data, convert to SI units
600  */
601
602 /* pressure from the sensor to altitude in meters */
603 int16_t
604 ao_pres_to_altitude(int16_t pres) __reentrant;
605
606 int16_t
607 ao_altitude_to_pres(int16_t alt) __reentrant;
608
609 int16_t
610 ao_temp_to_dC(int16_t temp) __reentrant;
611
612 /*
613  * ao_dbg.c
614  *
615  * debug another telemetrum board
616  */
617
618 /* Send a byte to the dbg target */
619 void
620 ao_dbg_send_byte(uint8_t byte);
621
622 /* Receive a byte from the dbg target */
623 uint8_t
624 ao_dbg_recv_byte(void);
625
626 /* Start a bulk transfer to/from dbg target memory */
627 void
628 ao_dbg_start_transfer(uint16_t addr);
629
630 /* End a bulk transfer to/from dbg target memory */
631 void
632 ao_dbg_end_transfer(void);
633
634 /* Write a byte to dbg target memory */
635 void
636 ao_dbg_write_byte(uint8_t byte);
637
638 /* Read a byte from dbg target memory */
639 uint8_t
640 ao_dbg_read_byte(void);
641
642 /* Enable dbg mode, switching use of the pins */
643 void
644 ao_dbg_debug_mode(void);
645
646 /* Reset the dbg target */
647 void
648 ao_dbg_reset(void);
649
650 void
651 ao_dbg_init(void);
652
653 /*
654  * ao_serial.c
655  */
656
657 #if !AO_NO_SERIAL_ISR
658 void
659 ao_serial_rx1_isr(void) interrupt 3;
660
661 void
662 ao_serial_tx1_isr(void) interrupt 14;
663 #endif
664
665 char
666 ao_serial_getchar(void) __critical;
667
668 void
669 ao_serial_putchar(char c) __critical;
670
671 void
672 ao_serial_init(void);
673
674 /*
675  * ao_gps.c
676  */
677
678 #define AO_GPS_NUM_SAT_MASK     (0xf << 0)
679 #define AO_GPS_NUM_SAT_SHIFT    (0)
680
681 #define AO_GPS_VALID            (1 << 4)
682 #define AO_GPS_LONGITUDE_MASK   (1 << 5)
683 #define AO_GPS_LONGITUDE_EAST   (0 << 5)
684 #define AO_GPS_LONGITUDE_WEST   (1 << 5)
685
686 #define AO_GPS_LATITUDE_MASK    (1 << 6)
687 #define AO_GPS_LATITUDE_NORTH   (0 << 6)
688 #define AO_GPS_LATITUDE_SOUTH   (1 << 6)
689
690 struct ao_gps_data {
691         uint8_t                 hour;
692         uint8_t                 minute;
693         uint8_t                 second;
694         uint8_t                 flags;
695         struct ao_gps_pos       latitude;
696         struct ao_gps_pos       longitude;
697         int16_t                 altitude;
698 };
699
700 extern __xdata uint8_t ao_gps_mutex;
701 extern __xdata struct ao_gps_data ao_gps_data;
702
703 void
704 ao_gps(void);
705
706 void
707 ao_gps_print(__xdata struct ao_gps_data *gps_data);
708
709 void
710 ao_gps_init(void);
711
712 /*
713  * ao_gps_report.c
714  */
715
716 void
717 ao_gps_report(void);
718
719 void
720 ao_gps_report_init(void);
721
722 /*
723  * ao_telemetry.c
724  */
725
726 #define AO_MAX_CALLSIGN         8
727
728 struct ao_telemetry {
729         uint8_t                 addr;
730         uint8_t                 flight_state;
731         int16_t                 flight_accel;
732         int16_t                 ground_accel;
733         int32_t                 flight_vel;
734         int16_t                 flight_pres;
735         int16_t                 ground_pres;
736         struct ao_adc           adc;
737         struct ao_gps_data      gps;
738         char                    callsign[AO_MAX_CALLSIGN];
739 };
740
741 /* Set delay between telemetry reports (0 to disable) */
742
743 #define AO_TELEMETRY_INTERVAL_PAD       AO_MS_TO_TICKS(1000)
744 #define AO_TELEMETRY_INTERVAL_FLIGHT    AO_MS_TO_TICKS(50)
745 #define AO_TELEMETRY_INTERVAL_RECOVER   AO_MS_TO_TICKS(1000)
746
747 void
748 ao_telemetry_set_interval(uint16_t interval);
749
750 void
751 ao_telemetry_init(void);
752
753 /*
754  * ao_radio.c
755  */
756
757 void
758 ao_radio_send(__xdata struct ao_telemetry *telemetry) __reentrant;
759
760 struct ao_radio_recv {
761         struct ao_telemetry     telemetry;
762         int8_t                  rssi;
763         uint8_t                 status;
764 };
765
766 void
767 ao_radio_recv(__xdata struct ao_radio_recv *recv) __reentrant;
768
769 void
770 ao_radio_init(void);
771
772 /*
773  * ao_monitor.c
774  */
775
776 extern const char const * const ao_state_names[];
777
778 void
779 ao_monitor(void);
780
781 void
782 ao_set_monitor(uint8_t monitoring);
783
784 void
785 ao_monitor_init(uint8_t led, uint8_t monitoring) __reentrant;
786
787 /*
788  * ao_stdio.c
789  */
790
791 void
792 flush(void);
793
794 /*
795  * ao_ignite.c
796  */
797
798 enum ao_igniter {
799         ao_igniter_drogue = 0,
800         ao_igniter_main = 1
801 };
802
803 void
804 ao_ignite(enum ao_igniter igniter);
805
806 enum ao_igniter_status {
807         ao_igniter_unknown,     /* unknown status (ambiguous voltage) */
808         ao_igniter_ready,       /* continuity detected */
809         ao_igniter_active,      /* igniter firing */
810         ao_igniter_open,        /* open circuit detected */
811 };
812
813 enum ao_igniter_status
814 ao_igniter_status(enum ao_igniter igniter);
815
816 void
817 ao_igniter_init(void);
818
819 /*
820  * ao_config.c
821  */
822
823 #define AO_CONFIG_MAJOR 1
824 #define AO_CONFIG_MINOR 0
825
826 struct ao_config {
827         uint8_t         major;
828         uint8_t         minor;
829         uint16_t        main_deploy;
830         int16_t         accel_zero_g;
831         uint8_t         radio_channel;
832         char            callsign[AO_MAX_CALLSIGN + 1];
833 };
834
835 extern __xdata struct ao_config ao_config;
836
837 void
838 ao_config_get(void);
839
840 void
841 ao_config_init(void);
842
843 /*
844  * ao_rssi.c
845  */
846
847 void
848 ao_rssi_set(int rssi_value);
849
850 void
851 ao_rssi_init(uint8_t rssi_led);
852
853 /*
854  * ao_product.c
855  *
856  * values which need to be defined for
857  * each instance of a product
858  */
859
860 extern const uint8_t ao_usb_descriptors [];
861 extern const uint16_t ao_serial_number;
862 extern const char ao_version[];
863 extern const char ao_manufacturer[];
864 extern const char ao_product[];
865
866 /*
867  * Fifos
868  */
869
870 #define AO_FIFO_SIZE    32
871
872 struct ao_fifo {
873         uint8_t insert;
874         uint8_t remove;
875         char    fifo[AO_FIFO_SIZE];
876 };
877
878 #define ao_fifo_insert(f,c) do { \
879         (f).fifo[(f).insert] = (c); \
880         (f).insert = ((f).insert + 1) & (AO_FIFO_SIZE-1); \
881 } while(0)
882
883 #define ao_fifo_remove(f,c) do {\
884         c = (f).fifo[(f).remove]; \
885         (f).remove = ((f).remove + 1) & (AO_FIFO_SIZE-1); \
886 } while(0)
887
888 #define ao_fifo_full(f)         ((((f).insert + 1) & (AO_FIFO_SIZE-1)) == (f).remove)
889 #define ao_fifo_empty(f)        ((f).insert == (f).remove)
890
891 /*
892  * ao_packet.c
893  *
894  * Packet-based command interface
895  */
896
897 #define AO_PACKET_MAX   32
898 #define AO_PACKET_WIN   256
899
900 #define AO_PACKET_FIN   (1 << 0)
901 #define AO_PACKET_SYN   (1 << 1)
902 #define AO_PACKET_RST   (1 << 2)
903 #define AO_PACKET_ACK   (1 << 3)
904
905 struct ao_packet {
906         uint8_t         addr;
907         uint8_t         flags;
908         uint16_t        seq;
909         uint16_t        ack;
910         uint16_t        window;
911         uint8_t         len;
912         uint8_t         d[AO_PACKET_MAX];
913 };
914
915 uint8_t
916 ao_packet_connect(uint8_t dest);
917
918 uint8_t
919 ao_packet_accept(void);
920
921 int
922 ao_packet_send(uint8_t *data, int len);
923
924 int
925 ao_packet_recv(uint8_t *data, int len);
926
927 void
928 ao_packet_init(void);
929
930 #endif /* _AO_H_ */