Functions

Random number generator (hal_rng)
[nRF24LE1 HAL]


The Random Number Generator (RNG) uses thermal noise to produce a non-deterministic bit stream. A digital corrector algorithm is used on the bit stream to remove any bias. The bits are then queued into an 8-bit register for parallel readout.

This module contains functions for initializing and enabling the number generator, for checking the status of the generator and for reading one random number.

Functions

void hal_rng_power_up (_Bool pwr_up)
void hal_rng_bias_corr_enable (_Bool en)
uint8_t hal_rng_read (void)
_Bool hal_rng_data_ready (void)

Function Documentation

void hal_rng_power_up ( _Bool  pwr_up )

Function to power up and power down the random number generator. When power up is set, the random number generator starts generating a random number.

Parameters:
pwr_upTrue to power up, false to power down

< The value of bit 7

< The value of bit 7

Definition at line 25 of file hal_rng.c.

{
  if(pwr_up)
  {
    RNGCTL = (RNGCTL | BIT_7);      // powerUp bit = 1, power up the RNG
  }
  else
  {
    RNGCTL = (RNGCTL & ~(BIT_7));   // powerUp bit = 0, turn off the RNG
  }
}
void hal_rng_bias_corr_enable ( _Bool  en )

Function to control the bias corrector on the random number generator. Use this function to enable or disable the bias corrector.

Parameters:
enTrue to enable, false to disable bias corrector

< The value of bit 6

< The value of bit 6

Definition at line 37 of file hal_rng.c.

{
  if(en)
  {
    RNGCTL = (RNGCTL | BIT_6);      // correctorEn bit = 1, turn on corrector
  }
  else
  {
    RNGCTL = (RNGCTL & ~(BIT_6));   // correctorEn bit = 0, turn off corrector
  }
}
uint8_t hal_rng_read ( void   )

Function to read the random data register on the random number generator. Use this function to get the random number from the random number generator.

Returns:
Random data

Definition at line 49 of file hal_rng.c.

{
  return RNGDAT;                    // Return data stored in RNGDAT register
}
_Bool hal_rng_data_ready ( void   )

Function that returns the status of the RNG. This function returns true if there is data ready from the RNG.

Returns:
RNG Data ready bit
Return values:
FALSEno data available
TRUEdata available

< The value of bit 5

Definition at line 54 of file hal_rng.c.

{
  return((RNGCTL & BIT_5) > 0);     // Return true if data ready bit is 1
}