Leandro Pereira | da9b0dd | 2017-10-13 16:30:55 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @file entropy.h |
| 3 | * |
| 4 | * @brief Public APIs for the entropy driver. |
| 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * Copyright (c) 2016 ARM Ltd. |
| 9 | * Copyright (c) 2017 Intel Corporation |
| 10 | * |
| 11 | * SPDX-License-Identifier: Apache-2.0 |
| 12 | */ |
| 13 | #ifndef __ENTROPY_H__ |
| 14 | #define __ENTROPY_H__ |
| 15 | |
| 16 | /** |
| 17 | * @brief Entropy Interface |
| 18 | * @defgroup entropy_interface Entropy Interface |
| 19 | * @ingroup io_interfaces |
| 20 | * @{ |
| 21 | */ |
| 22 | |
| 23 | #ifdef __cplusplus |
| 24 | extern "C" { |
| 25 | #endif |
| 26 | |
| 27 | #include <zephyr/types.h> |
| 28 | #include <device.h> |
| 29 | |
| 30 | /** |
| 31 | * @typedef entropy_get_entropy_t |
| 32 | * @brief Callback API to get entropy. |
| 33 | * |
| 34 | * See entropy_get_entropy() for argument description |
| 35 | */ |
| 36 | typedef int (*entropy_get_entropy_t)(struct device *dev, |
| 37 | u8_t *buffer, |
| 38 | u16_t length); |
| 39 | |
| 40 | struct entropy_driver_api { |
| 41 | entropy_get_entropy_t get_entropy; |
| 42 | }; |
| 43 | |
| 44 | /** |
| 45 | * @brief Fills a buffer with entropy. |
| 46 | * |
| 47 | * @param dev Pointer to the entropy device. |
| 48 | * @param buffer Buffer to fill with entropy. |
| 49 | * @param length Buffer length. |
| 50 | * @retval 0 on success. |
| 51 | * @retval -ERRNO errno code on error. |
| 52 | */ |
| 53 | __syscall int entropy_get_entropy(struct device *dev, |
| 54 | u8_t *buffer, |
| 55 | u16_t length); |
| 56 | |
| 57 | static inline int _impl_entropy_get_entropy(struct device *dev, |
| 58 | u8_t *buffer, |
| 59 | u16_t length) |
| 60 | { |
| 61 | const struct entropy_driver_api *api = dev->driver_api; |
| 62 | |
| 63 | __ASSERT(api->get_entropy, "Callback pointer should not be NULL"); |
| 64 | return api->get_entropy(dev, buffer, length); |
| 65 | } |
| 66 | |
| 67 | #ifdef __cplusplus |
| 68 | } |
| 69 | #endif |
| 70 | |
| 71 | /** |
| 72 | * @} |
| 73 | */ |
| 74 | |
| 75 | #include <syscalls/entropy.h> |
| 76 | |
| 77 | #endif /* __ENTROPY_H__ */ |