telegps-v1.0: Provide one log and append to it
[fw/altos] / src / kernel / 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 #ifndef ao_storage_pos_t
27 #define ao_storage_pos_t uint32_t
28 #endif
29
30 typedef ao_storage_pos_t ao_pos_t;
31
32 /* Total bytes of available storage */
33 extern __pdata ao_pos_t ao_storage_total;
34
35 /* Block size - device is erased in these units. At least 256 bytes */
36 extern __pdata ao_pos_t ao_storage_block;
37
38 #ifndef USE_STORAGE_CONFIG
39 #define USE_STORAGE_CONFIG 1
40 #endif
41
42 #if USE_STORAGE_CONFIG
43 /* Byte offset of config block. Will be ao_storage_block bytes long */
44 extern __pdata ao_pos_t ao_storage_config;
45
46 #define ao_storage_log_max      ao_storage_config
47 #else
48 #define ao_storage_log_max      ao_storage_total
49 #endif
50
51 /* Storage unit size - device reads and writes must be within blocks of this size. Usually 256 bytes. */
52 extern __pdata uint16_t ao_storage_unit;
53
54 /* Initialize above values. Can only be called once the OS is running */
55 void
56 ao_storage_setup(void) __reentrant;
57
58 /* Write data. Returns 0 on failure, 1 on success */
59 uint8_t
60 ao_storage_write(ao_pos_t pos, __xdata void *buf, uint16_t len) __reentrant;
61
62 /* Read data. Returns 0 on failure, 1 on success */
63 uint8_t
64 ao_storage_read(ao_pos_t pos, __xdata void *buf, uint16_t len) __reentrant;
65
66 /* Erase a block of storage. This always clears ao_storage_block bytes */
67 uint8_t
68 ao_storage_erase(ao_pos_t pos) __reentrant;
69
70 /* Flush any pending writes to stable storage */
71 void
72 ao_storage_flush(void) __reentrant;
73
74 /* Initialize the storage code */
75 void
76 ao_storage_init(void);
77
78 /*
79  * Low-level functions wrapped by ao_storage.c
80  */
81
82 /* Read data within a storage unit */
83 uint8_t
84 ao_storage_device_read(ao_pos_t pos, __xdata void *buf, uint16_t len) __reentrant;
85
86 /* Write data within a storage unit */
87 uint8_t
88 ao_storage_device_write(ao_pos_t pos, __xdata void *buf, uint16_t len) __reentrant;
89
90 /* Initialize low-level device bits */
91 void
92 ao_storage_device_init(void);
93
94 /* Print out information about flash chips */
95 void
96 ao_storage_device_info(void) __reentrant;
97
98 #endif /* _AO_STORAGE_H_ */