The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 167:84c0a372a020 1 /**
AnnaBridge 167:84c0a372a020 2 * @file
AnnaBridge 167:84c0a372a020 3 * @brief Pseudo-random number generator(PRNG) Peripheral Module.
AnnaBridge 167:84c0a372a020 4 * @note The PRNG hardware does not produce true random numbers. The
AnnaBridge 167:84c0a372a020 5 * output should be used as a seed to an approved random-number
AnnaBridge 167:84c0a372a020 6 * algorithm, per a certifying authority such as NIST or PCI. The
AnnaBridge 167:84c0a372a020 7 * approved algorithm will output random numbers which are cerfitied
AnnaBridge 167:84c0a372a020 8 * for use in encryption and authentication algorithms.
AnnaBridge 167:84c0a372a020 9 */
AnnaBridge 167:84c0a372a020 10 /* ****************************************************************************
AnnaBridge 167:84c0a372a020 11 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
AnnaBridge 167:84c0a372a020 12 *
AnnaBridge 167:84c0a372a020 13 * Permission is hereby granted, free of charge, to any person obtaining a
AnnaBridge 167:84c0a372a020 14 * copy of this software and associated documentation files (the "Software"),
AnnaBridge 167:84c0a372a020 15 * to deal in the Software without restriction, including without limitation
AnnaBridge 167:84c0a372a020 16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
AnnaBridge 167:84c0a372a020 17 * and/or sell copies of the Software, and to permit persons to whom the
AnnaBridge 167:84c0a372a020 18 * Software is furnished to do so, subject to the following conditions:
AnnaBridge 167:84c0a372a020 19 *
AnnaBridge 167:84c0a372a020 20 * The above copyright notice and this permission notice shall be included
AnnaBridge 167:84c0a372a020 21 * in all copies or substantial portions of the Software.
AnnaBridge 167:84c0a372a020 22 *
AnnaBridge 167:84c0a372a020 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
AnnaBridge 167:84c0a372a020 24 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
AnnaBridge 167:84c0a372a020 25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
AnnaBridge 167:84c0a372a020 26 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
AnnaBridge 167:84c0a372a020 27 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
AnnaBridge 167:84c0a372a020 28 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
AnnaBridge 167:84c0a372a020 29 * OTHER DEALINGS IN THE SOFTWARE.
AnnaBridge 167:84c0a372a020 30 *
AnnaBridge 167:84c0a372a020 31 * Except as contained in this notice, the name of Maxim Integrated
AnnaBridge 167:84c0a372a020 32 * Products, Inc. shall not be used except as stated in the Maxim Integrated
AnnaBridge 167:84c0a372a020 33 * Products, Inc. Branding Policy.
AnnaBridge 167:84c0a372a020 34 *
AnnaBridge 167:84c0a372a020 35 * The mere transfer of this software does not imply any licenses
AnnaBridge 167:84c0a372a020 36 * of trade secrets, proprietary technology, copyrights, patents,
AnnaBridge 167:84c0a372a020 37 * trademarks, maskwork rights, or any other form of intellectual
AnnaBridge 167:84c0a372a020 38 * property whatsoever. Maxim Integrated Products, Inc. retains all
AnnaBridge 167:84c0a372a020 39 * ownership rights.
AnnaBridge 167:84c0a372a020 40 *
AnnaBridge 167:84c0a372a020 41 * $Date: 2016-10-10 19:26:15 -0500 (Mon, 10 Oct 2016) $
AnnaBridge 167:84c0a372a020 42 * $Revision: 24668 $
AnnaBridge 167:84c0a372a020 43 *
AnnaBridge 167:84c0a372a020 44 ******************************************************************************/
AnnaBridge 167:84c0a372a020 45
AnnaBridge 167:84c0a372a020 46 /* **** Includes **** */
AnnaBridge 167:84c0a372a020 47 #include "prng_regs.h"
AnnaBridge 167:84c0a372a020 48
AnnaBridge 167:84c0a372a020 49 /* Define to prevent redundant inclusion */
AnnaBridge 167:84c0a372a020 50 #ifndef _PRNG_H_
AnnaBridge 167:84c0a372a020 51 #define _PRNG_H_
AnnaBridge 167:84c0a372a020 52
AnnaBridge 167:84c0a372a020 53 #ifdef __cplusplus
AnnaBridge 167:84c0a372a020 54 extern "C" {
AnnaBridge 167:84c0a372a020 55 #endif
AnnaBridge 167:84c0a372a020 56
AnnaBridge 167:84c0a372a020 57 /**
AnnaBridge 167:84c0a372a020 58 * @ingroup periphlibs
AnnaBridge 167:84c0a372a020 59 * @defgroup prng Pseudo-Random Number Generator (PRNG)
AnnaBridge 167:84c0a372a020 60 * @brief Pseudo-random number generator(PRNG) Peripheral Module.
AnnaBridge 167:84c0a372a020 61 * @note The PRNG hardware does not produce true random numbers. The
AnnaBridge 167:84c0a372a020 62 * output should be used as a seed to an approved random-number
AnnaBridge 167:84c0a372a020 63 * algorithm, per a certifying authority such as NIST or PCI. The
AnnaBridge 167:84c0a372a020 64 * approved algorithm will output random numbers which are cerfitied
AnnaBridge 167:84c0a372a020 65 * for use in encryption and authentication algorithms.
AnnaBridge 167:84c0a372a020 66 * @{
AnnaBridge 167:84c0a372a020 67 */
AnnaBridge 167:84c0a372a020 68
AnnaBridge 167:84c0a372a020 69 /* **** Definitions **** */
AnnaBridge 167:84c0a372a020 70
AnnaBridge 167:84c0a372a020 71 /* **** Globals **** */
AnnaBridge 167:84c0a372a020 72
AnnaBridge 167:84c0a372a020 73 /* **** Function Prototypes **** */
AnnaBridge 167:84c0a372a020 74
AnnaBridge 167:84c0a372a020 75 /**
AnnaBridge 167:84c0a372a020 76 * @brief Initialize required clocks and enable PRNG module
AnnaBridge 167:84c0a372a020 77 * @note This function will set the clock divisors to divide by 1 if they are disabled.
AnnaBridge 167:84c0a372a020 78 * Otherwise, the clock divisors are left unchanged.
AnnaBridge 167:84c0a372a020 79 */
AnnaBridge 167:84c0a372a020 80 void PRNG_Init(void);
AnnaBridge 167:84c0a372a020 81
AnnaBridge 167:84c0a372a020 82 /**
AnnaBridge 167:84c0a372a020 83 * @brief Returns ready bit to indicates that the PRNG_GetSeed can be
AnnaBridge 167:84c0a372a020 84 * called without being held off. Only needs to be called one time after a POR event.
AnnaBridge 167:84c0a372a020 85 *
AnnaBridge 167:84c0a372a020 86 * @retval 0 PRNG not ready
AnnaBridge 167:84c0a372a020 87 * @retval non-zero PRNG ready to read
AnnaBridge 167:84c0a372a020 88 */
AnnaBridge 167:84c0a372a020 89 __STATIC_INLINE uint16_t PRNG_Ready(void)
AnnaBridge 167:84c0a372a020 90 {
AnnaBridge 167:84c0a372a020 91 return (MXC_PRNG->user_entropy & MXC_F_PRNG_USER_ENTROPY_RND_NUM_READY);
AnnaBridge 167:84c0a372a020 92 }
AnnaBridge 167:84c0a372a020 93
AnnaBridge 167:84c0a372a020 94 /**
AnnaBridge 167:84c0a372a020 95 * @brief Retrieve a seed value from the PRNG.
AnnaBridge 167:84c0a372a020 96 * @note The PRNG hardware does not produce true random numbers. The
AnnaBridge 167:84c0a372a020 97 * output should be used as a seed to an approved random-number
AnnaBridge 167:84c0a372a020 98 * algorithm, per a certifying authority such as NIST or PCI. The
AnnaBridge 167:84c0a372a020 99 * approved algorithm will output random numbers which are cerfitied
AnnaBridge 167:84c0a372a020 100 * for use in encryption and authentication algorithms.
AnnaBridge 167:84c0a372a020 101 *
AnnaBridge 167:84c0a372a020 102 * @return 16-bit seed value
AnnaBridge 167:84c0a372a020 103 */
AnnaBridge 167:84c0a372a020 104 __STATIC_INLINE uint16_t PRNG_GetSeed(void)
AnnaBridge 167:84c0a372a020 105 {
AnnaBridge 167:84c0a372a020 106 return MXC_PRNG->rnd_num;
AnnaBridge 167:84c0a372a020 107 }
AnnaBridge 167:84c0a372a020 108
AnnaBridge 167:84c0a372a020 109 /**
AnnaBridge 167:84c0a372a020 110 * @brief Add user entropy to the PRNG entropy source.
AnnaBridge 167:84c0a372a020 111 *
AnnaBridge 167:84c0a372a020 112 * @param entropy A value to be mixed into the PRNG entropy source.
AnnaBridge 167:84c0a372a020 113 */
AnnaBridge 167:84c0a372a020 114 __STATIC_INLINE void PRNG_AddUserEntropy(uint8_t entropy)
AnnaBridge 167:84c0a372a020 115 {
AnnaBridge 167:84c0a372a020 116 MXC_PRNG->user_entropy = (uint32_t)entropy;
AnnaBridge 167:84c0a372a020 117 }
AnnaBridge 167:84c0a372a020 118 /**@}*/
AnnaBridge 167:84c0a372a020 119 #ifdef __cplusplus
AnnaBridge 167:84c0a372a020 120 }
AnnaBridge 167:84c0a372a020 121 #endif
AnnaBridge 167:84c0a372a020 122
AnnaBridge 167:84c0a372a020 123 #endif /* _PRNG_H_ */