zephyr/include/entropy.h
Patrik Flykt 4344e27c26 all: Update reserved function names
Update reserved function names starting with one underscore, replacing
them as follows:
   '_k_' with 'z_'
   '_K_' with 'Z_'
   '_handler_' with 'z_handl_'
   '_Cstart' with 'z_cstart'
   '_Swap' with 'z_swap'

This renaming is done on both global and those static function names
in kernel/include and include/. Other static function names in kernel/
are renamed by removing the leading underscore. Other function names
not starting with any prefix listed above are renamed starting with
a 'z_' or 'Z_' prefix.

Function names starting with two or three leading underscores are not
automatcally renamed since these names will collide with the variants
with two or three leading underscores.

Various generator scripts have also been updated as well as perf,
linker and usb files. These are
   drivers/serial/uart_handlers.c
   include/linker/kobject-text.ld
   kernel/include/syscall_handler.h
   scripts/gen_kobject_list.py
   scripts/gen_syscall_header.py

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-11 13:48:42 -04:00

118 lines
2.6 KiB
C

/**
* @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 ZEPHYR_INCLUDE_ENTROPY_H_
#define ZEPHYR_INCLUDE_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 z_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 != NULL,
"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 (unlikely(!api->get_entropy_isr)) {
return -ENOTSUP;
}
return api->get_entropy_isr(dev, buffer, length, flags);
}
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#include <syscalls/entropy.h>
#endif /* ZEPHYR_INCLUDE_ENTROPY_H_ */