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

Interfaces for NVMEM cells. More...

Files

file  nvmem.h
 Main header file for NVMEM API.

Data Structures

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

Macros

#define NVMEM_CELL_INIT(node_id)
 Static initializer for a struct nvmem_cell.
#define NVMEM_CELL_GET_BY_NAME(node_id, name)
 Static initializer for a struct nvmem_cell.
#define NVMEM_CELL_INST_GET_BY_NAME(inst, name)
 Static initializer for a struct nvmem_cell from a DT_DRV_COMPAT instance.
#define NVMEM_CELL_GET_BY_NAME_OR(node_id, name, default_value)
 Like NVMEM_CELL_GET_BY_NAME(), with a fallback to a default value.
#define NVMEM_CELL_INST_GET_BY_NAME_OR(inst, name, default_value)
 Like NVMEM_CELL_INST_GET_BY_NAME(), with a fallback to a default value.
#define NVMEM_CELL_GET_BY_IDX(node_id, idx)
 Static initializer for a struct nvmem_cell.
#define NVMEM_CELL_INST_GET_BY_IDX(inst, idx)
 Static initializer for a struct nvmem_cell from a DT_DRV_COMPAT instance.
#define NVMEM_CELL_GET_BY_IDX_OR(node_id, idx, default_value)
 Like NVMEM_CELL_GET_BY_IDX(), with a fallback to a default value.
#define NVMEM_CELL_INST_GET_BY_IDX_OR(inst, idx, default_value)
 Like NVMEM_CELL_INST_GET_BY_IDX(), with a fallback to a default value.

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)
 Validate that the NVMEM cell is ready.

Detailed Description

Interfaces for NVMEM 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:144
#define NVMEM_CELL_INIT(node_id)
Static initializer for a struct nvmem_cell.
Definition nvmem.h:91

Static initializer for a struct nvmem_cell.

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:196
#define NVMEM_CELL_GET_BY_IDX(node_id, idx)
Static initializer for a struct nvmem_cell.
Definition nvmem.h:256
Non-Volatile Memory cell representation.
Definition nvmem.h:36
Parameters
node_idDevicetree node identifier.
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_NODE_HAS_PROP(node_id, nvmem_cells), \
(NVMEM_CELL_GET_BY_IDX(node_id, idx)), \
(default_value))
#define DT_NODE_HAS_PROP(node_id, prop)
Does a devicetree node have a property?
Definition devicetree.h:3784
#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

Like NVMEM_CELL_GET_BY_IDX(), with a fallback to a default value.

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_idDevicetree node identifier.
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:195

Static initializer for a struct nvmem_cell.

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)
Static initializer for a struct nvmem_cell.
Definition nvmem.h:150
Parameters
node_idDevicetree node identifier.
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_NODE_HAS_PROP(node_id, nvmem_cells), \
(NVMEM_CELL_GET_BY_NAME(node_id, name)), \
(default_value))

Like NVMEM_CELL_GET_BY_NAME(), with a fallback to a default value.

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_idDevicetree node identifier.
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:314
#define DT_PROP(node_id, prop)
Get a devicetree property value.
Definition devicetree.h:762
#define DT_MTD_FROM_NVMEM_CELL(node_id)
Get the node identifier of the memory controller for an nvmem cell.
Definition nvmem.h:303
#define DT_REG_ADDR(node_id)
Get a node's (only) register block address.
Definition devicetree.h:2461
#define DT_REG_SIZE(node_id)
Get a node's (only) register block size.
Definition devicetree.h:2482

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_idDevicetree node identifier.
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:4037

Static initializer for a struct nvmem_cell from a DT_DRV_COMPAT instance.

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)
Like NVMEM_CELL_GET_BY_IDX(), with a fallback to a default value.
Definition nvmem.h:288

Like NVMEM_CELL_INST_GET_BY_IDX(), with a fallback to a default value.

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:

Static initializer for a struct nvmem_cell from a DT_DRV_COMPAT instance.

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)
Like NVMEM_CELL_GET_BY_NAME(), with a fallback to a default value.
Definition nvmem.h:184

Like NVMEM_CELL_INST_GET_BY_NAME(), with a fallback to a default value.

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>

Validate that the NVMEM cell is ready.

Parameters
cellThe NVMEM cell.
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
cellThe NVMEM cell.
dataBuffer to store read data.
offThe offset to start reading from.
lenNumber of bytes to read.
Attention
Available only when the following Kconfig option is enabled: CONFIG_NVMEM.
Returns
0 on success, negative errno code on failure.

◆ 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
cellThe NVMEM cell.
dataBuffer with data to write.
offThe offset to start writing to.
lenNumber of bytes to write.
Attention
Available only when the following Kconfig option is enabled: CONFIG_NVMEM.
Returns
0 on success, negative errno code on failure.