Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | /** * @file entropy.h * * @brief Public APIs for the entropy driver. */ /* * Copyright (c) 2016 ARM Ltd. * Copyright (c) 2017 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ #ifndef __ENTROPY_H__ #define __ENTROPY_H__ /** * @brief Entropy Interface * @defgroup entropy_interface Entropy Interface * @ingroup io_interfaces * @{ */ #ifdef __cplusplus extern "C" { #endif #include <zephyr/types.h> #include <device.h> /** * @typedef entropy_get_entropy_t * @brief Callback API to get entropy. * * See entropy_get_entropy() for argument description */ typedef int (*entropy_get_entropy_t)(struct device *dev, u8_t *buffer, u16_t length); /** * @typedef entropy_get_entropy_isr_t * @brief Callback API to get entropy from an ISR. * * See entropy_get_entropy_isr() for argument description */ typedef int (*entropy_get_entropy_isr_t)(struct device *dev, u8_t *buffer, u16_t length, u32_t flags); struct entropy_driver_api { entropy_get_entropy_t get_entropy; entropy_get_entropy_isr_t get_entropy_isr; }; /** * @brief Fills a buffer with entropy. Blocks if required in order to * generate the necessary random data. * * @param dev Pointer to the entropy device. * @param buffer Buffer to fill with entropy. * @param length Buffer length. * @retval 0 on success. * @retval -ERRNO errno code on error. */ __syscall int entropy_get_entropy(struct device *dev, u8_t *buffer, u16_t length); static inline int _impl_entropy_get_entropy(struct device *dev, u8_t *buffer, u16_t length) { const struct entropy_driver_api *api = dev->driver_api; __ASSERT(api->get_entropy, "Callback pointer should not be NULL"); return api->get_entropy(dev, buffer, length); } /* Busy-wait for random data to be ready */ #define ENTROPY_BUSYWAIT BIT(0) /** * @brief Fills a buffer with entropy in a non-blocking or busy-wait manner. * Callable from ISRs. * * @param dev Pointer to the device structure. * @param buffer Buffer to fill with entropy. * @param length Buffer length. * @param flags Flags to modify the behavior of the call. * @retval number of bytes filled with entropy or -error. */ static inline int entropy_get_entropy_isr(struct device *dev, u8_t *buffer, u16_t length, u32_t flags) { const struct entropy_driver_api *api = dev->driver_api; if (!api->get_entropy_isr) { return -ENOTSUP; } return api->get_entropy_isr(dev, buffer, length, flags); } #ifdef __cplusplus } #endif /** * @} */ #include <syscalls/entropy.h> #endif /* __ENTROPY_H__ */ |