ISR(TIMER1_COMPA_vect)
{
++ao_tick_count;
- if ((int16_t) (ao_tick_count - ao_wakeup_count) >= 0)
+ if ((AO_TICK_SIGNED) (ao_tick_count - ao_wakeup_count) >= 0)
ao_wakeup((void *) &ao_tick_count);
}
{
cli();
ao_wakeup_count = target;
- while ((int16_t) (target - ao_tick_count) > 0)
+ while ((AO_TICK_SIGNED) (target - ao_tick_count) > 0)
ao_sleep((void *) &ao_tick_count);
sei();
}
}
void
-ao_led_for(uint8_t colors, uint16_t ticks)
+ao_led_for(uint8_t colors, AO_TICK_TYPE ticks)
{
ao_led_on(colors);
ao_delay(ticks);
#include "ao.h"
-volatile uint16_t ao_tick_count;
+volatile AO_TICK_TYPE ao_tick_count;
-uint16_t ao_time(void)
+AO_TICK_TYPE ao_time(void)
{
uint16_t v;
ao_arch_critical(
}
uint8_t
-ao_event_get_for(struct ao_event *ev, uint16_t timeout)
+ao_event_get_for(struct ao_event *ev, AO_TICK_TYPE timeout)
{
uint8_t empty = 1;
ao_arch_critical(
struct ao_event {
uint8_t type;
uint8_t unit;
- uint16_t tick;
+ AO_TICK_TYPE tick;
int32_t value;
};
ao_event_get(struct ao_event *ev);
uint8_t
-ao_event_get_for(struct ao_event *ev, uint16_t timeout);
+ao_event_get_for(struct ao_event *ev, AO_TICK_TYPE timeout);
void
ao_event_put_isr(uint8_t type, uint8_t unit, int32_t value);
uint8_t ao_gps_new;
uint8_t ao_gps_mutex;
-uint16_t ao_gps_tick;
+AO_TICK_TYPE ao_gps_tick;
struct ao_telemetry_location ao_gps_data;
struct ao_telemetry_satellite ao_gps_tracking_data;
static uint8_t ao_gps_cksum;
static uint8_t ao_gps_error;
-uint16_t ao_gps_tick;
+AO_TICK_TYPE ao_gps_tick;
struct ao_telemetry_location ao_gps_data;
struct ao_telemetry_satellite ao_gps_tracking_data;
-static uint16_t ao_gps_next_tick;
+static AO_TICK_TYPE ao_gps_next_tick;
static struct ao_telemetry_location ao_gps_next;
static uint8_t ao_gps_date_flags;
static struct ao_telemetry_satellite ao_gps_tracking_next;
uint8_t ao_gps_new;
uint8_t ao_gps_mutex;
-uint16_t ao_gps_tick;
+AO_TICK_TYPE ao_gps_tick;
struct ao_telemetry_location ao_gps_data;
struct ao_telemetry_satellite ao_gps_tracking_data;
}
void
-ao_led_for(uint8_t colors, uint16_t ticks)
+ao_led_for(uint8_t colors, AO_TICK_TYPE ticks)
{
ao_led_on(colors);
ao_delay(ticks);
struct ao_config ao_config;
-extern volatile uint16_t ao_tick_count;
-uint16_t ao_boost_tick;
+extern volatile AO_TICK_TYPE ao_tick_count;
+AO_TICK_TYPE ao_boost_tick;
void ao_spi_slave(void)
{
};
#define AO_ADC_DUMP(p) \
- printf("tick: %5u A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
+ printf("tick: %5lu A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
(p)->tick, \
(p)->adc.sense[0], (p)->adc.sense[1], (p)->adc.sense[2], \
(p)->adc.sense[3], (p)->adc.sense[4], (p)->adc.sense[5], \
};
#define AO_ADC_DUMP(p) \
- printf("tick: %5u A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
+ printf("tick: %5lu A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
(p)->tick, \
(p)->adc.sense[0], (p)->adc.sense[1], (p)->adc.sense[2], \
(p)->adc.sense[3], (p)->adc.sense[4], (p)->adc.sense[5], \
#define HAS_BEEP 1
#define HAS_BATTERY_REPORT 1
-#define AO_STACK_SIZE 360
+#define AO_STACK_SIZE 352
#define SLEEP_HASH_SIZE 3
#define AO_NUM_TASKS 6
#define AO_SENSE_MAIN(p) ((p)->adc.sense_m)
#define AO_ADC_DUMP(p) \
- printf("tick: %5u apogee: %5d main: %5d batt: %5d\n", \
+ printf("tick: %5lu apogee: %5d main: %5d batt: %5d\n", \
(p)->tick, (p)->adc.sense_a, (p)->adc.sense_m, (p)->adc.v_batt)
/*
#define AO_SENSE_MAIN(p) ((p)->adc.sense_m)
#define AO_ADC_DUMP(p) \
- printf("tick: %5u apogee: %5d main: %5d batt: %5d\n", \
+ printf("tick: %5lu apogee: %5d main: %5d batt: %5d\n", \
(p)->tick, (p)->adc.sense_a, (p)->adc.sense_m, (p)->adc.v_batt)
/*
};
#define AO_ADC_DUMP(p) \
- printf("tick: %5u motor_pressure: %5d batt: %5d\n", \
+ printf("tick: %5lu motor_pressure: %5d batt: %5d\n", \
(p)->tick, \
(p)->adc.motor_pressure, \
(p)->adc.v_batt);
};
#define AO_ADC_DUMP(p) \
- printf("tick: %5u A: %5d B: %5d batt: %5d\n", \
+ printf("tick: %5lu A: %5d B: %5d batt: %5d\n", \
(p)->tick, \
(p)->adc.sense[0], (p)->adc.sense[1], \
(p)->adc.v_batt);
#define AO_GPS_NEW_TRACKING 2
extern uint8_t ao_gps_new;
-extern uint16_t ao_gps_tick;
+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;
#define AO_DATA_ALL (AO_DATA_ADC|AO_DATA_MS5607|AO_DATA_MPU6000|AO_DATA_HMC5883|AO_DATA_MMA655X|AO_DATA_MPU9250|AO_DATA_ADXL375|AO_DATA_BMX160|AO_DATA_MMC5983)
struct ao_data {
- uint16_t tick;
+ AO_TICK_TYPE tick;
#if HAS_ADC
struct ao_adc adc;
#endif
static uint8_t ao_fake_has_cur;
static volatile uint8_t ao_fake_has_next;
static uint8_t ao_fake_has_offset;
-static uint16_t ao_fake_tick_offset;
+static AO_TICK_TYPE ao_fake_tick_offset;
static struct ao_data ao_fake_cur, ao_fake_next;
void
/* Main flight thread. */
enum ao_flight_state ao_flight_state; /* current flight state */
-uint16_t ao_boost_tick; /* time of most recent boost detect */
-uint16_t ao_launch_tick; /* time of first boost detect */
+AO_TICK_TYPE ao_boost_tick; /* time of most recent boost detect */
+AO_TICK_TYPE ao_launch_tick; /* time of first boost detect */
uint16_t ao_motor_number; /* number of motors burned so far */
#if HAS_SENSOR_ERRORS
* (15 seconds) has past.
*/
if ((ao_accel < AO_MSS_TO_ACCEL(-2.5)) ||
- (int16_t) (ao_sample_tick - ao_boost_tick) > BOOST_TICKS_MAX)
+ (AO_TICK_SIGNED) (ao_sample_tick - ao_boost_tick) > BOOST_TICKS_MAX)
{
#if HAS_ACCEL
#if HAS_BARO
* number of seconds.
*/
if (ao_config.apogee_lockout) {
- if ((int16_t) (ao_sample_tick - ao_launch_tick) <
+ if ((AO_TICK_SIGNED) (ao_sample_tick - ao_launch_tick) <
AO_SEC_TO_TICKS(ao_config.apogee_lockout))
break;
}
#define MAX_QUIET_ACCEL 2
- if ((int16_t) (ao_sample_tick - ao_interval_end) >= 0) {
+ if ((AO_TICK_SIGNED) (ao_sample_tick - ao_interval_end) >= 0) {
if (ao_interval_max_accel_along - ao_interval_min_accel_along <= ao_data_accel_to_sample(MAX_QUIET_ACCEL) &&
ao_interval_max_accel_across - ao_interval_min_accel_across <= ao_data_accel_to_sample(MAX_QUIET_ACCEL) &&
ao_interval_max_accel_through - ao_interval_min_accel_through <= ao_data_accel_to_sample(MAX_QUIET_ACCEL))
if (ao_avg_height > ao_interval_max_height)
ao_interval_max_height = ao_avg_height;
- if ((int16_t) (ao_sample_tick - ao_interval_end) >= 0) {
+ if ((AO_TICK_SIGNED) (ao_sample_tick - ao_interval_end) >= 0) {
if (ao_interval_max_height - ao_interval_min_height <= AO_M_TO_HEIGHT(4))
{
ao_flight_state = ao_flight_landed;
};
extern enum ao_flight_state ao_flight_state;
-extern uint16_t ao_boost_tick;
-extern uint16_t ao_launch_tick;
+extern AO_TICK_TYPE ao_boost_tick;
+extern AO_TICK_TYPE ao_launch_tick;
extern uint16_t ao_motor_number;
extern uint16_t ao_launch_time;
/* Main flight thread. */
enum ao_flight_state ao_flight_state; /* current flight state */
-uint16_t ao_launch_tick; /* time of launch detect */
+AO_TICK_TYPE ao_launch_tick; /* time of launch detect */
/*
* track min/max data over a long interval to detect
* resting
*/
-uint16_t ao_interval_end;
+AO_TICK_TYPE ao_interval_end;
alt_t ao_interval_min_height;
alt_t ao_interval_max_height;
if (ao_height > ao_interval_max_height)
ao_interval_max_height = ao_height;
- if ((int16_t) (ao_sample_tick - ao_interval_end) >= 0) {
+ if ((AO_TICK_SIGNED) (ao_sample_tick - ao_interval_end) >= 0) {
if (ao_interval_max_height - ao_interval_min_height < AO_M_TO_HEIGHT(5))
{
ao_flight_state = ao_flight_landed;
* One set of samples read from the A/D converter
*/
struct ao_adc {
- uint16_t tick; /* tick when the sample was read */
+ AO_TICK_TYPE tick; /* tick when the sample was read */
int16_t accel; /* accelerometer */
int16_t pres; /* pressure sensor */
int16_t temp; /* temperature sensor */
ao_kalman_predict(void)
{
#ifdef AO_FLIGHT_TEST
- if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 50) {
+ if ((AO_TICK_SIGNED) (ao_sample_tick - ao_sample_prev_tick) > 50) {
ao_k_height += ((ao_k_t) ao_speed * AO_K_STEP_1 +
(ao_k_t) ao_accel * AO_K_STEP_2_2_1) >> 4;
ao_k_speed += (ao_k_t) ao_accel * AO_K_STEP_1;
return;
}
- if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 5) {
+ if ((AO_TICK_SIGNED) (ao_sample_tick - ao_sample_prev_tick) > 5) {
ao_k_height += ((ao_k_t) ao_speed * AO_K_STEP_10 +
(ao_k_t) ao_accel * AO_K_STEP_2_2_10) >> 4;
ao_k_speed += (ao_k_t) ao_accel * AO_K_STEP_10;
{
ao_kalman_err_height();
#ifdef AO_FLIGHT_TEST
- if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 50) {
+ if ((AO_TICK_SIGNED) (ao_sample_tick - ao_sample_prev_tick) > 50) {
ao_k_height += (ao_k_t) AO_BARO_K0_1 * ao_error_h;
ao_k_speed += (ao_k_t) AO_BARO_K1_1 * ao_error_h;
ao_k_accel += (ao_k_t) AO_BARO_K2_1 * ao_error_h;
return;
}
- if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 5) {
+ if ((AO_TICK_SIGNED) (ao_sample_tick - ao_sample_prev_tick) > 5) {
ao_k_height += (ao_k_t) AO_BARO_K0_10 * ao_error_h;
ao_k_speed += (ao_k_t) AO_BARO_K1_10 * ao_error_h;
ao_k_accel += (ao_k_t) AO_BARO_K2_10 * ao_error_h;
ao_kalman_err_accel();
#ifdef AO_FLIGHT_TEST
- if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 50) {
+ if ((AO_TICK_SIGNED) (ao_sample_tick - ao_sample_prev_tick) > 50) {
if (ao_flight_debug) {
printf ("correct speed %g + (%g * %g) + (%g * %g) = %g\n",
ao_k_speed / (65536.0 * 16.0),
(ao_k_t) AO_BOTH_K21_1 * ao_error_a;
return;
}
- if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 5) {
+ if ((AO_TICK_SIGNED) (ao_sample_tick - ao_sample_prev_tick) > 5) {
if (ao_flight_debug) {
printf ("correct speed %g + (%g * %g) + (%g * %g) = %g\n",
ao_k_speed / (65536.0 * 16.0),
ao_kalman_err_accel();
#ifdef AO_FLIGHT_TEST
- if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 5) {
+ if ((AO_TICK_SIGNED) (ao_sample_tick - ao_sample_prev_tick) > 5) {
ao_k_height +=(ao_k_t) AO_ACCEL_K0_10 * ao_error_a;
ao_k_speed += (ao_k_t) AO_ACCEL_K1_10 * ao_error_a;
ao_k_accel += (ao_k_t) AO_ACCEL_K2_10 * ao_error_a;
ao_avg_height_scaled = ao_avg_height_scaled - ao_avg_height + ao_height;
#endif
#ifdef AO_FLIGHT_TEST
- if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 50)
+ if ((AO_TICK_SIGNED) (ao_sample_tick - ao_sample_prev_tick) > 50)
ao_avg_height = (ao_avg_height_scaled + 1) >> 1;
- else if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 5)
+ else if ((AO_TICK_SIGNED) (ao_sample_tick - ao_sample_prev_tick) > 5)
ao_avg_height = (ao_avg_height_scaled + 7) >> 4;
else
#endif
void
ao_log(void)
{
- uint16_t next_sensor, next_other;
+ AO_TICK_TYPE next_sensor, next_other;
ao_storage_setup();
for (;;) {
/* Write samples to EEPROM */
while (ao_log_data_pos != ao_sample_data) {
- ao_log_data.tick = ao_data_ring[ao_log_data_pos].tick;
- if ((int16_t) (ao_log_data.tick - next_sensor) >= 0) {
+ AO_TICK_TYPE tick = ao_data_ring[ao_log_data_pos].tick;
+ ao_log_data.tick = tick;
+ if ((AO_TICK_SIGNED) (tick - next_sensor) >= 0) {
ao_log_data.type = AO_LOG_SENSOR;
ao_log_data.u.sensor.accel = ao_data_ring[ao_log_data_pos].adc.accel;
ao_log_data.u.sensor.pres = ao_data_ring[ao_log_data_pos].adc.pres;
ao_log_write(&ao_log_data);
if (ao_log_state <= ao_flight_coast)
- next_sensor = ao_log_data.tick + AO_SENSOR_INTERVAL_ASCENT;
+ next_sensor = tick + AO_SENSOR_INTERVAL_ASCENT;
else
- next_sensor = ao_log_data.tick + AO_SENSOR_INTERVAL_DESCENT;
+ next_sensor = tick + AO_SENSOR_INTERVAL_DESCENT;
}
- if ((int16_t) (ao_log_data.tick - next_other) >= 0) {
+ if ((AO_TICK_SIGNED) (tick - next_other) >= 0) {
ao_log_data.type = AO_LOG_TEMP_VOLT;
ao_log_data.u.temp_volt.temp = ao_data_ring[ao_log_data_pos].adc.temp;
ao_log_data.u.temp_volt.v_batt = ao_data_ring[ao_log_data_pos].adc.v_batt;
ao_log_data.u.deploy.drogue = ao_data_ring[ao_log_data_pos].adc.sense_d;
ao_log_data.u.deploy.main = ao_data_ring[ao_log_data_pos].adc.sense_m;
ao_log_write(&ao_log_data);
- next_other = ao_log_data.tick + AO_OTHER_INTERVAL;
+ next_other = tick + AO_OTHER_INTERVAL;
}
ao_log_data_pos = ao_data_ring_next(ao_log_data_pos);
}
}
void
-ao_log_gps_data(uint16_t tick, struct ao_telemetry_location *gps_data)
+ao_log_gps_data(AO_TICK_TYPE tick, struct ao_telemetry_location *gps_data)
{
ao_log_data.tick = tick;
ao_log_data.type = AO_LOG_GPS_TIME;
}
void
-ao_log_gps_tracking(uint16_t tick, struct ao_telemetry_satellite *gps_tracking_data)
+ao_log_gps_tracking(AO_TICK_TYPE tick, struct ao_telemetry_satellite *gps_tracking_data)
{
uint8_t c, n, i;
ao_log_gps_flight(void);
void
-ao_log_gps_data(uint16_t tick, struct ao_telemetry_location *gps_data);
+ao_log_gps_data(AO_TICK_TYPE tick, struct ao_telemetry_location *gps_data);
void
-ao_log_gps_tracking(uint16_t tick, struct ao_telemetry_satellite *gps_tracking_data);
+ao_log_gps_tracking(AO_TICK_TYPE tick, struct ao_telemetry_satellite *gps_tracking_data);
#endif /* _AO_LOG_GPS_H_ */
void
ao_log(void)
{
- uint16_t next_sensor, next_other;
+ AO_TICK_TYPE next_sensor, next_other;
uint8_t i;
ao_storage_setup();
for (;;) {
/* Write samples to EEPROM */
while (ao_log_data_pos != ao_data_head) {
- ao_log_data.tick = ao_data_ring[ao_log_data_pos].tick;
+ AO_TICK_TYPE tick = ao_data_ring[ao_log_data_pos].tick;
+ ao_log_data.tick = tick;
volatile struct ao_data *d = &ao_data_ring[ao_log_data_pos];
- if ((int16_t) (ao_log_data.tick - next_sensor) >= 0) {
+ if ((AO_TICK_SIGNED) (tick - next_sensor) >= 0) {
ao_log_data.type = AO_LOG_SENSOR;
#if HAS_MS5607
ao_log_data.u.sensor.pres = d->ms5607_raw.pres;
ao_log_data.u.sensor.accel = ao_data_accel(&ao_data_ring[ao_log_data_pos]);
ao_log_write(&ao_log_data);
if (ao_log_state <= ao_flight_coast)
- next_sensor = ao_log_data.tick + AO_SENSOR_INTERVAL_ASCENT;
+ next_sensor = tick + AO_SENSOR_INTERVAL_ASCENT;
else
- next_sensor = ao_log_data.tick + AO_SENSOR_INTERVAL_DESCENT;
+ next_sensor = tick + AO_SENSOR_INTERVAL_DESCENT;
}
- if ((int16_t) (ao_log_data.tick - next_other) >= 0) {
+ if ((AO_TICK_SIGNED) (tick - next_other) >= 0) {
ao_log_data.type = AO_LOG_TEMP_VOLT;
ao_log_data.u.volt.v_batt = d->adc.v_batt;
ao_log_data.u.volt.v_pbatt = d->adc.v_pbatt;
ao_log_data.u.volt.sense[i] = d->adc.sense[i];
ao_log_data.u.volt.pyro = ao_pyro_fired;
ao_log_write(&ao_log_data);
- next_other = ao_log_data.tick + AO_OTHER_INTERVAL;
+ next_other = tick + AO_OTHER_INTERVAL;
}
ao_log_data_pos = ao_data_ring_next(ao_log_data_pos);
}
for (;;) {
/* Write samples to EEPROM */
while (ao_log_data_pos != ao_data_head) {
- ao_log_data.tick = ao_data_ring[ao_log_data_pos].tick;
- if ((int16_t) (ao_log_data.tick - next_sensor) >= 0) {
+ AO_TICK_TYPE tick = ao_data_ring[ao_log_data_pos].tick;
+ ao_log_data.tick = tick;
+ if ((AO_TICK_SIGNED) (tick - next_sensor) >= 0) {
ao_log_data.type = AO_LOG_SENSOR;
#if HAS_MS5607
ao_log_data.u.sensor.pres = ao_data_ring[ao_log_data_pos].ms5607_raw.pres;
#endif
ao_log_write(&ao_log_data);
if (ao_log_state <= ao_flight_coast)
- next_sensor = ao_log_data.tick + AO_SENSOR_INTERVAL_ASCENT;
+ next_sensor = tick + AO_SENSOR_INTERVAL_ASCENT;
else
- next_sensor = ao_log_data.tick + AO_SENSOR_INTERVAL_DESCENT;
+ next_sensor = tick + AO_SENSOR_INTERVAL_DESCENT;
}
- if ((int16_t) (ao_log_data.tick - next_other) >= 0) {
+ if ((AO_TICK_SIGNED) (tick - next_other) >= 0) {
ao_log_data.type = AO_LOG_TEMP_VOLT;
ao_log_data.u.volt.v_batt = ao_data_ring[ao_log_data_pos].adc.v_batt;
ao_log_data.u.volt.sense_a = ao_data_ring[ao_log_data_pos].adc.sense_a;
ao_log_data.u.volt.sense_m = ao_data_ring[ao_log_data_pos].adc.sense_m;
ao_log_write(&ao_log_data);
- next_other = ao_log_data.tick + AO_OTHER_INTERVAL;
+ next_other = tick + AO_OTHER_INTERVAL;
}
ao_log_data_pos = ao_data_ring_next(ao_log_data_pos);
}
for (;;) {
/* Write samples to EEPROM */
while (ao_log_data_pos != ao_data_head) {
- ao_log_data.tick = ao_data_ring[ao_log_data_pos].tick;
- if ((int16_t) (ao_log_data.tick - next_sensor) >= 0) {
+ AO_TICK_TYPE tick = ao_data_ring[ao_log_data_pos].tick;
+ ao_log_data.tick = tick;
+ if ((AO_TICK_SIGNED) (tick - next_sensor) >= 0) {
ao_log_data.type = AO_LOG_SENSOR;
ao_log_pack24(ao_log_data.u.sensor.pres,
ao_data_ring[ao_log_data_pos].ms5607_raw.pres);
#endif
ao_log_write(&ao_log_data);
if (ao_log_state <= ao_flight_coast)
- next_sensor = ao_log_data.tick + AO_SENSOR_INTERVAL_ASCENT;
+ next_sensor = tick + AO_SENSOR_INTERVAL_ASCENT;
else
- next_sensor = ao_log_data.tick + AO_SENSOR_INTERVAL_DESCENT;
+ next_sensor = tick + AO_SENSOR_INTERVAL_DESCENT;
}
ao_log_data_pos = ao_data_ring_next(ao_log_data_pos);
}
for (;;) {
/* Write samples to EEPROM */
while (ao_log_data_pos != ao_data_head) {
- ao_log_data.tick = ao_data_ring[ao_log_data_pos].tick;
- if ((int16_t) (ao_log_data.tick - next_sensor) >= 0) {
+ AO_TICK_TYPE tick = ao_data_ring[ao_log_data_pos].tick;
+ ao_log_data.tick = tick;
+ if ((AO_TICK_SIGNED) (tick - next_sensor) >= 0) {
ao_log_data.type = AO_LOG_SENSOR;
ao_log_data.u.sensor.pressure = ao_data_motor_pressure(&ao_data_ring[ao_log_data_pos]);
ao_log_data.u.sensor.v_batt = ao_data_ring[ao_log_data_pos].adc.v_batt;
ao_log_data.u.sensor.accel_through = ao_data_through(&ao_data_ring[ao_log_data_pos]);
ao_log_write(&ao_log_data);
if (ao_log_state <= ao_flight_coast)
- next_sensor = ao_log_data.tick + AO_SENSOR_INTERVAL_ASCENT;
+ next_sensor = tick + AO_SENSOR_INTERVAL_ASCENT;
else
- next_sensor = ao_log_data.tick + AO_SENSOR_INTERVAL_DESCENT;
+ next_sensor = tick + AO_SENSOR_INTERVAL_DESCENT;
}
ao_log_data_pos = ao_data_ring_next(ao_log_data_pos);
}
#include "ao.h"
-static uint16_t ao_log_tiny_interval;
+static AO_TICK_TYPE ao_log_tiny_interval;
#define AO_LOG_TINY_INTERVAL_DEFAULT AO_MS_TO_TICKS(1000)
#if USE_FAST_ASCENT_LOG
#endif
void
-ao_log_tiny_set_interval(uint16_t ticks)
+ao_log_tiny_set_interval(AO_TICK_TYPE ticks)
{
ao_log_tiny_interval = ticks;
}
* Write out the sample when finished
*/
now = ao_time();
- if ((int16_t) (now - (last_time + ao_log_tiny_interval)) >= 0 && count) {
+ if ((AO_TICK_SIGNED) (now - (last_time + ao_log_tiny_interval)) >= 0 && count) {
count = sum / count;
if (ao_log_started)
ao_log_tiny_data(count);
uint32_t pa;
uint32_t pa_ground;
+uint32_t pa_ground_next;
uint32_t pa_min;
static void
time = ao_time();
ao_pa_get();
ao_microkalman_init();
- pa_ground = pa;
+ pa_ground_next = pa_ground = pa;
sample_count = 0;
h = 0;
for (;;) {
pa_sum += pa;
++sample_count;
} else {
- pa_ground = pa_sum >> GROUND_AVG_SHIFT;
+ pa_ground = pa_ground_next;
+ pa_ground_next = pa_sum >> GROUND_AVG_SHIFT;
pa_sum = 0;
sample_count = 0;
#if !BOOST_DETECT
ao_delay_until(AO_TICK_TYPE target)
{
ao_arch_block_interrupts();
- while ((int16_t) (target - ao_tick_count) > 0)
+ while ((AO_TICK_SIGNED) (target - ao_tick_count) > 0)
ao_sleep((void *) &ao_tick_count);
ao_arch_release_interrupts();
}
#endif
case ao_pyro_time_less:
- if ((int32_t) (ao_time() - ao_launch_tick) <= pyro->time_less)
+ if ((AO_TICK_SIGNED) (ao_time() - ao_launch_tick) <= pyro->time_less)
continue;
- DBG("time %d > %d\n", (int32_t)(ao_time() - ao_launch_tick), pyro->time_less);
+ DBG("time %d > %d\n", (AO_TICK_SIGNED)(ao_time() - ao_launch_tick), pyro->time_less);
break;
case ao_pyro_time_greater:
- if ((int32_t) (ao_time() - ao_launch_tick) >= pyro->time_greater)
+ if ((AO_TICK_SIGNED) (ao_time() - ao_launch_tick) >= pyro->time_greater)
continue;
- DBG("time %d < %d\n", (int32_t)(ao_time() - ao_launch_tick), pyro->time_greater);
+ DBG("time %d < %d\n", (AO_TICK_SIGNED)(ao_time() - ao_launch_tick), pyro->time_greater);
break;
case ao_pyro_ascending:
continue;
}
- if ((int32_t) (ao_time() - pyro->delay_done) < 0)
+ if ((AO_TICK_SIGNED) (ao_time() - pyro->delay_done) < 0)
continue;
}
#define ACCEL_TYPE int16_t
#endif
-uint16_t ao_sample_tick; /* time of last data */
+AO_TICK_TYPE ao_sample_tick; /* time of last data */
#if HAS_BARO
pres_t ao_sample_pres;
alt_t ao_sample_alt;
ao_sample_rotate(void)
{
#ifdef AO_FLIGHT_TEST
- float dt = (int16_t) (ao_sample_tick - ao_sample_prev_tick) / TIME_DIV;
+ float dt = (AO_TICK_SIGNED) (ao_sample_tick - ao_sample_prev_tick) / TIME_DIV;
#else
static const float dt = 1/TIME_DIV;
#endif
#define AO_MS_TO_SPEED(ms) ((ao_v_t) ((ms) * 16))
#define AO_MSS_TO_ACCEL(mss) ((ao_v_t) ((mss) * 16))
-extern uint16_t ao_sample_tick; /* time of last data */
+extern AO_TICK_TYPE ao_sample_tick; /* time of last data */
extern uint8_t ao_sample_adc; /* Ring position of last processed sample */
extern uint8_t ao_sample_data; /* Ring position of last processed sample */
uint8_t new;
int32_t ground_distance;
int16_t height;
- uint16_t gps_tick;
+ AO_TICK_TYPE gps_tick;
uint8_t new_tracker_running;
#if HAS_ADC
static void
ao_terragps(void)
{
- uint16_t gps_tick = ao_gps_progress;
+ AO_TICK_TYPE gps_tick = ao_gps_progress;
for (;;) {
while (ao_gps_tick == gps_tick)
outbyte(c);
}
-volatile uint16_t tick_count;
+volatile AO_TICK_TYPE tick_count;
void
stm_tim6_isr(void)
#define AO_ADC_RING 32
struct ao_adc {
- uint16_t tick;
+ AO_TICK_TYPE tick;
int16_t idd;
int16_t temp;
int16_t vref;
#define AO_ADC_RING 32
struct ao_adc {
- uint16_t tick;
+ AO_TICK_TYPE tick;
int16_t idd;
int16_t temp;
int16_t vref;
};
#define AO_ADC_DUMP(p) \
- printf("tick: %5u drogue: %5d main: %5d batt: %5d\n", \
+ printf("tick: %5lu drogue: %5d main: %5d batt: %5d\n", \
(p)->tick, \
(p)->adc.sense_a, (p)->adc.sense_m, \
(p)->adc.v_batt);
};
#define AO_ADC_DUMP(p) \
- printf("tick: %5u batt %5d\n", \
+ printf("tick: %5lu batt %5d\n", \
(p)->tick, \
(p)->adc.v_batt);
};
#define AO_ADC_DUMP(p) \
- printf("tick: %5u batt %5d\n", \
+ printf("tick: %5lu batt %5d\n", \
(p)->tick, \
(p)->adc.v_batt);
};
#define AO_ADC_DUMP(p) \
- printf ("tick: %5u " \
+ printf ("tick: %5lu " \
"0: %5d 1: %5d 2: %5d 3: %5d " \
"4: %5d 5: %5d 6: %5d 7: %5d " \
"pyro: %5d batt: %5d\n", \
};
#define AO_ADC_DUMP(p) \
- printf ("tick: %5u " \
+ printf ("tick: %5lu " \
"0: %5d 1: %5d 2: %5d 3: %5d " \
"4: %5d 5: %5d 6: %5d 7: %5d " \
"pyro: %5d batt: %5d\n", \
};
#define AO_ADC_DUMP(p) \
- printf ("tick: %5u 0: %5d pyro: %5d batt %5d thrust %5d pressure %5d\n", \
+ printf ("tick: %5lu 0: %5d pyro: %5d batt %5d thrust %5d pressure %5d\n", \
(p)->tick, \
(p)->adc.sense[0], \
(p)->adc.pyro, \
};
#define AO_ADC_DUMP(p) \
- printf ("tick: %5u 0: %5d 1: %5d pyro: %5d batt %5d\n", \
+ printf ("tick: %5lu 0: %5d 1: %5d pyro: %5d batt %5d\n", \
(p)->tick, \
(p)->adc.sense[0], \
(p)->adc.sense[1], \
};
#define AO_ADC_DUMP(p) \
- printf("tick: %5u batt: %5d\n", \
+ printf("tick: %5lu batt: %5d\n", \
(p)->tick, \
(p)->adc.v_batt)
};
#define AO_ADC_DUMP(p) \
- printf("tick: %5u batt: %5d\n", \
+ printf("tick: %5lu batt: %5d\n", \
(p)->tick, \
(p)->adc.v_batt)
};
#define AO_ADC_DUMP(p) \
- printf("tick: %5u A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
+ printf("tick: %5lu A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
(p)->tick, \
(p)->adc.sense[0], (p)->adc.sense[1], (p)->adc.sense[2], \
(p)->adc.sense[3], (p)->adc.sense[4], (p)->adc.sense[5], \
};
#define AO_ADC_DUMP(p) \
- printf("tick: %5u A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
+ printf("tick: %5lu A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
(p)->tick, \
(p)->adc.sense[0], (p)->adc.sense[1], (p)->adc.sense[2], \
(p)->adc.sense[3], (p)->adc.sense[4], (p)->adc.sense[5], \
};
#define AO_ADC_DUMP(p) \
- printf("tick: %5u A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
+ printf("tick: %5lu A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
(p)->tick, \
(p)->adc.sense[0], (p)->adc.sense[1], (p)->adc.sense[2], \
(p)->adc.sense[3], (p)->adc.sense[4], (p)->adc.sense[5], \
};
#define AO_ADC_DUMP(p) \
- printf("tick: %5u A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
+ printf("tick: %5lu A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
(p)->tick, \
(p)->adc.sense[0], (p)->adc.sense[1], (p)->adc.sense[2], \
(p)->adc.sense[3], (p)->adc.sense[4], (p)->adc.sense[5], \
};
#define AO_ADC_DUMP(p) \
- printf("tick: %5u A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
+ printf("tick: %5lu A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
(p)->tick, \
(p)->adc.sense[0], (p)->adc.sense[1], (p)->adc.sense[2], \
(p)->adc.sense[3], (p)->adc.sense[4], (p)->adc.sense[5], \
};
#define AO_ADC_DUMP(p) \
- printf("tick: %5u A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
+ printf("tick: %5lu A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
(p)->tick, \
(p)->adc.sense[0], (p)->adc.sense[1], (p)->adc.sense[2], \
(p)->adc.sense[3], (p)->adc.sense[4], (p)->adc.sense[5], \
};
#define AO_ADC_DUMP(p) \
- printf("tick: %5u drogue: %5d main: %5d batt: %5d\n", \
+ printf("tick: %5lu drogue: %5d main: %5d batt: %5d\n", \
(p)->tick, \
(p)->adc.sense_a, (p)->adc.sense_m, \
(p)->adc.v_batt);
};
#define AO_ADC_DUMP(p) \
- printf("tick: %5u drogue: %5d main: %5d batt: %5d\n", \
+ printf("tick: %5lu drogue: %5d main: %5d batt: %5d\n", \
(p)->tick, \
(p)->adc.sense_a, (p)->adc.sense_m, \
(p)->adc.v_batt);
#define AO_SENSE_MAIN(p) ((p)->adc.sense_m)
#define AO_ADC_DUMP(p) \
- printf("tick: %5u apogee: %5d main: %5d batt: %5d\n", \
+ printf("tick: %5lu apogee: %5d main: %5d batt: %5d\n", \
(p)->tick, (p)->adc.sense_a, (p)->adc.sense_m, (p)->adc.v_batt)
/*
uint16_t ao_serial_number;
int16_t ao_flight_number;
-extern uint16_t ao_sample_tick;
+extern AO_TICK_TYPE ao_sample_tick;
#if HAS_BARO
extern alt_t ao_sample_height;
double ao_sample_qangle;
-int ao_sample_prev_tick;
-uint16_t prev_tick;
+AO_TICK_TYPE ao_sample_prev_tick;
+AO_TICK_TYPE prev_tick;
#include "ao_kalman.c"