ChibiOS/HAL  7.0.3
TRNG Driver

Generic True Random Numbers Generator Driver. More...

Collaboration diagram for TRNG Driver:

Detailed Description

Generic True Random Numbers Generator Driver.

This module implements a generic TRNG driver.

Precondition
In order to use the TRNG driver the HAL_USE_TRNG option must be enabled in halconf.h.

Macros

#define trng_lld_driver_fields
 Low level fields of the TRNG driver structure. More...
 
#define trng_lld_config_fields
 Low level fields of the TRNG configuration structure. More...
 

PLATFORM configuration options

#define PLATFORM_TRNG_USE_TRNG1   FALSE
 TRNGD1 driver enable switch. More...
 

Typedefs

typedef struct hal_trng_driver TRNGDriver
 Type of a structure representing a TRNG driver. More...
 
typedef struct hal_trng_config TRNGConfig
 Driver configuration structure. More...
 

Data Structures

struct  hal_trng_config
 Driver configuration structure. More...
 
struct  hal_trng_driver
 Structure representing a TRNG driver. More...
 

Functions

void trngInit (void)
 TRNG Driver initialization. More...
 
void trngObjectInit (TRNGDriver *trngp)
 Initializes the standard part of a TRNGDriver structure. More...
 
void trngStart (TRNGDriver *trngp, const TRNGConfig *config)
 Configures and activates the TRNG peripheral. More...
 
void trngStop (TRNGDriver *trngp)
 Deactivates the TRNG peripheral. More...
 
bool trngGenerate (TRNGDriver *trngp, size_t size, uint8_t *out)
 True random numbers generator. More...
 
void trng_lld_init (void)
 Low level TRNG driver initialization. More...
 
void trng_lld_start (TRNGDriver *trngp)
 Configures and activates the TRNG peripheral. More...
 
void trng_lld_stop (TRNGDriver *trngp)
 Deactivates the TRNG peripheral. More...
 
bool trng_lld_generate (TRNGDriver *trngp, size_t size, uint8_t *out)
 True random numbers generator. More...
 

Enumerations

Variables

TRNGDriver TRNGD1
 TRNGD1 driver identifier. More...
 

Macro Definition Documentation

#define PLATFORM_TRNG_USE_TRNG1   FALSE

TRNGD1 driver enable switch.

If set to TRUE the support for TRNGD1 is included.

Note
The default is FALSE.

Definition at line 48 of file hal_trng_lld.h.

#define trng_lld_driver_fields
Value:
/* Dummy field, it is not needed.*/ \
uint32_t dummy

Low level fields of the TRNG driver structure.

Definition at line 67 of file hal_trng_lld.h.

#define trng_lld_config_fields
Value:
/* Dummy configuration, it is not needed.*/ \
uint32_t dummy

Low level fields of the TRNG configuration structure.

Definition at line 74 of file hal_trng_lld.h.

Typedef Documentation

typedef struct hal_trng_driver TRNGDriver

Type of a structure representing a TRNG driver.

Definition at line 59 of file hal_trng.h.

typedef struct hal_trng_config TRNGConfig

Driver configuration structure.

Note
It could be empty on some architectures.

Definition at line 65 of file hal_trng.h.

Enumeration Type Documentation

Driver state machine possible states.

Enumerator
TRNG_UNINIT 

Not initialized.

TRNG_STOP 

Stopped.

TRNG_READY 

Ready.

TRNG_RUNNING 

Generating random number.

Definition at line 49 of file hal_trng.h.

Function Documentation

void trngInit ( void  )

TRNG Driver initialization.

Note
This function is implicitly invoked by halInit(), there is no need to explicitly initialize the driver.
Function Class:Initializer, this function just initializes an object and can be invoked before the kernel is initialized.

Definition at line 56 of file hal_trng.c.

References trng_lld_init().

Referenced by halInit().

Here is the call graph for this function:

void trngObjectInit ( TRNGDriver trngp)

Initializes the standard part of a TRNGDriver structure.

Parameters
[out]trngppointer to the TRNGDriver object
Function Class:Initializer, this function just initializes an object and can be invoked before the kernel is initialized.

Definition at line 68 of file hal_trng.c.

References hal_trng_driver::config, hal_trng_driver::state, and TRNG_STOP.

Referenced by trng_lld_init().

void trngStart ( TRNGDriver trngp,
const TRNGConfig config 
)

Configures and activates the TRNG peripheral.

Parameters
[in]trngppointer to the TRNGDriver object
[in]configpointer to the TRNGConfig object or NULL for default configuration
Function Class:Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 83 of file hal_trng.c.

References hal_trng_driver::config, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), hal_trng_driver::state, trng_lld_start(), TRNG_READY, and TRNG_STOP.

Here is the call graph for this function:

void trngStop ( TRNGDriver trngp)

Deactivates the TRNG peripheral.

Parameters
[in]trngppointer to the TRNGDriver object
Function Class:Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 103 of file hal_trng.c.

References hal_trng_driver::config, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), hal_trng_driver::state, trng_lld_stop(), TRNG_READY, and TRNG_STOP.

Here is the call graph for this function:

bool trngGenerate ( TRNGDriver trngp,
size_t  size,
uint8_t *  out 
)

True random numbers generator.

Note
The function is blocking and likely performs polled waiting inside the low level implementation.
Parameters
[in]trngppointer to the TRNGDriver object
[in]sizesize of output buffer
[out]outoutput buffer
Returns
The operation status.
Return values
falseif a random number has been generated.
trueif an HW error occurred.
Function Class:Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 133 of file hal_trng.c.

References osalDbgAssert, osalDbgCheck, hal_trng_driver::state, trng_lld_generate(), TRNG_READY, and TRNG_RUNNING.

Here is the call graph for this function:

void trng_lld_init ( void  )

Low level TRNG driver initialization.

Function Class:Not an API, this function is for internal use only.

Definition at line 65 of file hal_trng_lld.c.

References trngObjectInit().

Referenced by trngInit().

Here is the call graph for this function:

void trng_lld_start ( TRNGDriver trngp)

Configures and activates the TRNG peripheral.

Parameters
[in]trngppointer to the TRNGDriver object
Function Class:Not an API, this function is for internal use only.

Definition at line 80 of file hal_trng_lld.c.

References hal_trng_driver::state, and TRNG_STOP.

Referenced by trngStart().

void trng_lld_stop ( TRNGDriver trngp)

Deactivates the TRNG peripheral.

Parameters
[in]trngppointer to the TRNGDriver object
Function Class:Not an API, this function is for internal use only.

Definition at line 101 of file hal_trng_lld.c.

References hal_trng_driver::state, and TRNG_READY.

Referenced by trngStop().

bool trng_lld_generate ( TRNGDriver trngp,
size_t  size,
uint8_t *  out 
)

True random numbers generator.

Note
The function is blocking and likely performs polled waiting inside the low level implementation.
Parameters
[in]trngppointer to the TRNGDriver object
[in]sizesize of output buffer
[out]outoutput buffer
Returns
The operation status.
Return values
falseif a random number has been generated.
trueif an HW error occurred.
Function Class:Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 129 of file hal_trng_lld.c.

Referenced by trngGenerate().

Variable Documentation

TRNGDriver TRNGD1

TRNGD1 driver identifier.

Definition at line 41 of file hal_trng_lld.c.