Zephyr API Documentation 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
nvmem.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 Basalte bv
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
11
12#ifndef ZEPHYR_INCLUDE_NVMEM_H_
13#define ZEPHYR_INCLUDE_NVMEM_H_
14
23
24#include <sys/types.h>
25#include <zephyr/device.h>
26#include <zephyr/devicetree.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
36struct nvmem_cell {
38 const struct device *dev;
42 size_t size;
45};
46
91#define NVMEM_CELL_INIT(node_id) \
92 { \
93 .dev = DEVICE_DT_GET(DT_MTD_FROM_NVMEM_CELL(node_id)), \
94 .offset = DT_REG_ADDR(node_id), \
95 .size = DT_REG_SIZE(node_id), \
96 .read_only = DT_PROP(node_id, read_only), \
97 }
98
150#define NVMEM_CELL_GET_BY_NAME(node_id, name) NVMEM_CELL_INIT(DT_NVMEM_CELL_BY_NAME(node_id, name))
151
164#define NVMEM_CELL_INST_GET_BY_NAME(inst, name) NVMEM_CELL_GET_BY_NAME(DT_DRV_INST(inst), name)
165
184#define NVMEM_CELL_GET_BY_NAME_OR(node_id, name, default_value) \
185 COND_CODE_1(DT_NODE_HAS_PROP(node_id, nvmem_cells), \
186 (NVMEM_CELL_GET_BY_NAME(node_id, name)), \
187 (default_value))
188
203#define NVMEM_CELL_INST_GET_BY_NAME_OR(inst, name, default_value) \
204 NVMEM_CELL_GET_BY_NAME_OR(DT_DRV_INST(inst), name, default_value)
205
256#define NVMEM_CELL_GET_BY_IDX(node_id, idx) NVMEM_CELL_INIT(DT_NVMEM_CELL_BY_IDX(node_id, idx))
257
269#define NVMEM_CELL_INST_GET_BY_IDX(inst, idx) NVMEM_CELL_GET_BY_IDX(DT_DRV_INST(inst), idx)
270
288#define NVMEM_CELL_GET_BY_IDX_OR(node_id, idx, default_value) \
289 COND_CODE_1(DT_NODE_HAS_PROP(node_id, nvmem_cells), \
290 (NVMEM_CELL_GET_BY_IDX(node_id, idx)), \
291 (default_value))
292
306#define NVMEM_CELL_INST_GET_BY_IDX_OR(inst, idx, default_value) \
307 NVMEM_CELL_GET_BY_IDX_OR(DT_DRV_INST(inst), idx, default_value)
308
321int nvmem_cell_read(const struct nvmem_cell *cell, void *data, off_t off, size_t len);
322
335int nvmem_cell_write(const struct nvmem_cell *cell, const void *data, off_t off, size_t len);
336
344static inline bool nvmem_cell_is_ready(const struct nvmem_cell *cell)
345{
346 return cell != NULL && device_is_ready(cell->dev);
347}
348
349#ifdef __cplusplus
350}
351#endif
352
356
357#endif /* ZEPHYR_INCLUDE_NVMEM_H_ */
irp nz macro MOVR cc s mov cc s endm endr irp aw macro LDR aa off
Definition asm-macro-32-bit-gnu.h:17
NVMEM Devicetree public API header file.
Devicetree main header.
bool device_is_ready(const struct device *dev)
Verify that a device is ready for use.
int nvmem_cell_read(const struct nvmem_cell *cell, void *data, off_t off, size_t len)
Read data from an NVMEM cell.
static bool nvmem_cell_is_ready(const struct nvmem_cell *cell)
Validate that the NVMEM cell is ready.
Definition nvmem.h:344
int nvmem_cell_write(const struct nvmem_cell *cell, const void *data, off_t off, size_t len)
Write data to an NVMEM cell.
#define NULL
Definition iar_missing_defs.h:20
__INTPTR_TYPE__ off_t
Definition types.h:36
Runtime device structure (in ROM) per driver instance.
Definition device.h:510
void * data
Address of the device instance private data.
Definition device.h:520
Non-Volatile Memory cell representation.
Definition nvmem.h:36
size_t size
Size of the NVMEM cell.
Definition nvmem.h:42
const struct device * dev
NVMEM parent controller device instance.
Definition nvmem.h:38
bool read_only
Indicator if the NVMEM cell is read-write or read-only.
Definition nvmem.h:44
off_t offset
Offset of the NVMEM cell relative to the parent controller's base address.
Definition nvmem.h:40