Zephyr API Documentation  3.6.0
A Scalable Open Source RTOS
3.6.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
eeprom.h
Go to the documentation of this file.
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
16#ifndef ZEPHYR_INCLUDE_DRIVERS_EEPROM_H_
17#define ZEPHYR_INCLUDE_DRIVERS_EEPROM_H_
18
26#include <zephyr/types.h>
27#include <stddef.h>
28#include <sys/types.h>
29#include <zephyr/device.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
45typedef int (*eeprom_api_read)(const struct device *dev, off_t offset,
46 void *data,
47 size_t len);
48
53typedef int (*eeprom_api_write)(const struct device *dev, off_t offset,
54 const void *data, size_t len);
55
60typedef size_t (*eeprom_api_size)(const struct device *dev);
61
62__subsystem struct eeprom_driver_api {
63 eeprom_api_read read;
64 eeprom_api_write write;
65 eeprom_api_size size;
66};
67
80__syscall int eeprom_read(const struct device *dev, off_t offset, void *data,
81 size_t len);
82
83static inline int z_impl_eeprom_read(const struct device *dev, off_t offset,
84 void *data, size_t len)
85{
86 const struct eeprom_driver_api *api =
87 (const struct eeprom_driver_api *)dev->api;
88
89 return api->read(dev, offset, data, len);
90}
91
102__syscall int eeprom_write(const struct device *dev, off_t offset,
103 const void *data,
104 size_t len);
105
106static inline int z_impl_eeprom_write(const struct device *dev, off_t offset,
107 const void *data, size_t len)
108{
109 const struct eeprom_driver_api *api =
110 (const struct eeprom_driver_api *)dev->api;
111
112 return api->write(dev, offset, data, len);
113}
114
122__syscall size_t eeprom_get_size(const struct device *dev);
123
124static inline size_t z_impl_eeprom_get_size(const struct device *dev)
125{
126 const struct eeprom_driver_api *api =
127 (const struct eeprom_driver_api *)dev->api;
128
129 return api->size(dev);
130}
131
132#ifdef __cplusplus
133}
134#endif
135
140#include <syscalls/eeprom.h>
141
142#endif /* ZEPHYR_INCLUDE_DRIVERS_EEPROM_H_ */
int eeprom_write(const struct device *dev, off_t offset, const void *data, size_t len)
Write data to EEPROM.
size_t eeprom_get_size(const struct device *dev)
Get the size of the EEPROM in bytes.
int eeprom_read(const struct device *dev, off_t offset, void *data, size_t len)
Read data from EEPROM.
__INTPTR_TYPE__ off_t
Definition: types.h:36
Size of off_t must be equal or less than size of size_t
Definition: retained_mem.h:28
Runtime device structure (in ROM) per driver instance.
Definition: device.h:387
void * data
Address of the device instance private data.
Definition: device.h:397
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:393