From: Keith Packard Date: Sat, 26 May 2012 05:18:06 +0000 (-0600) Subject: Get megametrum ready to at least log flight data X-Git-Tag: 1.0.9.5~19 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=78423f3fc5164ea9fd428606419784c1700ad5c5 Get megametrum ready to at least log flight data Doesn't track flight state changes correctly. Signed-off-by: Keith Packard --- diff --git a/src/core/ao_adc.h b/src/core/ao_adc.h index db5bfab3..8ec740c4 100644 --- a/src/core/ao_adc.h +++ b/src/core/ao_adc.h @@ -18,13 +18,11 @@ #ifndef _AO_ADC_H_ #define _AO_ADC_H_ - - /* * One set of samples read from the A/D converter or telemetry */ - +#if AO_ADC_RING /* * ao_adc.c */ @@ -42,6 +40,7 @@ extern volatile __data uint8_t ao_adc_head; #if HAS_ACCEL_REF extern volatile __xdata uint16_t ao_accel_ref[AO_ADC_RING]; #endif +#endif /* Trigger a conversion sequence (called from the timer interrupt) */ void diff --git a/src/core/ao_config.c b/src/core/ao_config.c index 55fb8590..55ec9f40 100644 --- a/src/core/ao_config.c +++ b/src/core/ao_config.c @@ -16,6 +16,9 @@ */ #include "ao.h" +#include "ao_log.h" +#include +#include __xdata struct ao_config ao_config; __pdata uint8_t ao_config_loaded; @@ -64,11 +67,13 @@ ao_config_put(void) } #endif +#if HAS_RADIO void ao_config_set_radio(void) { ao_config.radio_setting = ao_freq_to_set(ao_config.frequency, ao_config.radio_cal); } +#endif /* HAS_RADIO */ static void _ao_config_get(void) @@ -100,8 +105,10 @@ _ao_config_get(void) ao_config.accel_minus_g = 0; } /* Fixups for minor version 3 */ +#if HAS_RADIO if (ao_config.minor < 3) ao_config.radio_cal = ao_radio_cal; +#endif /* Fixups for minor version 4 */ if (ao_config.minor < 4) ao_config.flight_log_max = AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX; @@ -121,7 +128,9 @@ _ao_config_get(void) ao_config.minor = AO_CONFIG_MINOR; ao_config_dirty = 1; } +#if HAS_RADIO ao_config_set_radio(); +#endif ao_config_loaded = 1; } @@ -176,6 +185,7 @@ ao_config_callsign_set(void) __reentrant _ao_config_edit_finish(); } +#if HAS_RADIO void ao_config_frequency_show(void) __reentrant { @@ -195,6 +205,7 @@ ao_config_frequency_set(void) __reentrant _ao_config_edit_finish(); ao_radio_recv_abort(); } +#endif #if HAS_FLIGHT @@ -232,7 +243,7 @@ ao_config_accel_calibrate_auto(char *orientation) __reentrant { uint16_t i; int32_t accel_total; - uint8_t cal_adc_ring; + uint8_t cal_data_ring; printf("Orient antenna %s and press a key...", orientation); flush(); @@ -241,12 +252,14 @@ ao_config_accel_calibrate_auto(char *orientation) __reentrant puts("Calibrating..."); flush(); i = ACCEL_CALIBRATE_SAMPLES; accel_total = 0; - cal_adc_ring = ao_sample_adc; + cal_data_ring = ao_sample_data; while (i) { - ao_sleep(DATA_TO_XDATA(&ao_sample_adc)); - while (i && cal_adc_ring != ao_sample_adc) { - accel_total += (int32_t) ao_adc_ring[cal_adc_ring].accel; - cal_adc_ring = ao_adc_ring_next(cal_adc_ring); + ao_sleep(DATA_TO_XDATA(&ao_sample_data)); + while (i && cal_data_ring != ao_sample_data) { + int16_t accel = ao_data_accel(&ao_data_ring[cal_data_ring]); + printf ("accel %d\n", accel); + accel_total += (int32_t) ao_data_accel(&ao_data_ring[cal_data_ring]); + cal_data_ring = ao_data_ring_next(cal_data_ring); i--; } } @@ -320,6 +333,7 @@ ao_config_apogee_lockout_set(void) __reentrant #endif /* HAS_FLIGHT */ +#if HAS_RADIO void ao_config_radio_cal_show(void) __reentrant { @@ -337,6 +351,7 @@ ao_config_radio_cal_set(void) __reentrant ao_config_set_radio(); _ao_config_edit_finish(); } +#endif #if HAS_LOG void @@ -413,6 +428,7 @@ ao_config_pad_orientation_set(void) __reentrant } #endif +#if HAS_RADIO void ao_config_radio_enable_show(void) __reentrant { @@ -429,6 +445,7 @@ ao_config_radio_enable_set(void) __reentrant ao_config.radio_enable = ao_cmd_lex_i; _ao_config_edit_finish(); } +#endif /* HAS_RADIO */ #if HAS_AES void @@ -481,18 +498,22 @@ __code struct ao_config_var ao_config_vars[] = { { "L \0Apogee detect lockout (s)", ao_config_apogee_lockout_set, ao_config_apogee_lockout_show, }, #endif /* HAS_FLIGHT */ +#if HAS_RADIO { "F \0Frequency (kHz)", ao_config_frequency_set, ao_config_frequency_show }, { "c \0Callsign (8 char max)", ao_config_callsign_set, ao_config_callsign_show }, { "e <0 disable, 1 enable>\0Enable telemetry and RDF", ao_config_radio_enable_set, ao_config_radio_enable_show }, +#endif /* HAS_RADIO */ #if HAS_ACCEL { "a <+g> <-g>\0Accel calib (0 for auto)", ao_config_accel_calibrate_set,ao_config_accel_calibrate_show }, #endif /* HAS_ACCEL */ +#if HAS_RADIO { "f \0Radio calib (cal = rf/(xtal/2^16))", ao_config_radio_cal_set, ao_config_radio_cal_show }, +#endif /* HAS_RADIO */ #if HAS_LOG { "l \0Flight log size (kB)", ao_config_log_set, ao_config_log_show }, diff --git a/src/core/ao_kalman.c b/src/core/ao_kalman.c index ee01949e..68725f69 100644 --- a/src/core/ao_kalman.c +++ b/src/core/ao_kalman.c @@ -17,10 +17,13 @@ #ifndef AO_FLIGHT_TEST #include "ao.h" +#include "ao_flight.h" #endif +#include "ao_sample.h" #include "ao_kalman.h" + static __pdata int32_t ao_k_height; static __pdata int32_t ao_k_speed; static __pdata int32_t ao_k_accel; diff --git a/src/core/ao_log.c b/src/core/ao_log.c index db60707d..d696625e 100644 --- a/src/core/ao_log.c +++ b/src/core/ao_log.c @@ -16,12 +16,13 @@ */ #include "ao.h" +#include __pdata uint32_t ao_log_current_pos; __pdata uint32_t ao_log_end_pos; __pdata uint32_t ao_log_start_pos; __xdata uint8_t ao_log_running; -__pdata enum flight_state ao_log_state; +__pdata enum ao_flight_state ao_log_state; __xdata uint16_t ao_flight_number; __code uint8_t ao_log_format = AO_LOG_FORMAT_FULL; diff --git a/src/core/ao_log.h b/src/core/ao_log.h index 611c00d5..e585750f 100644 --- a/src/core/ao_log.h +++ b/src/core/ao_log.h @@ -18,6 +18,8 @@ #ifndef _AO_LOG_H_ #define _AO_LOG_H_ +#include + /* * ao_log.c */ @@ -32,7 +34,7 @@ extern __pdata uint32_t ao_log_current_pos; extern __pdata uint32_t ao_log_end_pos; extern __pdata uint32_t ao_log_start_pos; extern __xdata uint8_t ao_log_running; -extern __pdata enum flight_state ao_log_state; +extern __pdata enum ao_flight_state ao_log_state; /* required functions from the underlying log system */ @@ -41,6 +43,7 @@ extern __pdata enum flight_state ao_log_state; #define AO_LOG_FORMAT_TINY 2 /* two byte state/baro records */ #define AO_LOG_FORMAT_TELEMETRY 3 /* 32 byte ao_telemetry records */ #define AO_LOG_FORMAT_TELESCIENCE 4 /* 32 byte typed telescience records */ +#define AO_LOG_FORMAT_MEGAMETRUM 5 /* 32 byte typed megametrum records */ #define AO_LOG_FORMAT_NONE 127 /* No log at all */ extern __code uint8_t ao_log_format; @@ -189,8 +192,65 @@ struct ao_log_record { } u; }; +struct ao_log_mega { + char type; /* 0 */ + uint8_t csum; /* 1 */ + uint16_t tick; /* 2 */ + union { /* 4 */ + struct { + uint16_t flight; /* 4 */ + int16_t ground_accel; /* 6 */ + uint32_t ground_pres; /* 8 */ + uint32_t ground_temp; /* 12 */ + } flight; /* 16 */ + struct { + uint16_t state; + uint16_t reason; + } state; + struct { + uint32_t pres; /* 4 */ + uint32_t temp; /* 8 */ + int16_t accel_x; /* 12 */ + int16_t accel_y; /* 14 */ + int16_t accel_z; /* 16 */ + int16_t gyro_x; /* 18 */ + int16_t gyro_y; /* 20 */ + int16_t gyro_z; /* 22 */ + } sensor; /* 24 */ + struct { + int16_t v_batt; /* 4 */ + int16_t v_pbatt; /* 8 */ + int16_t n_sense; /* 10 */ + int16_t sense[10]; /* 12 */ + } volt; /* 32 */ + struct { + int32_t latitude; /* 4 */ + int32_t longitude; /* 8 */ + int16_t altitude; /* 12 */ + uint8_t hour; /* 14 */ + uint8_t minute; /* 15 */ + uint8_t second; /* 16 */ + uint8_t flags; /* 17 */ + uint8_t year; /* 18 */ + uint8_t month; /* 19 */ + uint8_t day; /* 20 */ + uint8_t pad; /* 21 */ + } gps; /* 22 */ + struct { + uint16_t channels; /* 4 */ + struct { + uint8_t svid; + uint8_t c_n; + } sats[12]; /* 6 */ + } gps_sat; /* 30 */ + } u; +}; + /* Write a record to the eeprom log */ uint8_t ao_log_data(__xdata struct ao_log_record *log) __reentrant; +uint8_t +ao_log_mega(__xdata struct ao_log_mega *log) __reentrant; + #endif /* _AO_LOG_H_ */ diff --git a/src/core/ao_sample.h b/src/core/ao_sample.h index fb0e69e8..189b2019 100644 --- a/src/core/ao_sample.h +++ b/src/core/ao_sample.h @@ -18,6 +18,8 @@ #ifndef _AO_SAMPLE_H_ #define _AO_SAMPLE_H_ +#include + /* * ao_sample.c */ @@ -88,21 +90,22 @@ #define AO_MSS_TO_ACCEL(mss) ((int16_t) ((mss) * 16)) extern __pdata uint16_t ao_sample_tick; /* time of last data */ -extern __pdata int16_t ao_sample_pres; /* most recent pressure sensor reading */ -extern __pdata int16_t ao_sample_alt; /* MSL of ao_sample_pres */ -extern __pdata int16_t ao_sample_height; /* AGL of ao_sample_pres */ +extern __pdata pres_t ao_sample_pres; /* most recent pressure sensor reading */ +extern __pdata alt_t ao_sample_alt; /* MSL of ao_sample_pres */ +extern __pdata alt_t ao_sample_height; /* AGL of ao_sample_pres */ extern __data uint8_t ao_sample_adc; /* Ring position of last processed sample */ +extern __data uint8_t ao_sample_data; /* Ring position of last processed sample */ #if HAS_ACCEL -extern __pdata int16_t ao_sample_accel; /* most recent accel sensor reading */ +extern __pdata accel_t ao_sample_accel; /* most recent accel sensor reading */ #endif -extern __pdata int16_t ao_ground_pres; /* startup pressure */ -extern __pdata int16_t ao_ground_height; /* MSL of ao_ground_pres */ +extern __pdata pres_t ao_ground_pres; /* startup pressure */ +extern __pdata alt_t ao_ground_height; /* MSL of ao_ground_pres */ #if HAS_ACCEL -extern __pdata int16_t ao_ground_accel; /* startup acceleration */ -extern __pdata int16_t ao_accel_2g; /* factory accel calibration */ +extern __pdata accel_t ao_ground_accel; /* startup acceleration */ +extern __pdata accel_t ao_accel_2g; /* factory accel calibration */ extern __pdata int32_t ao_accel_scale; /* sensor to m/s² conversion */ #endif diff --git a/src/megametrum-v0.1/Makefile b/src/megametrum-v0.1/Makefile index 6524d8b8..a07b25ee 100644 --- a/src/megametrum-v0.1/Makefile +++ b/src/megametrum-v0.1/Makefile @@ -9,6 +9,8 @@ INC = \ ao.h \ ao_arch.h \ ao_arch_funcs.h \ + ao_data.h \ + ao_sample.h \ ao_pins.h \ altitude.h \ ao_kalman.h \ @@ -21,6 +23,11 @@ INC = \ # # Common AltOS sources # + +# ao_cc1120.c \ +# ao_packet.c \ +# ao_packet_slave.c \ + ALTOS_SRC = \ ao_interrupt.c \ ao_product.c \ @@ -35,7 +42,6 @@ ALTOS_SRC = \ ao_mutex.c \ ao_serial_stm.c \ ao_gps_skytraq.c \ - ao_cc1120.c \ ao_freq.c \ ao_dma_stm.c \ ao_spi_stm.c \ @@ -46,12 +52,17 @@ ALTOS_SRC = \ ao_m25.c \ ao_usb_stm.c \ ao_exti_stm.c \ - ao_packet.c \ - ao_packet_slave.c \ + ao_report.c \ ao_i2c_stm.c \ ao_hmc5883.c \ ao_mpu6000.c \ - ao_convert_pa.c + ao_convert_pa.c \ + ao_log.c \ + ao_log_mega.c \ + ao_sample_mm.c \ + ao_kalman.c \ + ao_flight_mm.c + PRODUCT=MegaMetrum-v0.1 PRODUCT_DEF=-DMEGAMETRUM diff --git a/src/megametrum-v0.1/ao_megametrum.c b/src/megametrum-v0.1/ao_megametrum.c index 2e1f9298..19746d37 100644 --- a/src/megametrum-v0.1/ao_megametrum.c +++ b/src/megametrum-v0.1/ao_megametrum.c @@ -18,6 +18,7 @@ #include #include #include +#include #include void @@ -46,7 +47,6 @@ main(void) ao_timer_init(); ao_cmd_init(); ao_gps_init(); - ao_config_init(); ao_dma_init(); ao_spi_init(); ao_ms5607_init(); @@ -55,10 +55,14 @@ main(void) ao_storage_init(); ao_usb_init(); ao_exti_init(); - ao_radio_init(); +// ao_radio_init(); ao_i2c_init(); ao_hmc5883_init(); ao_mpu6000_init(); + ao_flight_init(); + ao_log_init(); + ao_report_init(); + ao_config_init(); ao_cmd_register(&ao_mm_cmds[0]); ao_start_scheduler(); diff --git a/src/megametrum-v0.1/ao_pins.h b/src/megametrum-v0.1/ao_pins.h index adc56151..3ab7e15a 100644 --- a/src/megametrum-v0.1/ao_pins.h +++ b/src/megametrum-v0.1/ao_pins.h @@ -94,9 +94,12 @@ #define LEDS_AVAILABLE (AO_LED_RED | AO_LED_GREEN) +#define HAS_GPS 1 +#define HAS_FLIGHT 1 #define HAS_ADC 1 +#define HAS_ACCEL 1 -#define AO_ADC_RING 32 +#define AO_DATA_RING 32 #define AO_ADC_NUM_SENSE 6 struct ao_adc { @@ -179,6 +182,7 @@ struct ao_adc { /* * Pressure sensor settings */ +#define HAS_MS5607 1 #define AO_MS5607_CS_GPIO stm_gpioc #define AO_MS5607_CS 4 #define AO_MS5607_CS_MASK (1 << AO_MS5607_CS) @@ -221,6 +225,7 @@ struct ao_adc { * mpu6000 */ +#define HAS_MPU6000 1 #define AO_MPU6000_INT_PORT stm_gpioc #define AO_MPU6000_INT_PIN 13 #define AO_MPU6000_I2C_INDEX STM_I2C_INDEX(1) diff --git a/src/stm/ao_adc_stm.c b/src/stm/ao_adc_stm.c index a2569908..af2968d6 100644 --- a/src/stm/ao_adc_stm.c +++ b/src/stm/ao_adc_stm.c @@ -16,10 +16,17 @@ */ #include +#include +#if HAS_MPU6000 +#include +#endif +#if HAS_MS5607 +#include +#endif +volatile __xdata struct ao_data ao_data_ring[AO_DATA_RING]; +volatile __data uint8_t ao_data_head; -volatile __xdata struct ao_adc ao_adc_ring[AO_ADC_RING]; -volatile __data uint8_t ao_adc_head; static uint8_t ao_adc_ready; #define AO_ADC_CR2_VAL ((0 << STM_ADC_CR2_SWSTART) | \ @@ -43,9 +50,15 @@ static uint8_t ao_adc_ready; */ static void ao_adc_done(int index) { - ao_adc_ring[ao_adc_head].tick = ao_time(); - ao_adc_head = ao_adc_ring_next(ao_adc_head); - ao_wakeup((void *) &ao_adc_head); + ao_data_ring[ao_data_head].adc.tick = ao_time(); +#if HAS_MPU6000 + ao_data_ring[ao_data_head].mpu6000 = ao_mpu6000_current; +#endif +#if HAS_MS5607 + ao_data_ring[ao_data_head].ms5607 = ao_ms5607_current; +#endif + ao_data_head = ao_data_ring_next(ao_data_head); + ao_wakeup((void *) &ao_data_head); ao_dma_done_transfer(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC1)); ao_adc_ready = 1; } @@ -62,7 +75,7 @@ ao_adc_poll(void) stm_adc.sr = 0; ao_dma_set_transfer(STM_DMA_INDEX(STM_DMA_CHANNEL_ADC1), &stm_adc.dr, - (void *) (&ao_adc_ring[ao_adc_head].tick + 1), + (void *) (&ao_data_ring[ao_data_head].tick + 1), AO_NUM_ADC, (0 << STM_DMA_CCR_MEM2MEM) | (STM_DMA_CCR_PL_HIGH << STM_DMA_CCR_PL) | @@ -84,20 +97,27 @@ ao_adc_poll(void) void ao_adc_get(__xdata struct ao_adc *packet) { - uint8_t i = ao_adc_ring_prev(ao_adc_head); - memcpy(packet, (void *) &ao_adc_ring[i], sizeof (struct ao_adc)); + uint8_t i = ao_data_ring_prev(ao_data_head); + memcpy(packet, (void *) &ao_data_ring[i].adc, sizeof (struct ao_adc)); +} + +void +ao_data_get(__xdata struct ao_data *packet) +{ + uint8_t i = ao_data_ring_prev(ao_data_head); + memcpy(packet, (void *) &ao_data_ring[i], sizeof (struct ao_data)); } static void ao_adc_dump(void) __reentrant { - struct ao_adc packet; + struct ao_data packet; int16_t *d; uint8_t i; - ao_adc_get(&packet); + ao_data_get(&packet); printf("tick: %5u", packet.tick); - d = (int16_t *) (&packet.tick + 1); + d = (int16_t *) (&packet.adc); for (i = 0; i < AO_NUM_ADC; i++) printf (" %2d: %5d", i, d[i]); printf("\n");