Zephyr API Documentation  3.7.0
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
93#define RESET_DT_SPEC_GET_BY_IDX_OR(node_id, idx, default_value) \
94 COND_CODE_1(DT_NODE_HAS_PROP(node_id, resets), \
95 (RESET_DT_SPEC_GET_BY_IDX(node_id, idx)), \
96 (default_value))
97
105#define RESET_DT_SPEC_GET(node_id) \
106 RESET_DT_SPEC_GET_BY_IDX(node_id, 0)
107
117#define RESET_DT_SPEC_GET_OR(node_id, default_value) \
118 RESET_DT_SPEC_GET_BY_IDX_OR(node_id, 0, default_value)
119
129#define RESET_DT_SPEC_INST_GET_BY_IDX(inst, idx) \
130 RESET_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), idx)
131
142#define RESET_DT_SPEC_INST_GET_BY_IDX_OR(inst, idx, default_value) \
143 COND_CODE_1(DT_PROP_HAS_IDX(DT_DRV_INST(inst), resets, idx), \
144 (RESET_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), idx)), \
145 (default_value))
146
154#define RESET_DT_SPEC_INST_GET(inst) \
155 RESET_DT_SPEC_INST_GET_BY_IDX(inst, 0)
156
166#define RESET_DT_SPEC_INST_GET_OR(inst, default_value) \
167 RESET_DT_SPEC_INST_GET_BY_IDX_OR(inst, 0, default_value)
168
176typedef int (*reset_api_status)(const struct device *dev, uint32_t id, uint8_t *status);
177
183typedef int (*reset_api_line_assert)(const struct device *dev, uint32_t id);
184
190typedef int (*reset_api_line_deassert)(const struct device *dev, uint32_t id);
191
197typedef int (*reset_api_line_toggle)(const struct device *dev, uint32_t id);
198
202__subsystem struct reset_driver_api {
203 reset_api_status status;
204 reset_api_line_assert line_assert;
205 reset_api_line_deassert line_deassert;
206 reset_api_line_toggle line_toggle;
207};
208
224__syscall int reset_status(const struct device *dev, uint32_t id, uint8_t *status);
225
226static inline int z_impl_reset_status(const struct device *dev, uint32_t id, uint8_t *status)
227{
228 const struct reset_driver_api *api = (const struct reset_driver_api *)dev->api;
229
230 if (api->status == NULL) {
231 return -ENOSYS;
232 }
233
234 return api->status(dev, id, status);
235}
236
249static inline int reset_status_dt(const struct reset_dt_spec *spec, uint8_t *status)
250{
251 return reset_status(spec->dev, spec->id, status);
252}
253
267__syscall int reset_line_assert(const struct device *dev, uint32_t id);
268
269static inline int z_impl_reset_line_assert(const struct device *dev, uint32_t id)
270{
271 const struct reset_driver_api *api = (const struct reset_driver_api *)dev->api;
272
273 if (api->line_assert == NULL) {
274 return -ENOSYS;
275 }
276
277 return api->line_assert(dev, id);
278}
279
291static inline int reset_line_assert_dt(const struct reset_dt_spec *spec)
292{
293 return reset_line_assert(spec->dev, spec->id);
294}
295
309__syscall int reset_line_deassert(const struct device *dev, uint32_t id);
310
311static inline int z_impl_reset_line_deassert(const struct device *dev, uint32_t id)
312{
313 const struct reset_driver_api *api = (const struct reset_driver_api *)dev->api;
314
315 if (api->line_deassert == NULL) {
316 return -ENOSYS;
317 }
318
319 return api->line_deassert(dev, id);
320}
321
333static inline int reset_line_deassert_dt(const struct reset_dt_spec *spec)
334{
335 return reset_line_deassert(spec->dev, spec->id);
336}
337
350__syscall int reset_line_toggle(const struct device *dev, uint32_t id);
351
352static inline int z_impl_reset_line_toggle(const struct device *dev, uint32_t id)
353{
354 const struct reset_driver_api *api = (const struct reset_driver_api *)dev->api;
355
356 if (api->line_toggle == NULL) {
357 return -ENOSYS;
358 }
359
360 return api->line_toggle(dev, id);
361}
362
374static inline int reset_line_toggle_dt(const struct reset_dt_spec *spec)
375{
376 return reset_line_toggle(spec->dev, spec->id);
377}
378
383#ifdef __cplusplus
384}
385#endif
386
387#include <zephyr/syscalls/reset.h>
388
389#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:333
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:249
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:291
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:374
#define ENOSYS
Function not implemented.
Definition: errno.h:82
__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:403
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:409
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