Skip to content

Commit 7f46240

Browse files
committed
altos: Switch all tick variables to AO_TICK_TYPE/AO_TICK_SIGNED
Instead of trying to pick and choose which work as 16-bit values, change everything that doesn't affect external values (log, companion, radio) to AO_TICK_TYPE. Signed-off-by: Keith Packard <[email protected]>
1 parent 0e06868 commit 7f46240

File tree

61 files changed

+125
-118
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+125
-118
lines changed

src/attiny/ao_clock.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static volatile AO_TICK_TYPE ao_wakeup_count;
2424
ISR(TIMER1_COMPA_vect)
2525
{
2626
++ao_tick_count;
27-
if ((int16_t) (ao_tick_count - ao_wakeup_count) >= 0)
27+
if ((AO_TICK_SIGNED) (ao_tick_count - ao_wakeup_count) >= 0)
2828
ao_wakeup((void *) &ao_tick_count);
2929
}
3030

@@ -131,7 +131,7 @@ ao_delay_until(AO_TICK_TYPE target)
131131
{
132132
cli();
133133
ao_wakeup_count = target;
134-
while ((int16_t) (target - ao_tick_count) > 0)
134+
while ((AO_TICK_SIGNED) (target - ao_tick_count) > 0)
135135
ao_sleep((void *) &ao_tick_count);
136136
sei();
137137
}

src/avr/ao_led_avr.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ ao_led_toggle(uint8_t colors)
4848
}
4949

