diff options
| author | Bdale Garbee <bdale@gag.com> | 2017-04-24 18:22:03 -0600 | 
|---|---|---|
| committer | Bdale Garbee <bdale@gag.com> | 2017-04-24 18:22:03 -0600 | 
| commit | b91f67005709cb7f65e0a461b49b5cb0952cb391 (patch) | |
| tree | e9f6c0f30a81cf30a9cfd52887171168f7830f85 /src/kernel | |
| parent | 1e956f93e0c9f8ed6180490f80e8aead5538f818 (diff) | |
| parent | 8a10ddb0bca7d6f6aa4aedda171899abd165fd74 (diff) | |
Merge branch 'branch-1.7' into debian
Diffstat (limited to 'src/kernel')
| -rw-r--r-- | src/kernel/ao.h | 30 | ||||
| -rw-r--r-- | src/kernel/ao_cmd.c | 21 | ||||
| -rw-r--r-- | src/kernel/ao_log.h | 30 | ||||
| -rw-r--r-- | src/kernel/ao_log_firetwo.c | 149 | ||||
| -rw-r--r-- | src/kernel/ao_pyro.c | 3 | ||||
| -rw-r--r-- | src/kernel/ao_report.c | 13 | ||||
| -rw-r--r-- | src/kernel/ao_stdio.c | 5 | ||||
| -rw-r--r-- | src/kernel/ao_task.c | 6 | ||||
| -rw-r--r-- | src/kernel/ao_telemetry.c | 2 | ||||
| -rw-r--r-- | src/kernel/ao_telemetry.h | 3 | 
10 files changed, 217 insertions, 45 deletions
| diff --git a/src/kernel/ao.h b/src/kernel/ao.h index fb41d7a9..e56fbb2e 100644 --- a/src/kernel/ao.h +++ b/src/kernel/ao.h @@ -170,6 +170,9 @@ void  ao_put_string(__code char *s);  void +ao_cmd_readline(void); + +char  ao_cmd_lex(void);  void @@ -853,33 +856,6 @@ struct ao_fifo {  #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   */ diff --git a/src/kernel/ao_cmd.c b/src/kernel/ao_cmd.c index 10716afd..881f3500 100644 --- a/src/kernel/ao_cmd.c +++ b/src/kernel/ao_cmd.c @@ -24,13 +24,15 @@ __pdata uint32_t ao_cmd_lex_u32;  __pdata char	ao_cmd_lex_c;  __pdata enum ao_cmd_status ao_cmd_status; +#ifndef AO_CMD_LEN  #if AO_PYRO_NUM -#define CMD_LEN 128 +#define AO_CMD_LEN 128  #else -#define CMD_LEN	48 +#define AO_CMD_LEN	48 +#endif  #endif -static __xdata char	cmd_line[CMD_LEN]; +static __xdata char	cmd_line[AO_CMD_LEN];  static __pdata uint8_t	cmd_len;  static __pdata uint8_t	cmd_i; @@ -48,8 +50,8 @@ backspace(void)  	ao_put_string ("\010 \010");  } -static void -readline(void) +void +ao_cmd_readline(void)  {  	char c;  	if (ao_echo()) @@ -88,7 +90,7 @@ readline(void)  			break;  		} -		if (cmd_len >= CMD_LEN - 2) +		if (cmd_len >= AO_CMD_LEN - 2)  			continue;  		cmd_line[cmd_len++] = c;  		if (ao_echo()) @@ -99,12 +101,13 @@ readline(void)  	cmd_i = 0;  } -void +char  ao_cmd_lex(void)  {  	ao_cmd_lex_c = '\n';  	if (cmd_i < cmd_len)  		ao_cmd_lex_c = cmd_line[cmd_i++]; +	return ao_cmd_lex_c;  }  static void @@ -307,7 +310,7 @@ version(void)  #endif  #endif  #if defined(AO_BOOT_APPLICATION_BASE) && defined(AO_BOOT_APPLICATION_BOUND) -	       , (uint32_t) AO_BOOT_APPLICATION_BOUND - (uint32_t) AO_BOOT_APPLICATION_BASE +	       , (unsigned) ((uint32_t) AO_BOOT_APPLICATION_BOUND - (uint32_t) AO_BOOT_APPLICATION_BASE)  #endif  		);  	printf("software-version %s\n", ao_version); @@ -376,7 +379,7 @@ ao_cmd(void)  	void (*__xdata func)(void);  	for (;;) { -		readline(); +		ao_cmd_readline();  		ao_cmd_lex();  		ao_cmd_white();  		c = ao_cmd_lex_c; diff --git a/src/kernel/ao_log.h b/src/kernel/ao_log.h index 13eb05bf..a2f2c6ca 100644 --- a/src/kernel/ao_log.h +++ b/src/kernel/ao_log.h @@ -47,10 +47,12 @@ extern __pdata enum ao_flight_state ao_log_state;  #define AO_LOG_FORMAT_TELEMEGA_OLD	5	/* 32 byte typed telemega records */  #define AO_LOG_FORMAT_EASYMINI		6	/* 16-byte MS5607 baro only, 3.0V supply */  #define AO_LOG_FORMAT_TELEMETRUM	7	/* 16-byte typed telemetrum records */ -#define AO_LOG_FORMAT_TELEMINI		8	/* 16-byte MS5607 baro only, 3.3V supply */ +#define AO_LOG_FORMAT_TELEMINI2		8	/* 16-byte MS5607 baro only, 3.3V supply, cc1111 SoC */  #define AO_LOG_FORMAT_TELEGPS		9	/* 32 byte telegps records */  #define AO_LOG_FORMAT_TELEMEGA		10	/* 32 byte typed telemega records with 32 bit gyro cal */  #define AO_LOG_FORMAT_DETHERM		11	/* 16-byte MS5607 baro only, no ADC */ +#define AO_LOG_FORMAT_TELEMINI3		12	/* 16-byte MS5607 baro only, 3.3V supply, stm32f042 SoC */ +#define AO_LOG_FORMAT_TELEFIRETWO	13	/* 32-byte test stand data */  #define AO_LOG_FORMAT_NONE		127	/* No log at all */  extern __code uint8_t ao_log_format; @@ -299,6 +301,32 @@ struct ao_log_mega {  						 ((l)->u.gps.altitude_high = (a) >> 16), \  						 (l)->u.gps.altitude_low = (a)) +struct ao_log_firetwo { +	char			type;			/* 0 */ +	uint8_t			csum;			/* 1 */ +	uint16_t		tick;			/* 2 */ +	union {						/* 4 */ +		/* AO_LOG_FLIGHT */ +		struct { +			uint16_t	flight;		/* 4 */ +			uint16_t	idle_pressure;	/* 6 */ +			uint16_t	idle_thrust;	/* 8 */ +		} flight;	/* 16 */ +		/* AO_LOG_STATE */ +		struct { +			uint16_t	state;		/* 4 */ +			uint16_t	reason;		/* 6 */ +		} state;	/* 8 */ +		/* AO_LOG_SENSOR */ +		struct { +			uint16_t	pressure;	/* 4 */ +			uint16_t	thrust;		/* 6 */ +			uint16_t	thermistor[4];	/* 8 */ +		} sensor;	/* 24 */ +		uint8_t		align[28];		/* 4 */ +	} u;	/* 32 */ +}; +  struct ao_log_metrum {  	char			type;			/* 0 */  	uint8_t			csum;			/* 1 */ diff --git a/src/kernel/ao_log_firetwo.c b/src/kernel/ao_log_firetwo.c new file mode 100644 index 00000000..4b42abe4 --- /dev/null +++ b/src/kernel/ao_log_firetwo.c @@ -0,0 +1,149 @@ +/* + * Copyright © 2017 Bdale Garbee <bdale@gag.com> + * + * 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; 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 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include "ao.h" +#include <ao_log.h> +#include <ao_data.h> +#include <ao_flight.h> + +static __xdata struct ao_log_firetwo log; + +__code uint8_t ao_log_format = AO_LOG_FORMAT_TELEFIRETWO; + +static uint8_t +ao_log_csum(__xdata uint8_t *b) __reentrant +{ +	uint8_t	sum = 0x5a; +	uint8_t	i; + +	for (i = 0; i < sizeof (struct ao_log_firetwo); i++) +		sum += *b++; +	return -sum; +} + +uint8_t +ao_log_firetwo(__xdata struct ao_log_firetwo *log) __reentrant +{ +	uint8_t wrote = 0; +	/* set checksum */ +	log->csum = 0; +	log->csum = ao_log_csum((__xdata uint8_t *) log); +	ao_mutex_get(&ao_log_mutex); { +		if (ao_log_current_pos >= ao_log_end_pos && ao_log_running) +			ao_log_stop(); +		if (ao_log_running) { +			wrote = 1; +			ao_storage_write(ao_log_current_pos, +					 log, +					 sizeof (struct ao_log_firetwo)); +			ao_log_current_pos += sizeof (struct ao_log_firetwo); +		} +	} ao_mutex_put(&ao_log_mutex); +	return wrote; +} + +static uint8_t +ao_log_dump_check_data(void) +{ +	if (ao_log_csum((uint8_t *) &log) != 0) +		return 0; +	return 1; +} + +#if HAS_ADC +static __data uint8_t	ao_log_data_pos; + +/* a hack to make sure that ao_log_metrums fill the eeprom block in even units */ +typedef uint8_t check_log_size[1-(256 % sizeof(struct ao_log_firetwo))] ; +#endif + +void +ao_log(void) +{ +	uint16_t ao_idle_pressure = 0;		// write code to capture pre-test values someday +	uint16_t ao_idle_thrust = 0; +	uint16_t ao_flight_state = ao_flight_startup; + +	ao_storage_setup(); + +	do { +		ao_log_scan(); +	 +		while (!ao_log_running) +			ao_sleep(&ao_log_running); +	 +		log.type = AO_LOG_FLIGHT; +		log.tick = ao_time(); +		log.u.flight.idle_pressure = ao_idle_pressure; +		log.u.flight.idle_thrust = ao_idle_thrust; +		log.u.flight.flight = ao_flight_number; +		ao_log_firetwo(&log); + +		/* Write the whole contents of the ring to the log +	 	* when starting up. +	 	*/ +		ao_log_data_pos = ao_data_ring_next(ao_data_head); +		ao_log_state = ao_flight_startup; +		for (;;) { +			/* Write samples to EEPROM */ +			while (ao_log_data_pos != ao_data_head) { +				log.tick = ao_data_ring[ao_log_data_pos].tick; +				log.type = AO_LOG_SENSOR; +				log.u.sensor.pressure = ao_data_ring[ao_log_data_pos].adc.pressure; +				log.u.sensor.thrust = ao_data_ring[ao_log_data_pos].adc.thrust; +	//			for (i = 0; i < 4; i++) { +	//				log.u.sensor.thermistor[i] = ao_data_ring[ao_log_data_pos].sensor.thermistor[i]; +	//			} +				ao_log_firetwo(&log); +				ao_log_data_pos = ao_data_ring_next(ao_log_data_pos); +			} +			/* Write state change to EEPROM */ +			if (ao_flight_state != ao_log_state) { +				ao_log_state = ao_flight_state; +				log.type = AO_LOG_STATE; +				log.tick = ao_time(); +				log.u.state.state = ao_log_state; +				log.u.state.reason = 0; +				ao_log_firetwo(&log); +	 +				if (ao_log_state == ao_flight_landed) +					ao_log_stop(); +			} +	 +			ao_log_flush(); + +			if (!ao_log_running) break; + +			/* Wait for a while */ +			ao_delay(AO_MS_TO_TICKS(100)); +		} +	} while (ao_log_running); +} + +uint16_t +ao_log_flight(uint8_t slot) +{ +	if (!ao_storage_read(ao_log_pos(slot), +			     &log, +			     sizeof (struct ao_log_firetwo))) +		return 0; + +	if (ao_log_dump_check_data() && log.type == AO_LOG_FLIGHT) +		return log.u.flight.flight; +	return 0; +} diff --git a/src/kernel/ao_pyro.c b/src/kernel/ao_pyro.c index 813e866a..a0881f9e 100644 --- a/src/kernel/ao_pyro.c +++ b/src/kernel/ao_pyro.c @@ -75,7 +75,8 @@ uint16_t	ao_pyro_fired;  #endif  #if PYRO_DBG -#define DBG(...)	do { printf("\t%d: ", (int) (pyro - ao_config.pyro)); printf(__VA_ARGS__); } while (0) +int pyro_dbg; +#define DBG(...)	do { if (pyro_dbg) printf("\t%d: ", (int) (pyro - ao_config.pyro)); printf(__VA_ARGS__); } while (0)  #else  #define DBG(...)  #endif diff --git a/src/kernel/ao_report.c b/src/kernel/ao_report.c index 6592d616..af48b390 100644 --- a/src/kernel/ao_report.c +++ b/src/kernel/ao_report.c @@ -45,9 +45,16 @@ static const uint8_t flight_reports[] = {  #define mid(time)	ao_beep_for(AO_BEEP_MID, time)  #define high(time)	ao_beep_for(AO_BEEP_HIGH, time)  #else -#define low(time)	ao_led_for(AO_LED_GREEN, time) -#define mid(time)	ao_led_for(AO_LED_RED, time) -#define high(time)	ao_led_for(AO_LED_GREEN|AO_LED_RED, time) +#ifndef AO_LED_LOW +#define AO_LED_LOW	AO_LED_GREEN +#endif +#ifndef AO_LED_MID +#define AO_LED_MID	AO_LED_RED +#endif + +#define low(time)	ao_led_for(AO_LED_LOW, time) +#define mid(time)	ao_led_for(AO_LED_MID, time) +#define high(time)	ao_led_for(AO_LED_MID|AO_LED_LOW, time)  #endif  #define pause(time)	ao_delay(time) diff --git a/src/kernel/ao_stdio.c b/src/kernel/ao_stdio.c index b79d465a..f0ee0a14 100644 --- a/src/kernel/ao_stdio.c +++ b/src/kernel/ao_stdio.c @@ -55,6 +55,9 @@  #ifndef PACKET_HAS_SLAVE  #define PACKET_HAS_SLAVE	0  #endif +#ifndef CONSOLE_STDIN +#define CONSOLE_STDIN		0 +#endif  #define USE_SERIAL_STDIN (USE_SERIAL_0_STDIN +	\  			  USE_SERIAL_1_STDIN +	\ @@ -67,7 +70,7 @@  			  USE_SERIAL_8_STDIN +	\  			  USE_SERIAL_9_STDIN) -#define AO_NUM_STDIOS	(HAS_USB + PACKET_HAS_SLAVE + USE_SERIAL_STDIN) +#define AO_NUM_STDIOS	(HAS_USB + PACKET_HAS_SLAVE + USE_SERIAL_STDIN + CONSOLE_STDIN)  __xdata struct ao_stdio ao_stdios[AO_NUM_STDIOS]; diff --git a/src/kernel/ao_task.c b/src/kernel/ao_task.c index e8a092aa..de23ea02 100644 --- a/src/kernel/ao_task.c +++ b/src/kernel/ao_task.c @@ -373,7 +373,11 @@ ao_yield(void) ao_arch_naked_define  		if (!ao_list_is_empty(&run_queue))  			break;  		/* Wait for interrupts when there's nothing ready */ -		ao_arch_wait_interrupt(); +		if (ao_task_minimize_latency) { +			ao_arch_release_interrupts(); +			ao_arch_block_interrupts(); +		} else +			ao_arch_wait_interrupt();  	}  	ao_cur_task = ao_list_first_entry(&run_queue, struct ao_task, queue);  #else diff --git a/src/kernel/ao_telemetry.c b/src/kernel/ao_telemetry.c index 15085bf4..fa817824 100644 --- a/src/kernel/ao_telemetry.c +++ b/src/kernel/ao_telemetry.c @@ -270,7 +270,7 @@ ao_send_mini(void)  	__xdata	struct ao_data *packet = (__xdata struct ao_data *) &ao_data_ring[ao_data_ring_prev(ao_sample_data)];  	telemetry.generic.tick = packet->tick; -	telemetry.generic.type = AO_TELEMETRY_MINI; +	telemetry.generic.type = AO_SEND_MINI;  	telemetry.mini.state = ao_flight_state; diff --git a/src/kernel/ao_telemetry.h b/src/kernel/ao_telemetry.h index c0f5e3c5..45aaeb07 100644 --- a/src/kernel/ao_telemetry.h +++ b/src/kernel/ao_telemetry.h @@ -270,7 +270,8 @@ struct ao_telemetry_metrum_data {  	/* 32 */  }; -#define AO_TELEMETRY_MINI		0x10 +#define AO_TELEMETRY_MINI2		0x10	/* CC1111 based */ +#define AO_TELEMETRY_MINI3		0x11	/* STMF042 based */  struct ao_telemetry_mini {  	uint16_t	serial;		/*  0 */ | 
