Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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 <zephyr/types.h>
24#include <device.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
36typedef int (*entropy_get_entropy_t)(const struct device *dev,
38 uint16_t length);
45typedef int (*entropy_get_entropy_isr_t)(const struct device *dev,
47 uint16_t length,
49__subsystem struct entropy_driver_api {
52};
53
64__syscall int entropy_get_entropy(const struct device *dev,
66 uint16_t length);
67
68static inline int z_impl_entropy_get_entropy(const struct device *dev,
70 uint16_t length)
71{
72 const struct entropy_driver_api *api =
73 (const struct entropy_driver_api *)dev->api;
74
75 __ASSERT(api->get_entropy != NULL,
76 "Callback pointer should not be NULL");
77 return api->get_entropy(dev, buffer, length);
78}
79
80/* Busy-wait for random data to be ready */
81#define ENTROPY_BUSYWAIT BIT(0)
82
93static inline int entropy_get_entropy_isr(const struct device *dev,
95 uint16_t length,
97{
98 const struct entropy_driver_api *api =
99 (const struct entropy_driver_api *)dev->api;
100
101 if (unlikely(!api->get_entropy_isr)) {
102 return -ENOTSUP;
103 }
104
105 return api->get_entropy_isr(dev, buffer, length, flags);
106}
107
108
109#ifdef __cplusplus
110}
111#endif
112
117#include <syscalls/entropy.h>
118
119#endif /* ZEPHYR_INCLUDE_DRIVERS_ENTROPY_H_ */
int entropy_get_entropy(const struct device *dev, uint8_t *buffer, uint16_t length)
Fills a buffer with entropy. Blocks if required in order to generate the necessary random data.
int(* entropy_get_entropy_t)(const struct device *dev, uint8_t *buffer, uint16_t length)
Callback API to get entropy.
Definition: entropy.h:36
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. Callable from ISRs.
Definition: entropy.h:93
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:45
static ZTEST_BMEM char buffer[8]
Test mailbox enhance capabilities.
Definition: test_mbox_api.c:566
#define ENOTSUP
Definition: errno.h:115
flags
Definition: http_parser.h:131
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
Runtime device structure (in ROM) per driver instance.
Definition: device.h:367
const void * api
Definition: device.h:373
Definition: entropy.h:49
entropy_get_entropy_t get_entropy
Definition: entropy.h:50
entropy_get_entropy_isr_t get_entropy_isr
Definition: entropy.h:51