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
38
43typedef int (*otp_api_read)(const struct device *dev, off_t offset, void *data, size_t len);
44
49typedef int (*otp_api_program)(const struct device *dev, off_t offset, const void *data,
50 size_t len);
51
52__subsystem struct otp_driver_api {
53 otp_api_read read;
54#if defined(CONFIG_OTP_PROGRAM) || defined(__DOXYGEN__)
55 otp_api_program program;
56#endif
57};
58
60
71__syscall int otp_read(const struct device *dev, off_t offset, void *data, size_t len);
72
73static inline int z_impl_otp_read(const struct device *dev, off_t offset, void *data, size_t len)
74{
75 return DEVICE_API_GET(otp, dev)->read(dev, offset, data, len);
76}
77
78#if defined(CONFIG_OTP_PROGRAM) || defined(__DOXYGEN__)
89__syscall int otp_program(const struct device *dev, off_t offset, const void *data, size_t len);
90
91static inline int z_impl_otp_program(const struct device *dev, off_t offset, const void *data,
92 size_t len)
93{
94 const struct otp_driver_api *api = DEVICE_API_GET(otp, dev);
95
96 if (api->program == NULL) {
97 return -ENOSYS;
98 }
99
100 return api->program(dev, offset, data, len);
101}
102#endif
103
104#ifdef __cplusplus
105}
106#endif
107
111
112#include <zephyr/syscalls/otp.h>
113
114#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_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