23 lines
434 B
C
23 lines
434 B
C
#include "random.h"
|
|
#include "base.h"
|
|
#include "stm32f4xx.h"
|
|
|
|
static int g_inited = 0;
|
|
void RANDOM_Init(void) {
|
|
if (g_inited == 0) {
|
|
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
|
|
RNG_Cmd(ENABLE);
|
|
RANDOM_Get();
|
|
g_inited = 1;
|
|
}
|
|
}
|
|
|
|
uint32_t RANDOM_Get(void) {
|
|
if (RNG->CR & RNG_CR_RNGEN) {
|
|
while (RNG_GetFlagStatus(RNG_FLAG_DRDY) != SET)
|
|
;
|
|
return RNG_GetRandomNumber();
|
|
} else
|
|
return 0;
|
|
}
|