Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Non-volatile memory cells. More...

Topics

 NVMEM Devicetree Helpers
 Devicetree support for NVMEM.

Files

file  nvmem.h
 Public NVMEM header file.

Data Structures

struct  nvmem_cell
 Non-Volatile Memory cell representation. More...

Macros

#define NVMEM_CELL_INIT(node_id)
 Get a static initializer for a struct nvmem_cell.
#define NVMEM_CELL_GET_BY_NAME(node_id, name)
 Get a static initializer for a struct nvmem_cell by name.
#define NVMEM_CELL_INST_GET_BY_NAME(inst, name)
 Get a static initializer for a struct nvmem_cell from a DT_DRV_COMPAT instance by name.
#define NVMEM_CELL_GET_BY_NAME_OR(node_id, name, default_value)
 Get a static initializer for a struct nvmem_cell by name, with a fallback.
#define NVMEM_CELL_INST_GET_BY_NAME_OR(inst, name, default_value)
 Get a static initializer for a struct nvmem_cell from a DT_DRV_COMPAT instance by name, with a fallback.
#define NVMEM_CELL_GET_BY_IDX(node_id, idx)
 Get a static initializer for a struct nvmem_cell by index.
#define NVMEM_CELL_INST_GET_BY_IDX(inst, idx)
 Get a static initializer for a struct nvmem_cell from a DT_DRV_COMPAT instance by index.
#define NVMEM_CELL_GET_BY_IDX_OR(node_id, idx, default_value)
 Get a static initializer for a struct nvmem_cell by index, with a fallback.
#define NVMEM_CELL_INST_GET_BY_IDX_OR(inst, idx, default_value)
 Get a static initializer for a struct nvmem_cell from a DT_DRV_COMPAT instance by index, with a fallback.

Functions

int nvmem_cell_read (const struct nvmem_cell *cell, void *data, off_t off, size_t len)
 Read data from an NVMEM cell.
int nvmem_cell_write (const struct nvmem_cell *cell, const void *data, off_t off, size_t len)
 Write data to an NVMEM cell.
static bool nvmem_cell_is_ready (const struct nvmem_cell *cell)
 Check if an NVMEM cell is ready.

Detailed Description

Non-volatile memory cells.

Since
4.3
Version
0.1.0

Macro Definition Documentation

◆ NVMEM_CELL_GET_BY_IDX

#define NVMEM_CELL_GET_BY_IDX ( node_id,
idx )

#include <zephyr/nvmem.h>

Value:
#define DT_NVMEM_CELL_BY_IDX(node_id, idx)
Get the node identifier for the NVMEM cell from the nvmem-cells property by index.
Definition nvmem.h:147
#define NVMEM_CELL_INIT(node_id)
Get a static initializer for a struct nvmem_cell.
Definition nvmem.h:91

Get a static initializer for a struct nvmem_cell by index.

This returns a static initializer for a struct nvmem_cell given a devicetree node identifier and an index.

Example devicetree fragment:

mac_eeprom: mac_eeprom@2 {
nvmem-layout {
compatible = "fixed-layout";
#address-cells = <1>;
#size-cells = <1>;
mac_address: mac_address@fa {
reg = <0xfa 0x06>;
#nvmem-cell-cells = <0>;
};
};
};
eth: ethernet {
nvmem-cells = <&mac_address>;
nvmem-cell-names = "mac-address";
};

Example usage:

const struct nvmem_cell cell =
// Initializes 'cell' to:
// {
// .dev = DEVICE_DT_GET(DT_NODELABEL(mac_eeprom)),
// .offset = 0xfa,
// .size = 6,
// .read_only = false,
// }
#define DT_NODELABEL(label)
Get a node identifier for a node label.
Definition devicetree.h:197
#define NVMEM_CELL_GET_BY_IDX(node_id, idx)
Get a static initializer for a struct nvmem_cell by index.
Definition nvmem.h:256
Non-Volatile Memory cell representation.
Definition nvmem.h:36
Parameters
node_idNode identifier for a node with an nvmem-cells property.
idxLogical index into 'nvmem-cells' property.
Returns
Static initializer for a struct nvmem_cell for the property.
See also
NVMEM_CELL_INST_GET_BY_IDX

◆ NVMEM_CELL_GET_BY_IDX_OR

#define NVMEM_CELL_GET_BY_IDX_OR ( node_id,
idx,
default_value )

#include <zephyr/nvmem.h>

Value:
COND_CODE_1(DT_PROP_HAS_IDX(node_id, nvmem_cells, idx), \
(NVMEM_CELL_GET_BY_IDX(node_id, idx)), \
(default_value))
#define DT_PROP_HAS_IDX(node_id, prop, idx)
Is index idx valid for an array type property?
Definition devicetree.h:872
#define COND_CODE_1(_flag, _if_1_code, _else_code)
Insert code depending on whether _flag expands to 1 or not.
Definition util_macro.h:203

Get a static initializer for a struct nvmem_cell by index, with a fallback.

If the devicetree node identifier 'node_id' refers to a node with a property 'nvmem-cells', this expands to NVMEM_CELL_GET_BY_IDX(node_id, idx). The default_value parameter is not expanded in this case. Otherwise, this expands to default_value.

Parameters
node_idNode identifier for a node that may have an nvmem-cells property.
idxLogical index into 'nvmem-cells' property.
default_valueFallback value to expand to.
Returns
Static initializer for a struct nvmem_cell for the property, or default_value if the node or property do not exist.
See also
NVMEM_CELL_INST_GET_BY_IDX_OR

◆ NVMEM_CELL_GET_BY_NAME

#define NVMEM_CELL_GET_BY_NAME ( node_id,
name )

#include <zephyr/nvmem.h>

Value:
#define DT_NVMEM_CELL_BY_NAME(node_id, name)
Get the node identifier for the NVMEM cell from the nvmem-cells property by name.
Definition nvmem.h:200

Get a static initializer for a struct nvmem_cell by name.

This returns a static initializer for a struct nvmem_cell given a devicetree node identifier and a name.

Example devicetree fragment:

mac_eeprom: mac_eeprom@2 {
nvmem-layout {
compatible = "fixed-layout";
#address-cells = <1>;
#size-cells = <1>;
mac_address: mac_address@fa {
reg = <0xfa 0x06>;
#nvmem-cell-cells = <0>;
};
};
};
eth: ethernet {
nvmem-cells = <&mac_address>;
nvmem-cell-names = "mac-address";
};

Example usage:

const struct nvmem_cell cell =
// Initializes 'cell' to:
// {
// .dev = DEVICE_DT_GET(DT_NODELABEL(mac_eeprom)),
// .offset = 0xfa,
// .size = 6,
// .read_only = false,
// }
#define NVMEM_CELL_GET_BY_NAME(node_id, name)
Get a static initializer for a struct nvmem_cell by name.
Definition nvmem.h:150
Parameters
node_idNode identifier for a node with an nvmem-cells property.
nameLowercase-and-underscores name of an nvmem-cells element as defined by the node's nvmem-cell-names property.
Returns
Static initializer for a struct nvmem_cell for the property.
See also
NVMEM_CELL_INST_GET_BY_NAME

◆ NVMEM_CELL_GET_BY_NAME_OR

#define NVMEM_CELL_GET_BY_NAME_OR ( node_id,
name,
default_value )

#include <zephyr/nvmem.h>

Value:
COND_CODE_1(DT_PROP_HAS_NAME(node_id, nvmem_cells, name), \
(NVMEM_CELL_GET_BY_NAME(node_id, name)), \
(default_value))
#define DT_PROP_HAS_NAME(node_id, prop, name)
Is name name available in a foo-names property?
Definition devicetree.h:907

