Hardware Abstraction Layer (HAL)
TRNG (True Random Number Generator)

General Description

High level interface to the True Random Number Generator (TRNG).

This block uses dedicated hardware to efficiently generate true random numbers.

Features

Quick Start

cyhal_trng_init initializes the TRNG and passes a pointer to the TRNG block through the obj object of type cyhal_trng_t.

See Simple TRNG number generation example.

Simple TRNG number generation example

The following snippet initializes a TRNG and generates a true random number.

cy_rslt_t rslt;
cyhal_trng_t trng_obj;
uint32_t rnd_num;
/* Initialize the true random number generator block */
rslt = cyhal_trng_init(&trng_obj);
/* Generate a true random number */
rnd_num = cyhal_trng_generate(&trng_obj);
/* Release the true random number generator block
* Note: Free only if not required anymore
*/
cyhal_trng_free(&trng_obj);

API Reference

 TRNG HAL Results
 TRNG specific return codes.
 

Functions

cy_rslt_t cyhal_trng_init (cyhal_trng_t *obj)
 Initialize the random number generator. More...
 
void cyhal_trng_free (cyhal_trng_t *obj)
 Release the random number generator. More...
 
uint32_t cyhal_trng_generate (const cyhal_trng_t *obj)
 Generate a random number. More...
 

Function Documentation

◆ cyhal_trng_init()

cy_rslt_t cyhal_trng_init ( cyhal_trng_t obj)

Initialize the random number generator.

Parameters
[out]objPointer to a random number generator object. The caller must allocate the memory for this object but the init function will initialize its contents.
Returns
The status of the init request

Returns CY_RSLT_SUCCESS if the operation was successful

◆ cyhal_trng_free()

void cyhal_trng_free ( cyhal_trng_t obj)

Release the random number generator.

Parameters
[in,out]objThe random number generator object

◆ cyhal_trng_generate()

uint32_t cyhal_trng_generate ( const cyhal_trng_t obj)

Generate a random number.

Parameters
[in]objThe random number generator object
Returns
The random number generated

See Simple TRNG number generation example