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.
18 #ifndef _AO_STORAGE_H_
19 #define _AO_STORAGE_H_
22 * Storage interface, provided by one of the eeprom or flash
26 #ifndef ao_storage_pos_t
27 #define ao_storage_pos_t uint32_t
30 typedef ao_storage_pos_t ao_pos_t;
32 /* Total bytes of available storage */
33 extern __pdata ao_pos_t ao_storage_total;
35 /* Block size - device is erased in these units. At least 256 bytes */
36 extern __pdata ao_pos_t ao_storage_block;
38 /* Byte offset of config block. Will be ao_storage_block bytes long */
39 extern __pdata ao_pos_t ao_storage_config;
41 /* Storage unit size - device reads and writes must be within blocks of this size. Usually 256 bytes. */
42 extern __pdata uint16_t ao_storage_unit;
44 #define AO_STORAGE_ERASE_LOG (ao_storage_config + AO_CONFIG_MAX_SIZE)
46 /* Initialize above values. Can only be called once the OS is running */
48 ao_storage_setup(void) __reentrant;
50 /* Write data. Returns 0 on failure, 1 on success */
52 ao_storage_write(ao_pos_t pos, __xdata void *buf, uint16_t len) __reentrant;
54 /* Read data. Returns 0 on failure, 1 on success */
56 ao_storage_read(ao_pos_t pos, __xdata void *buf, uint16_t len) __reentrant;
58 /* Erase a block of storage. This always clears ao_storage_block bytes */
60 ao_storage_erase(ao_pos_t pos) __reentrant;
62 /* Flush any pending writes to stable storage */
64 ao_storage_flush(void) __reentrant;
66 /* Initialize the storage code */
68 ao_storage_init(void);
71 * Low-level functions wrapped by ao_storage.c
74 /* Read data within a storage unit */
76 ao_storage_device_read(ao_pos_t pos, __xdata void *buf, uint16_t len) __reentrant;
78 /* Write data within a storage unit */
80 ao_storage_device_write(ao_pos_t pos, __xdata void *buf, uint16_t len) __reentrant;
82 /* Initialize low-level device bits */
84 ao_storage_device_init(void);
86 /* Print out information about flash chips */
88 ao_storage_device_info(void) __reentrant;
90 #endif /* _AO_STORAGE_H_ */