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
40#define ENTROPY_BUSYWAIT BIT(0)
41
47
56typedef int (*entropy_get_entropy_t)(const struct device *dev,
57 uint8_t *buffer,
58 uint16_t length);
59
65typedef int (*entropy_get_entropy_isr_t)(const struct device *dev,
66 uint8_t *buffer,
67 uint16_t length,
69
79
81
94static inline const struct device *entropy_get_default_device(void)
95{
96 const struct device *device = DEVICE_DT_GET_OR_NULL(DT_CHOSEN(zephyr_entropy));
97
98#ifdef CONFIG_ARCH_HAS_ENTROPY
99 if (device == NULL) {
100 extern const struct device *const z_arch_entropy_dev;
101
102 device = z_arch_entropy_dev;
103 }
104#endif
105
106 return device;
107}
108
119__syscall int entropy_get_entropy(const struct device *dev,
120 uint8_t *buffer,
121 uint16_t length);
122
123static inline int z_impl_entropy_get_entropy(const struct device *dev,
124 uint8_t *buffer,
125 uint16_t length)
126{
127 const struct entropy_driver_api *api = DEVICE_API_GET(entropy, dev);
128
129 __ASSERT(api->get_entropy != NULL,
130 "Callback pointer should not be NULL");
131 return api->get_entropy(dev, buffer, length);
132}
133
145static inline int entropy_get_entropy_isr(const struct device *dev,
146 uint8_t *buffer,
147 uint16_t length,
149{
150 const struct entropy_driver_api *api = DEVICE_API_GET(entropy, dev);
151
152 if (unlikely(api->get_entropy_isr == NULL)) {
153 return -ENOSYS;
154 }
155
156 return api->get_entropy_isr(dev, buffer, length, flags);
157}
158
159
160#ifdef __cplusplus
161}
162#endif
163
167
168#include <zephyr/syscalls/entropy.h>
169
170#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:1449
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:3507
int(* entropy_get_entropy_t)(const struct device *dev, uint8_t *buffer, uint16_t length)
Callback API to get entropy.
Definition entropy.h:56
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:65
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:94
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:145
#define ENOSYS
Function not implemented.
Definition errno.h:83
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:73
entropy_get_entropy_t get_entropy
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition entropy.h:75
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:77