diff options
| -rw-r--r-- | src/avr/ao_adc_avr.c | 24 | ||||
| -rw-r--r-- | src/avr/ao_pins.h | 3 | ||||
| -rw-r--r-- | src/core/ao_log_telescience.c | 14 | ||||
| -rw-r--r-- | src/core/ao_stdio.c | 16 | ||||
| -rw-r--r-- | src/drivers/ao_science_slave.c | 2 | ||||
| -rw-r--r-- | src/test/Makefile | 4 | ||||
| -rw-r--r-- | src/test/ao_flight_test.c | 58 | 
7 files changed, 61 insertions, 60 deletions
diff --git a/src/avr/ao_adc_avr.c b/src/avr/ao_adc_avr.c index 4f6f0e60..928cd3e1 100644 --- a/src/avr/ao_adc_avr.c +++ b/src/avr/ao_adc_avr.c @@ -17,8 +17,8 @@  #include "ao.h" -volatile __xdata struct ao_adc	ao_adc_ring[AO_ADC_RING]; -volatile __data uint8_t		ao_adc_head; +volatile __xdata struct ao_data	ao_data_ring[AO_DATA_RING]; +volatile __data uint8_t		ao_data_head;  #ifdef TELESCIENCE  const uint8_t	adc_channels[AO_LOG_TELESCIENCE_NUM_ADC] = { @@ -92,14 +92,14 @@ ISR(ADC_vect)  	/* Must read ADCL first or the value there will be lost */  	value = ADCL;  	value |= (ADCH << 8); -	ao_adc_ring[ao_adc_head].adc[ao_adc_channel] = value; +	ao_data_ring[ao_data_head].adc.adc[ao_adc_channel] = value;  	if (++ao_adc_channel < NUM_ADC)  		ao_adc_start();  	else {  		ADCSRA = ADCSRA_INIT; -		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].tick = ao_time(); +		ao_data_head = ao_data_ring_next(ao_data_head); +		ao_wakeup((void *) &ao_data_head);  		ao_cpu_sleep_disable = 0;  	}  } @@ -113,18 +113,18 @@ ao_adc_poll(void)  }  void -ao_adc_get(__xdata struct ao_adc *packet) +ao_data_get(__xdata struct ao_data *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], sizeof (struct ao_data));  }  static void  ao_adc_dump(void) __reentrant  { -	static __xdata struct ao_adc	packet; +	static __xdata struct ao_data	packet;  	uint8_t i; -	ao_adc_get(&packet); +	ao_data_get(&packet);  #ifdef TELEPYRO  	printf("ADMUX:  %02x\n", ADMUX);  	printf("ADCSRA: %02x\n", ADCSRA); @@ -137,7 +137,7 @@ ao_adc_dump(void) __reentrant  #endif  	printf("tick: %5u",  packet.tick);  	for (i = 0; i < NUM_ADC; i++) -		printf (" %2d: %5u", i, packet.adc[i]); +		printf (" %2d: %5u", i, packet.adc.adc[i]);  	printf("\n"); diff --git a/src/avr/ao_pins.h b/src/avr/ao_pins.h index f2b40fb4..850a08ec 100644 --- a/src/avr/ao_pins.h +++ b/src/avr/ao_pins.h @@ -91,10 +91,9 @@  #define AO_TELESCIENCE_NUM_ADC	12  struct ao_adc { -	uint16_t	tick;		/* tick when the sample was read */  	uint16_t	adc[AO_TELESCIENCE_NUM_ADC];	/* samples */  }; -#define AO_ADC_RING	16 +#define AO_DATA_RING	16  #endif /* _AO_PINS_H_ */ diff --git a/src/core/ao_log_telescience.c b/src/core/ao_log_telescience.c index ae045281..002a10bd 100644 --- a/src/core/ao_log_telescience.c +++ b/src/core/ao_log_telescience.c @@ -20,7 +20,7 @@  #include "ao_log.h"  #include "ao_companion.h" -static uint8_t	ao_log_adc_pos; +static uint8_t	ao_log_data_pos;  __code uint8_t ao_log_format = AO_LOG_FORMAT_TELESCIENCE; @@ -62,20 +62,20 @@ ao_log_single(void)  		/* Write the whole contents of the ring to the log  		 * when starting up.  		 */ -		ao_log_adc_pos = ao_adc_ring_next(ao_adc_head); +		ao_log_data_pos = ao_data_ring_next(ao_data_head);  		ao_log_single_write_data.telescience.type = AO_LOG_TELESCIENCE_DATA;  		while (ao_log_running) {  			/* Write samples to EEPROM */ -			while (ao_log_adc_pos != ao_adc_head) { -				ao_log_single_write_data.telescience.tick = ao_adc_ring[ao_log_adc_pos].tick; -				memcpy(&ao_log_single_write_data.telescience.adc, (void *) ao_adc_ring[ao_log_adc_pos].adc, +			while (ao_log_data_pos != ao_data_head) { +				ao_log_single_write_data.telescience.tick = ao_data_ring[ao_log_data_pos].tick; +				memcpy(&ao_log_single_write_data.telescience.adc, (void *) ao_data_ring[ao_log_data_pos].adc.adc,  				       AO_LOG_TELESCIENCE_NUM_ADC * sizeof (uint16_t));  				ao_log_telescience_csum();  				ao_log_single_write(); -				ao_log_adc_pos = ao_adc_ring_next(ao_log_adc_pos); +				ao_log_data_pos = ao_data_ring_next(ao_log_data_pos);  			}  			/* Wait for more ADC data to arrive */ -			ao_sleep((void *) &ao_adc_head); +			ao_sleep((void *) &ao_data_head);  		}  		memset(&ao_log_single_write_data.telescience.adc, '\0', sizeof (ao_log_single_write_data.telescience.adc));  	} diff --git a/src/core/ao_stdio.c b/src/core/ao_stdio.c index 9b4ea473..656b23c9 100644 --- a/src/core/ao_stdio.c +++ b/src/core/ao_stdio.c @@ -53,14 +53,14 @@  #endif  #define USE_SERIAL_STDIN (USE_SERIAL_0_STDIN +	\ -			  USE_SERIAL_1_STDIN |	\ -			  USE_SERIAL_2_STDIN |	\ -			  USE_SERIAL_3_STDIN |	\ -			  USE_SERIAL_4_STDIN |	\ -			  USE_SERIAL_5_STDIN |	\ -			  USE_SERIAL_6_STDIN |	\ -			  USE_SERIAL_7_STDIN |	\ -			  USE_SERIAL_8_STDIN |	\ +			  USE_SERIAL_1_STDIN +	\ +			  USE_SERIAL_2_STDIN +	\ +			  USE_SERIAL_3_STDIN +	\ +			  USE_SERIAL_4_STDIN +	\ +			  USE_SERIAL_5_STDIN +	\ +			  USE_SERIAL_6_STDIN +	\ +			  USE_SERIAL_7_STDIN +	\ +			  USE_SERIAL_8_STDIN +	\  			  USE_SERIAL_9_STDIN)  #define AO_NUM_STDIOS	(HAS_USB + PACKET_HAS_SLAVE + USE_SERIAL_STDIN) diff --git a/src/drivers/ao_science_slave.c b/src/drivers/ao_science_slave.c index a86b5151..996e98d9 100644 --- a/src/drivers/ao_science_slave.c +++ b/src/drivers/ao_science_slave.c @@ -42,7 +42,7 @@ void ao_spi_slave(void)  				  sizeof (ao_telescience_setup));  		break;  	case AO_COMPANION_FETCH: -		ao_spi_slave_send((uint8_t *) &ao_adc_ring[ao_adc_ring_prev(ao_adc_head)].adc, +		ao_spi_slave_send((uint8_t *) &ao_data_ring[ao_data_ring_prev(ao_data_head)].adc,  				  AO_LOG_TELESCIENCE_NUM_ADC * sizeof (uint16_t));  		break;  	case AO_COMPANION_NOTIFY: diff --git a/src/test/Makefile b/src/test/Makefile index 3c2b8732..1e54f5e0 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -13,10 +13,10 @@ clean:  install: -ao_flight_test: ao_flight_test.c ao_host.h ao_flight.c ao_sample.c ao_kalman.c altitude.h ao_kalman.h +ao_flight_test: ao_flight_test.c ao_host.h ao_flight_mm.c ao_sample_mm.c ao_kalman.c altitude.h ao_kalman.h  	cc $(CFLAGS) -o $@ $< -ao_flight_test_noisy_accel: ao_flight_test.c ao_host.h ao_flight.c ao_sample.c ao_kalman.c altitude.h ao_kalman.h +ao_flight_test_noisy_accel: ao_flight_test.c ao_host.h ao_flight_mm.c ao_sample_mm.c ao_kalman.c altitude.h ao_kalman.h  	cc -DNOISY_ACCEL=1 $(CFLAGS) -o $@ $<  ao_flight_test_baro: ao_flight_test.c ao_host.h ao_flight.c  ao_sample.c ao_kalman.c altitude.h ao_kalman.h diff --git a/src/test/ao_flight_test.c b/src/test/ao_flight_test.c index 4a8625cf..baf2ad1d 100644 --- a/src/test/ao_flight_test.c +++ b/src/test/ao_flight_test.c @@ -26,9 +26,10 @@  #define AO_HERTZ	100 -#define AO_ADC_RING	64 -#define ao_adc_ring_next(n)	(((n) + 1) & (AO_ADC_RING - 1)) -#define ao_adc_ring_prev(n)	(((n) - 1) & (AO_ADC_RING - 1)) +#define HAS_ADC 1 +#define AO_DATA_RING	64 +#define ao_data_ring_next(n)	(((n) + 1) & (AO_DATA_RING - 1)) +#define ao_data_ring_prev(n)	(((n) - 1) & (AO_DATA_RING - 1))  #define AO_M_TO_HEIGHT(m)	((int16_t) (m))  #define AO_MS_TO_SPEED(ms)	((int16_t) ((ms) * 16)) @@ -38,7 +39,6 @@   * One set of samples read from the A/D converter   */  struct ao_adc { -	uint16_t	tick;		/* tick when the sample was read */  	int16_t		accel;		/* accelerometer */  	int16_t		pres;		/* pressure sensor */  	int16_t		pres_real;	/* unclipped */ @@ -54,6 +54,8 @@ struct ao_adc {  #define __code  #define __reentrant +#include <ao_data.h> +  #define to_fix16(x) ((int16_t) ((x) * 65536.0 + 0.5))  #define to_fix32(x) ((int32_t) ((x) * 65536.0 + 0.5))  #define from_fix(x)	((x) >> 16) @@ -90,8 +92,8 @@ extern enum ao_flight_state ao_flight_state;  #define FALSE 0  #define TRUE 1 -struct ao_adc ao_adc_ring[AO_ADC_RING]; -uint8_t ao_adc_head; +volatile struct ao_data ao_data_ring[AO_DATA_RING]; +volatile uint8_t ao_data_head;  int	ao_summary = 0;  #define ao_led_on(l) @@ -110,7 +112,7 @@ enum ao_igniter {  	ao_igniter_main = 1  }; -struct ao_adc ao_adc_static; +struct ao_data ao_data_static;  int	drogue_height;  double	drogue_time; @@ -124,7 +126,7 @@ static int32_t	ao_k_height;  void  ao_ignite(enum ao_igniter igniter)  { -	double time = (double) (ao_adc_static.tick + tick_offset) / 100; +	double time = (double) (ao_data_static.tick + tick_offset) / 100;  	if (igniter == ao_igniter_drogue) {  		drogue_time = time; @@ -221,8 +223,8 @@ int ao_sample_prev_tick;  uint16_t	prev_tick;  #include "ao_kalman.c" -#include "ao_sample.c" -#include "ao_flight.c" +#include "ao_sample_mm.c" +#include "ao_flight_mm.c"  #define to_double(f)	((f) / 65536.0) @@ -282,19 +284,19 @@ ao_insert(void)  {  	double	time; -	ao_adc_ring[ao_adc_head] = ao_adc_static; -	ao_adc_head = ao_adc_ring_next(ao_adc_head); +	ao_data_ring[ao_data_head] = ao_data_static; +	ao_data_head = ao_data_ring_next(ao_data_head);  	if (ao_flight_state != ao_flight_startup) { -		double	height = ao_pres_to_altitude(ao_adc_static.pres_real) - ao_ground_height; -		double  accel = ((ao_flight_ground_accel - ao_adc_static.accel) * GRAVITY * 2.0) / +		double	height = ao_pres_to_altitude(ao_data_static.adc.pres_real) - ao_ground_height; +		double  accel = ((ao_flight_ground_accel - ao_data_static.adc.accel) * GRAVITY * 2.0) /  			(ao_config.accel_minus_g - ao_config.accel_plus_g);  		if (!tick_offset) -			tick_offset = -ao_adc_static.tick; -		if ((prev_tick - ao_adc_static.tick) > 0x400) +			tick_offset = -ao_data_static.tick; +		if ((prev_tick - ao_data_static.tick) > 0x400)  			tick_offset += 65536; -		prev_tick = ao_adc_static.tick; -		time = (double) (ao_adc_static.tick + tick_offset) / 100; +		prev_tick = ao_data_static.tick; +		time = (double) (ao_data_static.tick + tick_offset) / 100;  		if (ao_test_max_height < height) {  			ao_test_max_height = height; @@ -474,7 +476,7 @@ int16(uint8_t *bytes, int off)  void  ao_sleep(void *wchan)  { -	if (wchan == &ao_adc_head) { +	if (wchan == &ao_data_head) {  		char		type;  		uint16_t	tick;  		uint16_t	a, b; @@ -490,7 +492,7 @@ ao_sleep(void *wchan)  		for (;;) {  			if (ao_records_read > 2 && ao_flight_state == ao_flight_startup)  			{ -				ao_adc_static.accel = ao_flight_ground_accel; +				ao_data_static.adc.accel = ao_flight_ground_accel;  				ao_insert();  				return;  			} @@ -501,7 +503,7 @@ ao_sleep(void *wchan)  						printf ("no more data, exiting simulation\n");  					ao_test_exit();  				} -				ao_adc_static.tick += 10; +				ao_data_static.tick += 10;  				ao_insert();  				return;  			} @@ -639,19 +641,19 @@ ao_sleep(void *wchan)  			case 'S':  				break;  			case 'A': -				ao_adc_static.tick = tick; -				ao_adc_static.accel = a; -				ao_adc_static.pres_real = b; +				ao_data_static.tick = tick; +				ao_data_static.adc.accel = a; +				ao_data_static.adc.pres_real = b;  				if (b < AO_MIN_BARO_VALUE)  					b = AO_MIN_BARO_VALUE; -				ao_adc_static.pres = b; +				ao_data_static.adc.pres = b;  				ao_records_read++;  				ao_insert();  				return;  			case 'T': -				ao_adc_static.tick = tick; -				ao_adc_static.temp = a; -				ao_adc_static.v_batt = b; +				ao_data_static.tick = tick; +				ao_data_static.adc.temp = a; +				ao_data_static.adc.v_batt = b;  				break;  			case 'D':  			case 'G':  | 
