00001 /* ---------------------------------------------------------------------------- 00002 * SAM Software Package License 00003 * ---------------------------------------------------------------------------- 00004 * Copyright (c) 2014, Atmel Corporation 00005 * 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are met: 00010 * 00011 * - Redistributions of source code must retain the above copyright notice, 00012 * this list of conditions and the disclaimer below. 00013 * 00014 * Atmel's name may not be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR 00018 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00019 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 00020 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, 00021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00022 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00023 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00024 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00025 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00026 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 * ---------------------------------------------------------------------------- 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 SAM V71 Xplained Ultra 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 SAM V71 Xplained Ultra board. 00051 * Please refer to the Getting Started with SAM V71 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 rates 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