libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
rng_common_v1.h
Go to the documentation of this file.
1/** @addtogroup rng_file
2 */
3/*
4 * This file is part of the libopencm3 project.
5 *
6 *
7 * This library is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA RNG.H
22The order of header inclusion is important. rng.h includes the device
23specific memorymap.h header before including this header file.*/
24
25/** @cond */
26#ifdef LIBOPENCM3_RNG_H
27/** @endcond */
28#ifndef LIBOPENCM3_RNG_V1_H
29#define LIBOPENCM3_RNG_V1_H
30
31#include <stdbool.h>
32#include <stdint.h>
33
34/**@{*/
35
36/* --- Random number generator registers ----------------------------------- */
37
38/* Control register */
39#define RNG_CR MMIO32(RNG_BASE + 0x00)
40
41/* Status register */
42#define RNG_SR MMIO32(RNG_BASE + 0x04)
43
44/* Data register */
45#define RNG_DR MMIO32(RNG_BASE + 0x08)
46
47/* --- RNG_CR values ------------------------------------------------------- */
48
49/* RNG ENABLE */
50#define RNG_CR_RNGEN (1 << 2)
51
52/* RNG interrupt enable */
53#define RNG_CR_IE (1 << 3)
54
55/* --- RNG_SR values ------------------------------------------------------- */
56
57/* Data ready */
58#define RNG_SR_DRDY (1 << 0)
59
60/* Clock error current status */
61#define RNG_SR_CECS (1 << 1)
62
63/* Seed error current status */
64#define RNG_SR_SECS (1 << 2)
65
66/* Clock error interrupt status */
67#define RNG_SR_CEIS (1 << 5)
68
69/* Seed error interrupt status */
70#define RNG_SR_SEIS (1 << 6)
71
72/* --- Function prototypes ------------------------------------------------- */
73
75
76void rng_enable(void);
77void rng_disable(void);
78void rng_interrupt_enable(void);
79void rng_interrupt_disable(void);
80bool rng_get_random(uint32_t *rand_nr);
81uint32_t rng_get_random_blocking(void);
82
84
85/**@}*/
86
87#endif
88/** @cond */
89#else
90#warning "rng_common_v1.h should not be included explicitly, only via rng.h"
91#endif
92/** @endcond */
93
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
void rng_enable(void)
Enable the Random Number Generator peripheral.
Definition: rng_common_v1.c:42
void rng_disable(void)
Disable the Random Number Generator peripheral.
Definition: rng_common_v1.c:35
void rng_interrupt_enable(void)
Enable the Random Number Generator error interrupt.
Definition: rng_common_v1.c:49
bool rng_get_random(uint32_t *rand_nr)
Randomizes a number (non-blocking).
Definition: rng_common_v1.c:68
uint32_t rng_get_random_blocking(void)
Get a random number and block until it works.
Definition: rng_common_v1.c:95
void rng_interrupt_disable(void)
Disable the Random Number Generator error interrupt.
Definition: rng_common_v1.c:56