libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
|
This library supports "version 1" of the random number generator peripheral (RNG) in the STM32 series of ARM Cortex Microcontrollers by ST Microelectronics. More...
Macros | |
#define | RNG_CR MMIO32(RNG_BASE + 0x00) |
#define | RNG_SR MMIO32(RNG_BASE + 0x04) |
#define | RNG_DR MMIO32(RNG_BASE + 0x08) |
#define | RNG_CR_RNGEN (1 << 2) |
#define | RNG_CR_IE (1 << 3) |
#define | RNG_SR_DRDY (1 << 0) |
#define | RNG_SR_CECS (1 << 1) |
#define | RNG_SR_SECS (1 << 2) |
#define | RNG_SR_CEIS (1 << 5) |
#define | RNG_SR_SEIS (1 << 6) |
Functions | |
void | rng_enable (void) |
Enable the Random Number Generator peripheral. More... | |
void | rng_disable (void) |
Disable the Random Number Generator peripheral. More... | |
void | rng_interrupt_enable (void) |
Enable the Random Number Generator error interrupt. More... | |
void | rng_interrupt_disable (void) |
Disable the Random Number Generator error interrupt. More... | |
bool | rng_get_random (uint32_t *rand_nr) |
Randomizes a number (non-blocking). More... | |
uint32_t | rng_get_random_blocking (void) |
Get a random number and block until it works. More... | |
This library supports "version 1" of the random number generator peripheral (RNG) in the STM32 series of ARM Cortex Microcontrollers by ST Microelectronics.
This is a common peripheral available on multiple devices in the family.
LGPL License Terms libopencm3 License
Definition at line 39 of file rng_common_v1.h.
#define RNG_CR_IE (1 << 3) |
Definition at line 53 of file rng_common_v1.h.
#define RNG_CR_RNGEN (1 << 2) |
Definition at line 50 of file rng_common_v1.h.
Definition at line 45 of file rng_common_v1.h.
Definition at line 42 of file rng_common_v1.h.
#define RNG_SR_CECS (1 << 1) |
Definition at line 61 of file rng_common_v1.h.
#define RNG_SR_CEIS (1 << 5) |
Definition at line 67 of file rng_common_v1.h.
#define RNG_SR_DRDY (1 << 0) |
Definition at line 58 of file rng_common_v1.h.
#define RNG_SR_SECS (1 << 2) |
Definition at line 64 of file rng_common_v1.h.
#define RNG_SR_SEIS (1 << 6) |
Definition at line 70 of file rng_common_v1.h.
void rng_disable | ( | void | ) |
Disable the Random Number Generator peripheral.
Definition at line 35 of file rng_common_v1.c.
References RNG_CR.
void rng_enable | ( | void | ) |
Enable the Random Number Generator peripheral.
Definition at line 42 of file rng_common_v1.c.
References RNG_CR, and RNG_CR_RNGEN.
bool rng_get_random | ( | uint32_t * | rand_nr | ) |
Randomizes a number (non-blocking).
Can fail if a clock error or seed error is detected. Consult the Reference Manual, but "try again", potentially after resetting the peripheral
rand_nr | pointer to a uint32_t that will be randomized. |
Definition at line 68 of file rng_common_v1.c.
References RNG_DR, RNG_SR, RNG_SR_CECS, RNG_SR_DRDY, and RNG_SR_SECS.
Referenced by rng_get_random_blocking().
uint32_t rng_get_random_blocking | ( | void | ) |
Get a random number and block until it works.
Unless you have a clock problem, this should always return "promptly" If you have a clock problem, you will wait here forever! Check device RM for clock requirements (usually fRNGCLK > fHCLK/16 or fRNGCLK > fHCLK/32
Definition at line 95 of file rng_common_v1.c.
References RNG_CR, RNG_CR_RNGEN, RNG_DR, rng_get_random(), RNG_SR, RNG_SR_CEIS, and RNG_SR_SEIS.
void rng_interrupt_disable | ( | void | ) |
Disable the Random Number Generator error interrupt.
Definition at line 56 of file rng_common_v1.c.
References RNG_CR.
void rng_interrupt_enable | ( | void | ) |
Enable the Random Number Generator error interrupt.
Definition at line 49 of file rng_common_v1.c.