Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
entropy.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 ARM Ltd.
3 * Copyright (c) 2017 Intel Corporation
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
13
14
15 #ifndef ZEPHYR_INCLUDE_DRIVERS_ENTROPY_H_
16#define ZEPHYR_INCLUDE_DRIVERS_ENTROPY_H_
17
26
27#include <errno.h>
28
29#include <zephyr/types.h>
30#include <zephyr/device.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
37#define ENTROPY_BUSYWAIT BIT(0)
38
44
53typedef int (*entropy_get_entropy_t)(const struct device *dev,
54 uint8_t *buffer,
55 uint16_t length);
56
62typedef int (*entropy_get_entropy_isr_t)(const struct device *dev,
63 uint8_t *buffer,
64 uint16_t length,
66
76
78
91static inline const struct device *entropy_get_default_device(void)
92{
93 const struct device *device = DEVICE_DT_GET_OR_NULL(DT_CHOSEN(zephyr_entropy));
94
95#ifdef CONFIG_ARCH_HAS_ENTROPY
96 if (device == NULL) {
97 extern const struct device *const z_arch_entropy_dev;
98
99 device = z_arch_entropy_dev;
100 }
101#endif
102
103 return device;
104}
105
116__syscall int entropy_get_entropy(const struct device *dev,
117 uint8_t *buffer,
118 uint16_t length);
119
120static inline int z_impl_entropy_get_entropy(const struct device *dev,
121 uint8_t *buffer,
122 uint16_t length)
123{
124 const struct entropy_driver_api *api = DEVICE_API_GET(entropy, dev);
125
126 __ASSERT(api->get_entropy != NULL,
127 "Callback pointer should not be NULL");
128 return api->get_entropy(dev, buffer, length);
129}
130
142static inline int entropy_get_entropy_isr(const struct device *dev,
143 uint8_t *buffer,
144 uint16_t length,
146{
147 const struct entropy_driver_api *api = DEVICE_API_GET(entropy, dev);
148
149 if (unlikely(api->get_entropy_isr == NULL)) {
150 return -ENOSYS;
151 }
152
153 return api->get_entropy_isr(dev, buffer, length, flags);
154}
155
156
157#ifdef __cplusplus
158}
159#endif
160
164
165#include <zephyr/syscalls/entropy.h>
166
167#endif /* ZEPHYR_INCLUDE_DRIVERS_ENTROPY_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.
#define DEVICE_DT_GET_OR_NULL(node_id)
Utility macro to obtain an optional reference to a device.
Definition device.h:382
#define DT_CHOSEN(prop)
Get a node identifier for a /chosen node property.
Definition devicetree.h:3099
int(* entropy_get_entropy_t)(const struct device *dev, uint8_t *buffer, uint16_t length)
Callback API to get entropy.
Definition entropy.h:53
int(* entropy_get_entropy_isr_t)(const struct device *dev, uint8_t *buffer, uint16_t length, uint32_t flags)
Callback API to get entropy from an ISR.
Definition entropy.h:62
int entropy_get_entropy(const struct device *dev, uint8_t *buffer, uint16_t length)
Fills a buffer with entropy.
static const struct device * entropy_get_default_device(void)
Return the default entropy device if available.
Definition entropy.h:91
static int entropy_get_entropy_isr(const struct device *dev, uint8_t *buffer, uint16_t length, uint32_t flags)
Fills a buffer with entropy in a non-blocking or busy-wait manner.
Definition entropy.h:142
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define NULL
Definition iar_missing_defs.h:20
flags
Definition parser.h:97
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
<span class="mlabel">Driver Operations</span> Entropy driver operations
Definition entropy.h:70
entropy_get_entropy_t get_entropy
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition entropy.h:72
entropy_get_entropy_isr_t get_entropy_isr
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition entropy.h:74