altos/test: Adjust CRC error rate after FEC fix
[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 #ifndef ao_storage_total
35 extern ao_pos_t ao_storage_total;
36 #endif
37
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;
41 #endif
42
43 #ifndef USE_STORAGE_CONFIG
44 #define USE_STORAGE_CONFIG 1
45 #endif
46
47 #ifndef AO_STORAGE_ERASED_BYTE
48 #define AO_STORAGE_ERASED_BYTE 0xff
49 #endif
50
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;
54
55 #define ao_storage_log_max      ao_storage_config
56 #else
57 #define ao_storage_log_max      ao_storage_total
58 #endif
59
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;
63 #endif
64
65 /* Initialize above values. Can only be called once the OS is running */
66 void
67 ao_storage_setup(void);
68
69 /* Write data. Returns 0 on failure, 1 on success */
70 uint8_t
71 ao_storage_write(ao_pos_t pos, void *buf, uint16_t len);
72
73 /* Read data. Returns 0 on failure, 1 on success */
74 uint8_t
75 ao_storage_read(ao_pos_t pos, void *buf, uint16_t len);
76
77 /* Erase a block of storage. This always clears ao_storage_block bytes */
78 uint8_t
79 ao_storage_erase(ao_pos_t pos, uint32_t len);
80
81 /* Check storage starting at pos to see if the chunk there
82  * is erased
83  */
84 uint8_t
85 ao_storage_is_erased(uint32_t pos);
86
87 /* Flush any pending writes to stable storage */
88 void
89 ao_storage_flush(void);
90
91 /* Initialize the storage code */
92 void
93 ao_storage_init(void);
94
95 /*
96  * Low-level functions wrapped by ao_storage.c
97  */
98
99 /* Read data within a storage unit */
100 uint8_t
101 ao_storage_device_read(ao_pos_t pos, void *buf, uint16_t len);
102
103 /* Write data within a storage unit */
104 uint8_t
105 ao_storage_device_write(ao_pos_t pos, void *buf, uint16_t len);
106
107 /* Erase device from pos through pos + ao_storage_block */
108 uint8_t
109 ao_storage_device_erase(uint32_t pos);
110
111 /* Initialize low-level device bits */
112 void
113 ao_storage_device_init(void);
114
115 /* Print out information about flash chips */
116 void
117 ao_storage_device_info(void);
118
119 #endif /* _AO_STORAGE_H_ */