#include "bsp_rng.h"
#include "ch32v30x_rng.h"
#include "rtdef.h"

#define LOG_LVL LOG_LVL_DBG
#include <ulog.h>

int BSP_Rng_Init(void)
{
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_RNG, ENABLE);
    RNG_Cmd(ENABLE);

    return 0;
}
// INIT_PREV_EXPORT(BSP_Rng_Init);

int Get_RandomNumber(void)
{
    u32 random = 0;
    while(RNG_GetFlagStatus(RNG_FLAG_DRDY) == RESET);
    random = RNG_GetRandomNumber();

   LOG_D("random = %d\r\n", random % 31);

    // 生成0到1000之间的随机数
    return random % 1000;
}
