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; 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.
19 #include <ao_micropeak.h>
20 #include <ao_log_micro.h>
23 static uint16_t ao_log_offset = STARTING_LOG_OFFSET;
26 ao_log_micro_save(void)
28 uint16_t n_samples = (ao_log_offset - STARTING_LOG_OFFSET) / sizeof (uint16_t);
29 ao_eeprom_write(PA_GROUND_OFFSET, &pa_ground, sizeof (pa_ground));
30 ao_eeprom_write(PA_MIN_OFFSET, &pa_min, sizeof (pa_min));
31 ao_eeprom_write(N_SAMPLES_OFFSET, &n_samples, sizeof (n_samples));
35 ao_log_micro_restore(void)
37 ao_eeprom_read(PA_GROUND_OFFSET, &pa_ground, sizeof (pa_ground));
38 ao_eeprom_read(PA_MIN_OFFSET, &pa_min, sizeof (pa_min));
42 ao_log_micro_data(void)
44 uint16_t low_bits = pa;
46 if (ao_log_offset < MAX_LOG_OFFSET) {
47 ao_eeprom_write(ao_log_offset, &low_bits, sizeof (low_bits));
48 ao_log_offset += sizeof (low_bits);
55 ao_log_micro_crc(uint16_t crc, uint8_t byte)
59 for (i = 0; i < 8; i++) {
60 if ((crc & 0x0001) ^ (byte & 0x0001))
61 crc = (crc >> 1) ^ POLY;
70 ao_log_hex_nibble(uint8_t b)
73 ao_async_byte('0' + b);
75 ao_async_byte('a' - 10 + b);
81 ao_log_hex_nibble(b>>4);
82 ao_log_hex_nibble(b&0xf);
93 ao_log_micro_dump(void)
99 uint16_t crc = 0xffff;
101 ao_eeprom_read(N_SAMPLES_OFFSET, &n_samples, sizeof (n_samples));
102 if (n_samples == 0xffff)
104 nbytes = STARTING_LOG_OFFSET + sizeof (uint16_t) * n_samples;
108 for (b = 0; b < nbytes; b++) {
111 ao_eeprom_read(b, &byte, 1);
113 crc = ao_log_micro_crc(crc, byte);
117 ao_log_hex(crc >> 8);