00001 /* ---------------------------------------------------------------------------- */ 00002 /* Atmel Microcontroller Software Support */ 00003 /* SAM Software Package License */ 00004 /* ---------------------------------------------------------------------------- */ 00005 /* Copyright (c) 2015, Atmel Corporation */ 00006 /* */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without */ 00010 /* modification, are permitted provided that the following condition is met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, */ 00013 /* this list of conditions and the disclaimer below. */ 00014 /* */ 00015 /* Atmel's name may not be used to endorse or promote products derived from */ 00016 /* this software without specific prior written permission. */ 00017 /* */ 00018 /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ 00019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ 00020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ 00021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ 00022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 00023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ 00024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ 00025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ 00026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ 00027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 00028 /* ---------------------------------------------------------------------------- */ 00029 00030 /** \addtogroup rtng_module Working with RTNG 00031 * \ingroup peripherals_module 00032 * The TRNG driver provides the interface to configure and use the TRNG 00033 * peripheral.\n 00034 * 00035 * The True Random Number Generator (TRNG) passes the American NIST Special 00036 * Publication 800-22 and Diehard Random Tests Suites. As soon as the TRNG is 00037 * enabled (TRNG_Enable()), the generator provides one 32-bit value every 84 00038 * clock cycles. Interrupt trng_int can be enabled through TRNG_EnableIt() 00039 * (respectively disabled in TRNG_IDR). 00040 * This interrupt is set when a new random value is available and is cleared 00041 * when the status register is read (TRNG_SR register). The flag DATRDY of 00042 * the status register (TRNG_ISR) is set when the random data is ready to be 00043 * read out on the 32-bit output data through TRNG_GetRandData(). 00044 * 00045 * For more accurate information, please look at the SHA section of the 00046 * Datasheet. 00047 * 00048 * Related files :\n 00049 * \ref trng.c\n 00050 * \ref trng.h\n 00051 */ 00052 /*@{*/ 00053 /*@}*/ 00054 00055 /** 00056 * \file 00057 * 00058 * Implementation of True Random Number Generator (TRNG) 00059 * 00060 */ 00061 00062 /*---------------------------------------------------------------------------- 00063 * Headers 00064 *----------------------------------------------------------------------------*/ 00065 00066 #include "chip.h" 00067 00068 /*---------------------------------------------------------------------------- 00069 * Exported functions 00070 *----------------------------------------------------------------------------*/ 00071 00072 /** 00073 * \brief Enables the TRNG to provide Random Values. 00074 * \param key This key is to be written when the ENABLE bit is set. 00075 */ 00076 void TRNG_Enable(void) 00077 { 00078 TRNG->TRNG_CR = TRNG_CR_ENABLE | TRNG_CR_KEY_PASSWD; 00079 } 00080 00081 /** 00082 * \brief Disables the TRNG to provide Random Values. 00083 * \param key This key is to be written when the DISABLE bit is set. 00084 */ 00085 void TRNG_Disable(void) 00086 { 00087 TRNG->TRNG_CR = TRNG_CR_KEY_PASSWD; 00088 } 00089 00090 /** 00091 * \brief Data Ready Interrupt enable. 00092 */ 00093 void TRNG_EnableIt(void) 00094 { 00095 TRNG->TRNG_IER = TRNG_IER_DATRDY; 00096 } 00097 00098 /** 00099 * \brief Data Ready Interrupt Disable. 00100 */ 00101 void TRNG_DisableIt(void) 00102 { 00103 TRNG->TRNG_IDR = TRNG_IDR_DATRDY; 00104 } 00105 00106 /** 00107 * \brief Get the current status register of the given TRNG peripheral. 00108 * \return TRNG status register. 00109 */ 00110 uint32_t TRNG_GetStatus(void) 00111 { 00112 return TRNG->TRNG_ISR; 00113 } 00114 00115 /** 00116 * \brief Get the 32-bit Output Data from TRNG peripheral. 00117 * \return TRNG output data. 00118 */ 00119 uint32_t TRNG_GetRandData(void) 00120 { 00121 return TRNG->TRNG_ODATA; 00122 }