altos: Make sure pa to altitude conversion is done with 32 bits
[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 #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 /* Byte offset of config block. Will be ao_storage_block bytes long */
39 extern __pdata ao_pos_t ao_storage_config;
40
41 /* Storage unit size - device reads and writes must be within blocks of this size. Usually 256 bytes. */
42 extern __pdata uint16_t ao_storage_unit;
43
44 #define AO_STORAGE_ERASE_LOG    (ao_storage_config + AO_CONFIG_MAX_SIZE)
45
46 /* Initialize above values. Can only be called once the OS is running */
47 void
48 ao_storage_setup(void) __reentrant;
49
50 /* Write data. Returns 0 on failure, 1 on success */
51 uint8_t
52 ao_storage_write(ao_pos_t pos, __xdata void *buf, uint16_t len) __reentrant;
53
54 /* Read data. Returns 0 on failure, 1 on success */
55 uint8_t
56 ao_storage_read(ao_pos_t pos, __xdata void *buf, uint16_t len) __reentrant;
57
58 /* Erase a block of storage. This always clears ao_storage_block bytes */
59 uint8_t
60 ao_storage_erase(ao_pos_t pos) __reentrant;
61
62 /* Flush any pending writes to stable storage */
63 void
64 ao_storage_flush(void) __reentrant;
65
66 /* Initialize the storage code */
67 void
68 ao_storage_init(void);
69
70 /*
71  * Low-level functions wrapped by ao_storage.c
72  */
73
74 /* Read data within a storage unit */
75 uint8_t
76 ao_storage_device_read(ao_pos_t pos, __xdata void *buf, uint16_t len) __reentrant;
77
78 /* Write data within a storage unit */
79 uint8_t
80 ao_storage_device_write(ao_pos_t pos, __xdata void *buf, uint16_t len) __reentrant;
81
82 /* Initialize low-level device bits */
83 void
84 ao_storage_device_init(void);
85
86 /* Print out information about flash chips */
87 void
88 ao_storage_device_info(void) __reentrant;
89
90 #endif /* _AO_STORAGE_H_ */