ChibiOS 21.11.4
TRNG Driver

Generic True Random Numbers Generator Driver. More...

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.
Collaboration diagram for TRNG Driver:

PLATFORM configuration options

#define PLATFORM_TRNG_USE_TRNG1   FALSE
 TRNGD1 driver enable switch.

Data Structures

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

Macros

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

Typedefs

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

Enumerations

enum  trngstate_t { TRNG_UNINIT = 0 , TRNG_STOP = 1 , TRNG_READY = 2 , TRNG_RUNNING = 3 }
 Driver state machine possible states. More...

Functions

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

Variables

TRNGDriver TRNGD1
 TRNGD1 driver identifier.

Macro Definition Documentation

◆ PLATFORM_TRNG_USE_TRNG1

#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.

◆ trng_lld_driver_fields

#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.

◆ trng_lld_config_fields

#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

◆ TRNGDriver

typedef struct hal_trng_driver TRNGDriver

Type of a structure representing a TRNG driver.

Definition at line 59 of file hal_trng.h.

◆ TRNGConfig

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

◆ trngstate_t

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

◆ trngInit()

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:
Object or module nitializer function.

Definition at line 56 of file hal_trng.c.

References trng_lld_init().

Referenced by halInit().

Here is the call graph for this function:

◆ trngObjectInit()

void trngObjectInit ( TRNGDriver * trngp)

Initializes the standard part of a TRNGDriver structure.

Parameters
[out]trngppointer to the TRNGDriver object
Function Class:
Object or module nitializer function.

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().

◆ trngStart()

msg_t 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
Returns
The operation status.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 84 of file hal_trng.c.

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

Here is the call graph for this function:

◆ trngStop()

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 121 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:

◆ trngGenerate()

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 151 of file hal_trng.c.

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

Here is the call graph for this function:

◆ trng_lld_init()

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 TRNGD1, and trngObjectInit().

Referenced by trngInit().

Here is the call graph for this function:

◆ trng_lld_start()

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, TRNG_STOP, and TRNGD1.

Referenced by trngStart().

◆ trng_lld_stop()

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, TRNG_READY, and TRNGD1.

Referenced by trngStop().

◆ trng_lld_generate()

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.

References out.

Referenced by trngGenerate().

Variable Documentation

◆ TRNGD1

TRNGDriver TRNGD1

TRNGD1 driver identifier.

Definition at line 41 of file hal_trng_lld.c.

Referenced by trng_lld_init(), trng_lld_start(), and trng_lld_stop().