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 #ifndef ao_storage_total
35 extern ao_pos_t ao_storage_total;
38 /* Block size - device is erased in these units. At least 256 bytes */
39 #ifndef ao_storage_block
40 extern ao_pos_t ao_storage_block;
43 #ifndef USE_STORAGE_CONFIG
44 #define USE_STORAGE_CONFIG 1
47 #ifndef AO_STORAGE_ERASED_BYTE
48 #define AO_STORAGE_ERASED_BYTE 0xff
51 #if USE_STORAGE_CONFIG
52 /* Byte offset of config block. Will be ao_storage_block bytes long */
53 extern ao_pos_t ao_storage_config;
55 #define ao_storage_log_max ao_storage_config
57 #define ao_storage_log_max ao_storage_total
60 /* Storage unit size - device reads and writes must be within blocks of this size. Usually 256 bytes. */
61 #ifndef ao_storage_unit
62 extern uint16_t ao_storage_unit;
65 /* Initialize above values. Can only be called once the OS is running */
67 ao_storage_setup(void);
69 /* Write data. Returns 0 on failure, 1 on success */
71 ao_storage_write(ao_pos_t pos, void *buf, uint16_t len);
73 /* Read data. Returns 0 on failure, 1 on success */
75 ao_storage_read(ao_pos_t pos, void *buf, uint16_t len);
77 /* Erase a block of storage. This always clears ao_storage_block bytes */
79 ao_storage_erase(ao_pos_t pos, uint32_t len);
81 /* Check storage starting at pos to see if the chunk there
85 ao_storage_is_erased(uint32_t pos);
87 /* Flush any pending writes to stable storage */
89 ao_storage_flush(void);
91 /* Initialize the storage code */
93 ao_storage_init(void);
96 * Low-level functions wrapped by ao_storage.c
99 /* Read data within a storage unit */
101 ao_storage_device_read(ao_pos_t pos, void *buf, uint16_t len);
103 /* Write data within a storage unit */
105 ao_storage_device_write(ao_pos_t pos, void *buf, uint16_t len);
107 /* Erase device from pos through pos + ao_storage_block */
109 ao_storage_device_erase(uint32_t pos);
111 /* Initialize low-level device bits */
113 ao_storage_device_init(void);
115 /* Print out information about flash chips */
117 ao_storage_device_info(void);
119 #endif /* _AO_STORAGE_H_ */