1 /* ----------------------------------------------------------------------------
\r
2 * SAM Software Package License
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2013, Atmel Corporation
\r
6 * All rights reserved.
\r
8 * Redistribution and use in source and binary forms, with or without
\r
9 * modification, are permitted provided that the following conditions are met:
\r
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\r
14 * Atmel's name may not be used to endorse or promote products derived from
\r
15 * this software without specific prior written permission.
\r
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
\r
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
\r
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
27 * ----------------------------------------------------------------------------
\r
30 /** \addtogroup rtng_module Working with RTNG
\r
31 * \ingroup peripherals_module
\r
32 * The TRNG driver provides the interface to configure and use the TRNG peripheral.
\r
35 * The True Random Number Generator (TRNG) passes the American NIST Special Publication
\r
36 * 800-22 and Diehard Random Tests Suites. As soon as the TRNG is enabled (TRNG_Enable()),
\r
37 * the generator provides one 32-bit value every 84 clock cycles.
\r
38 * Interrupt trng_int can be enabled through TRNG_EnableIt()(respectively disabled in TRNG_IDR).
\r
39 * This interrupt is set when a new random value is available and is cleared when the status
\r
40 * register is read (TRNG_SR register). The flag DATRDY of the status register (TRNG_ISR) is set
\r
41 * when the random data is ready to be read out on the 32-bit output data through TRNG_GetRandData().
\r
43 * For more accurate information, please look at the SHA section of the
\r
56 * Implementation of True Random Number Generator (TRNG)
\r
60 /*----------------------------------------------------------------------------
\r
62 *----------------------------------------------------------------------------*/
\r
66 /*----------------------------------------------------------------------------
\r
67 * Exported functions
\r
68 *----------------------------------------------------------------------------*/
\r
71 * \brief Enables the TRNG to provide Random Values.
\r
72 * \param key This key is to be written when the ENABLE bit is set.
\r
74 void TRNG_Enable(void)
\r
76 TRNG->TRNG_CR = TRNG_CR_ENABLE | TRNG_CR_KEY_PASSWD;
\r
80 * \brief Disables the TRNG to provide Random Values.
\r
81 * \param key This key is to be written when the DISABLE bit is set.
\r
83 void TRNG_Disable(void)
\r
85 TRNG->TRNG_CR = TRNG_CR_KEY_PASSWD;
\r
89 * \brief Data Ready Interrupt enable.
\r
91 void TRNG_EnableIt(void)
\r
93 TRNG->TRNG_IER = TRNG_IER_DATRDY;
\r
97 * \brief Data Ready Interrupt Disable.
\r
99 void TRNG_DisableIt(void)
\r
101 TRNG->TRNG_IDR = TRNG_IDR_DATRDY;
\r
105 * \brief Get the current status register of the given TRNG peripheral.
\r
106 * \return TRNG status register.
\r
108 uint32_t TRNG_GetStatus(void)
\r
110 return TRNG->TRNG_ISR;
\r
114 * \brief Get the 32-bit Output Data from TRNG peripheral.
\r
115 * \return TRNG output data.
\r
117 uint32_t TRNG_GetRandData(void)
\r
119 return TRNG->TRNG_ODATA;
\r