X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=src%2Fkernel%2Fao.h;h=910c1d8ed97c532c70da13957fd087f6ee06b84a;hp=ad5bbf8e76ae152fefaed06eed6758963b8ec0da;hb=8cc418ed3b0df0e465f0af27c2255cb97294e6ce;hpb=4828be0ca5252ac9cd6061209385dcd6c4c57965 diff --git a/src/kernel/ao.h b/src/kernel/ao.h index ad5bbf8e..910c1d8e 100644 --- a/src/kernel/ao.h +++ b/src/kernel/ao.h @@ -3,7 +3,8 @@ * * 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 @@ -22,31 +23,23 @@ #include #include #include +#include #include #include -#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; #if HAS_TASK @@ -76,15 +69,32 @@ typedef AO_PORT_TYPE ao_port_t; #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_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_romconfig.c + */ + +#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 + /* * ao_timer.c */ @@ -94,7 +104,7 @@ ao_panic(uint8_t reason); #define AO_TICK_SIGNED int16_t #endif -extern volatile __data AO_TICK_TYPE ao_tick_count; +extern volatile AO_TICK_TYPE ao_tick_count; /* Our timer runs at 100Hz */ #ifndef AO_HERTZ @@ -115,10 +125,6 @@ ao_delay(uint16_t ticks); 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); @@ -127,19 +133,29 @@ 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(__xdata uint8_t *ao_mutex, uint8_t task_id) __reentrant; +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 /* @@ -152,15 +168,16 @@ enum ao_cmd_status { 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 @@ -178,33 +195,36 @@ ao_cmd_white(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 @@ -224,7 +244,7 @@ ao_cmd_filter(void); #include #endif -#if LEDS_AVAILABLE +#if LEDS_AVAILABLE || HAS_LED #include #endif @@ -281,13 +301,13 @@ ao_report_init(void); #if HAS_BARO /* pressure from the sensor to altitude in meters */ alt_t -ao_pres_to_altitude(pres_t pres) __reentrant; +ao_pres_to_altitude(pres_t pres); pres_t -ao_altitude_to_pres(alt_t alt) __reentrant; +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 /* @@ -363,11 +383,11 @@ ao_spi_slave(void); #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 uint16_t 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; @@ -407,13 +427,13 @@ void 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); @@ -518,15 +538,9 @@ struct ao_telemetry_raw_recv { /* 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); @@ -550,9 +564,9 @@ ao_telemetry_tiny_init(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 @@ -577,17 +591,14 @@ extern __xdata int8_t ao_radio_rssi; #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, uint8_t timeout); void ao_radio_recv_abort(void); @@ -637,6 +648,12 @@ ao_radio_continuity(uint8_t c); void ao_radio_rdf_abort(void); +void +ao_radio_test_on(void); + +void +ao_radio_test_off(void); + void ao_radio_init(void); @@ -646,7 +663,7 @@ 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 @@ -659,12 +676,14 @@ union ao_monitor { #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); @@ -682,7 +701,7 @@ void ao_monitor_enable(void); void -ao_monitor_init(void) __reentrant; +ao_monitor_init(void); #endif @@ -694,27 +713,27 @@ ao_monitor_init(void) __reentrant; 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 int8_t ao_cur_stdio; +extern int8_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 ao_add_stdio(int (*pollchar)(void), - void (*putchar)(char) __reentrant, - void (*flush)(void)) __reentrant; + void (*putchar)(char) , + void (*flush)(void)); /* * ao_ignite.c @@ -741,14 +760,14 @@ struct ao_ignition { 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); @@ -769,7 +788,7 @@ ao_igniter_init(void); /* * Set this to force the frequency to 434.550MHz */ -extern __xdata uint8_t ao_force_freq; +extern uint8_t ao_force_freq; #endif /* @@ -818,6 +837,8 @@ struct ao_fifo { } 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 @@ -840,33 +861,6 @@ struct ao_fifo { #include #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 */ @@ -894,8 +888,8 @@ union ao_log_single { 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); @@ -957,9 +951,6 @@ ao_terraui_init(void); */ #ifdef BATTERY_PIN -void -ao_battery_isr(void) ao_arch_interrupt(1); - uint16_t ao_battery_get(void); @@ -978,7 +969,7 @@ ao_sqrt(uint32_t op); * 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