Get a static initializer for a struct nvmem_cell by name, with a fallback.

If the devicetree node identifier 'node_id' refers to a node with a property 'nvmem-cells', this expands to NVMEM_CELL_GET_BY_NAME(node_id, name). The default_value parameter is not expanded in this case. Otherwise, this expands to default_value.

Parameters
node_idNode identifier for a node that may have an nvmem-cells property.
nameLowercase-and-underscores name of an nvmem-cells element as defined by the node's nvmem-cell-names property.
default_valueFallback value to expand to.
Returns
Static initializer for a struct nvmem_cell for the property, or default_value if the node or property do not exist.
See also
NVMEM_CELL_INST_GET_BY_NAME_OR

◆ NVMEM_CELL_INIT

#define NVMEM_CELL_INIT ( node_id)

#include <zephyr/nvmem.h>

Value:
{ \
.offset = DT_REG_ADDR(node_id), \
.size = DT_REG_SIZE(node_id), \
.read_only = DT_PROP(node_id, read_only), \
}
#define DEVICE_DT_GET(node_id)
Get a device reference from a devicetree node identifier.
Definition device.h:317
#define DT_PROP(node_id, prop)
Get a devicetree property value.
Definition devicetree.h:798
#define DT_MTD_FROM_NVMEM_CELL(node_id)
Get the node identifier of the memory controller for an nvmem cell.
Definition nvmem.h:316
#define DT_REG_ADDR(node_id)
Get a node's (only) register block address.
Definition devicetree.h:2509
#define DT_REG_SIZE(node_id)
Get a node's (only) register block size.
Definition devicetree.h:2530

Get a static initializer for a struct nvmem_cell.

This returns a static initializer for a struct nvmem_cell given a devicetree node identifier.

Note
This is a helper macro for other NVMEM_CELL_GET macros to initialize the nvmem_cell struct.

Example devicetree fragment:

mac_eeprom: mac_eeprom@2 {
nvmem-layout {
compatible = "fixed-layout";
#address-cells = <1>;
#size-cells = <1>;
mac_address: mac_address@fa {
reg = <0xfa 0x06>;
#nvmem-cell-cells = <0>;
};
};
};

Example usage:

const struct nvmem_cell cell = NVMEM_CELL_INIT(DT_NODELABEL(mac_address));
// Initializes 'cell' to:
// {
// .dev = DEVICE_DT_GET(DT_NODELABEL(mac_eeprom)),
// .offset = 0xfa,
// .size = 6,
// .read_only = false,
// }
Parameters
node_idNode identifier for an NVMEM cell.
Returns
Static initializer for a struct nvmem_cell

◆ NVMEM_CELL_INST_GET_BY_IDX

#define NVMEM_CELL_INST_GET_BY_IDX ( inst,
idx )

#include <zephyr/nvmem.h>

Value:
#define DT_DRV_INST(inst)
Node identifier for an instance of a DT_DRV_COMPAT compatible.
Definition devicetree.h:4085

Get a static initializer for a struct nvmem_cell from a DT_DRV_COMPAT instance by index.

Parameters
instDT_DRV_COMPAT instance number.
idxLogical index into 'nvmem-cells' property.
Returns
Static initializer for a struct nvmem_cell for the property.
See also
NVMEM_CELL_GET_BY_IDX

◆ NVMEM_CELL_INST_GET_BY_IDX_OR

#define NVMEM_CELL_INST_GET_BY_IDX_OR ( inst,
idx,
default_value )

#include <zephyr/nvmem.h>

Value:
NVMEM_CELL_GET_BY_IDX_OR(DT_DRV_INST(inst), idx, default_value)
#define NVMEM_CELL_GET_BY_IDX_OR(node_id, idx, default_value)
Get a static initializer for a struct nvmem_cell by index, with a fallback.
Definition nvmem.h:288

