mirror of
https://github.com/zephyrproject-rtos/zephyr
synced 2025-09-03 08:23:10 +00:00
move entropy.h to drivers/entropy.h and create a shim for backward-compatibility. No functional changes to the headers. A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES. Related to #16539 Signed-off-by: Anas Nashif <anas.nashif@intel.com>
45 lines
1.1 KiB
C
45 lines
1.1 KiB
C
/*
|
|
* Copyright (c) 2017 Intel Corporation
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <sys/atomic.h>
|
|
#include <kernel.h>
|
|
#include <drivers/entropy.h>
|
|
|
|
static struct device *entropy_driver;
|
|
|
|
u32_t sys_rand32_get(void)
|
|
{
|
|
struct device *dev = entropy_driver;
|
|
u32_t random_num;
|
|
int ret;
|
|
|
|
if (unlikely(!dev)) {
|
|
/* Only one entropy device exists, so this is safe even
|
|
* if the whole operation isn't atomic.
|
|
*/
|
|
dev = device_get_binding(CONFIG_ENTROPY_NAME);
|
|
__ASSERT((dev != NULL),
|
|
"Device driver for %s (CONFIG_ENTROPY_NAME) not found. "
|
|
"Check your build configuration!",
|
|
CONFIG_ENTROPY_NAME);
|
|
entropy_driver = dev;
|
|
}
|
|
|
|
ret = entropy_get_entropy(dev, (u8_t *)&random_num,
|
|
sizeof(random_num));
|
|
if (unlikely(ret < 0)) {
|
|
/* Use system timer in case the entropy device couldn't deliver
|
|
* 32-bit of data. There's not much that can be done in this
|
|
* situation. An __ASSERT() isn't used here as the HWRNG might
|
|
* still be gathering entropy during early boot situations.
|
|
*/
|
|
|
|
random_num = k_cycle_get_32();
|
|
}
|
|
|
|
return random_num;
|
|
}
|