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 ao_storage_read(uint32_t pos, __xdata void *buf, uint16_t len) __reentrant
27 if (pos >= ao_storage_total || pos + len > ao_storage_total)
31 /* Compute portion of transfer within
34 this_off = (uint16_t) pos & (ao_storage_unit - 1);
35 this_len = ao_storage_unit - this_off;
39 if (!ao_storage_device_read(pos, buf, this_len))
42 /* See how much is left */
51 ao_storage_write(uint32_t pos, __xdata void *buf, uint16_t len) __reentrant
57 if (pos >= ao_storage_total || pos + len > ao_storage_total)
61 /* Compute portion of transfer within
64 this_off = (uint16_t) pos & (ao_storage_unit - 1);
65 this_len = ao_storage_unit - this_off;
69 if (!ao_storage_device_write(pos, buf, this_len))
72 /* See how much is left */
80 static __xdata uint8_t storage_data[8];
83 ao_storage_dump(void) __reentrant
88 if (ao_cmd_status != ao_cmd_success)
90 for (i = 0; ; i += 8) {
91 if (ao_storage_read(((uint32_t) (ao_cmd_lex_i) << 8) + i,
94 ao_cmd_put16((uint16_t) i);
95 for (j = 0; j < 7; j++) {
97 ao_cmd_put8(storage_data[j]);
107 ao_storage_store(void) __reentrant
112 static __xdata uint8_t b;
116 block = ao_cmd_lex_i;
119 addr = ((uint32_t) block << 8) | i;
122 if (ao_cmd_status != ao_cmd_success)
126 if (ao_cmd_status != ao_cmd_success)
129 ao_storage_write(addr, &b, 1);
135 ao_storage_zap(void) __reentrant
138 if (ao_cmd_status != ao_cmd_success)
140 ao_storage_erase((uint32_t) ao_cmd_lex_i << 8);
144 ao_storage_info(void) __reentrant
146 printf("Storage size: %ld\n", ao_storage_total);
147 printf("Storage erase unit: %ld\n", ao_storage_block);
148 ao_storage_device_info();
151 __code struct ao_cmds ao_storage_cmds[] = {
152 { 'f', ao_storage_info, "f Show storage info" },
153 { 'e', ao_storage_dump, "e <block> Dump a block of flash data" },
154 { 'w', ao_storage_store,"w <block> <start> <len> <data> ... Write data to flash" },
155 { 'z', ao_storage_zap, "z <block> Erase flash containing <block>" },
156 { 0, ao_storage_zap, NULL },
160 ao_storage_init(void)
162 ao_storage_device_init();
163 ao_cmd_register(&ao_storage_cmds[0]);