5050
void
51-
ao_led_for(uint8_t colors, uint16_t ticks)
51+
ao_led_for(uint8_t colors, AO_TICK_TYPE ticks)
5252
{
5353
ao_led_on(colors);
5454
ao_delay(ticks);

src/avr/ao_timer.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
#include "ao.h"
2020

21-
volatile uint16_t ao_tick_count;
21+
volatile AO_TICK_TYPE ao_tick_count;
2222

23-
uint16_t ao_time(void)
23+
AO_TICK_TYPE ao_time(void)
2424
{
2525
uint16_t v;
2626
ao_arch_critical(

src/drivers/ao_event.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ ao_event_get(struct ao_event *ev)
4343
}
4444

4545
uint8_t
46-
ao_event_get_for(struct ao_event *ev, uint16_t timeout)
46+
ao_event_get_for(struct ao_event *ev, AO_TICK_TYPE timeout)
4747
{
4848
uint8_t empty = 1;
4949
ao_arch_critical(

src/drivers/ao_event.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
struct ao_event {
2828
uint8_t type;
2929
uint8_t unit;
30-
uint16_t tick;
30+
AO_TICK_TYPE tick;
3131
int32_t value;
3232
};
3333

3434
void
3535
ao_event_get(struct ao_event *ev);
3636

3737
uint8_t
38-
ao_event_get_for(struct ao_event *ev, uint16_t timeout);
38+
ao_event_get_for(struct ao_event *ev, AO_TICK_TYPE timeout);
3939

4040
void
4141
ao_event_put_isr(uint8_t type, uint8_t unit, int32_t value);

src/drivers/ao_gps_sirf.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
uint8_t ao_gps_new;
2424
uint8_t ao_gps_mutex;
25-
uint16_t ao_gps_tick;
25+
AO_TICK_TYPE ao_gps_tick;
2626
struct ao_telemetry_location ao_gps_data;
2727
struct ao_telemetry_satellite ao_gps_tracking_data;
2828

src/drivers/ao_gps_skytraq.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ static char ao_gps_char;
3939
static uint8_t ao_gps_cksum;
4040
static uint8_t ao_gps_error;
4141

42-
uint16_t ao_gps_tick;
42+
AO_TICK_TYPE ao_gps_tick;
4343
struct ao_telemetry_location ao_gps_data;
4444
struct ao_telemetry_satellite ao_gps_tracking_data;
4545

46-
static uint16_t ao_gps_next_tick;
46+
static AO_TICK_TYPE ao_gps_next_tick;
4747
static struct ao_telemetry_location ao_gps_next;
4848
static uint8_t ao_gps_date_flags;
4949
static struct ao_telemetry_satellite ao_gps_tracking_next;

src/drivers/ao_gps_ublox.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
uint8_t ao_gps_new;
3030
uint8_t ao_gps_mutex;
31-
uint16_t ao_gps_tick;
31+
AO_TICK_TYPE ao_gps_tick;
3232
struct ao_telemetry_location ao_gps_data;
3333
struct ao_telemetry_satellite ao_gps_tracking_data;
3434

src/drivers/ao_pca9922.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ ao_led_toggle(uint8_t colors)
9393
}
9494

9595
void
96-
ao_led_for(uint8_t colors, uint16_t ticks)
96+
ao_led_for(uint8_t colors, AO_TICK_TYPE ticks)
9797
{
9898
ao_led_on(colors);
9999
ao_delay(ticks);

src/drivers/ao_pyro_slave.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ static const struct ao_companion_setup ao_telepyro_setup = {
3333

3434
struct ao_config ao_config;
3535

36-
extern volatile uint16_t ao_tick_count;
37-
uint16_t ao_boost_tick;
36+
extern volatile AO_TICK_TYPE ao_tick_count;
37+
AO_TICK_TYPE ao_boost_tick;
3838

3939
void ao_spi_slave(void)
4040
{

src/easymega-v1.0/ao_pins.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ struct ao_adc {
182182
};
183183

184184
#define AO_ADC_DUMP(p) \
185-
printf("tick: %5u A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
185+
printf("tick: %5lu A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
186186
(p)->tick, \
187187
(p)->adc.sense[0], (p)->adc.sense[1], (p)->adc.sense[2], \
188188
(p)->adc.sense[3], (p)->adc.sense[4], (p)->adc.sense[5], \

src/easymega-v2.0/ao_pins.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ struct ao_adc {
177177
};
178178

179179
#define AO_ADC_DUMP(p) \
180-
printf("tick: %5u A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
180+
printf("tick: %5lu A: %5d B: %5d C: %5d D: %5d drogue: %5d main: %5d batt: %5d pbatt: %5d temp: %5d\n", \
181181
(p)->tick, \
182182
(p)->adc.sense[0], (p)->adc.sense[1], (p)->adc.sense[2], \
183183
(p)->adc.sense[3], (p)->adc.sense[4], (p)->adc.sense[5], \

src/easymini-v1.0/ao_pins.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define HAS_BEEP 1
2020
#define HAS_BATTERY_REPORT 1
2121

22-
#define AO_STACK_SIZE 360
22+
#define AO_STACK_SIZE 352
2323
#define SLEEP_HASH_SIZE 3
2424
#define AO_NUM_TASKS 6
2525

@@ -134,7 +134,7 @@ struct ao_adc {
134134
#define AO_SENSE_MAIN(p) ((p)->adc.sense_m)
135135

136136
#define AO_ADC_DUMP(p) \
137-
printf("tick: %5u apogee: %5d main: %5d batt: %5d\n", \
137+
printf("tick: %5lu apogee: %5d main: %5d batt: %5d\n", \
138138
(p)->tick, (p)->adc.sense_a, (p)->adc.sense_m, (p)->adc.v_batt)
139139

140140
/*

src/easymini-v2.0/ao_pins.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ struct ao_adc {
139139
#define AO_SENSE_MAIN(p) ((p)->adc.sense_m)
140140

141141
#define AO_ADC_DUMP(p) \
142-
printf("tick: %5u apogee: %5d main: %5d batt: %5d\n", \
142+
printf("tick: %5lu apogee: %5d main: %5d batt: %5d\n", \
143143
(p)->tick, (p)->adc.sense_a, (p)->adc.sense_m, (p)->adc.v_batt)
144144

145145
/*

src/easymotor-v2/ao_pins.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ struct ao_adc {
109109
};
110110

111111
#define AO_ADC_DUMP(p) \
112-
printf("tick: %5u motor_pressure: %5d batt: %5d\n", \
112+
printf("tick: %5lu motor_pressure: %5d batt: %5d\n", \
113113
(p)->tick, \
114114
(p)->adc.motor_pressure, \
115115
(p)->adc.v_batt);

src/easytimer-v1/ao_pins.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ struct ao_adc {
154154
};
155155

156156
#define AO_ADC_DUMP(p) \
157-
printf("tick: %5u A: %5d B: %5d batt: %5d\n", \
157+
printf("tick: %5lu A: %5d B: %5d batt: %5d\n", \
158158
(p)->tick, \
159159
(p)->adc.sense[0], (p)->adc.sense[1], \
160160
(p)->adc.v_batt);

src/kernel/ao.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ ao_spi_slave(void);
389389
#define AO_GPS_NEW_TRACKING 2
390390

391391
extern uint8_t ao_gps_new;
392-
extern uint16_t ao_gps_tick;
392+
extern AO_TICK_TYPE ao_gps_tick;
393393
extern uint8_t ao_gps_mutex;
394394
extern struct ao_telemetry_location ao_gps_data;
395395
extern struct ao_telemetry_satellite ao_gps_tracking_data;

src/kernel/ao_data.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ extern uint8_t ao_sensor_errors;
105105
#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)
106106

107107
struct ao_data {
108-
uint16_t tick;
108+
AO_TICK_TYPE tick;
109109
#if HAS_ADC
110110
struct ao_adc adc;
111111
#endif

src/kernel/ao_fake_flight.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ uint8_t ao_fake_flight_active;
2727
static uint8_t ao_fake_has_cur;
2828
static volatile uint8_t ao_fake_has_next;
2929
static uint8_t ao_fake_has_offset;
30-
static uint16_t ao_fake_tick_offset;
30+
static AO_TICK_TYPE ao_fake_tick_offset;
3131
static struct ao_data ao_fake_cur, ao_fake_next;
3232

3333
void

src/kernel/ao_flight.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
/* Main flight thread. */
5151

5252
enum ao_flight_state ao_flight_state; /* current flight state */
53-
uint16_t ao_boost_tick; /* time of most recent boost detect */
54-
uint16_t ao_launch_tick; /* time of first boost detect */
53+
AO_TICK_TYPE ao_boost_tick; /* time of most recent boost detect */
54+
AO_TICK_TYPE ao_launch_tick; /* time of first boost detect */
5555
uint16_t ao_motor_number; /* number of motors burned so far */
5656

5757
#if HAS_SENSOR_ERRORS
@@ -272,7 +272,7 @@ ao_flight(void)
272272
* (15 seconds) has past.
273273
*/
274274
if ((ao_accel < AO_MSS_TO_ACCEL(-2.5)) ||
275-
(int16_t) (ao_sample_tick - ao_boost_tick) > BOOST_TICKS_MAX)
275+
(AO_TICK_SIGNED) (ao_sample_tick - ao_boost_tick) > BOOST_TICKS_MAX)
276276
{
277277
#if HAS_ACCEL
278278
#if HAS_BARO
@@ -319,7 +319,7 @@ ao_flight(void)
319319
* number of seconds.
320320
*/
321321
if (ao_config.apogee_lockout) {
322-
if ((int16_t) (ao_sample_tick - ao_launch_tick) <
322+
if ((AO_TICK_SIGNED) (ao_sample_tick - ao_launch_tick) <
323323
AO_SEC_TO_TICKS(ao_config.apogee_lockout))
324324
break;
325325
}
@@ -363,7 +363,7 @@ ao_flight(void)
363363

364364
#define MAX_QUIET_ACCEL 2
365365

366-
if ((int16_t) (ao_sample_tick - ao_interval_end) >= 0) {
366+
if ((AO_TICK_SIGNED) (ao_sample_tick - ao_interval_end) >= 0) {
367367
if (ao_interval_max_accel_along - ao_interval_min_accel_along <= ao_data_accel_to_sample(MAX_QUIET_ACCEL) &&
368368
ao_interval_max_accel_across - ao_interval_min_accel_across <= ao_data_accel_to_sample(MAX_QUIET_ACCEL) &&
369369
ao_interval_max_accel_through - ao_interval_min_accel_through <= ao_data_accel_to_sample(MAX_QUIET_ACCEL))
@@ -443,7 +443,7 @@ ao_flight(void)
443443
if (ao_avg_height > ao_interval_max_height)
444444
ao_interval_max_height = ao_avg_height;
445445

446-
if ((int16_t) (ao_sample_tick - ao_interval_end) >= 0) {
446+
if ((AO_TICK_SIGNED) (ao_sample_tick - ao_interval_end) >= 0) {
447447
if (ao_interval_max_height - ao_interval_min_height <= AO_M_TO_HEIGHT(4))
448448
{
449449
ao_flight_state = ao_flight_landed;

src/kernel/ao_flight.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ enum ao_flight_state {
3939
};
4040

4141
extern enum ao_flight_state ao_flight_state;
42-
extern uint16_t ao_boost_tick;
43-
extern uint16_t ao_launch_tick;
42+
extern AO_TICK_TYPE ao_boost_tick;
43+
extern AO_TICK_TYPE ao_launch_tick;
4444
extern uint16_t ao_motor_number;
4545

4646
extern uint16_t ao_launch_time;

src/kernel/ao_flight_nano.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
/* Main flight thread. */
2222

2323
enum ao_flight_state ao_flight_state; /* current flight state */
24-
uint16_t ao_launch_tick; /* time of launch detect */
24+
AO_TICK_TYPE ao_launch_tick; /* time of launch detect */
2525

2626
/*
2727
* track min/max data over a long interval to detect
2828
* resting
2929
*/
30-
uint16_t ao_interval_end;
30+
AO_TICK_TYPE ao_interval_end;
3131
alt_t ao_interval_min_height;
3232
alt_t ao_interval_max_height;
3333

@@ -94,7 +94,7 @@ ao_flight_nano(void)
9494
if (ao_height > ao_interval_max_height)
9595
ao_interval_max_height = ao_height;
9696

97-
if ((int16_t) (ao_sample_tick - ao_interval_end) >= 0) {
97+
if ((AO_TICK_SIGNED) (ao_sample_tick - ao_interval_end) >= 0) {
9898
if (ao_interval_max_height - ao_interval_min_height < AO_M_TO_HEIGHT(5))
9999
{
100100
ao_flight_state = ao_flight_landed;

src/kernel/ao_host.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* One set of samples read from the A/D converter
3333
*/
3434
struct ao_adc {
35-
uint16_t tick; /* tick when the sample was read */
35+
AO_TICK_TYPE tick; /* tick when the sample was read */
3636
int16_t accel; /* accelerometer */
3737
int16_t pres; /* pressure sensor */
3838
int16_t temp; /* temperature sensor */

src/kernel/ao_kalman.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ static void
6161
ao_kalman_predict(void)
6262
{
6363
#ifdef AO_FLIGHT_TEST
64-
if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 50) {
64+
if ((AO_TICK_SIGNED) (ao_sample_tick - ao_sample_prev_tick) > 50) {
6565
ao_k_height += ((ao_k_t) ao_speed * AO_K_STEP_1 +
6666
(ao_k_t) ao_accel * AO_K_STEP_2_2_1) >> 4;
6767
ao_k_speed += (ao_k_t) ao_accel * AO_K_STEP_1;
6868

6969
return;
7070
}
71-
if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 5) {
71+
if ((AO_TICK_SIGNED) (ao_sample_tick - ao_sample_prev_tick) > 5) {
7272
ao_k_height += ((ao_k_t) ao_speed * AO_K_STEP_10 +
7373
(ao_k_t) ao_accel * AO_K_STEP_2_2_10) >> 4;
7474
ao_k_speed += (ao_k_t) ao_accel * AO_K_STEP_10;
@@ -149,13 +149,13 @@ ao_kalman_correct_baro(void)
149149
{
150150
ao_kalman_err_height();
151151
#ifdef AO_FLIGHT_TEST
152-
if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 50) {
152+
if ((AO_TICK_SIGNED) (ao_sample_tick - ao_sample_prev_tick) > 50) {
153153
ao_k_height += (ao_k_t) AO_BARO_K0_1 * ao_error_h;
154154
ao_k_speed += (ao_k_t) AO_BARO_K1_1 * ao_error_h;
155155
ao_k_accel += (ao_k_t) AO_BARO_K2_1 * ao_error_h;
156156
return;
157157
}
158-
if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 5) {
158+
if ((AO_TICK_SIGNED) (ao_sample_tick - ao_sample_prev_tick) > 5) {
159159
ao_k_height += (ao_k_t) AO_BARO_K0_10 * ao_error_h;
160160
ao_k_speed += (ao_k_t) AO_BARO_K1_10 * ao_error_h;
161161
ao_k_accel += (ao_k_t) AO_BARO_K2_10 * ao_error_h;
@@ -189,7 +189,7 @@ ao_kalman_correct_both(void)
189189
ao_kalman_err_accel();
190190

191191
#ifdef AO_FLIGHT_TEST
192-
if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 50) {
192+
if ((AO_TICK_SIGNED) (ao_sample_tick - ao_sample_prev_tick) > 50) {
193193
if (ao_flight_debug) {
194194
printf ("correct speed %g + (%g * %g) + (%g * %g) = %g\n",
195195
ao_k_speed / (65536.0 * 16.0),
@@ -210,7 +210,7 @@ ao_kalman_correct_both(void)
210210
(ao_k_t) AO_BOTH_K21_1 * ao_error_a;
211211
return;
212212
}
213-
if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 5) {
213+
if ((AO_TICK_SIGNED) (ao_sample_tick - ao_sample_prev_tick) > 5) {
214214
if (ao_flight_debug) {
215215
printf ("correct speed %g + (%g * %g) + (%g * %g) = %g\n",
216216
ao_k_speed / (65536.0 * 16.0),
@@ -260,7 +260,7 @@ ao_kalman_correct_accel(void)
260260
ao_kalman_err_accel();
261261

262262
#ifdef AO_FLIGHT_TEST
263-
if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 5) {
263+
if ((AO_TICK_SIGNED) (ao_sample_tick - ao_sample_prev_tick) > 5) {
264264
ao_k_height +=(ao_k_t) AO_ACCEL_K0_10 * ao_error_a;
265265
ao_k_speed += (ao_k_t) AO_ACCEL_K1_10 * ao_error_a;
266266
ao_k_accel += (ao_k_t) AO_ACCEL_K2_10 * ao_error_a;
@@ -325,9 +325,9 @@ ao_kalman(void)
325325
ao_avg_height_scaled = ao_avg_height_scaled - ao_avg_height + ao_height;
326326
#endif
327327
#ifdef AO_FLIGHT_TEST
328-
if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 50)
328+
if ((AO_TICK_SIGNED) (ao_sample_tick - ao_sample_prev_tick) > 50)
329329
ao_avg_height = (ao_avg_height_scaled + 1) >> 1;
330-
else if ((int16_t) (ao_sample_tick - ao_sample_prev_tick) > 5)
330+
else if ((AO_TICK_SIGNED) (ao_sample_tick - ao_sample_prev_tick) > 5)
331331
ao_avg_height = (ao_avg_height_scaled + 7) >> 4;
332332
else
333333
#endif

0 commit comments

Comments
 (0)