File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change 23
23
#include <stdlib.h>
24
24
#include "cmsis.h"
25
25
#include "trng_api.h"
26
+ #include "mbed_error.h"
27
+ #include "mbed_critical.h"
26
28
29
+ static uint8_t users = 0 ;
27
30
28
31
void trng_init (trng_t * obj )
29
32
{
30
33
uint32_t dummy ;
34
+
35
+ /* We're only supporting a single user of RNG */
36
+ if (core_util_atomic_incr_u8 (& users , 1 ) > 1 ) {
37
+ error ("Only 1 RNG instance supported\r\n" );
38
+ }
39
+
31
40
#if defined(TARGET_STM32L4 )
32
41
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct ;
33
42
@@ -57,6 +66,8 @@ void trng_free(trng_t *obj)
57
66
HAL_RNG_DeInit (& obj -> handle );
58
67
/* RNG Peripheral clock disable - assume we're the only users of RNG */
59
68
__HAL_RCC_RNG_CLK_DISABLE ();
69
+
70
+ users = 0 ;
60
71
}
61
72
62
73
int trng_get_bytes (trng_t * obj , uint8_t * output , size_t length , size_t * output_length )
You can’t perform that action at this time.
0 commit comments