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:
Gerard Marull-Paretas 2022-08-17 14:11:58 +02:00 committed by Carles Cufí
commit 51932c2cec
2 changed files with 4 additions and 3 deletions

View file

@ -9,7 +9,8 @@
#include <zephyr/drivers/entropy.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)
uint32_t z_impl_sys_rand32_get(void)

View file

@ -32,7 +32,8 @@
#include <zephyr/kernel.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 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)
{
entropy_driver = DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy));
if (!device_is_ready(entropy_driver)) {
return -ENODEV;
}