Line data Source code
1 1 : /*
2 : * Copyright (c) 2019 Vestas Wind Systems A/S
3 : *
4 : * Heavily based on drivers/flash.h which is:
5 : * Copyright (c) 2017 Nordic Semiconductor ASA
6 : * Copyright (c) 2016 Intel Corporation
7 : *
8 : * SPDX-License-Identifier: Apache-2.0
9 : */
10 :
11 : /**
12 : * @file
13 : * @ingroup eeprom_interface
14 : * @brief Main header file for EEPROM driver API.
15 : */
16 :
17 : #ifndef ZEPHYR_INCLUDE_DRIVERS_EEPROM_H_
18 : #define ZEPHYR_INCLUDE_DRIVERS_EEPROM_H_
19 :
20 : /**
21 : * @brief Interfaces for Electrically Erasable Programmable Read-Only Memory (EEPROM).
22 : * @defgroup eeprom_interface EEPROM
23 : * @since 2.1
24 : * @version 1.0.0
25 : * @ingroup io_interfaces
26 : * @{
27 : */
28 :
29 : #include <zephyr/types.h>
30 : #include <stddef.h>
31 : #include <sys/types.h>
32 : #include <zephyr/device.h>
33 :
34 : #ifdef __cplusplus
35 : extern "C" {
36 : #endif
37 :
38 : /**
39 : * @cond INTERNAL_HIDDEN
40 : *
41 : * For internal driver use only, skip these in public documentation.
42 : */
43 :
44 : /**
45 : * @brief Callback API upon reading from the EEPROM.
46 : * See @a eeprom_read() for argument description
47 : */
48 : typedef int (*eeprom_api_read)(const struct device *dev, off_t offset,
49 : void *data,
50 : size_t len);
51 :
52 : /**
53 : * @brief Callback API upon writing to the EEPROM.
54 : * See @a eeprom_write() for argument description
55 : */
56 : typedef int (*eeprom_api_write)(const struct device *dev, off_t offset,
57 : const void *data, size_t len);
58 :
59 : /**
60 : * @brief Callback API upon getting the EEPROM size.
61 : * See @a eeprom_get_size() for argument description
62 : */
63 : typedef size_t (*eeprom_api_size)(const struct device *dev);
64 :
65 : __subsystem struct eeprom_driver_api {
66 : eeprom_api_read read;
67 : eeprom_api_write write;
68 : eeprom_api_size size;
69 : };
70 :
71 : /** @endcond */
72 :
73 : /**
74 : * @brief Read data from EEPROM
75 : *
76 : * @param dev EEPROM device
77 : * @param offset Address offset to read from.
78 : * @param data Buffer to store read data.
79 : * @param len Number of bytes to read.
80 : *
81 : * @return 0 on success, negative errno code on failure.
82 : */
83 1 : __syscall int eeprom_read(const struct device *dev, off_t offset, void *data,
84 : size_t len);
85 :
86 : static inline int z_impl_eeprom_read(const struct device *dev, off_t offset,
87 : void *data, size_t len)
88 : {
89 : const struct eeprom_driver_api *api =
90 : (const struct eeprom_driver_api *)dev->api;
91 :
92 : return api->read(dev, offset, data, len);
93 : }
94 :
95 : /**
96 : * @brief Write data to EEPROM
97 : *
98 : * @param dev EEPROM device
99 : * @param offset Address offset to write data to.
100 : * @param data Buffer with data to write.
101 : * @param len Number of bytes to write.
102 : *
103 : * @return 0 on success, negative errno code on failure.
104 : */
105 1 : __syscall int eeprom_write(const struct device *dev, off_t offset,
106 : const void *data,
107 : size_t len);
108 :
109 : static inline int z_impl_eeprom_write(const struct device *dev, off_t offset,
110 : const void *data, size_t len)
111 : {
112 : const struct eeprom_driver_api *api =
113 : (const struct eeprom_driver_api *)dev->api;
114 :
115 : return api->write(dev, offset, data, len);
116 : }
117 :
118 : /**
119 : * @brief Get the size of the EEPROM in bytes
120 : *
121 : * @param dev EEPROM device.
122 : *
123 : * @return EEPROM size in bytes.
124 : */
125 1 : __syscall size_t eeprom_get_size(const struct device *dev);
126 :
127 : static inline size_t z_impl_eeprom_get_size(const struct device *dev)
128 : {
129 : const struct eeprom_driver_api *api =
130 : (const struct eeprom_driver_api *)dev->api;
131 :
132 : return api->size(dev);
133 : }
134 :
135 : #ifdef __cplusplus
136 : }
137 : #endif
138 :
139 : /**
140 : * @}
141 : */
142 :
143 : #include <zephyr/syscalls/eeprom.h>
144 :
145 : #endif /* ZEPHYR_INCLUDE_DRIVERS_EEPROM_H_ */
|