2 * Copyright © 2012 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.
20 #include <ao_micropeak.h>
21 #include <ao_ms5607.h>
23 #include <ao_log_micro.h>
25 static struct ao_ms5607_value value;
27 alt_t ground_alt, max_alt;
33 ao_ms5607_sample(&ao_ms5607_current);
34 ao_ms5607_convert(&ao_ms5607_current, &value);
41 for (i = 0; i < 10; i++) {
42 ao_led_toggle(AO_LED_REPORT);
43 ao_delay(AO_MS_TO_TICKS(80));
45 ao_delay(AO_MS_TO_TICKS(200));
51 ao_log_micro_crc(uint16_t crc, uint8_t byte)
55 for (i = 0; i < 8; i++) {
56 if ((crc & 0x0001) ^ (byte & 0x0001))
57 crc = (crc >> 1) ^ POLY;
66 uint32_t pa_ground_offset;
67 uint32_t pa_min_offset;
68 N_SAMPLES_TYPE nsamples;
71 static const struct header head = {
72 .pa_ground_offset = 0xfffefdfc,
73 .pa_min_offset = 0xfbfaf9f8,
78 ao_test_micro_dump(void)
80 N_SAMPLES_TYPE n_samples;
84 uint16_t crc = 0xffff;
86 n_samples = head.nsamples;
87 nbytes = STARTING_LOG_OFFSET + sizeof (uint16_t) * n_samples;
90 * Rewrite n_samples so that it includes the log ID value with
91 * 32-bit n_samples split into two chunks
93 if (sizeof (n_samples) > 2) {
94 N_SAMPLES_TYPE n_samples_low;
95 N_SAMPLES_TYPE n_samples_high;
96 n_samples_low = n_samples & ((1 << AO_LOG_ID_SHIFT) - 1);
97 n_samples_high = (n_samples - n_samples_low) << AO_LOG_ID_WIDTH;
98 n_samples = n_samples_low | n_samples_high;
101 n_samples |= AO_LOG_ID << AO_LOG_ID_SHIFT;
106 for (b = 0; b < nbytes; b++) {
109 if (b < sizeof (head))
110 byte = ((uint8_t *) &head)[b];
114 if (N_SAMPLES_OFFSET <= b && b < (N_SAMPLES_OFFSET + sizeof(n_samples))) {
115 byte = n_samples >> ((b - N_SAMPLES_OFFSET) << 3);
119 crc = ao_log_micro_crc(crc, byte);
123 ao_log_hex(crc >> 8);
135 /* Init external hardware */
142 ao_delay(AO_MS_TO_TICKS(1000));
145 ao_test_micro_dump();