The MCUXpresso SDK provides a peripheral driver for the Random Number Generator (RNG) module of MCUXpresso SDK devices.
Typical use case
Example use of RNG API.
int main(void)
{
uint32_t i;
uint8_t data[RNG_EXAMPLE_RANDOM_NUMBER];
BOARD_InitHardware();
PRINTF("\r\nRandom number generator example.\r\n");
PRINTF("RNG configuration Done.\r\n");
PRINTF("Input any character to get random number ...\r\n");
while (1)
{
PRINTF("Generate %d random numbers: \r\n", RNG_EXAMPLE_RANDOM_NUMBER);
if (status == kStatus_Success)
{
for (i = 0; i < RNG_EXAMPLE_RANDOM_NUMBER; i++)
{
PRINTF("Random[%d] = 0x%X\r\n", i, data[i]);
}
}
else
{
PRINTF("TRNG failed!\r\n");
}
PRINTF("\r\nInput any character to continue... \r\n");
GETCHAR();
}
}
Enumerator |
---|
kRNG_BusyFlag |
RNG busy flag.
|
void RNG_Init |
( |
RNG_Type * |
base | ) |
|
This function initializes the RNG.
- Parameters
-
void RNG_Deinit |
( |
RNG_Type * |
base | ) |
|
static void RNG_Enable |
( |
RNG_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | RNG peripheral base address. |
enable | true to enable the RNG, false to disable. |
static void RNG_EnableInterrupt |
( |
RNG_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RNG peripheral base address. |
static void RNG_DisableInterrupt |
( |
RNG_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RNG peripheral base address. |
static void RNG_ClearInterruptFlag |
( |
RNG_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RNG peripheral base address. |
static uint32_t RNG_GetStatusFlags |
( |
RNG_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RNG peripheral base address. |
- Returns
- RNG status
static void RNG_Start |
( |
RNG_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RNG peripheral base address. |
static uint32_t RNG_GetRandomNumber |
( |
RNG_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | RNG peripheral base address. |
- Returns
- random number
status_t RNG_GetRandomData |
( |
RNG_Type * |
base, |
|
|
void * |
data, |
|
|
size_t |
dataSize |
|
) |
| |
This function gets random data from the RNG.
- Parameters
-
base | RNG base address |
data | Pointer address used to store random data |
dataSize | Size of the buffer pointed by the data parameter |
- Returns
- random data