source: rtems/bsps/arm/atsam/contrib/libraries/libchip/source/trng.c @ 54aabb7

5
Last change on this file since 54aabb7 was 54aabb7, checked in by Sebastian Huber <sebastian.huber@…>, on 04/22/18 at 13:11:43

bsp/atsam: Move libraries to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/* ---------------------------------------------------------------------------- */
2/*                  Atmel Microcontroller Software Support                      */
3/*                       SAM Software Package License                           */
4/* ---------------------------------------------------------------------------- */
5/* Copyright (c) 2015, Atmel Corporation                                        */
6/*                                                                              */
7/* All rights reserved.                                                         */
8/*                                                                              */
9/* Redistribution and use in source and binary forms, with or without           */
10/* modification, are permitted provided that the following condition is met:    */
11/*                                                                              */
12/* - Redistributions of source code must retain the above copyright notice,     */
13/* this list of conditions and the disclaimer below.                            */
14/*                                                                              */
15/* Atmel's name may not be used to endorse or promote products derived from     */
16/* this software without specific prior written permission.                     */
17/*                                                                              */
18/* DISCLAIMER:  THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR   */
19/* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
20/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE   */
21/* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,      */
22/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
23/* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,  */
24/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    */
25/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING         */
26/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
27/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                           */
28/* ---------------------------------------------------------------------------- */
29
30/** \addtogroup rtng_module Working with RTNG
31 * \ingroup peripherals_module
32 * The TRNG driver provides the interface to configure and use the TRNG
33 * peripheral.\n
34 *
35 * The True Random Number Generator (TRNG) passes the American NIST Special
36 * Publication 800-22 and Diehard Random Tests Suites. As soon as the TRNG is
37 * enabled (TRNG_Enable()),  the generator provides one 32-bit value every 84
38 * clock cycles.  Interrupt trng_int can be enabled through TRNG_EnableIt()
39 * (respectively disabled in TRNG_IDR).
40 * This interrupt is set when a new random value is available and is cleared
41 * when the status  register is read (TRNG_SR register). The flag DATRDY of
42 * the status register (TRNG_ISR) is set when the random data is ready to be
43 * read out on the 32-bit output data through TRNG_GetRandData().
44 *
45 * For more accurate information, please look at the SHA section of the
46 * Datasheet.
47 *
48 * Related files :\n
49 * \ref trng.c\n
50 * \ref trng.h\n
51 */
52/*@{*/
53/*@}*/
54
55/**
56 * \file
57 *
58 * Implementation of True Random Number Generator (TRNG)
59 *
60 */
61
62/*----------------------------------------------------------------------------
63 *        Headers
64 *----------------------------------------------------------------------------*/
65
66#include "chip.h"
67
68/*----------------------------------------------------------------------------
69 *        Exported functions
70 *----------------------------------------------------------------------------*/
71
72/**
73 * \brief Enables the TRNG to provide Random Values.
74 * \param key  This key is to be written when the ENABLE bit is set.
75 */
76void TRNG_Enable(void)
77{
78        TRNG->TRNG_CR = TRNG_CR_ENABLE | TRNG_CR_KEY_PASSWD;
79}
80
81/**
82 * \brief Disables the TRNG to provide Random Values.
83 * \param key  This key is to be written when the DISABLE bit is set.
84 */
85void TRNG_Disable(void)
86{
87        TRNG->TRNG_CR = TRNG_CR_KEY_PASSWD;
88}
89
90/**
91 * \brief Data Ready Interrupt enable.
92 */
93void TRNG_EnableIt(void)
94{
95        TRNG->TRNG_IER = TRNG_IER_DATRDY;
96}
97
98/**
99 * \brief Data Ready Interrupt Disable.
100 */
101void TRNG_DisableIt(void)
102{
103        TRNG->TRNG_IDR = TRNG_IDR_DATRDY;
104}
105
106/**
107 * \brief Get the current status register of the given TRNG peripheral.
108 * \return  TRNG status register.
109 */
110uint32_t TRNG_GetStatus(void)
111{
112        return TRNG->TRNG_ISR;
113}
114
115/**
116 * \brief Get the  32-bit Output Data from TRNG peripheral.
117 * \return  TRNG output data.
118 */
119uint32_t TRNG_GetRandData(void)
120{
121        return TRNG->TRNG_ODATA;
122}
Note: See TracBrowser for help on using the repository browser.