LoRa-BLE-Sensor
Loading...
Searching...
No Matches
Macros | Functions
sensor_nvs.c File Reference

This is a library to keep track of sensor information and configurations that are stored in the non-volatile storage (NVS) of the device. nrf52840_partition gives 32KB for storage_partition. More...

#include "sensor_nvs.h"
#include <zephyr/fs/nvs.h>
#include <zephyr/logging/log.h>
#include <zephyr/storage/flash_map.h>
#include <zephyr/drivers/flash.h>
Include dependency graph for sensor_nvs.c:

Macros

#define NVS_PARTITION   storage_partition
 
#define NVS_PARTITION_DEVICE   FIXED_PARTITION_DEVICE(NVS_PARTITION)
 
#define NVS_PARTITION_OFFSET   FIXED_PARTITION_OFFSET(NVS_PARTITION)
 

Functions

 LOG_MODULE_REGISTER (SENSOR_NVS, LOG_LEVEL_INF)
 
int sensor_nvs_setup (uint8_t nvs_address_count)
 Setup NVS for use. An enum list of addresses should be defined in application code, with the maximum number of addresses being defined. This must be called before any other NVS functions. This mounts the NVS partition and initializes it. The nvs_address_count will be used to know when the address is out of bounds.
 
int sensor_nvs_write (uint8_t address, const void *data, size_t length)
 Write given data buffer to NVS with given address.
 
int sensor_nvs_read (uint8_t address, void *data, size_t length)
 Read data from NVS with given address, data is written to the provided buffer.
 
int sensor_nvs_delete (uint8_t address)
 Delete data from NVS with given address.
 
int sensor_nvs_clear (void)
 Clear all data from NVS. NVS must be setup again after clearing.
 

Detailed Description

This is a library to keep track of sensor information and configurations that are stored in the non-volatile storage (NVS) of the device. nrf52840_partition gives 32KB for storage_partition.

Author
Tyler Garcia
Version
0.1
Date
2025-05-08

Function Documentation

◆ sensor_nvs_clear()

int sensor_nvs_clear ( void  )

Clear all data from NVS. NVS must be setup again after clearing.

Returns
int 0 on success, -ERRNO errno code if error

◆ sensor_nvs_delete()

int sensor_nvs_delete ( uint8_t  address)

Delete data from NVS with given address.

Parameters
addressaddress of NVS to delete
Returns
int 0 on success, -1 on error

◆ sensor_nvs_read()

int sensor_nvs_read ( uint8_t  address,
void *  data,
size_t  length 
)

Read data from NVS with given address, data is written to the provided buffer.

Parameters
addressaddress of NVS to read from
datapointer to data buffer to write
lengthlength of data to read
Returns
int 0 on success, -1 on error

◆ sensor_nvs_setup()

int sensor_nvs_setup ( uint8_t  nvs_address_count)

Setup NVS for use. An enum list of addresses should be defined in application code, with the maximum number of addresses being defined. This must be called before any other NVS functions. This mounts the NVS partition and initializes it. The nvs_address_count will be used to know when the address is out of bounds.

Parameters
nvs_address_countthe number of addresses to use in the NVS partition
Returns
int 0 on success, -1 on error

◆ sensor_nvs_write()

int sensor_nvs_write ( uint8_t  address,
const void *  data,
size_t  length 
)

Write given data buffer to NVS with given address.

Parameters
addressaddress of NVS to write to
datapointer to data buffer to write
lengthlength of data to write
Returns
int 0 on success, -1 on error