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