altos: Massive product config cleanup
[fw/altos] / src / core / ao_storage.h
1 /*
2  * Copyright © 2012 Keith Packard <keithp@keithp.com>
3  *
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.
7  *
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.
12  *
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.
16  */
17
18 #ifndef _AO_STORAGE_H_
19 #define _AO_STORAGE_H_
20
21 /*
22  * Storage interface, provided by one of the eeprom or flash
23  * drivers
24  */
25
26 /* Total bytes of available storage */
27 extern __pdata uint32_t ao_storage_total;
28
29 /* Block size - device is erased in these units. At least 256 bytes */
30 extern __pdata uint32_t ao_storage_block;
31
32 /* Byte offset of config block. Will be ao_storage_block bytes long */
33 extern __pdata uint32_t ao_storage_config;
34
35 /* Storage unit size - device reads and writes must be within blocks of this size. Usually 256 bytes. */
36 extern __pdata uint16_t ao_storage_unit;
37
38 #define AO_STORAGE_ERASE_LOG    (ao_storage_config + AO_CONFIG_MAX_SIZE)
39
40 /* Initialize above values. Can only be called once the OS is running */
41 void
42 ao_storage_setup(void) __reentrant;
43
44 /* Write data. Returns 0 on failure, 1 on success */
45 uint8_t
46 ao_storage_write(uint32_t pos, __xdata void *buf, uint16_t len) __reentrant;
47
48 /* Read data. Returns 0 on failure, 1 on success */
49 uint8_t
50 ao_storage_read(uint32_t pos, __xdata void *buf, uint16_t len) __reentrant;
51
52 /* Erase a block of storage. This always clears ao_storage_block bytes */
53 uint8_t
54 ao_storage_erase(uint32_t pos) __reentrant;
55
56 /* Flush any pending writes to stable storage */
57 void
58 ao_storage_flush(void) __reentrant;
59
60 /* Initialize the storage code */
61 void
62 ao_storage_init(void);
63
64 /*
65  * Low-level functions wrapped by ao_storage.c
66  */
67
68 /* Read data within a storage unit */
69 uint8_t
70 ao_storage_device_read(uint32_t pos, __xdata void *buf, uint16_t len) __reentrant;
71
72 /* Write data within a storage unit */
73 uint8_t
74 ao_storage_device_write(uint32_t pos, __xdata void *buf, uint16_t len) __reentrant;
75
76 /* Initialize low-level device bits */
77 void
78 ao_storage_device_init(void);
79
80 /* Print out information about flash chips */
81 void
82 ao_storage_device_info(void) __reentrant;
83
84 #endif /* _AO_STORAGE_H_ */