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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 #ifndef _AO_STORAGE_H_
20 #define _AO_STORAGE_H_
23 * Storage interface, provided by one of the eeprom or flash
27 #ifndef ao_storage_pos_t
28 #define ao_storage_pos_t uint32_t
31 typedef ao_storage_pos_t ao_pos_t;
33 /* Total bytes of available storage */
34 extern ao_pos_t ao_storage_total;
36 /* Block size - device is erased in these units. At least 256 bytes */
37 extern ao_pos_t ao_storage_block;
39 #ifndef USE_STORAGE_CONFIG
40 #define USE_STORAGE_CONFIG 1
43 #if USE_STORAGE_CONFIG
44 /* Byte offset of config block. Will be ao_storage_block bytes long */
45 extern ao_pos_t ao_storage_config;
47 #define ao_storage_log_max ao_storage_config
49 #define ao_storage_log_max ao_storage_total
52 /* Storage unit size - device reads and writes must be within blocks of this size. Usually 256 bytes. */
53 extern uint16_t ao_storage_unit;
55 /* Initialize above values. Can only be called once the OS is running */
57 ao_storage_setup(void);
59 /* Write data. Returns 0 on failure, 1 on success */
61 ao_storage_write(ao_pos_t pos, void *buf, uint16_t len);
63 /* Read data. Returns 0 on failure, 1 on success */
65 ao_storage_read(ao_pos_t pos, void *buf, uint16_t len);
67 /* Erase a block of storage. This always clears ao_storage_block bytes */
69 ao_storage_erase(ao_pos_t pos);
71 /* Flush any pending writes to stable storage */
73 ao_storage_flush(void);
75 /* Initialize the storage code */
77 ao_storage_init(void);
80 * Low-level functions wrapped by ao_storage.c
83 /* Read data within a storage unit */
85 ao_storage_device_read(ao_pos_t pos, void *buf, uint16_t len);
87 /* Write data within a storage unit */
89 ao_storage_device_write(ao_pos_t pos, void *buf, uint16_t len);
91 /* Initialize low-level device bits */
93 ao_storage_device_init(void);
95 /* Print out information about flash chips */
97 ao_storage_device_info(void);
99 #endif /* _AO_STORAGE_H_ */