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.
21 * Stores a sequence of fixed-size (32 byte) chunks
22 * without splitting memory up into separate flights
26 #include "ao_product.h"
28 static __xdata struct ao_task ao_log_single_task;
30 __xdata uint8_t ao_log_running;
31 __xdata uint8_t ao_log_mutex;
32 __pdata uint32_t ao_log_start_pos;
33 __pdata uint32_t ao_log_end_pos;
34 __pdata uint32_t ao_log_current_pos;
36 __xdata union ao_log_single ao_log_single_write_data;
37 __xdata union ao_log_single ao_log_single_read_data;
40 ao_log_single_write(void)
44 ao_mutex_get(&ao_log_mutex); {
45 if (ao_log_current_pos >= ao_log_end_pos && ao_log_running)
49 ao_storage_write(ao_log_current_pos,
50 &ao_log_single_write_data,
52 ao_log_current_pos += AO_LOG_SINGLE_SIZE;
54 } ao_mutex_put(&ao_log_mutex);
59 ao_log_single_valid(void)
61 __xdata uint8_t *d = ao_log_single_read_data.bytes;
63 for (i = 0; i < AO_LOG_SINGLE_SIZE; i++)
70 ao_log_single_read(uint32_t pos)
72 if (!ao_storage_read(pos, &ao_log_single_read_data, AO_LOG_SINGLE_SIZE))
74 return ao_log_single_valid();
78 ao_log_single_start(void)
80 if (!ao_log_running) {
82 ao_wakeup(&ao_log_running);
87 ao_log_single_stop(void)
95 ao_log_single_restart(void)
97 /* Find end of data */
98 ao_log_end_pos = ao_storage_config;
99 for (ao_log_current_pos = 0;
100 ao_log_current_pos < ao_storage_config;
101 ao_log_current_pos += ao_storage_block)
103 if (!ao_log_single_read(ao_log_current_pos))
106 if (ao_log_current_pos > 0) {
107 ao_log_current_pos -= ao_storage_block;
108 for (; ao_log_current_pos < ao_storage_config;
109 ao_log_current_pos += sizeof (struct ao_log_telescience))
111 if (!ao_log_single_read(ao_log_current_pos))
118 ao_log_single_set(void)
120 printf("Logging currently %s\n", ao_log_running ? "on" : "off");
122 if (ao_cmd_status == ao_cmd_success) {
124 printf("Logging from %ld to %ld\n", ao_log_current_pos, ao_log_end_pos);
125 ao_log_single_start();
127 printf ("Log stopped at %ld\n", ao_log_current_pos);
128 ao_log_single_stop();
131 ao_cmd_status = ao_cmd_success;
135 ao_log_single_delete(void)
140 if (ao_cmd_status != ao_cmd_success)
142 if (ao_cmd_lex_i != 1) {
143 ao_cmd_status = ao_cmd_syntax_error;
144 printf("No such flight: %d\n", ao_cmd_lex_i);
147 ao_log_single_stop();
148 for (pos = 0; pos < ao_storage_config; pos += ao_storage_block) {
149 if (!ao_log_single_read(pos))
151 ao_storage_erase(pos);
153 ao_log_current_pos = ao_log_start_pos = 0;
155 printf("No such flight: %d\n", ao_cmd_lex_i);
163 return ao_log_current_pos >= ao_log_end_pos;
169 return ao_log_single_read(0);
173 ao_log_single_query(void)
175 printf("Logging enabled: %d\n", ao_log_running);
176 printf("Log start: %ld\n", ao_log_start_pos);
177 printf("Log cur: %ld\n", ao_log_current_pos);
178 printf("Log end: %ld\n", ao_log_end_pos);
179 ao_log_single_extra_query();
182 const struct ao_cmds ao_log_single_cmds[] = {
183 { ao_log_single_set, "L <0 off, 1 on>\0Set logging" },
184 { ao_log_single_list, "l\0List stored logs" },
185 { ao_log_single_delete, "d 1\0Delete all stored logs" },
186 { ao_log_single_query, "q\0Query log status" },
191 ao_log_single_init(void)
195 ao_cmd_register(&ao_log_single_cmds[0]);
197 ao_add_task(&ao_log_single_task, ao_log_single, "log");