esp-sdr-zephyr
Raw I/Q receive and transmit on the ESP32-S3/C6 Wi-Fi radio, for Zephyr
Loading...
Searching...
No Matches
znp_nv.h
1
/*
2
* SPDX-License-Identifier: GPL-3.0-or-later
3
*
4
* The ZNP non-volatile item store: Z-Stack's OSAL NV (16-bit id) and the extended NV
5
* (system, item, sub id) as one key space, items of fixed length created by the host.
6
* RAM copy in a pool; changes are written through a backend by znp_nv_flush(), which
7
* the application calls some time after the last change.
8
*/
9
#ifndef ZIGBEE_ZNP_NV_H_
10
#define ZIGBEE_ZNP_NV_H_
11
12
#include <stdbool.h>
13
#include <stdint.h>
14
15
#include <zephyr/kernel.h>
16
17
#define ZNP_NV_SYS_ZSTACK 1
18
/* Extended NV item id under which OSAL NV ids are kept (the id is the sub id). */
19
#define ZNP_NV_ITEM_LEGACY 0
20
21
struct
znp_nv_key
{
22
uint8_t sys;
23
uint16_t item;
24
uint16_t sub;
25
};
26
27
static
inline
struct
znp_nv_key
znp_nv_osal(uint16_t id)
28
{
29
return
(
struct
znp_nv_key
){.sys = ZNP_NV_SYS_ZSTACK, .item = ZNP_NV_ITEM_LEGACY, .sub =
id
};
30
}
31
32
struct
znp_nv_backend
{
33
/* Store one slot (len > 0) or erase it (len == 0); 0 on success. */
34
int (*store)(
void
*ctx, uint16_t slot,
const
struct
znp_nv_key
*key,
const
void
*data,
35
uint16_t len);
36
void
*ctx;
37
};
38
39
struct
znp_nv_item
{
40
struct
znp_nv_key
key;
41
uint16_t len;
42
uint16_t off;
43
bool
used;
44
bool
dirty;
45
};
46
47
struct
znp_nv
{
48
struct
znp_nv_item
items[CONFIG_ZNP_NV_ITEMS];
49
uint8_t pool[CONFIG_ZNP_NV_POOL_SIZE];
50
uint16_t pool_used;
51
struct
znp_nv_backend
be;
52
struct
k_mutex lock;
53
};
54
55
void
znp_nv_init(
struct
znp_nv
*nv,
const
struct
znp_nv_backend
*be);
56
57
/* Length of an item, 0 when it does not exist. */
58
uint16_t znp_nv_len(
struct
znp_nv
*nv,
struct
znp_nv_key
key);
59
60
/* Create an item of @p len bytes, zero filled but for @p init_len bytes of @p init. */
61
int
znp_nv_create(
struct
znp_nv
*nv,
struct
znp_nv_key
key, uint16_t len,
const
void
*init,
62
uint16_t init_len);
63
64
/* Copy up to @p n bytes from @p off; returns the count (0 at the end) or a -errno. */
65
int
znp_nv_read(
struct
znp_nv
*nv,
struct
znp_nv_key
key, uint16_t off,
void
*buf, uint16_t n);
66
67
/* Overwrite @p n bytes at @p off; -ENOENT, or -EINVAL when it runs past the item. */
68
int
znp_nv_write(
struct
znp_nv
*nv,
struct
znp_nv_key
key, uint16_t off,
const
void
*buf,
69
uint16_t n);
70
71
int
znp_nv_delete(
struct
znp_nv
*nv,
struct
znp_nv_key
key);
72
73
/* Create-or-replace the whole item (for the stack's own state); marks it dirty. */
74
int
znp_nv_set(
struct
znp_nv
*nv,
struct
znp_nv_key
key,
const
void
*data, uint16_t len);
75
76
/* Load a stored slot at boot (does not mark dirty); the slot number is kept. */
77
int
znp_nv_restore(
struct
znp_nv
*nv, uint16_t slot,
struct
znp_nv_key
key,
const
void
*data,
78
uint16_t len);
79
80
/* Push changed slots to the backend; returns the first backend error or 0. */
81
int
znp_nv_flush(
struct
znp_nv
*nv);
82
83
/* Items that need a flush. */
84
bool
znp_nv_dirty(
struct
znp_nv
*nv);
85
86
#endif
/* ZIGBEE_ZNP_NV_H_ */
znp_nv_backend
Definition
znp_nv.h:32
znp_nv_item
Definition
znp_nv.h:39
znp_nv_key
Definition
znp_nv.h:21
znp_nv
Definition
znp_nv.h:47
zigbee
znp_nv.h
Generated by
1.15.0