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