Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
otp.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 STMicroelectronics
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
11
12#ifndef ZEPHYR_INCLUDE_DRIVERS_OTP_H_
13#define ZEPHYR_INCLUDE_DRIVERS_OTP_H_
14
23
24#include <stddef.h>
25#include <sys/types.h>
26#include <zephyr/device.h>
27#include <zephyr/types.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
37
42typedef int (*otp_api_read)(const struct device *dev, off_t offset, void *data, size_t len);
43
48typedef int (*otp_api_program)(const struct device *dev, off_t offset, const void *data,
49 size_t len);
50
52__subsystem struct otp_driver_api {
55#if defined(CONFIG_OTP_PROGRAM) || defined(__DOXYGEN__)
61#endif
62};
63
67
78__syscall int otp_read(const struct device *dev, off_t offset, void *data, size_t len);
79
80static inline int z_impl_otp_read(const struct device *dev, off_t offset, void *data, size_t len)
81{
82 return DEVICE_API_GET(otp, dev)->read(dev, offset, data, len);
83}
84
85#if defined(CONFIG_OTP_PROGRAM) || defined(__DOXYGEN__)
96__syscall int otp_program(const struct device *dev, off_t offset, const void *data, size_t len);
97
98static inline int z_impl_otp_program(const struct device *dev, off_t offset, const void *data,
99 size_t len)
100{
101 const struct otp_driver_api *api = DEVICE_API_GET(otp, dev);
102
103 if (api->program == NULL) {
104 return -ENOSYS;
105 }
106
107 return api->program(dev, offset, data, len);
108}
109#endif
110
111#ifdef __cplusplus
112}
113#endif
114
118
119#include <zephyr/syscalls/otp.h>
120
121#endif /* ZEPHYR_INCLUDE_DRIVERS_OTP_H_ */
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1353
int(* otp_api_read)(const struct device *dev, off_t offset, void *data, size_t len)
Callback API upon reading from the OTP memory.
Definition otp.h:42
int(* otp_api_program)(const struct device *dev, off_t offset, const void *data, size_t len)
Callback API upon writing to the OTP memory.
Definition otp.h:48
int otp_read(const struct device *dev, off_t offset, void *data, size_t len)
Read data from OTP memory.
int otp_program(const struct device *dev, off_t offset, const void *data, size_t len)
Program data to the given OTP memory.
#define ENOSYS
Function not implemented.
Definition errno.h:82
#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:513
void * data
Address of the device instance private data.
Definition device.h:523
<span class="mlabel">Driver Operations</span> OTP driver operations
Definition otp.h:52
otp_api_read read
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition otp.h:54
otp_api_program program
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition otp.h:60