NEORV32 Software Framework Documentation
The NEORV32 RISC-V Processor
Loading...
Searching...
No Matches
neorv32_trng.h File Reference

True Random Number Generator (TRNG) HW driver header file. More...

#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  neorv32_trng_t
 

Functions

Prototypes
int neorv32_trng_available (void)
 
void neorv32_trng_enable (int irq_sel)
 
void neorv32_trng_disable (void)
 
void neorv32_trng_fifo_clear (void)
 
int neorv32_trng_get_fifo_depth (void)
 
int neorv32_trng_get (uint8_t *data)
 
int neorv32_trng_check_sim_mode (void)
 

IO Device: True Random Number Generator (TRNG)

#define NEORV32_TRNG   ((neorv32_trng_t*) (NEORV32_TRNG_BASE))
 
enum  NEORV32_TRNG_CTRL_enum {
  TRNG_CTRL_DATA_LSB = 0 , TRNG_CTRL_DATA_MSB = 7 , TRNG_CTRL_FIFO_LSB = 16 , TRNG_CTRL_FIFO_MSB = 19 ,
  TRNG_CTRL_IRQ_SEL = 27 , TRNG_CTRL_FIFO_CLR = 28 , TRNG_CTRL_SIM_MODE = 29 , TRNG_CTRL_EN = 30 ,
  TRNG_CTRL_VALID = 31
}
 

Detailed Description

True Random Number Generator (TRNG) HW driver header file.

Note
These functions should only be used if the TRNG unit was synthesized (IO_TRNG_EN = true).
See also
https://stnolting.github.io/neorv32/sw/files.html

Macro Definition Documentation

◆ NEORV32_TRNG

#define NEORV32_TRNG   ((neorv32_trng_t*) (NEORV32_TRNG_BASE))

TRNG module hardware access (neorv32_trng_t)

Enumeration Type Documentation

◆ NEORV32_TRNG_CTRL_enum

TRNG control/data register bits

Enumerator
TRNG_CTRL_DATA_LSB 

TRNG data/control register(0) (r/-): Random data byte LSB

TRNG_CTRL_DATA_MSB 

TRNG data/control register(7) (r/-): Random data byte MSB

TRNG_CTRL_FIFO_LSB 

TRNG data/control register(16) (r/-): log2(FIFO size), LSB

TRNG_CTRL_FIFO_MSB 

TRNG data/control register(19) (r/-): log2(FIFO size), MSB

TRNG_CTRL_IRQ_SEL 

TRNG data/control register(27) (r/w): Interrupt trigger select (0 = data available, 1 = FIFO full)

TRNG_CTRL_FIFO_CLR 

TRNG data/control register(28) (-/w): Clear data FIFO (auto clears)

TRNG_CTRL_SIM_MODE 

TRNG data/control register(29) (r/-): PRNG mode (simulation mode)

TRNG_CTRL_EN 

TRNG data/control register(30) (r/w): TRNG enable

TRNG_CTRL_VALID 

TRNG data/control register(31) (r/-): Random data output valid

Function Documentation

◆ neorv32_trng_available()

int neorv32_trng_available ( void )

Check if TRNG unit was synthesized.

Returns
0 if TRNG was not synthesized, 1 if TRNG is available.

◆ neorv32_trng_check_sim_mode()

int neorv32_trng_check_sim_mode ( void )

Check if TRNG is implemented using SIMULATION mode.

Warning
In simulation mode the physical entropy source is replaced by a PRNG (LFSR) with very bad random quality.
Returns
Simulation mode active when not zero.

◆ neorv32_trng_disable()

void neorv32_trng_disable ( void )

Reset and disable TRNG.

◆ neorv32_trng_enable()

void neorv32_trng_enable ( int irq_sel)

Reset, configure and enable TRNG.

Parameters
[in]irq_selInterrupt trigger select (0 = data available, 1 = FIFO full).

◆ neorv32_trng_fifo_clear()

void neorv32_trng_fifo_clear ( void )

Flush TRNG random data FIFO.

◆ neorv32_trng_get()

int neorv32_trng_get ( uint8_t * data)

Get random data byte from TRNG.

Parameters
[in,out]datauint8_t pointer for storing random data byte. Will be set to zero if no valid data available.
Returns
Data is valid when 0 and invalid otherwise.

◆ neorv32_trng_get_fifo_depth()

int neorv32_trng_get_fifo_depth ( void )

Get TRNG FIFO depth.

Returns
TRNG FIFO size (number of entries).