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 /** 00031 * \page trng True Random Number Generator Example 00032 * 00033 * \section Purpose 00034 * The TRNG example shows how to generate random data with TRNG peripheral. 00035 * 00036 * \section Requirements 00037 * 00038 * This package can be used with SAMV71 Xplained Ultra board or SAME70 Xplained board. 00039 * 00040 * \section Description 00041 * 00042 * The demonstration program configure TRNG peripheral. As soon as the TRNG is 00043 * enabled the generator provides one 32-bit value every 84 clock cycles. 00044 * TRNG interrupt status DATRDY is set when a new random value is ready, it can 00045 * be read out on the 32-bit output data register (TRNG_ODATA)in TRNG interrupt 00046 * routine. 00047 * 00048 * \section Usage 00049 * 00050 * -# Build the program and download it inside the board. 00051 * Please refer to the Getting Started with SAM V71/E70 Microcontrollers.pdf 00052 * -# On the computer, open and configure a terminal application 00053 * (e.g. HyperTerminal on Microsoft Windows) with these settings: 00054 * - 115200 baud rate 00055 * - 8 bits of data 00056 * - No parity 00057 * - 1 stop bit 00058 * - No flow control 00059 * -# In the terminal window, the 00060 * following text should appear (values depend on the board and chip used): 00061 * \code 00062 * -- TRNG Example xxx -- 00063 * -- SAMxxxxxx-xx 00064 * -- Compiled: xxx xx xxxx xx:xx:xx -- 00065 * \endcode 00066 * -# In the terminal window, we will see random data generated by TRNG 00067 * peripheral. 00068 * 00069 * \section References 00070 * - trng/main.c 00071 * - trng.h 00072 */ 00073 00074 /** \file 00075 * 00076 * This file contains all the specific code for the TRNG 00077 */ 00078 00079 /*---------------------------------------------------------------------------- 00080 * Headers 00081 *----------------------------------------------------------------------------*/ 00082 #include <board.h> 00083 00084 /*---------------------------------------------------------------------------- 00085 * Local functions 00086 *----------------------------------------------------------------------------*/ 00087 /** 00088 * \brief TRNG interrupt handler 00089 */ 00090 void TRNG_Handler(void) 00091 { 00092 if (TRNG_GetStatus() == TRNG_ISR_DATRDY) { 00093 TRNG_DisableIt(); 00094 printf("0x%x \n\r", (unsigned int)TRNG_GetRandData()); 00095 TRNG_EnableIt(); 00096 } 00097 } 00098 00099 /*---------------------------------------------------------------------------- 00100 * Exported functions 00101 *----------------------------------------------------------------------------*/ 00102 /** 00103 * \brief Application entry point for TRNG example 00104 * 00105 * \return Unused (ANSI-C compatibility). 00106 * \callgraph 00107 */ 00108 int main( void ) 00109 { 00110 /* Disable watchdog */ 00111 WDT_Disable(WDT); 00112 00113 /* Enable I and D cache */ 00114 SCB_EnableICache(); 00115 SCB_EnableDCache(); 00116 00117 /* Output example information */ 00118 printf("-- TRNG Example %s --\n\r", SOFTPACK_VERSION ); 00119 printf("-- %s\n\r", BOARD_NAME); 00120 printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME); 00121 00122 /* Enable TRNG peripheral clock */ 00123 PMC_EnablePeripheral(ID_TRNG); 00124 00125 /* Configure TC interrupts */ 00126 NVIC_ClearPendingIRQ(TRNG_IRQn); 00127 NVIC_SetPriority(TRNG_IRQn ,1); 00128 NVIC_EnableIRQ(TRNG_IRQn); 00129 00130 /* Enable TRNG interrupt */ 00131 TRNG_EnableIt(); 00132 00133 /* Enable TRNG */ 00134 TRNG_Enable(); 00135 while (1); 00136 } 00137