Zephyr API Documentation  3.5.0
A Scalable Open Source RTOS
3.5.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
entropy.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2016 ARM Ltd.
9 * Copyright (c) 2017 Intel Corporation
10 *
11 * SPDX-License-Identifier: Apache-2.0
12 */
13#ifndef ZEPHYR_INCLUDE_DRIVERS_ENTROPY_H_
14#define ZEPHYR_INCLUDE_DRIVERS_ENTROPY_H_
15
23#include <errno.h>
24
25#include <zephyr/types.h>
26#include <zephyr/device.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
41typedef int (*entropy_get_entropy_t)(const struct device *dev,
42 uint8_t *buffer,
43 uint16_t length);
50typedef int (*entropy_get_entropy_isr_t)(const struct device *dev,
51 uint8_t *buffer,
52 uint16_t length,
54__subsystem struct entropy_driver_api {
57};
58
69__syscall int entropy_get_entropy(const struct device *dev,
70 uint8_t *buffer,
71 uint16_t length);
72
73static inline int z_impl_entropy_get_entropy(const struct device *dev,
74 uint8_t *buffer,
75 uint16_t length)
76{
77 const struct entropy_driver_api *api =
78 (const struct entropy_driver_api *)dev->api;
79
80 __ASSERT(api->get_entropy != NULL,
81 "Callback pointer should not be NULL");
82 return api->get_entropy(dev, buffer, length);
83}
84
85/* Busy-wait for random data to be ready */
86#define ENTROPY_BUSYWAIT BIT(0)
87
98static inline int entropy_get_entropy_isr(const struct device *dev,
99 uint8_t *buffer,
100 uint16_t length,
102{
103 const struct entropy_driver_api *api =
104 (const struct entropy_driver_api *)dev->api;
105
106 if (unlikely(!api->get_entropy_isr)) {
107 return -ENOTSUP;
108 }
109
110 return api->get_entropy_isr(dev, buffer, length, flags);
111}
112
113
114#ifdef __cplusplus
115}
116#endif
117
122#include <syscalls/entropy.h>
123
124#endif /* ZEPHYR_INCLUDE_DRIVERS_ENTROPY_H_ */
System error numbers.
int entropy_get_entropy(const struct device *dev, uint8_t *buffer, uint16_t length)
Fills a buffer with entropy.
int(* entropy_get_entropy_t)(const struct device *dev, uint8_t *buffer, uint16_t length)
Callback API to get entropy.
Definition: entropy.h:41
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:98
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:50
#define ENOTSUP
Unsupported value.
Definition: errno.h:115
flags
Definition: parser.h:96
__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:381
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:387
Definition: entropy.h:54
entropy_get_entropy_t get_entropy
Definition: entropy.h:55
entropy_get_entropy_isr_t get_entropy_isr
Definition: entropy.h:56