random: initialize devices at compile time
Initialize devices at compile time so that device pointer can be constified. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
d520029900
commit
51932c2cec
2 changed files with 4 additions and 3 deletions
|
@ -9,7 +9,8 @@
|
||||||
#include <zephyr/drivers/entropy.h>
|
#include <zephyr/drivers/entropy.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static const struct device *entropy_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy));
|
static const struct device *const entropy_dev =
|
||||||
|
DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy));
|
||||||
|
|
||||||
#if defined(CONFIG_ENTROPY_DEVICE_RANDOM_GENERATOR)
|
#if defined(CONFIG_ENTROPY_DEVICE_RANDOM_GENERATOR)
|
||||||
uint32_t z_impl_sys_rand32_get(void)
|
uint32_t z_impl_sys_rand32_get(void)
|
||||||
|
|
|
@ -32,7 +32,8 @@
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static const struct device *entropy_driver;
|
static const struct device *const entropy_driver =
|
||||||
|
DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy));
|
||||||
static uint32_t state[4];
|
static uint32_t state[4];
|
||||||
static bool initialized;
|
static bool initialized;
|
||||||
|
|
||||||
|
@ -43,7 +44,6 @@ static inline uint32_t rotl(const uint32_t x, int k)
|
||||||
|
|
||||||
static int xoshiro128_initialize(const struct device *dev)
|
static int xoshiro128_initialize(const struct device *dev)
|
||||||
{
|
{
|
||||||
entropy_driver = DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy));
|
|
||||||
if (!device_is_ready(entropy_driver)) {
|
if (!device_is_ready(entropy_driver)) {
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue