Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
reset.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Andrei-Edward Popa <andrei.popa105@yahoo.com>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12#ifndef ZEPHYR_INCLUDE_DRIVERS_RESET_H_
13#define ZEPHYR_INCLUDE_DRIVERS_RESET_H_
14
24#include <errno.h>
25
26#include <zephyr/types.h>
27#include <zephyr/device.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
36 const struct device *dev;
39};
40
71#define RESET_DT_SPEC_GET_BY_IDX(node_id, idx) \
72 { \
73 .dev = DEVICE_DT_GET(DT_RESET_CTLR_BY_IDX(node_id, idx)), \
74 .id = DT_RESET_ID_BY_IDX(node_id, idx) \
75 }
76
84#define RESET_DT_SPEC_GET(node_id) \
85 RESET_DT_SPEC_GET_BY_IDX(node_id, 0)
86
96#define RESET_DT_SPEC_INST_GET_BY_IDX(inst, idx) \
97 RESET_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), idx)
98
106#define RESET_DT_SPEC_INST_GET(inst) \
107 RESET_DT_SPEC_INST_GET_BY_IDX(inst, 0)
108
116typedef int (*reset_api_status)(const struct device *dev, uint32_t id, uint8_t *status);
117
123typedef int (*reset_api_line_assert)(const struct device *dev, uint32_t id);
124
130typedef int (*reset_api_line_deassert)(const struct device *dev, uint32_t id);
131
137typedef int (*reset_api_line_toggle)(const struct device *dev, uint32_t id);
138
142__subsystem struct reset_driver_api {
143 reset_api_status status;
144 reset_api_line_assert line_assert;
145 reset_api_line_deassert line_deassert;
146 reset_api_line_toggle line_toggle;
147};
148
164__syscall int reset_status(const struct device *dev, uint32_t id, uint8_t *status);
165
166static inline int z_impl_reset_status(const struct device *dev, uint32_t id, uint8_t *status)
167{
168 const struct reset_driver_api *api = (const struct reset_driver_api *)dev->api;
169
170 if (api->status == NULL) {
171 return -ENOSYS;
172 }
173
174 return api->status(dev, id, status);
175}
176
189static inline int reset_status_dt(const struct reset_dt_spec *spec, uint8_t *status)
190{
191 return reset_status(spec->dev, spec->id, status);
192}
193
207__syscall int reset_line_assert(const struct device *dev, uint32_t id);
208
209static inline int z_impl_reset_line_assert(const struct device *dev, uint32_t id)
210{
211 const struct reset_driver_api *api = (const struct reset_driver_api *)dev->api;
212
213 if (api->line_assert == NULL) {
214 return -ENOSYS;
215 }
216
217 return api->line_assert(dev, id);
218}
219
231static inline int reset_line_assert_dt(const struct reset_dt_spec *spec)
232{
233 return reset_line_assert(spec->dev, spec->id);
234}
235
249__syscall int reset_line_deassert(const struct device *dev, uint32_t id);
250
251static inline int z_impl_reset_line_deassert(const struct device *dev, uint32_t id)
252{
253 const struct reset_driver_api *api = (const struct reset_driver_api *)dev->api;
254
255 if (api->line_deassert == NULL) {
256 return -ENOSYS;
257 }
258
259 return api->line_deassert(dev, id);
260}
261
273static inline int reset_line_deassert_dt(const struct reset_dt_spec *spec)
274{
275 return reset_line_deassert(spec->dev, spec->id);
276}
277
290__syscall int reset_line_toggle(const struct device *dev, uint32_t id);
291
292static inline int z_impl_reset_line_toggle(const struct device *dev, uint32_t id)
293{
294 const struct reset_driver_api *api = (const struct reset_driver_api *)dev->api;
295
296 if (api->line_toggle == NULL) {
297 return -ENOSYS;
298 }
299
300 return api->line_toggle(dev, id);
301}
302
314static inline int reset_line_toggle_dt(const struct reset_dt_spec *spec)
315{
316 return reset_line_toggle(spec->dev, spec->id);
317}
318
323#ifdef __cplusplus
324}
325#endif
326
327#include <syscalls/reset.h>
328
329#endif /* ZEPHYR_INCLUDE_DRIVERS_RESET_H_ */
System error numbers.
int reset_line_toggle(const struct device *dev, uint32_t id)
Reset the device.
static int reset_line_deassert_dt(const struct reset_dt_spec *spec)
Deassert the reset state from a reset_dt_spec.
Definition: reset.h:273
static int reset_status_dt(const struct reset_dt_spec *spec, uint8_t *status)
Get the reset status from a reset_dt_spec.
Definition: reset.h:189
int reset_line_deassert(const struct device *dev, uint32_t id)
Take out the device from reset state.
int reset_line_assert(const struct device *dev, uint32_t id)
Put the device in reset state.
static int reset_line_assert_dt(const struct reset_dt_spec *spec)
Assert the reset state from a reset_dt_spec.
Definition: reset.h:231
int reset_status(const struct device *dev, uint32_t id, uint8_t *status)
Get the reset status.
static int reset_line_toggle_dt(const struct reset_dt_spec *spec)
Reset the device from a reset_dt_spec.
Definition: reset.h:314
#define ENOSYS
Function not implemented.
Definition: errno.h:83
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
Runtime device structure (in ROM) per driver instance.
Definition: device.h:399
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:405
Reset controller device configuration.
Definition: reset.h:34
const struct device * dev
Reset controller device.
Definition: reset.h:36
uint32_t id
Reset line.
Definition: reset.h:38