Zephyr Project API  3.3.0
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 <errno.h>
24
25#include <zephyr/types.h>
26#include <zephyr/device.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
38typedef int (*entropy_get_entropy_t)(const struct device *dev,
40 uint16_t length);
47typedef int (*entropy_get_entropy_isr_t)(const struct device *dev,
49 uint16_t length,
51__subsystem struct entropy_driver_api {
54};
55
66__syscall int entropy_get_entropy(const struct device *dev,
68 uint16_t length);
69
70static inline int z_impl_entropy_get_entropy(const struct device *dev,
72 uint16_t length)
73{
74 const struct entropy_driver_api *api =
75 (const struct entropy_driver_api *)dev->api;
76
77 __ASSERT(api->get_entropy != NULL,
78 "Callback pointer should not be NULL");
79 return api->get_entropy(dev, buffer, length);
80}
81
82/* Busy-wait for random data to be ready */
83#define ENTROPY_BUSYWAIT BIT(0)
84
95static inline int entropy_get_entropy_isr(const struct device *dev,
97 uint16_t length,
99{
100 const struct entropy_driver_api *api =
101 (const struct entropy_driver_api *)dev->api;
102
103 if (unlikely(!api->get_entropy_isr)) {
104 return -ENOTSUP;
105 }
106
107 return api->get_entropy_isr(dev, buffer, length, flags);
108}
109
110
111#ifdef __cplusplus
112}
113#endif
114
119#include <syscalls/entropy.h>
120
121#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. 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:38
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:95
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:47
#define ENOTSUP
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:378
const void * api
Definition: device.h:384
Definition: entropy.h:51
entropy_get_entropy_t get_entropy
Definition: entropy.h:52
entropy_get_entropy_isr_t get_entropy_isr
Definition: entropy.h:53
static ZTEST_BMEM char buffer[8]
Definition: test_mbox_api.c:551