forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentropy_stm32.h
105 lines (97 loc) · 2.68 KB
/
entropy_stm32.h
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* Copyright (c) 2025 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <stm32_ll_rng.h>
/**
* This driver supports two compatibles:
* - "st,stm32-rng" for TRNG with IRQ lines
* - "st,stm32-rng-noirq" for TRNG without IRQ lines
*/
#define IRQLESS_TRNG DT_HAS_COMPAT_STATUS_OKAY(st_stm32_rng_noirq)
#if IRQLESS_TRNG
#define DT_DRV_COMPAT st_stm32_rng_noirq
#define TRNG_GENERATION_DELAY K_NSEC(DT_INST_PROP_OR(0, generation_delay_ns, 0))
#else /* !IRQLESS_TRNG */
#define DT_DRV_COMPAT st_stm32_rng
#define IRQN DT_INST_IRQN(0)
#define IRQ_PRIO DT_INST_IRQ(0, priority)
#endif /* IRQLESS_TRNG */
/* Cross-series LL compatibility wrappers */
static inline void ll_rng_enable_it(RNG_TypeDef *RNGx)
{
/* Silence "unused" warning on IRQ-less hardware*/
ARG_UNUSED(RNGx);
#if !IRQLESS_TRNG
# if defined(CONFIG_SOC_STM32WB09XX)
LL_RNG_EnableEnErrorIrq(RNGx);
LL_RNG_EnableEnFfFullIrq(RNGx);
# else
LL_RNG_EnableIT(RNGx);
# endif
#endif /* !IRQLESS_TRNG */
}
static inline uint32_t ll_rng_is_active_seis(RNG_TypeDef *RNGx)
{
#if defined(CONFIG_SOC_SERIES_STM32WB0X)
# if defined(CONFIG_SOC_STM32WB09XX)
return LL_RNG_IsActiveFlag_ENTROPY_ERR(RNGx);
# else
return LL_RNG_IsActiveFlag_FAULT(RNGx);
# endif
#else
return LL_RNG_IsActiveFlag_SEIS(RNGx);
#endif /* CONFIG_SOC_SERIES_STM32WB0X */
}
static inline void ll_rng_clear_seis(RNG_TypeDef *RNGx)
{
#if defined(CONFIG_SOC_SERIES_STM32WB0X)
# if defined(CONFIG_SOC_STM32WB09XX)
LL_RNG_SetResetHealthErrorFlags(RNGx, 1);
# else
LL_RNG_ClearFlag_FAULT(RNGx);
# endif
#else
LL_RNG_ClearFlag_SEIS(RNGx);
#endif /* CONFIG_SOC_SERIES_STM32WB0X */
}
static inline uint32_t ll_rng_is_active_secs(RNG_TypeDef *RNGx)
{
#if !defined(CONFIG_SOC_SERIES_STM32WB0X)
return LL_RNG_IsActiveFlag_SECS(RNGx);
#else
/**
* STM32WB0x RNG has no equivalent of SECS.
* Since this flag is always checked in conjunction
* with FAULT (the SEIS equivalent), returning 0 is OK.
*/
return 0;
#endif /* !CONFIG_SOC_SERIES_STM32WB0X */
}
static inline uint32_t ll_rng_is_active_drdy(RNG_TypeDef *RNGx)
{
#if defined(CONFIG_SOC_SERIES_STM32WB0X)
# if defined(CONFIG_SOC_STM32WB09XX)
return LL_RNG_IsActiveFlag_VAL_READY(RNGx);
# else
return LL_RNG_IsActiveFlag_RNGRDY(RNGx);
# endif
#else
return LL_RNG_IsActiveFlag_DRDY(RNGx);
#endif /* CONFIG_SOC_SERIES_STM32WB0X */
}
static inline uint16_t ll_rng_read_rand_data(RNG_TypeDef *RNGx)
{
#if defined(CONFIG_SOC_SERIES_STM32WB0X)
# if defined(CONFIG_SOC_STM32WB09XX)
return (uint16_t)LL_RNG_GetRndVal(RNGx);
# else
return LL_RNG_ReadRandData16(RNGx);
# endif
#else
return (uint16_t)LL_RNG_ReadRandData32(RNGx);
#endif /* CONFIG_SOC_SERIES_STM32WB0X */
}