*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
#include <stdio.h>
#include <string.h>
#include <stddef.h>
+#include <stdbool.h>
#include <ao_pins.h>
#include <ao_arch.h>
-#define TRUE 1
-#define FALSE 0
+/* replace stdio macros with direct calls to our functions */
+#undef putchar
+#undef getchar
+#define putchar(c) ao_putchar(c)
+#define getchar ao_getchar
-/* Convert a __data pointer into an __xdata pointer */
-#ifndef DATA_TO_XDATA
-#define DATA_TO_XDATA(a) (a)
-#endif
-#ifndef PDATA_TO_XDATA
-#define PDATA_TO_XDATA(a) (a)
-#endif
-#ifndef CODE_TO_XDATA
-#define CODE_TO_XDATA(a) (a)
-#endif
+extern int ao_putchar(char c);
+extern char ao_getchar(void);
#ifndef HAS_TASK
#define HAS_TASK 1
#endif
-#ifndef AO_PORT_TYPE
-#define AO_PORT_TYPE uint8_t
-#endif
-
typedef AO_PORT_TYPE ao_port_t;
+#ifndef AO_TICK_TYPE
+#define AO_TICK_TYPE uint32_t
+#define AO_TICK_SIGNED int32_t
+#endif
+
#if HAS_TASK
#include <ao_task.h>
#else
#define AO_PANIC_BUFIO 15 /* Mis-using bufio API */
#define AO_PANIC_EXTI 16 /* Mis-using exti API */
#define AO_PANIC_FAST_TIMER 17 /* Mis-using fast timer API */
+#define AO_PANIC_ADC 18 /* Mis-using ADC interface */
+#define AO_PANIC_IRQ 19 /* interrupts not blocked */
#define AO_PANIC_SELF_TEST_CC1120 0x40 | 1 /* Self test failure */
#define AO_PANIC_SELF_TEST_HMC5883 0x40 | 2 /* Self test failure */
#define AO_PANIC_SELF_TEST_MPU6000 0x40 | 3 /* Self test failure */
+#define AO_PANIC_SELF_TEST_MPU9250 0x40 | 3 /* Self test failure */
+#define AO_PANIC_SELF_TEST_BMX160 0x40 | 3 /* Self test failure */
#define AO_PANIC_SELF_TEST_MS5607 0x40 | 4 /* Self test failure */
+#define AO_PANIC_SELF_TEST_ADS124S0X 0x40 | 5 /* Self test failure */
/* Stop the operating system, beeping and blinking the reason */
void
-ao_panic(uint8_t reason);
+ao_panic(uint8_t reason) __attribute__((noreturn));
/*
- * ao_timer.c
+ * ao_romconfig.c
*/
-#ifndef AO_TICK_TYPE
-#define AO_TICK_TYPE uint16_t
-#define AO_TICK_SIGNED int16_t
+#define AO_ROMCONFIG_VERSION 2
+
+extern AO_ROMCONFIG_SYMBOL uint16_t ao_romconfig_version;
+extern AO_ROMCONFIG_SYMBOL uint16_t ao_romconfig_check;
+extern AO_ROMCONFIG_SYMBOL uint16_t ao_serial_number;
+#if HAS_RADIO
+extern AO_ROMCONFIG_SYMBOL uint32_t ao_radio_cal;
#endif
-extern volatile __data AO_TICK_TYPE ao_tick_count;
+/*
+ * ao_timer.c
+ */
+
+extern volatile AO_TICK_TYPE ao_tick_count;
/* Our timer runs at 100Hz */
#ifndef AO_HERTZ
#define AO_HERTZ 100
#endif
#define AO_MS_TO_TICKS(ms) ((ms) / (1000 / AO_HERTZ))
-#define AO_SEC_TO_TICKS(s) ((s) * AO_HERTZ)
+#define AO_SEC_TO_TICKS(s) ((AO_TICK_TYPE) (s) * AO_HERTZ)
/* Returns the current time in ticks */
AO_TICK_TYPE
ao_time(void);
+/* Returns the current time in ns */
+uint64_t
+ao_time_ns(void);
+
/* Suspend the current task until ticks time has passed */
void
-ao_delay(uint16_t ticks);
+ao_delay(AO_TICK_TYPE ticks);
/* Set the ADC interval */
void
ao_timer_set_adc_interval(uint8_t interval);
-/* Timer interrupt */
-void
-ao_timer_isr(void) ao_arch_interrupt(9);
-
/* Initialize the timer */
void
ao_timer_init(void);
void
ao_clock_init(void);
+#if AO_POWER_MANAGEMENT
+/* Go to low power clock */
+void
+ao_clock_suspend(void);
+
+/* Restart full-speed clock */
+void
+ao_clock_resume(void);
+#endif
+
/*
* ao_mutex.c
*/
#ifndef ao_mutex_get
+uint8_t
+ao_mutex_try(uint8_t *ao_mutex, uint8_t task_id);
+
void
-ao_mutex_get(__xdata uint8_t *ao_mutex) __reentrant;
+ao_mutex_get(uint8_t *ao_mutex);
void
-ao_mutex_put(__xdata uint8_t *ao_mutex) __reentrant;
+ao_mutex_put(uint8_t *ao_mutex);
#endif
/*
ao_cmd_syntax_error = 2,
};
-extern __pdata uint16_t ao_cmd_lex_i;
-extern __pdata uint32_t ao_cmd_lex_u32;
-extern __pdata char ao_cmd_lex_c;
-extern __pdata enum ao_cmd_status ao_cmd_status;
+extern char ao_cmd_lex_c;
+extern enum ao_cmd_status ao_cmd_status;
void
-ao_put_string(__code char *s);
+ao_put_string(const char *s);
void
+ao_cmd_readline(const char *prompt);
+
+char
ao_cmd_lex(void);
void
int8_t
ao_cmd_hexchar(char c);
-void
+uint8_t
ao_cmd_hexbyte(void);
-void
+uint32_t
ao_cmd_hex(void);
-void
-ao_cmd_decimal(void) __reentrant;
+uint32_t
+ao_cmd_decimal(void);
/* Read a single hex nibble off stdin. */
uint8_t
ao_getnibble(void);
uint8_t
-ao_match_word(__code char *word);
+ao_match_word(const char *word);
struct ao_cmds {
void (*func)(void);
- __code char *help;
+ const char *help;
};
void
-ao_cmd_register(const __code struct ao_cmds *cmds);
+ao_cmd_register(const struct ao_cmds *cmds);
void
ao_cmd_init(void);
+void
+ao_cmd(void);
+
#if HAS_CMD_FILTER
/*
* Provided by an external module to filter raw command lines
#include <ao_beep.h>
#endif
-#if LEDS_AVAILABLE
+#if LEDS_AVAILABLE || HAS_LED
#include <ao_led.h>
#endif
* Given raw data, convert to SI units
*/
+#if HAS_BARO
/* pressure from the sensor to altitude in meters */
-int16_t
-ao_pres_to_altitude(int16_t pres) __reentrant;
+alt_t
+ao_pres_to_altitude(pres_t pres);
-int16_t
-ao_altitude_to_pres(int16_t alt) __reentrant;
+pres_t
+ao_altitude_to_pres(alt_t alt);
int16_t
-ao_temp_to_dC(int16_t temp) __reentrant;
+ao_temp_to_dC(int16_t temp);
+#endif
/*
* ao_convert_pa.c
#include <ao_data.h>
+#if HAS_BARO
alt_t
-ao_pa_to_altitude(int32_t pa);
+ao_pa_to_altitude(pres_t pa);
int32_t
ao_altitude_to_pa(alt_t alt);
+#endif
#if HAS_DBG
#include <ao_dbg.h>
#define AO_GPS_NEW_DATA 1
#define AO_GPS_NEW_TRACKING 2
-extern __xdata uint8_t ao_gps_new;
-extern __pdata uint16_t ao_gps_tick;
-extern __xdata uint8_t ao_gps_mutex;
-extern __xdata struct ao_telemetry_location ao_gps_data;
-extern __xdata struct ao_telemetry_satellite ao_gps_tracking_data;
+extern uint8_t ao_gps_new;
+extern AO_TICK_TYPE ao_gps_tick;
+extern uint8_t ao_gps_mutex;
+extern struct ao_telemetry_location ao_gps_data;
+extern struct ao_telemetry_satellite ao_gps_tracking_data;
struct ao_gps_orig {
uint8_t year;
ao_gps(void);
void
-ao_gps_print(__xdata struct ao_gps_orig *gps_data);
+ao_gps_print(struct ao_gps_orig *gps_data);
void
-ao_gps_tracking_print(__xdata struct ao_gps_tracking_orig *gps_tracking_data);
+ao_gps_tracking_print(struct ao_gps_tracking_orig *gps_tracking_data);
void
-ao_gps_show(void) __reentrant;
+ao_gps_show(void);
void
ao_gps_init(void);
/* Set delay between telemetry reports (0 to disable) */
-#ifdef AO_SEND_ALL_BARO
-#define AO_TELEMETRY_INTERVAL_PAD AO_MS_TO_TICKS(100)
-#define AO_TELEMETRY_INTERVAL_FLIGHT AO_MS_TO_TICKS(100)
-#define AO_TELEMETRY_INTERVAL_RECOVER AO_MS_TO_TICKS(100)
-#else
#define AO_TELEMETRY_INTERVAL_PAD AO_MS_TO_TICKS(1000)
#define AO_TELEMETRY_INTERVAL_FLIGHT AO_MS_TO_TICKS(100)
#define AO_TELEMETRY_INTERVAL_RECOVER AO_MS_TO_TICKS(1000)
-#endif
void
ao_telemetry_reset_interval(void);
* ao_radio.c
*/
-extern __xdata uint8_t ao_radio_dma;
+extern uint8_t ao_radio_dma;
-extern __xdata int8_t ao_radio_rssi;
+extern int8_t ao_radio_rssi;
#ifdef PKT_APPEND_STATUS_1_CRC_OK
#define AO_RADIO_STATUS_CRC_OK PKT_APPEND_STATUS_1_CRC_OK
#define HAS_RADIO_RATE HAS_RADIO
#endif
-void
-ao_radio_general_isr(void) ao_arch_interrupt(16);
-
#if HAS_RADIO_XMIT
void
-ao_radio_send(const __xdata void *d, uint8_t size) __reentrant;
+ao_radio_send(const void *d, uint8_t size);
#endif
#if HAS_RADIO_RECV
uint8_t
-ao_radio_recv(__xdata void *d, uint8_t size, uint8_t timeout) __reentrant;
+ao_radio_recv(void *d, uint8_t size, AO_TICK_TYPE timeout);
void
ao_radio_recv_abort(void);
void
ao_radio_rdf_abort(void);
+void
+ao_radio_test_on(void);
+
+void
+ao_radio_test_off(void);
+
void
ao_radio_init(void);
#if HAS_MONITOR
-extern const char const * const ao_state_names[];
+extern const char * const ao_state_names[];
#define AO_MONITOR_RING 8
#endif
};
-extern __xdata union ao_monitor ao_monitor_ring[AO_MONITOR_RING];
+extern union ao_monitor ao_monitor_ring[AO_MONITOR_RING];
#define ao_monitor_ring_next(n) (((n) + 1) & (AO_MONITOR_RING - 1))
+#define ao_monitor_ring_prev(n) (((n) - 1) & (AO_MONITOR_RING - 1))
-extern __data uint8_t ao_monitoring;
-extern __data uint8_t ao_monitor_head;
+extern uint8_t ao_monitoring_mutex;
+extern uint8_t ao_monitoring;
+extern uint8_t ao_monitor_head;
void
ao_monitor(void);
ao_monitor_enable(void);
void
-ao_monitor_init(void) __reentrant;
+ao_monitor_init(void);
#endif
struct ao_stdio {
int (*_pollchar)(void); /* Called with interrupts blocked */
- void (*putchar)(char c) __reentrant;
+ void (*putchar)(char c);
void (*flush)(void);
uint8_t echo;
};
-extern __xdata struct ao_stdio ao_stdios[];
-extern __pdata int8_t ao_cur_stdio;
-extern __pdata int8_t ao_num_stdios;
+extern struct ao_stdio ao_stdios[];
+extern uint8_t ao_cur_stdio;
+extern uint8_t ao_num_stdios;
void
flush(void);
-extern __xdata uint8_t ao_stdin_ready;
+extern uint8_t ao_stdin_ready;
uint8_t
ao_echo(void);
-int8_t
+uint8_t
ao_add_stdio(int (*pollchar)(void),
- void (*putchar)(char) __reentrant,
- void (*flush)(void)) __reentrant;
+ void (*putchar)(char) ,
+ void (*flush)(void));
/*
* ao_ignite.c
ao_igniter_main = 1
};
-void
-ao_ignite(enum ao_igniter igniter);
-
enum ao_igniter_status {
ao_igniter_unknown, /* unknown status (ambiguous voltage) */
ao_igniter_ready, /* continuity detected */
uint8_t firing;
};
-extern __code char * __code ao_igniter_status_names[];
+extern const char * const ao_igniter_status_names[];
-extern __xdata struct ao_ignition ao_ignition[2];
+extern struct ao_ignition ao_ignition[2];
enum ao_igniter_status
ao_igniter_status(enum ao_igniter igniter);
-extern __pdata uint8_t ao_igniter_present;
+extern uint8_t ao_igniter_present;
void
ao_ignite_set_pins(void);
/*
* Set this to force the frequency to 434.550MHz
*/
-extern __xdata uint8_t ao_force_freq;
+extern uint8_t ao_force_freq;
#endif
/*
} while(0)
#define ao_fifo_full(f) ((((f).insert + 1) & (AO_FIFO_SIZE-1)) == (f).remove)
+#define ao_fifo_mostly(f) ((((f).insert - (f).remove) & (AO_FIFO_SIZE-1)) >= (AO_FIFO_SIZE * 3 / 4))
+#define ao_fifo_barely(f) ((((f).insert - (f).remove) & (AO_FIFO_SIZE-1)) >= (AO_FIFO_SIZE * 1 / 4))
#define ao_fifo_empty(f) ((f).insert == (f).remove)
#if PACKET_HAS_MASTER || PACKET_HAS_SLAVE
#include <ao_aes.h>
#endif
-/* ao_launch.c */
-
-struct ao_launch_command {
- uint16_t tick;
- uint16_t serial;
- uint8_t cmd;
- uint8_t channel;
- uint16_t unused;
-};
-
-#define AO_LAUNCH_QUERY 1
-
-struct ao_launch_query {
- uint16_t tick;
- uint16_t serial;
- uint8_t channel;
- uint8_t valid;
- uint8_t arm_status;
- uint8_t igniter_status;
-};
-
-#define AO_LAUNCH_ARM 2
-#define AO_LAUNCH_FIRE 3
-
-void
-ao_launch_init(void);
-
/*
* ao_log_single.c
*/
uint8_t bytes[AO_LOG_SINGLE_SIZE];
};
-extern __xdata union ao_log_single ao_log_single_write_data;
-extern __xdata union ao_log_single ao_log_single_read_data;
+extern union ao_log_single ao_log_single_write_data;
+extern union ao_log_single ao_log_single_read_data;
void
ao_log_single_extra_query(void);
#define AO_TELEPYRO_NUM_ADC 9
-#ifndef ao_xmemcpy
-#define ao_xmemcpy(d,s,c) memcpy(d,s,c)
-#define ao_xmemset(d,v,c) memset(d,v,c)
-#define ao_xmemcmp(d,s,c) memcmp(d,s,c)
-#endif
-
/*
* ao_terraui.c
*/
*/
#ifdef BATTERY_PIN
-void
-ao_battery_isr(void) ao_arch_interrupt(1);
-
uint16_t
ao_battery_get(void);
* ao_freq.c
*/
-int32_t ao_freq_to_set(int32_t freq, int32_t cal) __reentrant;
+int32_t ao_freq_to_set(int32_t freq, int32_t cal);
/*
* ao_ms5607.c