Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
nvs.h
Go to the documentation of this file.
1/* NVS: non volatile storage in flash
2 *
3 * Copyright (c) 2018 Laczen
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7#ifndef ZEPHYR_INCLUDE_FS_NVS_H_
8#define ZEPHYR_INCLUDE_FS_NVS_H_
9
10#include <sys/types.h>
11#include <zephyr/kernel.h>
12#include <zephyr/device.h>
13#include <zephyr/toolchain.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
39struct nvs_fs {
55 bool ready;
59 const struct device *flash_device;
62#if CONFIG_NVS_LOOKUP_CACHE
63 uint32_t lookup_cache[CONFIG_NVS_LOOKUP_CACHE_SIZE];
64#endif
65};
66
85int nvs_mount(struct nvs_fs *fs);
86
94int nvs_clear(struct nvs_fs *fs);
95
113ssize_t nvs_write(struct nvs_fs *fs, uint16_t id, const void *data, size_t len);
114
123int nvs_delete(struct nvs_fs *fs, uint16_t id);
124
138ssize_t nvs_read(struct nvs_fs *fs, uint16_t id, void *data, size_t len);
139
154ssize_t nvs_read_hist(struct nvs_fs *fs, uint16_t id, void *data, size_t len, uint16_t cnt);
155
166
175
190
195#ifdef __cplusplus
196}
197#endif
198
199#endif /* ZEPHYR_INCLUDE_FS_NVS_H_ */
ssize_t nvs_read(struct nvs_fs *fs, uint16_t id, void *data, size_t len)
Read an entry from the file system.
ssize_t nvs_write(struct nvs_fs *fs, uint16_t id, const void *data, size_t len)
Write an entry to the file system.
ssize_t nvs_calc_free_space(struct nvs_fs *fs)
Calculate the available free space in the file system.
int nvs_clear(struct nvs_fs *fs)
Clear the NVS file system from flash.
int nvs_sector_use_next(struct nvs_fs *fs)
Close the currently active sector and switch to the next one.
int nvs_delete(struct nvs_fs *fs, uint16_t id)
Delete an entry from the file system.
size_t nvs_sector_max_data_size(struct nvs_fs *fs)
Tell how many contiguous free space remains in the currently active NVS sector.
ssize_t nvs_read_hist(struct nvs_fs *fs, uint16_t id, void *data, size_t len, uint16_t cnt)
Read a history entry from the file system.
int nvs_mount(struct nvs_fs *fs)
Mount an NVS file system onto the flash device specified in fs.
Public kernel APIs.
__SIZE_TYPE__ ssize_t
Definition types.h:28
__INTPTR_TYPE__ off_t
Definition types.h:36
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:411
Flash memory parameters.
Definition flash.h:59
Mutex Structure.
Definition kernel.h:3004
Non-volatile Storage File system structure.
Definition nvs.h:39
const struct device * flash_device
Flash device runtime structure.
Definition nvs.h:59
uint16_t sector_size
File system is split into sectors, each sector must be multiple of erase-block-size.
Definition nvs.h:51
bool ready
Flag indicating if the file system is initialized.
Definition nvs.h:55
const struct flash_parameters * flash_parameters
Flash memory parameters structure.
Definition nvs.h:61
struct k_mutex nvs_lock
Mutex.
Definition nvs.h:57
off_t offset
File system offset in flash.
Definition nvs.h:41
uint32_t ate_wra
Allocation table entry write address.
Definition nvs.h:47
uint16_t sector_count
Number of sectors in the file system.
Definition nvs.h:53
uint32_t data_wra
Data write address.
Definition nvs.h:49
Macros to abstract toolchain specific capabilities.