1 /*  NVS: non volatile storage in flash
2  *
3  * Copyright (c) 2018 Laczen
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 #ifndef __NVS_PRIV_H_
8 #define __NVS_PRIV_H_
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 /*
15  * MASKS AND SHIFT FOR ADDRESSES
16  * an address in nvs is an uint32_t where:
17  *   high 2 bytes represent the sector number
18  *   low 2 bytes represent the offset in a sector
19  */
20 #define ADDR_SECT_MASK 0xFFFF0000
21 #define ADDR_SECT_SHIFT 16
22 #define ADDR_OFFS_MASK 0x0000FFFF
23 
24 /*
25  * Status return values
26  */
27 #define NVS_STATUS_NOSPACE 1
28 
29 #define NVS_BLOCK_SIZE 32
30 
31 #define NVS_LOOKUP_CACHE_NO_ADDR 0xFFFFFFFF
32 
33 /* Allocation Table Entry */
34 struct nvs_ate {
35 	uint16_t id;	/* data id */
36 	uint16_t offset;	/* data offset within sector */
37 	uint16_t len;	/* data len within sector */
38 	uint8_t part;	/* part of a multipart data - future extension */
39 	uint8_t crc8;	/* crc8 check of the entry */
40 } __packed;
41 
42 BUILD_ASSERT(offsetof(struct nvs_ate, crc8) ==
43 		 sizeof(struct nvs_ate) - sizeof(uint8_t),
44 		 "crc8 must be the last member");
45 
46 #ifdef __cplusplus
47 }
48 #endif
49 
50 #endif /* __NVS_PRIV_H_ */
51