Zephyr Project API 4.2.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
13#ifndef ZEPHYR_INCLUDE_DRIVERS_RESET_H_
14#define ZEPHYR_INCLUDE_DRIVERS_RESET_H_
15
25#include <errno.h>
26
27#include <zephyr/types.h>
28#include <zephyr/device.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
37 const struct device *dev;
40};
41
72#define RESET_DT_SPEC_GET_BY_IDX(node_id, idx) \
73 { \
74 .dev = DEVICE_DT_GET(DT_RESET_CTLR_BY_IDX(node_id, idx)), \
75 .id = DT_RESET_ID_BY_IDX(node_id, idx) \
76 }
77
94#define RESET_DT_SPEC_GET_BY_IDX_OR(node_id, idx, default_value) \
95 COND_CODE_1(DT_NODE_HAS_PROP(node_id, resets), \
96 (RESET_DT_SPEC_GET_BY_IDX(node_id, idx)), \
97 (default_value))
98
106#define RESET_DT_SPEC_GET(node_id) \
107 RESET_DT_SPEC_GET_BY_IDX(node_id, 0)
108
118#define RESET_DT_SPEC_GET_OR(node_id, default_value) \
119 RESET_DT_SPEC_GET_BY_IDX_OR(node_id, 0, default_value)
120
130#define RESET_DT_SPEC_INST_GET_BY_IDX(inst, idx) \
131 RESET_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), idx)
132
143#define RESET_DT_SPEC_INST_GET_BY_IDX_OR(inst, idx, default_value) \
144 COND_CODE_1(DT_PROP_HAS_IDX(DT_DRV_INST(inst), resets, idx), \
145 (RESET_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), idx)), \
146 (default_value))
147
155#define RESET_DT_SPEC_INST_GET(inst) \
156 RESET_DT_SPEC_INST_GET_BY_IDX(inst, 0)
157
167#define RESET_DT_SPEC_INST_GET_OR(inst, default_value) \
168 RESET_DT_SPEC_INST_GET_BY_IDX_OR(inst, 0, default_value)
169
177typedef int (*reset_api_status)(const struct device *dev, uint32_t id, uint8_t *status);
178
184typedef int (*reset_api_line_assert)(const struct device *dev, uint32_t id);
185
191typedef int (*reset_api_line_deassert)(const struct device *dev, uint32_t id);
192
198typedef int (*reset_api_line_toggle)(const struct device *dev, uint32_t id);
199
203__subsystem struct reset_driver_api {
204 reset_api_status status;
205 reset_api_line_assert line_assert;
206 reset_api_line_deassert line_deassert;
207 reset_api_line_toggle line_toggle;
208};
209
225__syscall int reset_status(const struct device *dev, uint32_t id, uint8_t *status);
226
227static inline int z_impl_reset_status(const struct device *dev, uint32_t id, uint8_t *status)
228{
229 const struct reset_driver_api *api = (const struct reset_driver_api *)dev->api;
230
231 if (api->status == NULL) {
232 return -ENOSYS;
233 }
234
235 return api->status(dev, id, status);
236}
237
250static inline int reset_status_dt(const struct reset_dt_spec *spec, uint8_t *status)
251{
252 return reset_status(spec->dev, spec->id, status);
253}
254
268__syscall int reset_line_assert(const struct device *dev, uint32_t id);
269
270static inline int z_impl_reset_line_assert(const struct device *dev, uint32_t id)
271{
272 const struct reset_driver_api *api = (const struct reset_driver_api *)dev->api;
273
274 if (api->line_assert == NULL) {
275 return -ENOSYS;
276 }
277
278 return api->line_assert(dev, id);
279}
280
292static inline int reset_line_assert_dt(const struct reset_dt_spec *spec)
293{
294 return reset_line_assert(spec->dev, spec->id);
295}
296
310__syscall int reset_line_deassert(const struct device *dev, uint32_t id);
311
312static inline int z_impl_reset_line_deassert(const struct device *dev, uint32_t id)
313{
314 const struct reset_driver_api *api = (const struct reset_driver_api *)dev->api;
315
316 if (api->line_deassert == NULL) {
317 return -ENOSYS;
318 }
319
320 return api->line_deassert(dev, id);
321}
322
334static inline int reset_line_deassert_dt(const struct reset_dt_spec *spec)
335{
336 return reset_line_deassert(spec->dev, spec->id);
337}
338
351__syscall int reset_line_toggle(const struct device *dev, uint32_t id);
352
353static inline int z_impl_reset_line_toggle(const struct device *dev, uint32_t id)
354{
355 const struct reset_driver_api *api = (const struct reset_driver_api *)dev->api;
356
357 if (api->line_toggle == NULL) {
358 return -ENOSYS;
359 }
360
361 return api->line_toggle(dev, id);
362}
363
375static inline int reset_line_toggle_dt(const struct reset_dt_spec *spec)
376{
377 return reset_line_toggle(spec->dev, spec->id);
378}
379
384#ifdef __cplusplus
385}
386#endif
387
388#include <zephyr/syscalls/reset.h>
389
390#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:334
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:250
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:292
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:375
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define NULL
Definition iar_missing_defs.h:20
__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:510
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:516
Reset controller device configuration.
Definition reset.h:35
const struct device * dev
Reset controller device.
Definition reset.h:37
uint32_t id
Reset line.
Definition reset.h:39