Files
player/Project/Src/Drive/Source/random.c

23 lines
434 B
C
Raw Normal View History

2025-06-27 00:32:57 +08:00
#include "random.h"
#include "base.h"
#include "stm32f4xx.h"
2025-06-27 00:32:57 +08:00
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;
}
2025-06-27 00:32:57 +08:00
}
uint32_t RANDOM_Get(void) {
if (RNG->CR & RNG_CR_RNGEN) {
while (RNG_GetFlagStatus(RNG_FLAG_DRDY) != SET)
;
return RNG_GetRandomNumber();
} else
return 0;
2025-06-27 00:32:57 +08:00
}