forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentropy_renesas_ra.c
49 lines (38 loc) · 1.02 KB
/
entropy_renesas_ra.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright (c) 2024 Renesas Electronics Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT renesas_ra_rsip_e51a_trng
#include <soc.h>
#include <zephyr/drivers/entropy.h>
#include "hw_sce_trng_private.h"
#include "hw_sce_private.h"
static int entropy_ra_rsip_trng_get_entropy(const struct device *dev, uint8_t *buf, uint16_t len)
{
ARG_UNUSED(dev);
if (buf == NULL) {
return -EINVAL;
}
while (len > 0) {
uint32_t n[4];
const uint32_t to_copy = MIN(sizeof(n), len);
if (FSP_SUCCESS != HW_SCE_RNG_Read(n)) {
return -ENODATA;
}
memcpy(buf, n, to_copy);
buf += to_copy;
len -= to_copy;
}
return 0;
}
static const struct entropy_driver_api entropy_ra_rsip_trng_api = {
.get_entropy = entropy_ra_rsip_trng_get_entropy,
};
static int entropy_ra_rsip_trng_init(const struct device *dev)
{
HW_SCE_McuSpecificInit();
return 0;
}
DEVICE_DT_INST_DEFINE(0, entropy_ra_rsip_trng_init, NULL, NULL, NULL, PRE_KERNEL_1,
CONFIG_ENTROPY_INIT_PRIORITY, &entropy_ra_rsip_trng_api);