思澈科技软件开发工具包  2.20
RNG

SiFli 芯片组内部的 RNG(随机数生成器)模块用于生成随机数种子和随机数。 建议用户使用自己的随机算法生成随机数以获得更好的随机性,同时使用硬件生成的随机数作为种子。

使用RNG.

{
#include "bf0_hal.h"
...
RNG_HandleTypeDef RngHandle;
if (HAL_RNG_Init(&RngHandle) == HAL_OK) { // Initialize RNG module
uint32_t value = 0;
if (HAL_RNG_Generate(&RngHandle, &value, 1)== HAL_OK) // Generate random seed
printf("Generated Randome seed %d\n", value);
if (HAL_RNG_Generate(&RngHandle, &value, 0)== HAL_OK) // Generate random number, it is recommed to use this number as random seed to user random algorithm
printf("Generated Randome number %d\n", value);
}
...
}
__RNG_HandleTypeDef
RNG Handle Structure definition.
Definition: bf0_hal_rng.h:99
HAL_OK
@ HAL_OK
Definition: bf0_hal_def.h:75
HAL_RNG_Init
HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng)
Initialize the RNG peripheral and initialize the associated handle.
HAL_RNG_Generate
HAL_StatusTypeDef HAL_RNG_Generate(RNG_HandleTypeDef *hrng, uint32_t *random32bit, uint8_t is_seed)
Generate a 32-bit random number or seed.