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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 static __data uint16_t ao_log_tiny_interval;
22 #define AO_LOG_TINY_INTERVAL_DEFAULT AO_MS_TO_TICKS(1000)
23 #if USE_FAST_ASCENT_LOG
24 #define AO_LOG_TINY_INTERVAL_ASCENT AO_MS_TO_TICKS(100)
27 #define AO_LOG_TINY_INTERVAL_ASCENT AO_LOG_TINY_INTERVAL_DEFAULT
32 ao_log_tiny_set_interval(uint16_t ticks)
34 ao_log_tiny_interval = ticks;
38 static void ao_log_tiny_data(uint16_t d)
40 if (ao_log_current_pos >= ao_log_end_pos && ao_log_running)
43 ao_storage_write(ao_log_current_pos, DATA_TO_XDATA(&d), 2);
44 ao_log_current_pos += 2;
48 static __xdata uint16_t ao_log_pad_ring[AO_PAD_RING];
49 static __pdata uint8_t ao_log_pad_ring_pos;
51 #define ao_pad_ring_next(n) (((n) + 1) & (AO_PAD_RING - 1))
53 static void ao_log_tiny_queue(uint16_t d)
55 ao_log_pad_ring[ao_log_pad_ring_pos] = d;
56 ao_log_pad_ring_pos = ao_pad_ring_next(ao_log_pad_ring_pos);
59 static void ao_log_tiny_start(void)
64 ao_log_tiny_data(ao_flight_number);
65 ao_log_tiny_data(ao_ground_pres);
66 p = ao_log_pad_ring_pos;
68 d = ao_log_pad_ring[p];
70 * ignore unwritten slots
74 p = ao_pad_ring_next(p);
75 } while (p != ao_log_pad_ring_pos);
83 enum ao_flight_state ao_log_tiny_state;
87 uint8_t ao_log_started = 0;
93 ao_log_tiny_state = ao_flight_invalid;
94 ao_log_tiny_interval = AO_LOG_TINY_INTERVAL_ASCENT;
97 ao_log_adc = ao_sample_adc;
98 last_time = ao_time();
102 * Add in pending sample data
104 ao_sleep(DATA_TO_XDATA(&ao_sample_adc));
105 while (ao_log_adc != ao_sample_adc) {
106 sum += ao_adc_ring[ao_log_adc].pres;
108 ao_log_adc = ao_adc_ring_next(ao_log_adc);
110 if (ao_log_running) {
111 if (!ao_log_started) {
115 if (ao_flight_state != ao_log_tiny_state) {
116 ao_log_tiny_data(ao_flight_state | 0x8000);
117 ao_log_tiny_state = ao_flight_state;
118 ao_log_tiny_interval = AO_LOG_TINY_INTERVAL_DEFAULT;
119 #if AO_LOG_TINY_INTERVAL_ASCENT != AO_LOG_TINY_INTERVAL_DEFAULT
120 if (ao_log_tiny_state <= ao_flight_coast)
121 ao_log_tiny_interval = AO_LOG_TINY_INTERVAL_ASCENT;
123 if (ao_log_tiny_state == ao_flight_landed)
128 /* Stop logging when told to */
129 if (!ao_log_running && ao_log_started)
133 * Write out the sample when finished
136 if ((int16_t) (now - (last_time + ao_log_tiny_interval)) >= 0 && count) {
139 ao_log_tiny_data(count);
141 ao_log_tiny_queue(count);
150 ao_log_flight(uint8_t slot)
152 static __xdata uint16_t flight;
155 ao_storage_read(0, &flight, 2);
156 if (flight == 0xffff)