altos: megadongle radio int is C13, not C14
[fw/altos] / src / micropeak / ao_log_micro.c
1 /*
2  * Copyright © 2012 Keith Packard <keithp@keithp.com>
3  *
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.
7  *
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.
12  *
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.
16  */
17
18 #include <ao.h>
19 #include <ao_log_micro.h>
20 #include <ao_async.h>
21
22 #if HAS_EEPROM
23
24 ao_pos_t        ao_log_micro_pos;
25
26 void
27 ao_log_micro_data(uint32_t data)
28 {
29         ao_storage_write(ao_log_micro_pos, &data, sizeof (data));
30         ao_log_micro_pos += sizeof (data);
31 }
32
33 uint32_t        ao_log_last_ground;
34 uint32_t        ao_log_last_done;
35
36 uint8_t
37 ao_log_micro_scan(void)
38 {
39         uint32_t        data;
40         ao_pos_t        pos;
41
42         ao_storage_read(0, &data, sizeof (data));
43         if ((data & AO_LOG_MICRO_MASK) != AO_LOG_MICRO_GROUND)
44                 return 0;
45
46         ao_log_last_ground = data & ~(AO_LOG_MICRO_MASK);
47         for (pos = 4; pos < ao_storage_total; pos += 4) {
48                 ao_storage_read(pos, &data, sizeof (data));
49                 if ((data & AO_LOG_MICRO_MASK) == AO_LOG_MICRO_GROUND) {
50                         ao_log_last_done = data & ~(AO_LOG_MICRO_MASK);
51                         return 1;
52                 }
53         }
54         return 0;
55 }
56
57 void
58 ao_log_micro_dump(void)
59 {
60         ao_pos_t        pos;
61         uint8_t         data[4];
62         uint8_t         i;
63
64         for (pos = 0; pos < ao_storage_total; pos += 4) {
65                 ao_storage_read(pos, data, 4);
66                 for (i = 0; i < 4; i++)
67                         ao_async_byte(data[i]);
68                 if (data[3] == (uint8_t) (AO_LOG_MICRO_GROUND >> 24))
69                         break;
70         }
71 }
72
73 #endif