Zephyr Project API 4.4.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
13#ifndef ZEPHYR_INCLUDE_DRIVERS_RESET_H_
14#define ZEPHYR_INCLUDE_DRIVERS_RESET_H_
15
24
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
175
181typedef int (*reset_api_status)(const struct device *dev, uint32_t id, uint8_t *status);
182
188typedef int (*reset_api_line_assert)(const struct device *dev, uint32_t id);
189
195typedef int (*reset_api_line_deassert)(const struct device *dev, uint32_t id);
196
202typedef int (*reset_api_line_toggle)(const struct device *dev, uint32_t id);
203
217
219
233__syscall int reset_status(const struct device *dev, uint32_t id, uint8_t *status);
234
235static inline int z_impl_reset_status(const struct device *dev, uint32_t id, uint8_t *status)
236{
237 const struct reset_driver_api *api = DEVICE_API_GET(reset, dev);
238
239 if (api->status == NULL) {
240 return -ENOSYS;
241 }
242
243 return api->status(dev, id, status);
244}
245
258static inline int reset_status_dt(const struct reset_dt_spec *spec, uint8_t *status)
259{
260 return reset_status(spec->dev, spec->id, status);
261}
262
276__syscall int reset_line_assert(const struct device *dev, uint32_t id);
277
278static inline int z_impl_reset_line_assert(const struct device *dev, uint32_t id)
279{
280 const struct reset_driver_api *api = DEVICE_API_GET(reset, dev);
281
282 if (api->line_assert == NULL) {
283 return -ENOSYS;
284 }
285
286 return api->line_assert(dev, id);
287}
288
300static inline int reset_line_assert_dt(const struct reset_dt_spec *spec)
301{
302 return reset_line_assert(spec->dev, spec->id);
303}
304
318__syscall int reset_line_deassert(const struct device *dev, uint32_t id);
319
320static inline int z_impl_reset_line_deassert(const struct device *dev, uint32_t id)
321{
322 const struct reset_driver_api *api = DEVICE_API_GET(reset, dev);
323
324 if (api->line_deassert == NULL) {
325 return -ENOSYS;
326 }
327
328 return api->line_deassert(dev, id);
329}
330
342static inline int reset_line_deassert_dt(const struct reset_dt_spec *spec)
343{
344 return reset_line_deassert(spec->dev, spec->id);
345}
346
359__syscall int reset_line_toggle(const struct device *dev, uint32_t id);
360
361static inline int z_impl_reset_line_toggle(const struct device *dev, uint32_t id)
362{
363 const struct reset_driver_api *api = DEVICE_API_GET(reset, dev);
364
365 if (api->line_toggle == NULL) {
366 return -ENOSYS;
367 }
368
369 return api->line_toggle(dev, id);
370}
371
383static inline int reset_line_toggle_dt(const struct reset_dt_spec *spec)
384{
385 return reset_line_toggle(spec->dev, spec->id);
386}
387
391
392#ifdef __cplusplus
393}
394#endif
395
396#include <zephyr/syscalls/reset.h>
397
398#endif /* ZEPHYR_INCLUDE_DRIVERS_RESET_H_ */
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1425
System error numbers.
int(* reset_api_line_toggle)(const struct device *dev, uint32_t id)
API template to reset the device.
Definition reset.h:202
int reset_line_toggle(const struct device *dev, uint32_t id)
Reset the device.
int(* reset_api_status)(const struct device *dev, uint32_t id, uint8_t *status)
@def_driverbackendgroup{Reset Controller,reset_controller_interface}
Definition reset.h:181
int(* reset_api_line_deassert)(const struct device *dev, uint32_t id)
API template to take out the device from reset state.
Definition reset.h:195
static int reset_line_deassert_dt(const struct reset_dt_spec *spec)
Deassert the reset state from a reset_dt_spec.
Definition reset.h:342
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:258
int(* reset_api_line_assert)(const struct device *dev, uint32_t id)
API template to put the device in reset state.
Definition reset.h:188
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:300
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:383
#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:513
@driver_ops{Reset Controller}
Definition reset.h:207
reset_api_line_toggle line_toggle
@driver_ops_optional API template to reset the device.
Definition reset.h:215
reset_api_line_deassert line_deassert
@driver_ops_optional API template to take out the device from reset state.
Definition reset.h:213
reset_api_status status
@driver_ops_optional @def_driverbackendgroup{Reset Controller,reset_controller_interface}
Definition reset.h:209
reset_api_line_assert line_assert
@driver_ops_optional API template to put the device in reset state.
Definition reset.h:211
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