Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

Overview

This section describes the programming interface of the RNGA Peripheral driver. The RNGA driver provides an easy way to initialize and configure the RNGA.

RNGA Initialization

  1. To initialize the RNGA module, call the RNGA_DRV_Init() function and pass the user configuration structure. This function automatically enables the RNGA module and clock.
  2. After calling the RNGA_DRV_Init() function, the RNGA is enabled and the counter starts working.

This example code shows how to initialize and configure the driver:

// Define device configuration.
const rnga_user_config_t init =
{
.isIntMasked = true, // Mask RNGA Error Interrupt //
.highAssuranceEnable = true, // Enable high assurance //
};
// Initialize RNGA.

RNGA Set/Get Working Mode

The RNGA works either in sleep mode or normal mode

  1. RNGA_DRV_SetMode() function sets the RNGA mode.
  2. RNGA_DRV_GetMode() function gets the RNGA working mode.

Get random data from RNGA

  1. RNGA_DRV_GetRandomData() function gets random data from the RNGA module.

Seed RNGA

  1. RNGA_DRV_Seed() function inputs an entropy value that the RNGA can use to seed the pseudo random algorithm.

RNGA interrupt

If the RNGA interrupt is enabled, the RNGA asserts an interrupt when an underflow error happens.

  1. Enable the RNGA interrupt with the rnga_user_config_t.isIntMasked = false.
  2. Define the RNGA IRQ function.
void RNGA_IRQHandler()
{
// Enter RNGA ISR //
}

Data Structures

struct  rnga_user_config_t
 Data structure for the RNGA initialization. More...
 

Macros

#define RNGA_DRV_RTOS_MULTI_THREAD   (USE_RTOS)
 Enables/disables multi-thread support in RNGA driver. More...
 

Functions

rnga_status_t RNGA_DRV_Init (uint32_t instance, const rnga_user_config_t *config)
 Initializes the RNGA. More...
 
void RNGA_DRV_Deinit (uint32_t instance)
 Shuts down the RNGA. More...
 
static void RNGA_DRV_SetMode (uint32_t instance, rnga_mode_t mode)
 Sets the RNGA in normal mode or sleep mode. More...
 
static rnga_mode_t RNGA_DRV_GetMode (uint32_t instance)
 Gets the RNGA working mode. More...
 
rnga_status_t RNGA_DRV_GetRandomData (uint32_t instance, void *data, uint32_t data_size)
 Gets random data. More...
 
static void RNGA_DRV_Seed (uint32_t instance, uint32_t seed)
 Feeds the RNGA module. More...
 
void RNGA_DRV_IRQHandler (uint32_t instance)
 RNGA interrupt handler. More...
 

Variables

RNG_Type *const g_rngaBase []
 Table of base addresses for RNGA instances. More...
 
const IRQn_Type g_rngaIrqId [RNG_INSTANCE_COUNT]
 Table to save RNGA IRQ enumeration numbers defined in the CMSIS header file. More...
 

Data Structure Documentation

struct rnga_user_config_t

This structure initializes the RNGA by calling the the rnga_init function. It contains all RNGA configurations.

Data Fields

bool isIntMasked
 Masks the triggering of error interrupt.
 
bool highAssuranceEnable
 Enables notification of security violations.
 

Macro Definition Documentation

#define RNGA_DRV_RTOS_MULTI_THREAD   (USE_RTOS)

It is achieved by mutex locking of critical sections. It is enabled by default for RTOS. It is optional and may be disabled if TRNG is used only by one RTOS task.

Function Documentation

rnga_status_t RNGA_DRV_Init ( uint32_t  instance,
const rnga_user_config_t config 
)

This function initializes the RNGA. When called, the RNGA runs immediately according to the specifications in the configuration.

Parameters
instance,RNGAinstance ID
config,pointerto initialize configuration structure
Returns
RNGA status
void RNGA_DRV_Deinit ( uint32_t  instance)

This function shuts down the RNGA.

Parameters
instance,RNGAinstance ID
static void RNGA_DRV_SetMode ( uint32_t  instance,
rnga_mode_t  mode 
)
inlinestatic

This function sets the RNGA in sleep mode or normal mode.

Parameters
instance,RNGAinstance ID
mode,normalmode or sleep mode
static rnga_mode_t RNGA_DRV_GetMode ( uint32_t  instance)
inlinestatic

This function gets the RNGA working mode.

Parameters
instance,RNGAinstance ID
Returns
normal mode or sleep mode
rnga_status_t RNGA_DRV_GetRandomData ( uint32_t  instance,
void *  data,
uint32_t  data_size 
)

This function gets random data from the RNGA.

Parameters
instance,RNGAinstance ID
datapointer to user buffer to be filled by random data size of data in bytes
Returns
RNGA status
static void RNGA_DRV_Seed ( uint32_t  instance,
uint32_t  seed 
)
inlinestatic

This function inputs an entropy value that the RNGA uses to seed its pseudo-random algorithm.

Parameters
instance,RNGAinstance ID
seed,inputseed value
void RNGA_DRV_IRQHandler ( uint32_t  instance)

This function handles the error interrupt caused by the RNGA underflow.

Parameters
instance,RNGAinstance ID

Variable Documentation

RNG_Type* const g_rngaBase[]
const IRQn_Type g_rngaIrqId[RNG_INSTANCE_COUNT]