2 * Copyright © 2009 Keith Packard <keithp@keithp.com>
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
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.
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.
31 /* Convert a __data pointer into an __xdata pointer */
32 #define DATA_TO_XDATA(a) ((void __xdata *) ((uint8_t) (a) | 0xff00))
34 /* Stack runs from above the allocated __data space to 0xfe, which avoids
35 * writing to 0xff as that triggers the stack overflow indicator
37 #define AO_STACK_START 0x90
38 #define AO_STACK_END 0xfe
39 #define AO_STACK_SIZE (AO_STACK_END - AO_STACK_START + 1)
43 __xdata void *wchan; /* current wait channel (NULL if running) */
44 uint16_t alarm; /* abort ao_sleep time */
45 uint8_t stack_count; /* amount of saved stack */
46 uint8_t task_id; /* unique id */
47 __code char *name; /* task name */
48 uint8_t stack[AO_STACK_SIZE]; /* saved stack */
51 extern __xdata struct ao_task *__data ao_cur_task;
53 #define AO_NUM_TASKS 16 /* maximum number of tasks */
54 #define AO_NO_TASK 0 /* no task id */
60 /* Suspend the current task until wchan is awoken.
66 ao_sleep(__xdata void *wchan);
68 /* Wake all tasks sleeping on wchan */
70 ao_wakeup(__xdata void *wchan);
72 /* set an alarm to go off in 'delay' ticks */
74 ao_alarm(uint16_t delay);
76 /* Yield the processor to another task */
78 ao_yield(void) __naked;
80 /* Add a task to the run queue */
82 ao_add_task(__xdata struct ao_task * task, void (*start)(void), __code char *name) __reentrant;
84 /* Terminate the current task */
88 /* Dump task info to console */
92 /* Start the scheduler. This will not return */
94 ao_start_scheduler(void);
100 #define AO_PANIC_NO_TASK 1 /* AO_NUM_TASKS is not large enough */
101 #define AO_PANIC_DMA 2 /* Attempt to start DMA while active */
102 #define AO_PANIC_MUTEX 3 /* Mis-using mutex API */
103 #define AO_PANIC_EE 4 /* Mis-using eeprom API */
104 #define AO_PANIC_LOG 5 /* Failing to read/write log data */
105 #define AO_PANIC_CMD 6 /* Too many command sets registered */
106 #define AO_PANIC_STDIO 7 /* Too many stdio handlers registered */
107 #define AO_PANIC_REBOOT 8 /* Reboot failed */
108 #define AO_PANIC_FLASH 9 /* Invalid flash part (or wrong blocksize) */
109 #define AO_PANIC_USB 10 /* Trying to send USB packet while busy */
111 /* Stop the operating system, beeping and blinking the reason */
113 ao_panic(uint8_t reason);
119 /* Our timer runs at 100Hz */
121 #define AO_MS_TO_TICKS(ms) ((ms) / (1000 / AO_HERTZ))
122 #define AO_SEC_TO_TICKS(s) ((s) * AO_HERTZ)
124 /* Returns the current time in ticks */
128 /* Suspend the current task until ticks time has passed */
130 ao_delay(uint16_t ticks);
132 /* Set the ADC interval */
134 ao_timer_set_adc_interval(uint8_t interval) __critical;
136 /* Timer interrupt */
138 ao_timer_isr(void) __interrupt 9;
140 /* Initialize the timer */
144 /* Initialize the hardware clock. Must be called first */
149 * One set of samples read from the A/D converter or telemetry
152 uint16_t tick; /* tick when the sample was read */
153 int16_t accel; /* accelerometer */
154 int16_t pres; /* pressure sensor */
155 int16_t temp; /* temperature sensor */
156 int16_t v_batt; /* battery voltage */
157 int16_t sense_d; /* drogue continuity sense */
158 int16_t sense_m; /* main continuity sense */
162 #error Please define HAS_ADC
168 #ifndef HAS_ACCEL_REF
169 #error Please define HAS_ACCEL_REF
172 #define HAS_ACCEL_REF 0
179 #define AO_ADC_RING 32
180 #define ao_adc_ring_next(n) (((n) + 1) & (AO_ADC_RING - 1))
181 #define ao_adc_ring_prev(n) (((n) - 1) & (AO_ADC_RING - 1))
185 * A/D data is stored in a ring, with the next sample to be written
188 extern volatile __xdata struct ao_adc ao_adc_ring[AO_ADC_RING];
189 extern volatile __data uint8_t ao_adc_head;
191 extern volatile __xdata uint16_t ao_accel_ref[AO_ADC_RING];
194 /* Trigger a conversion sequence (called from the timer interrupt) */
198 /* Suspend the current task until another A/D sample is converted */
202 /* Get a copy of the last complete A/D sample set */
204 ao_adc_get(__xdata struct ao_adc *packet);
206 /* The A/D interrupt handler */
209 ao_adc_isr(void) __interrupt 1;
211 /* Initialize the A/D converter */
222 * Various pre-defined beep frequencies
224 * frequency = 1/2 (24e6/32) / beep
227 #define AO_BEEP_LOW 150 /* 2500Hz */
228 #define AO_BEEP_MID 94 /* 3989Hz */
229 #define AO_BEEP_HIGH 75 /* 5000Hz */
230 #define AO_BEEP_OFF 0 /* off */
232 #define AO_BEEP_g 240 /* 1562.5Hz */
233 #define AO_BEEP_gs 227 /* 1652Hz (1655Hz) */
234 #define AO_BEEP_aa 214 /* 1752Hz (1754Hz) */
235 #define AO_BEEP_bbf 202 /* 1856Hz (1858Hz) */
236 #define AO_BEEP_bb 190 /* 1974Hz (1969Hz) */
237 #define AO_BEEP_cc 180 /* 2083Hz (2086Hz) */
238 #define AO_BEEP_ccs 170 /* 2205Hz (2210Hz) */
239 #define AO_BEEP_dd 160 /* 2344Hz (2341Hz) */
240 #define AO_BEEP_eef 151 /* 2483Hz (2480Hz) */
241 #define AO_BEEP_ee 143 /* 2622Hz (2628Hz) */
242 #define AO_BEEP_ff 135 /* 2778Hz (2784Hz) */
243 #define AO_BEEP_ffs 127 /* 2953Hz (2950Hz) */
244 #define AO_BEEP_gg 120 /* 3125Hz */
245 #define AO_BEEP_ggs 113 /* 3319Hz (3311Hz) */
246 #define AO_BEEP_aaa 107 /* 3504Hz (3508Hz) */
247 #define AO_BEEP_bbbf 101 /* 3713Hz (3716Hz) */
248 #define AO_BEEP_bbb 95 /* 3947Hz (3937Hz) */
249 #define AO_BEEP_ccc 90 /* 4167Hz (4171Hz) */
250 #define AO_BEEP_cccs 85 /* 4412Hz (4419Hz) */
251 #define AO_BEEP_ddd 80 /* 4688Hz (4682Hz) */
252 #define AO_BEEP_eeef 76 /* 4934Hz (4961Hz) */
253 #define AO_BEEP_eee 71 /* 5282Hz (5256Hz) */
254 #define AO_BEEP_fff 67 /* 5597Hz (5568Hz) */
255 #define AO_BEEP_fffs 64 /* 5859Hz (5899Hz) */
256 #define AO_BEEP_ggg 60 /* 6250Hz */
258 /* Set the beeper to the specified tone */
260 ao_beep(uint8_t beep);
262 /* Turn on the beeper for the specified time */
264 ao_beep_for(uint8_t beep, uint16_t ticks) __reentrant;
266 /* Initialize the beeper */
274 #define AO_LED_NONE 0
276 /* Turn on the specified LEDs */
278 ao_led_on(uint8_t colors);
280 /* Turn off the specified LEDs */
282 ao_led_off(uint8_t colors);
284 /* Set all of the LEDs to the specified state */
286 ao_led_set(uint8_t colors);
288 /* Toggle the specified LEDs */
290 ao_led_toggle(uint8_t colors);
292 /* Turn on the specified LEDs for the indicated interval */
294 ao_led_for(uint8_t colors, uint16_t ticks) __reentrant;
296 /* Initialize the LEDs */
298 ao_led_init(uint8_t enable);
304 #define AO_ROMCONFIG_VERSION 2
306 extern __code __at (0x00a0) uint16_t ao_romconfig_version;
307 extern __code __at (0x00a2) uint16_t ao_romconfig_check;
308 extern __code __at (0x00a4) uint16_t ao_serial_number;
309 extern __code __at (0x00a6) uint32_t ao_radio_cal;
312 #error Please define HAS_USB
316 extern __code __at (0x00aa) uint8_t ao_usb_descriptors [];
323 /* Put one character to the USB output queue */
325 ao_usb_putchar(char c);
327 /* Get one character from the USB input queue */
329 ao_usb_getchar(void);
331 /* Poll for a charcter on the USB input queue.
332 * returns AO_READ_AGAIN if none are available
335 ao_usb_pollchar(void);
337 /* Flush the USB output queue */
342 /* USB interrupt handler */
344 ao_usb_isr(void) __interrupt 6;
347 /* Enable the USB controller */
351 /* Disable the USB controller */
353 ao_usb_disable(void);
355 /* Initialize the USB system */
365 ao_cmd_lex_error = 1,
366 ao_cmd_syntax_error = 2,
369 extern __xdata uint16_t ao_cmd_lex_i;
370 extern __xdata uint32_t ao_cmd_lex_u32;
371 extern __xdata char ao_cmd_lex_c;
372 extern __xdata enum ao_cmd_status ao_cmd_status;
378 ao_cmd_put8(uint8_t v);
381 ao_cmd_put16(uint16_t v);
390 ao_cmd_decimal(void);
393 ao_match_word(__code char *word);
401 ao_cmd_register(__code struct ao_cmds *cmds);
408 * Provided by an external module to filter raw command lines
418 /* Allocate a DMA channel. the 'done' parameter will be set when the
419 * dma is finished and will be used to wakeup any waiters
423 ao_dma_alloc(__xdata uint8_t * done);
425 /* Setup a DMA channel */
427 ao_dma_set_transfer(uint8_t id,
428 void __xdata *srcaddr,
429 void __xdata *dstaddr,
434 /* Start a DMA channel */
436 ao_dma_start(uint8_t id);
438 /* Manually trigger a DMA channel */
440 ao_dma_trigger(uint8_t id);
442 /* Abort a running DMA transfer */
444 ao_dma_abort(uint8_t id);
446 /* DMA interrupt routine */
448 ao_dma_isr(void) __interrupt 8;
455 ao_mutex_get(__xdata uint8_t *ao_mutex) __reentrant;
458 ao_mutex_put(__xdata uint8_t *ao_mutex) __reentrant;
461 * Storage interface, provided by one of the eeprom or flash
465 /* Total bytes of available storage */
466 extern __xdata uint32_t ao_storage_total;
468 /* Block size - device is erased in these units. At least 256 bytes */
469 extern __xdata uint32_t ao_storage_block;
471 /* Byte offset of config block. Will be ao_storage_block bytes long */
472 extern __xdata uint32_t ao_storage_config;
474 /* Storage unit size - device reads and writes must be within blocks of this size. Usually 256 bytes. */
475 extern __xdata uint16_t ao_storage_unit;
477 #define AO_STORAGE_ERASE_LOG (ao_storage_config + AO_CONFIG_MAX_SIZE)
479 /* Initialize above values. Can only be called once the OS is running */
481 ao_storage_setup(void) __reentrant;
483 /* Write data. Returns 0 on failure, 1 on success */
485 ao_storage_write(uint32_t pos, __xdata void *buf, uint16_t len) __reentrant;
487 /* Read data. Returns 0 on failure, 1 on success */
489 ao_storage_read(uint32_t pos, __xdata void *buf, uint16_t len) __reentrant;
491 /* Erase a block of storage. This always clears ao_storage_block bytes */
493 ao_storage_erase(uint32_t pos) __reentrant;
495 /* Flush any pending writes to stable storage */
497 ao_storage_flush(void) __reentrant;
499 /* Initialize the storage code */
501 ao_storage_init(void);
504 * Low-level functions wrapped by ao_storage.c
507 /* Read data within a storage unit */
509 ao_storage_device_read(uint32_t pos, __xdata void *buf, uint16_t len) __reentrant;
511 /* Write data within a storage unit */
513 ao_storage_device_write(uint32_t pos, __xdata void *buf, uint16_t len) __reentrant;
515 /* Initialize low-level device bits */
517 ao_storage_device_init(void);
519 /* Print out information about flash chips */
521 ao_storage_device_info(void) __reentrant;
527 /* We record flight numbers in the first record of
528 * the log. Tasks may wait for this to be initialized
529 * by sleeping on this variable.
531 extern __xdata uint16_t ao_flight_number;
533 extern __pdata uint32_t ao_log_current_pos;
534 extern __pdata uint32_t ao_log_end_pos;
535 extern __pdata uint32_t ao_log_start_pos;
536 extern __xdata uint8_t ao_log_running;
537 extern __xdata enum flight_state ao_log_state;
539 /* required functions from the underlying log system */
541 /* Return the flight number from the given log slot, 0 if none */
543 ao_log_flight(uint8_t slot);
549 /* Logging thread main routine */
553 /* functions provided in ao_log.c */
555 /* Figure out the current flight number */
557 ao_log_scan(void) __reentrant;
559 /* Return the position of the start of the given log slot */
561 ao_log_pos(uint8_t slot);
563 /* Start logging to eeprom */
571 /* Initialize the logging system */
575 /* Write out the current flight number to the erase log */
577 ao_log_write_erase(uint8_t pos);
579 /* Returns true if there are any logs stored in eeprom */
581 ao_log_present(void);
583 /* Returns true if there is no more storage space available */
592 * The data log is recorded in the eeprom as a sequence
595 * Each packet starts with a 4-byte header that has the
596 * packet type, the packet checksum and the tick count. Then
597 * they all contain 2 16 bit values which hold packet-specific
600 * For each flight, the first packet
601 * is FLIGHT packet, indicating the serial number of the
602 * device and a unique number marking the number of flights
603 * recorded by this device.
605 * During flight, data from the accelerometer and barometer
606 * are recorded in SENSOR packets, using the raw 16-bit values
607 * read from the A/D converter.
609 * Also during flight, but at a lower rate, the deployment
610 * sensors are recorded in DEPLOY packets. The goal here is to
611 * detect failure in the deployment circuits.
613 * STATE packets hold state transitions as the flight computer
614 * transitions through different stages of the flight.
616 #define AO_LOG_FLIGHT 'F'
617 #define AO_LOG_SENSOR 'A'
618 #define AO_LOG_TEMP_VOLT 'T'
619 #define AO_LOG_DEPLOY 'D'
620 #define AO_LOG_STATE 'S'
621 #define AO_LOG_GPS_TIME 'G'
622 #define AO_LOG_GPS_LAT 'N'
623 #define AO_LOG_GPS_LON 'W'
624 #define AO_LOG_GPS_ALT 'H'
625 #define AO_LOG_GPS_SAT 'V'
626 #define AO_LOG_GPS_DATE 'Y'
628 #define AO_LOG_POS_NONE (~0UL)
630 struct ao_log_record {
636 int16_t ground_accel;
661 int32_t gps_latitude;
662 int32_t gps_longitude;
685 /* Write a record to the eeprom log */
687 ao_log_data(__xdata struct ao_log_record *log) __reentrant;
693 enum ao_flight_state {
694 ao_flight_startup = 0,
700 ao_flight_drogue = 6,
702 ao_flight_landed = 8,
703 ao_flight_invalid = 9
706 extern __pdata enum ao_flight_state ao_flight_state;
708 extern __pdata uint16_t ao_launch_time;
709 extern __xdata uint8_t ao_flight_force_idle;
715 /* Initialize flight thread */
717 ao_flight_init(void);
724 ao_flight_nano_init(void);
731 * Barometer calibration
733 * We directly sample the barometer. The specs say:
735 * Pressure range: 15-115 kPa
736 * Voltage at 115kPa: 2.82
737 * Output scale: 27mV/kPa
739 * If we want to detect launch with the barometer, we need
740 * a large enough bump to not be fooled by noise. At typical
741 * launch elevations (0-2000m), a 200Pa pressure change cooresponds
742 * to about a 20m elevation change. This is 5.4mV, or about 3LSB.
743 * As all of our calculations are done in 16 bits, we'll actually see a change
744 * of 16 times this though
746 * 27 mV/kPa * 32767 / 3300 counts/mV = 268.1 counts/kPa
749 /* Accelerometer calibration
751 * We're sampling the accelerometer through a resistor divider which
752 * consists of 5k and 10k resistors. This multiplies the values by 2/3.
753 * That goes into the cc1111 A/D converter, which is running at 11 bits
754 * of precision with the bits in the MSB of the 16 bit value. Only positive
755 * values are used, so values should range from 0-32752 for 0-3.3V. The
756 * specs say we should see 40mV/g (uncalibrated), multiply by 2/3 for what
757 * the A/D converter sees (26.67 mV/g). We should see 32752/3300 counts/mV,
758 * for a final computation of:
760 * 26.67 mV/g * 32767/3300 counts/mV = 264.8 counts/g
762 * Zero g was measured at 16000 (we would expect 16384).
763 * Note that this value is only require to tell if the
764 * rocket is standing upright. Once that is determined,
765 * the value of the accelerometer is averaged for 100 samples
766 * to find the resting accelerometer value, which is used
767 * for all further flight computations
770 #define GRAVITY 9.80665
773 * Above this height, the baro sensor doesn't work
775 #define AO_MAX_BARO_HEIGHT 12000
778 * Above this speed, baro measurements are unreliable
780 #define AO_MAX_BARO_SPEED 200
782 #define ACCEL_NOSE_UP (ao_accel_2g >> 2)
785 * Speed and acceleration are scaled by 16 to provide a bit more
786 * resolution while still having reasonable range. Note that this
787 * limits speed to 2047m/s (around mach 6) and acceleration to
788 * 2047m/s² (over 200g)
791 #define AO_M_TO_HEIGHT(m) ((int16_t) (m))
792 #define AO_MS_TO_SPEED(ms) ((int16_t) ((ms) * 16))
793 #define AO_MSS_TO_ACCEL(mss) ((int16_t) ((mss) * 16))
795 extern __pdata uint16_t ao_sample_tick; /* time of last data */
796 extern __pdata int16_t ao_sample_pres; /* most recent pressure sensor reading */
797 extern __pdata int16_t ao_sample_alt; /* MSL of ao_sample_pres */
798 extern __pdata int16_t ao_sample_height; /* AGL of ao_sample_pres */
799 extern __data uint8_t ao_sample_adc; /* Ring position of last processed sample */
802 extern __pdata int16_t ao_sample_accel; /* most recent accel sensor reading */
805 extern __xdata int16_t ao_ground_pres; /* startup pressure */
806 extern __xdata int16_t ao_ground_height; /* MSL of ao_ground_pres */
809 extern __xdata int16_t ao_ground_accel; /* startup acceleration */
810 extern __xdata int16_t ao_accel_2g; /* factory accel calibration */
811 extern __xdata int32_t ao_accel_scale; /* sensor to m/s² conversion */
814 void ao_sample_init(void);
816 /* returns FALSE in preflight mode, TRUE in flight mode */
817 uint8_t ao_sample(void);
823 #define to_fix16(x) ((int16_t) ((x) * 65536.0 + 0.5))
824 #define to_fix32(x) ((int32_t) ((x) * 65536.0 + 0.5))
825 #define from_fix(x) ((x) >> 16)
827 extern __pdata int16_t ao_height; /* meters */
828 extern __pdata int16_t ao_speed; /* m/s * 16 */
829 extern __pdata int16_t ao_accel; /* m/s² * 16 */
830 extern __pdata int16_t ao_max_height; /* max of ao_height */
832 extern __pdata int16_t ao_error_h;
833 extern __pdata int16_t ao_error_h_sq_avg;
836 extern __pdata int16_t ao_error_a;
839 void ao_kalman(void);
846 ao_report_init(void);
851 * Given raw data, convert to SI units
854 /* pressure from the sensor to altitude in meters */
856 ao_pres_to_altitude(int16_t pres) __reentrant;
859 ao_altitude_to_pres(int16_t alt) __reentrant;
862 ao_temp_to_dC(int16_t temp) __reentrant;
867 * debug another telemetrum board
870 /* Send a byte to the dbg target */
872 ao_dbg_send_byte(uint8_t byte);
874 /* Receive a byte from the dbg target */
876 ao_dbg_recv_byte(void);
878 /* Start a bulk transfer to/from dbg target memory */
880 ao_dbg_start_transfer(uint16_t addr);
882 /* End a bulk transfer to/from dbg target memory */
884 ao_dbg_end_transfer(void);
886 /* Write a byte to dbg target memory */
888 ao_dbg_write_byte(uint8_t byte);
890 /* Read a byte from dbg target memory */
892 ao_dbg_read_byte(void);
894 /* Enable dbg mode, switching use of the pins */
896 ao_dbg_debug_mode(void);
898 /* Reset the dbg target */
910 #error Please define HAS_SERIAL_1
914 #ifndef USE_SERIAL_STDIN
915 #error Please define USE_SERIAL_STDIN
919 ao_serial_rx1_isr(void) __interrupt 3;
922 ao_serial_tx1_isr(void) __interrupt 14;
925 ao_serial_getchar(void) __critical;
929 ao_serial_pollchar(void) __critical;
932 ao_serial_set_stdin(uint8_t stdin);
936 ao_serial_putchar(char c) __critical;
939 ao_serial_drain(void) __critical;
941 #define AO_SERIAL_SPEED_4800 0
942 #define AO_SERIAL_SPEED_9600 1
943 #define AO_SERIAL_SPEED_19200 2
944 #define AO_SERIAL_SPEED_57600 3
947 ao_serial_set_speed(uint8_t speed);
950 ao_serial_init(void);
958 ao_spi_send(void __xdata *block, uint16_t len) __reentrant;
961 ao_spi_recv(void __xdata *block, uint16_t len) __reentrant;
970 #define AO_GPS_NUM_SAT_MASK (0xf << 0)
971 #define AO_GPS_NUM_SAT_SHIFT (0)
973 #define AO_GPS_VALID (1 << 4)
974 #define AO_GPS_RUNNING (1 << 5)
975 #define AO_GPS_DATE_VALID (1 << 6)
976 #define AO_GPS_COURSE_VALID (1 << 7)
978 extern __xdata uint16_t ao_gps_tick;
988 int32_t latitude; /* degrees * 10⁷ */
989 int32_t longitude; /* degrees * 10⁷ */
990 int16_t altitude; /* m */
991 uint16_t ground_speed; /* cm/s */
992 uint8_t course; /* degrees / 2 */
993 uint8_t hdop; /* * 5 */
994 int16_t climb_rate; /* cm/s */
995 uint16_t h_error; /* m */
996 uint16_t v_error; /* m */
999 struct ao_gps_sat_data {
1004 #define AO_MAX_GPS_TRACKING 12
1006 struct ao_gps_tracking_data {
1008 struct ao_gps_sat_data sats[AO_MAX_GPS_TRACKING];
1011 extern __xdata uint8_t ao_gps_mutex;
1012 extern __xdata struct ao_gps_data ao_gps_data;
1013 extern __xdata struct ao_gps_tracking_data ao_gps_tracking_data;
1019 ao_gps_print(__xdata struct ao_gps_data *gps_data);
1022 ao_gps_tracking_print(__xdata struct ao_gps_tracking_data *gps_tracking_data);
1032 ao_gps_report(void);
1035 ao_gps_report_init(void);
1041 #define AO_MAX_CALLSIGN 8
1043 struct ao_telemetry {
1046 uint8_t flight_state;
1048 int16_t ground_accel;
1057 int16_t ground_pres;
1058 int16_t accel_plus_g;
1059 int16_t accel_minus_g;
1061 struct ao_gps_data gps;
1062 char callsign[AO_MAX_CALLSIGN];
1063 struct ao_gps_tracking_data gps_tracking;
1066 struct ao_telemetry_tiny {
1069 uint8_t flight_state;
1070 int16_t height; /* AGL in meters */
1071 int16_t speed; /* in m/s * 16 */
1072 int16_t accel; /* in m/s² * 16 */
1073 int16_t ground_pres; /* sensor units */
1074 struct ao_adc adc; /* raw ADC readings */
1075 char callsign[AO_MAX_CALLSIGN];
1079 * ao_radio_recv tacks on rssi and status bytes
1081 struct ao_telemetry_recv {
1082 struct ao_telemetry telemetry;
1087 struct ao_telemetry_tiny_recv {
1088 struct ao_telemetry_tiny telemetry_tiny;
1093 /* Set delay between telemetry reports (0 to disable) */
1095 #define AO_TELEMETRY_INTERVAL_PAD AO_MS_TO_TICKS(1000)
1096 #define AO_TELEMETRY_INTERVAL_FLIGHT AO_MS_TO_TICKS(100)
1097 #define AO_TELEMETRY_INTERVAL_RECOVER AO_MS_TO_TICKS(1000)
1100 ao_telemetry_set_interval(uint16_t interval);
1103 ao_rdf_set(uint8_t rdf);
1106 ao_telemetry_init(void);
1109 ao_telemetry_tiny_init(void);
1115 extern __xdata uint8_t ao_radio_dma;
1116 extern __xdata uint8_t ao_radio_dma_done;
1117 extern __xdata uint8_t ao_radio_done;
1118 extern __xdata uint8_t ao_radio_mutex;
1121 ao_radio_general_isr(void) __interrupt 16;
1124 ao_radio_get(uint8_t len);
1126 #define ao_radio_put() ao_mutex_put(&ao_radio_mutex)
1129 ao_radio_set_packet(void);
1132 ao_radio_send(__xdata void *data, uint8_t size) __reentrant;
1135 ao_radio_recv(__xdata void *data, uint8_t size) __reentrant;
1138 ao_radio_recv_abort(void);
1141 ao_radio_rdf(int ms);
1144 ao_radio_rdf_abort(void);
1147 ao_radio_idle(void);
1150 ao_radio_init(void);
1156 extern const char const * const ao_state_names[];
1161 #define AO_MONITORING_OFF 0
1162 #define AO_MONITORING_FULL 1
1163 #define AO_MONITORING_TINY 2
1166 ao_set_monitor(uint8_t monitoring);
1169 ao_monitor_init(uint8_t led, uint8_t monitoring) __reentrant;
1175 #define AO_READ_AGAIN ((char) -1)
1178 char (*pollchar)(void);
1179 void (*putchar)(char c) __reentrant;
1180 void (*flush)(void);
1183 extern __data int8_t ao_cur_stdio;
1184 extern __data int8_t ao_num_stdios;
1189 extern __xdata uint8_t ao_stdin_ready;
1192 ao_add_stdio(char (*pollchar)(void),
1193 void (*putchar)(char) __reentrant,
1194 void (*flush)(void)) __reentrant;
1201 ao_igniter_drogue = 0,
1206 ao_ignite(enum ao_igniter igniter);
1208 enum ao_igniter_status {
1209 ao_igniter_unknown, /* unknown status (ambiguous voltage) */
1210 ao_igniter_ready, /* continuity detected */
1211 ao_igniter_active, /* igniter firing */
1212 ao_igniter_open, /* open circuit detected */
1215 enum ao_igniter_status
1216 ao_igniter_status(enum ao_igniter igniter);
1219 ao_igniter_init(void);
1225 #define AO_CONFIG_MAJOR 1
1226 #define AO_CONFIG_MINOR 4
1231 uint16_t main_deploy;
1232 int16_t accel_plus_g; /* changed for minor version 2 */
1233 uint8_t radio_channel;
1234 char callsign[AO_MAX_CALLSIGN + 1];
1235 uint8_t apogee_delay; /* minor version 1 */
1236 int16_t accel_minus_g; /* minor version 2 */
1237 uint32_t radio_cal; /* minor version 3 */
1238 uint32_t flight_log_max; /* minor version 4 */
1241 extern __xdata struct ao_config ao_config;
1243 #define AO_CONFIG_MAX_SIZE 128
1246 ao_config_get(void);
1249 ao_config_put(void);
1252 ao_config_init(void);
1259 ao_rssi_set(int rssi_value);
1262 ao_rssi_init(uint8_t rssi_led);
1267 * values which need to be defined for
1268 * each instance of a product
1271 extern const char ao_version[];
1272 extern const char ao_manufacturer[];
1273 extern const char ao_product[];
1279 #define AO_FIFO_SIZE 32
1284 char fifo[AO_FIFO_SIZE];
1287 #define ao_fifo_insert(f,c) do { \
1288 (f).fifo[(f).insert] = (c); \
1289 (f).insert = ((f).insert + 1) & (AO_FIFO_SIZE-1); \
1292 #define ao_fifo_remove(f,c) do {\
1293 c = (f).fifo[(f).remove]; \
1294 (f).remove = ((f).remove + 1) & (AO_FIFO_SIZE-1); \
1297 #define ao_fifo_full(f) ((((f).insert + 1) & (AO_FIFO_SIZE-1)) == (f).remove)
1298 #define ao_fifo_empty(f) ((f).insert == (f).remove)
1303 * Packet-based command interface
1306 #define AO_PACKET_MAX 64
1307 #define AO_PACKET_SYN (uint8_t) 0xff
1314 uint8_t d[AO_PACKET_MAX];
1315 uint8_t callsign[AO_MAX_CALLSIGN];
1318 struct ao_packet_recv {
1319 struct ao_packet packet;
1324 extern __xdata struct ao_packet_recv ao_rx_packet;
1325 extern __xdata struct ao_packet ao_tx_packet;
1326 extern __xdata struct ao_task ao_packet_task;
1327 extern __xdata uint8_t ao_packet_enable;
1328 extern __xdata uint8_t ao_packet_master_sleeping;
1329 extern __pdata uint8_t ao_packet_rx_len, ao_packet_rx_used, ao_packet_tx_used;
1332 ao_packet_send(void);
1335 ao_packet_recv(void);
1338 ao_packet_flush(void);
1341 ao_packet_putchar(char c) __reentrant;
1344 ao_packet_pollchar(void) __critical;
1346 /* ao_packet_master.c */
1349 ao_packet_master_init(void);
1351 /* ao_packet_slave.c */
1354 ao_packet_slave_start(void);
1357 ao_packet_slave_stop(void);
1360 ao_packet_slave_init(uint8_t enable);