Get a static initializer for a struct nvmem_cell from a DT_DRV_COMPAT instance by index, with a fallback.

Parameters
instDT_DRV_COMPAT instance number.
idxLogical index into 'nvmem-cells' property.
default_valueFallback value to expand to.
Returns
Static initializer for a struct nvmem_cell for the property, or default_value if the node or property do not exist.
See also
NVMEM_CELL_GET_BY_IDX_OR

◆ NVMEM_CELL_INST_GET_BY_NAME

#define NVMEM_CELL_INST_GET_BY_NAME ( inst,
name )

#include <zephyr/nvmem.h>

Value:

Get a static initializer for a struct nvmem_cell from a DT_DRV_COMPAT instance by name.

Parameters
instDT_DRV_COMPAT instance number.
nameLowercase-and-underscores name of an nvmem-cells element as defined by the node's nvmem-cell-names property.
Returns
Static initializer for a struct nvmem_cell for the property.
See also
NVMEM_CELL_GET_BY_NAME

◆ NVMEM_CELL_INST_GET_BY_NAME_OR

#define NVMEM_CELL_INST_GET_BY_NAME_OR ( inst,
name,
default_value )

#include <zephyr/nvmem.h>

Value:
NVMEM_CELL_GET_BY_NAME_OR(DT_DRV_INST(inst), name, default_value)
#define NVMEM_CELL_GET_BY_NAME_OR(node_id, name, default_value)
Get a static initializer for a struct nvmem_cell by name, with a fallback.
Definition nvmem.h:184

Get a static initializer for a struct nvmem_cell from a DT_DRV_COMPAT instance by name, with a fallback.

Parameters
instDT_DRV_COMPAT instance number.
nameLowercase-and-underscores name of an nvmem-cells element as defined by the node's nvmem-cell-names property.
default_valueFallback value to expand to.
Returns
Static initializer for a struct nvmem_cell for the property, or default_value if the node or property do not exist.
See also
NVMEM_CELL_GET_BY_NAME_OR

Function Documentation

◆ nvmem_cell_is_ready()

bool nvmem_cell_is_ready ( const struct nvmem_cell * cell)
inlinestatic

#include <zephyr/nvmem.h>

Check if an NVMEM cell is ready.

Parameters
cellNVMEM cell to check. May be NULL.
Returns
True if the NVMEM cell is ready for use and false otherwise.

◆ nvmem_cell_read()

int nvmem_cell_read ( const struct nvmem_cell * cell,
void * data,
off_t off,
size_t len )

#include <zephyr/nvmem.h>

Read data from an NVMEM cell.

Parameters
cellNVMEM cell to read from.
[out]dataBuffer to store the read data. Must be at least len bytes.
offOffset within the cell to start reading from, in bytes. Must be less than the cell size.
lenNumber of bytes to read. off + len must not exceed the cell size.
Attention
Available only when the following Kconfig option is enabled: CONFIG_NVMEM.
Return values
-EINVALInvalid offset or length arguments.
-ENODEVThe controller device is not ready.
-ENXIONo runtime device API available.
Returns
The result of the underlying device API call.

◆ nvmem_cell_write()

int nvmem_cell_write ( const struct nvmem_cell * cell,
const void * data,
off_t off,
size_t len )

#include <zephyr/nvmem.h>

Write data to an NVMEM cell.

Parameters
cellNVMEM cell to write to. Must not be read-only.
dataBuffer containing data to write. Must be at least len bytes.
offOffset within the cell to start writing to, in bytes. Must be less than the cell size.
lenNumber of bytes to write. off + len must not exceed the cell size.
Attention
Available only when the following Kconfig option is enabled: CONFIG_NVMEM.
Return values
-EINVALInvalid offset or length arguments.
-EROFSWriting to a read-only NVMEM Cell.
-ENODEVThe controller device is not ready.
-ENXIONo runtime device API available.
Returns
The result of the underlying device API call.