2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 static AO_TICK_TYPE ao_log_tiny_interval;
23 #define AO_LOG_TINY_INTERVAL_DEFAULT AO_MS_TO_TICKS(1000)
24 #if USE_FAST_ASCENT_LOG
25 #define AO_LOG_TINY_INTERVAL_ASCENT AO_MS_TO_TICKS(100)
28 #define AO_LOG_TINY_INTERVAL_ASCENT AO_LOG_TINY_INTERVAL_DEFAULT
33 ao_log_tiny_set_interval(AO_TICK_TYPE ticks)
35 ao_log_tiny_interval = ticks;
39 static void ao_log_tiny_data(uint16_t d)
41 if (ao_log_current_pos >= ao_log_end_pos && ao_log_running)
44 ao_storage_write(ao_log_current_pos, &d, 2);
45 ao_log_current_pos += 2;
49 static uint16_t ao_log_pad_ring[AO_PAD_RING];
50 static uint8_t ao_log_pad_ring_pos;
52 #define ao_pad_ring_next(n) (((n) + 1) & (AO_PAD_RING - 1))
54 static void ao_log_tiny_queue(uint16_t d)
56 ao_log_pad_ring[ao_log_pad_ring_pos] = d;
57 ao_log_pad_ring_pos = ao_pad_ring_next(ao_log_pad_ring_pos);
60 static void ao_log_tiny_start(void)
65 ao_log_tiny_data(ao_flight_number);
66 ao_log_tiny_data(ao_ground_pres);
67 p = ao_log_pad_ring_pos;
69 d = ao_log_pad_ring[p];
71 * ignore unwritten slots
75 p = ao_pad_ring_next(p);
76 } while (p != ao_log_pad_ring_pos);
84 enum ao_flight_state ao_log_tiny_state;
88 uint8_t ao_log_started = 0;
94 ao_log_tiny_state = ao_flight_invalid;
95 ao_log_tiny_interval = AO_LOG_TINY_INTERVAL_ASCENT;
98 ao_log_data = ao_sample_data;
99 last_time = ao_time();
103 * Add in pending sample data
105 ao_sleep(&ao_sample_data);
106 while (ao_log_data != ao_sample_data) {
107 sum += ao_data_pres(&ao_data_ring[ao_log_data]);
109 ao_log_data = ao_data_ring_next(ao_log_data);
111 if (ao_log_running) {
112 if (!ao_log_started) {
116 if (ao_flight_state != ao_log_tiny_state) {
117 ao_log_tiny_data(ao_flight_state | 0x8000);
118 ao_log_tiny_state = ao_flight_state;
119 ao_log_tiny_interval = AO_LOG_TINY_INTERVAL_DEFAULT;
120 #if AO_LOG_TINY_INTERVAL_ASCENT != AO_LOG_TINY_INTERVAL_DEFAULT
121 if (ao_log_tiny_state <= ao_flight_coast)
122 ao_log_tiny_interval = AO_LOG_TINY_INTERVAL_ASCENT;
124 if (ao_log_tiny_state == ao_flight_landed)
129 /* Stop logging when told to */
130 if (!ao_log_running && ao_log_started)
134 * Write out the sample when finished
137 if ((AO_TICK_SIGNED) (now - (last_time + ao_log_tiny_interval)) >= 0 && count) {
140 ao_log_tiny_data(count);
142 ao_log_tiny_queue(count);
151 ao_log_flight(uint8_t slot)
153 static uint16_t flight;
156 ao_storage_read(0, &flight, 2);
157 if (flight == 0xffff)