Skip to content

Commit 45ac7ed

Browse files
committed
doc: services: Add NVMEM subsystem
Introduce a page for the Non-Volatile Memory subsystem with a reference to the doxygen API. Signed-off-by: Pieter De Gendt <[email protected]>
1 parent f2aa04c commit 45ac7ed

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed

doc/services/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ OS Services
2424
resource_management/index.rst
2525
mem_mgmt/index.rst
2626
net_buf/index.rst
27+
nvmem/index.rst
2728
modem/index.rst
2829
notify.rst
2930
pm/index.rst
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
&eeprom0 {
2+
nvmem-layout {
3+
compatible = "fixed-layout";
4+
#address-cells = <1>;
5+
#size-cells = <1>;
6+
7+
mac_address: mac_address@0 {
8+
reg = <0x0 6>;
9+
#nvmem-cell-cells = <0>;
10+
read-only;
11+
};
12+
13+
calibration_data: calibration_data@6 {
14+
reg = <0x6 100>;
15+
#nvmem-cell-cells = <0>;
16+
};
17+
};
18+
};

doc/services/nvmem/index.rst

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
.. _nvmem:
2+
3+
Non-Volatile Memory (NVMEM)
4+
###########################
5+
6+
The NVMEM subsystem provides a generic interface for accessing non-volatile
7+
memory devices. It abstracts the underlying hardware and provides a unified API
8+
for reading and writing data.
9+
10+
Key Concepts
11+
************
12+
13+
NVMEM Provider
14+
==============
15+
16+
An NVMEM provider is a driver that exposes NVMEM cells. For example, an EEPROM
17+
driver can be an NVMEM provider. The NVMEM provider is responsible for reading
18+
and writing data to the underlying hardware.
19+
20+
NVMEM Cell
21+
==========
22+
23+
An NVMEM cell is a region of non-volatile memory. It is defined in the
24+
devicetree and has properties like offset, size, and read-only status.
25+
26+
NVMEM Consumer
27+
==============
28+
29+
An NVMEM consumer is a driver or application that uses NVMEM cells to store or
30+
retrieve data.
31+
32+
Configuration
33+
*************
34+
35+
* :kconfig:option:`CONFIG_NVMEM`: Enables the NVMEM subsystem.
36+
* :kconfig:option:`CONFIG_NVMEM_EEPROM`: Enables NVMEM support for EEPROM devices.
37+
38+
Devicetree Bindings
39+
*******************
40+
41+
The NVMEM subsystem relies on devicetree bindings to define NVMEM cells.
42+
The following is an example of how to define an NVMEM provider and cells in the
43+
devicetree:
44+
45+
.. literalinclude:: devicetree_bindings.txt
46+
:language: dts
47+
48+
49+
A consumer can then reference the NVMEM cells like this:
50+
51+
.. literalinclude:: my_consumer.txt
52+
:language: dts
53+
54+
55+
Usage Example
56+
*************
57+
58+
The following is an example of how to use the NVMEM API to read data from an
59+
NVMEM cell:
60+
61+
.. literalinclude:: usage_example.txt
62+
:language: c
63+
64+
65+
API Reference
66+
*************
67+
68+
.. doxygengroup:: nvmem_interface

doc/services/nvmem/my_consumer.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
my_consumer: my-consumer {
2+
compatible = "my,consumer";
3+
nvmem-cells = <&mac_address>, <&calibration_data>;
4+
nvmem-cell-names = "mac-address", "calibration-data";
5+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <zephyr/nvmem.h>
2+
3+
static const struct nvmem_cell mac_address =
4+
NVMEM_CELL_GET_BY_NAME(DT_NODELABEL(my_consumer), mac_address);
5+
6+
int main(void)
7+
{
8+
uint8_t mac[6];
9+
int ret;
10+
11+
if (!nvmem_cell_is_ready(&mac_address)) {
12+
printk("NVMEM cell is not ready\n");
13+
return -ENODEV;
14+
}
15+
16+
ret = nvmem_cell_read(&mac_address, mac, 0, sizeof(mac));
17+
if (ret < 0) {
18+
printk("Failed to read MAC address: %d\n", ret);
19+
return ret;
20+
}
21+
22+
/* ... */
23+
}

0 commit comments

Comments
 (0)