Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
Non-volatile Storage APIs

Non-volatile Storage APIs. More...

Functions

int nvs_init (struct nvs_fs *fs, const char *dev_name)
 nvs_init More...
 
int nvs_clear (struct nvs_fs *fs)
 nvs_clear More...
 
ssize_t nvs_write (struct nvs_fs *fs, uint16_t id, const void *data, size_t len)
 nvs_write More...
 
int nvs_delete (struct nvs_fs *fs, uint16_t id)
 nvs_delete More...
 
ssize_t nvs_read (struct nvs_fs *fs, uint16_t id, void *data, size_t len)
 nvs_read More...
 
ssize_t nvs_read_hist (struct nvs_fs *fs, uint16_t id, void *data, size_t len, uint16_t cnt)
 nvs_read_hist More...
 
ssize_t nvs_calc_free_space (struct nvs_fs *fs)
 nvs_calc_free_space More...
 

Detailed Description

Non-volatile Storage APIs.

Function Documentation

◆ nvs_calc_free_space()

ssize_t nvs_calc_free_space ( struct nvs_fs fs)

#include <include/fs/nvs.h>

nvs_calc_free_space

Calculate the available free space in the file system.

Parameters
fsPointer to file system
Returns
Number of bytes free. On success, it will be equal to the number of bytes that can still be written to the file system. Calculating the free space is a time consuming operation, especially on spi flash. On error returns -ERRNO code.

◆ nvs_clear()

int nvs_clear ( struct nvs_fs fs)

#include <include/fs/nvs.h>

nvs_clear

Clears the NVS file system from flash.

Parameters
fsPointer to file system
Return values
0Success
-ERRNOerrno code if error

◆ nvs_delete()

int nvs_delete ( struct nvs_fs fs,
uint16_t  id 
)

#include <include/fs/nvs.h>

nvs_delete

Delete an entry from the file system

Parameters
fsPointer to file system
idId of the entry to be deleted
Return values
0Success
-ERRNOerrno code if error

◆ nvs_init()

int nvs_init ( struct nvs_fs fs,
const char *  dev_name 
)

#include <include/fs/nvs.h>

nvs_init

Initializes a NVS file system in flash.

Parameters
fsPointer to file system
dev_namePointer to flash device name
Return values
0Success
-ERRNOerrno code if error

◆ nvs_read()

ssize_t nvs_read ( struct nvs_fs fs,
uint16_t  id,
void data,
size_t  len 
)

#include <include/fs/nvs.h>

nvs_read

Read an entry from the file system.

Parameters
fsPointer to file system
idId of the entry to be read
dataPointer to data buffer
lenNumber of bytes to be read
Returns
Number of bytes read. On success, it will be equal to the number of bytes requested to be read. When the return value is larger than the number of bytes requested to read this indicates not all bytes were read, and more data is available. On error returns -ERRNO code.

◆ nvs_read_hist()

ssize_t nvs_read_hist ( struct nvs_fs fs,
uint16_t  id,
void data,
size_t  len,
uint16_t  cnt 
)

#include <include/fs/nvs.h>

nvs_read_hist

Read a history entry from the file system.

Parameters
fsPointer to file system
idId of the entry to be read
dataPointer to data buffer
lenNumber of bytes to be read
cntHistory counter: 0: latest entry, 1:one before latest ...
Returns
Number of bytes read. On success, it will be equal to the number of bytes requested to be read. When the return value is larger than the number of bytes requested to read this indicates not all bytes were read, and more data is available. On error returns -ERRNO code.

◆ nvs_write()

ssize_t nvs_write ( struct nvs_fs fs,
uint16_t  id,
const void data,
size_t  len 
)

#include <include/fs/nvs.h>

nvs_write

Write an entry to the file system.

Parameters
fsPointer to file system
idId of the entry to be written
dataPointer to the data to be written
lenNumber of bytes to be written
Returns
Number of bytes written. On success, it will be equal to the number of bytes requested to be written. On error returns -ERRNO code.