MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
RNG: Random Number Generator

Overview

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;
status_t status;
uint8_t data[RNG_EXAMPLE_RANDOM_NUMBER];
/* Initialize board hardware. */
BOARD_InitHardware();
PRINTF("\r\nRandom number generator example.\r\n");
/* Enable ADC power */
/* Configure the RNG */
RNG_Init(DEMO_RNG_BASE);
RNG_Enable(DEMO_RNG_BASE, true);
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);
/* Get Random data*/
status = RNG_GetRandomData(RNG, data, sizeof(data));
if (status == kStatus_Success)
{
/* Print data*/
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");
}
/* Print a note.*/
PRINTF("\r\nInput any character to continue... \r\n");
GETCHAR();
}
}

Files

file  fsl_rng.h
 

Enumerations

enum  _rng_status_flags { kRNG_BusyFlag = RNG_STAT_BUSY_MASK }
 List of RNG flags. More...
 

Driver version

#define FSL_RNG_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))
 QN RNG driver version 2.0.0. More...
 

Initialization

void RNG_Init (RNG_Type *base)
 Initializes the RNG. More...
 
void RNG_Deinit (RNG_Type *base)
 Deinitialize the RNG module. More...
 
static void RNG_Enable (RNG_Type *base, bool enable)
 Enable/Disable RNG. More...
 

Interrupt Interface

static void RNG_EnableInterrupt (RNG_Type *base)
 Enable RNG interrupt. More...
 
static void RNG_DisableInterrupt (RNG_Type *base)
 Disable RNG interrupt. More...
 
static void RNG_ClearInterruptFlag (RNG_Type *base)
 Clear RNG interrupt flag. More...
 

Status Interface

static uint32_t RNG_GetStatusFlags (RNG_Type *base)
 Get RNG status flag. More...
 

Get Random Number Interface

static void RNG_Start (RNG_Type *base)
 Start random number generation. More...
 
static uint32_t RNG_GetRandomNumber (RNG_Type *base)
 Get random number. More...
 
status_t RNG_GetRandomData (RNG_Type *base, void *data, size_t dataSize)
 Gets random data. More...
 

Macro Definition Documentation

#define FSL_RNG_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))

Enumeration Type Documentation

Enumerator
kRNG_BusyFlag 

RNG busy flag.

Function Documentation

void RNG_Init ( RNG_Type *  base)

This function initializes the RNG.

Parameters
baseRNG base address
void RNG_Deinit ( RNG_Type *  base)
Parameters
baseRNG base address
static void RNG_Enable ( RNG_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseRNG peripheral base address.
enabletrue to enable the RNG, false to disable.
static void RNG_EnableInterrupt ( RNG_Type *  base)
inlinestatic
Parameters
baseRNG peripheral base address.
static void RNG_DisableInterrupt ( RNG_Type *  base)
inlinestatic
Parameters
baseRNG peripheral base address.
static void RNG_ClearInterruptFlag ( RNG_Type *  base)
inlinestatic
Parameters
baseRNG peripheral base address.
static uint32_t RNG_GetStatusFlags ( RNG_Type *  base)
inlinestatic
Parameters
baseRNG peripheral base address.
Returns
RNG status
static void RNG_Start ( RNG_Type *  base)
inlinestatic
Parameters
baseRNG peripheral base address.
static uint32_t RNG_GetRandomNumber ( RNG_Type *  base)
inlinestatic
Parameters
baseRNG 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
baseRNG base address
dataPointer address used to store random data
dataSizeSize of the buffer pointed by the data parameter
Returns
random data