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:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
TARGET_USENSE/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL82Z/drivers/fsl_trng.h@145:64910690c574
mbed library. Release version 164

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 145:64910690c574 1 /*
AnnaBridge 145:64910690c574 2 * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
AnnaBridge 145:64910690c574 3 * All rights reserved.
AnnaBridge 145:64910690c574 4 *
AnnaBridge 145:64910690c574 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 145:64910690c574 6 * are permitted provided that the following conditions are met:
AnnaBridge 145:64910690c574 7 *
AnnaBridge 145:64910690c574 8 * o Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 145:64910690c574 9 * of conditions and the following disclaimer.
AnnaBridge 145:64910690c574 10 *
AnnaBridge 145:64910690c574 11 * o Redistributions in binary form must reproduce the above copyright notice, this
AnnaBridge 145:64910690c574 12 * list of conditions and the following disclaimer in the documentation and/or
AnnaBridge 145:64910690c574 13 * other materials provided with the distribution.
AnnaBridge 145:64910690c574 14 *
AnnaBridge 145:64910690c574 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
AnnaBridge 145:64910690c574 16 * contributors may be used to endorse or promote products derived from this
AnnaBridge 145:64910690c574 17 * software without specific prior written permission.
AnnaBridge 145:64910690c574 18 *
AnnaBridge 145:64910690c574 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 145:64910690c574 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 145:64910690c574 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 145:64910690c574 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 145:64910690c574 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 145:64910690c574 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 145:64910690c574 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 145:64910690c574 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 145:64910690c574 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 145:64910690c574 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 145:64910690c574 29 */
AnnaBridge 145:64910690c574 30 #ifndef _FSL_TRNG_DRIVER_H_
AnnaBridge 145:64910690c574 31 #define _FSL_TRNG_DRIVER_H_
AnnaBridge 145:64910690c574 32
AnnaBridge 145:64910690c574 33 #include "fsl_common.h"
AnnaBridge 145:64910690c574 34
AnnaBridge 145:64910690c574 35 #if defined(FSL_FEATURE_SOC_TRNG_COUNT) && FSL_FEATURE_SOC_TRNG_COUNT
AnnaBridge 145:64910690c574 36
AnnaBridge 145:64910690c574 37 /*!
AnnaBridge 145:64910690c574 38 * @addtogroup trng_driver
AnnaBridge 145:64910690c574 39 * @{
AnnaBridge 145:64910690c574 40 */
AnnaBridge 145:64910690c574 41
AnnaBridge 145:64910690c574 42
AnnaBridge 145:64910690c574 43 /*******************************************************************************
AnnaBridge 145:64910690c574 44 * Definitions
AnnaBridge 145:64910690c574 45 *******************************************************************************/
AnnaBridge 145:64910690c574 46
AnnaBridge 145:64910690c574 47 /*! @name Driver version */
AnnaBridge 145:64910690c574 48 /*@{*/
AnnaBridge 145:64910690c574 49 /*! @brief TRNG driver version 2.0.1.
AnnaBridge 145:64910690c574 50 *
AnnaBridge 145:64910690c574 51 * Current version: 2.0.1
AnnaBridge 145:64910690c574 52 *
AnnaBridge 145:64910690c574 53 * Change log:
AnnaBridge 145:64910690c574 54 * - Version 2.0.1
AnnaBridge 145:64910690c574 55 * - add support for KL8x and KL28Z
AnnaBridge 145:64910690c574 56 * - update default OSCDIV for K81 to divide by 2
AnnaBridge 145:64910690c574 57 */
AnnaBridge 145:64910690c574 58 #define FSL_TRNG_DRIVER_VERSION (MAKE_VERSION(2, 0, 1))
AnnaBridge 145:64910690c574 59 /*@}*/
AnnaBridge 145:64910690c574 60
AnnaBridge 145:64910690c574 61 /*! @brief TRNG sample mode. Used by trng_config_t. */
AnnaBridge 145:64910690c574 62 typedef enum _trng_sample_mode
AnnaBridge 145:64910690c574 63 {
AnnaBridge 145:64910690c574 64 kTRNG_SampleModeVonNeumann = 0U, /*!< Use von Neumann data in both Entropy shifter and Statistical Checker. */
AnnaBridge 145:64910690c574 65 kTRNG_SampleModeRaw = 1U, /*!< Use raw data into both Entropy shifter and Statistical Checker. */
AnnaBridge 145:64910690c574 66 kTRNG_SampleModeVonNeumannRaw =
AnnaBridge 145:64910690c574 67 2U /*!< Use von Neumann data in Entropy shifter. Use raw data into Statistical Checker. */
AnnaBridge 145:64910690c574 68 } trng_sample_mode_t;
AnnaBridge 145:64910690c574 69
AnnaBridge 145:64910690c574 70 /*! @brief TRNG clock mode. Used by trng_config_t. */
AnnaBridge 145:64910690c574 71 typedef enum _trng_clock_mode
AnnaBridge 145:64910690c574 72 {
AnnaBridge 145:64910690c574 73 kTRNG_ClockModeRingOscillator = 0U, /*!< Ring oscillator is used to operate the TRNG (default). */
AnnaBridge 145:64910690c574 74 kTRNG_ClockModeSystem = 1U /*!< System clock is used to operate the TRNG. This is for test use only, and
AnnaBridge 145:64910690c574 75 indeterminate results may occur. */
AnnaBridge 145:64910690c574 76 } trng_clock_mode_t;
AnnaBridge 145:64910690c574 77
AnnaBridge 145:64910690c574 78 /*! @brief TRNG ring oscillator divide. Used by trng_config_t. */
AnnaBridge 145:64910690c574 79 typedef enum _trng_ring_osc_div
AnnaBridge 145:64910690c574 80 {
AnnaBridge 145:64910690c574 81 kTRNG_RingOscDiv0 = 0U, /*!< Ring oscillator with no divide */
AnnaBridge 145:64910690c574 82 kTRNG_RingOscDiv2 = 1U, /*!< Ring oscillator divided-by-2. */
AnnaBridge 145:64910690c574 83 kTRNG_RingOscDiv4 = 2U, /*!< Ring oscillator divided-by-4. */
AnnaBridge 145:64910690c574 84 kTRNG_RingOscDiv8 = 3U /*!< Ring oscillator divided-by-8. */
AnnaBridge 145:64910690c574 85 } trng_ring_osc_div_t;
AnnaBridge 145:64910690c574 86
AnnaBridge 145:64910690c574 87 /*! @brief Data structure for definition of statistical check limits. Used by trng_config_t. */
AnnaBridge 145:64910690c574 88 typedef struct _trng_statistical_check_limit
AnnaBridge 145:64910690c574 89 {
AnnaBridge 145:64910690c574 90 uint32_t maximum; /*!< Maximum limit.*/
AnnaBridge 145:64910690c574 91 uint32_t minimum; /*!< Minimum limit.*/
AnnaBridge 145:64910690c574 92 } trng_statistical_check_limit_t;
AnnaBridge 145:64910690c574 93
AnnaBridge 145:64910690c574 94 /*!
AnnaBridge 145:64910690c574 95 * @brief Data structure for the TRNG initialization
AnnaBridge 145:64910690c574 96 *
AnnaBridge 145:64910690c574 97 * This structure initializes the TRNG by calling the the TRNG_Init() function.
AnnaBridge 145:64910690c574 98 * It contains all TRNG configurations.
AnnaBridge 145:64910690c574 99 */
AnnaBridge 145:64910690c574 100 typedef struct _trng_user_config
AnnaBridge 145:64910690c574 101 {
AnnaBridge 145:64910690c574 102 bool lock; /*!< @brief Disable programmability of TRNG registers. */
AnnaBridge 145:64910690c574 103 trng_clock_mode_t clockMode; /*!< @brief Clock mode used to operate TRNG.*/
AnnaBridge 145:64910690c574 104 trng_ring_osc_div_t ringOscDiv; /*!< @brief Ring oscillator divide used by TRNG. */
AnnaBridge 145:64910690c574 105 trng_sample_mode_t sampleMode; /*!< @brief Sample mode of the TRNG ring oscillator. */
AnnaBridge 145:64910690c574 106 /* Seed Control*/
AnnaBridge 145:64910690c574 107 uint16_t
AnnaBridge 145:64910690c574 108 entropyDelay; /*!< @brief Entropy Delay. Defines the length (in system clocks) of each Entropy sample taken. */
AnnaBridge 145:64910690c574 109 uint16_t sampleSize; /*!< @brief Sample Size. Defines the total number of Entropy samples that will be taken during
AnnaBridge 145:64910690c574 110 Entropy generation. */
AnnaBridge 145:64910690c574 111 uint16_t
AnnaBridge 145:64910690c574 112 sparseBitLimit; /*!< @brief Sparse Bit Limit which defines the maximum number of
AnnaBridge 145:64910690c574 113 * consecutive samples that may be discarded before an error is generated.
AnnaBridge 145:64910690c574 114 * This limit is used only for during von Neumann sampling (enabled by TRNG_HAL_SetSampleMode()).
AnnaBridge 145:64910690c574 115 * Samples are discarded if two consecutive raw samples are both 0 or both 1. If
AnnaBridge 145:64910690c574 116 * this discarding occurs for a long period of time, it indicates that there is
AnnaBridge 145:64910690c574 117 * insufficient Entropy. */
AnnaBridge 145:64910690c574 118 /* Statistical Check Parameters.*/
AnnaBridge 145:64910690c574 119 uint8_t retryCount; /*!< @brief Retry count. It defines the number of times a statistical check may fails
AnnaBridge 145:64910690c574 120 * during the TRNG Entropy Generation before generating an error. */
AnnaBridge 145:64910690c574 121 uint8_t longRunMaxLimit; /*!< @brief Largest allowable number of consecutive samples of all 1, or all 0,
AnnaBridge 145:64910690c574 122 * that is allowed during the Entropy generation. */
AnnaBridge 145:64910690c574 123 trng_statistical_check_limit_t
AnnaBridge 145:64910690c574 124 monobitLimit; /*!< @brief Maximum and minimum limits for statistical check of number of ones/zero detected
AnnaBridge 145:64910690c574 125 during entropy generation. */
AnnaBridge 145:64910690c574 126 trng_statistical_check_limit_t
AnnaBridge 145:64910690c574 127 runBit1Limit; /*!< @brief Maximum and minimum limits for statistical check of number of runs of length 1
AnnaBridge 145:64910690c574 128 detected during entropy generation. */
AnnaBridge 145:64910690c574 129 trng_statistical_check_limit_t
AnnaBridge 145:64910690c574 130 runBit2Limit; /*!< @brief Maximum and minimum limits for statistical check of number of runs of length 2
AnnaBridge 145:64910690c574 131 detected during entropy generation. */
AnnaBridge 145:64910690c574 132 trng_statistical_check_limit_t
AnnaBridge 145:64910690c574 133 runBit3Limit; /*!< @brief Maximum and minimum limits for statistical check of number of runs of length 3
AnnaBridge 145:64910690c574 134 detected during entropy generation. */
AnnaBridge 145:64910690c574 135 trng_statistical_check_limit_t
AnnaBridge 145:64910690c574 136 runBit4Limit; /*!< @brief Maximum and minimum limits for statistical check of number of runs of length 4
AnnaBridge 145:64910690c574 137 detected during entropy generation. */
AnnaBridge 145:64910690c574 138 trng_statistical_check_limit_t
AnnaBridge 145:64910690c574 139 runBit5Limit; /*!< @brief Maximum and minimum limits for statistical check of number of runs of length 5
AnnaBridge 145:64910690c574 140 detected during entropy generation. */
AnnaBridge 145:64910690c574 141 trng_statistical_check_limit_t runBit6PlusLimit; /*!< @brief Maximum and minimum limits for statistical check of
AnnaBridge 145:64910690c574 142 number of runs of length 6 or more detected during entropy
AnnaBridge 145:64910690c574 143 generation. */
AnnaBridge 145:64910690c574 144 trng_statistical_check_limit_t
AnnaBridge 145:64910690c574 145 pokerLimit; /*!< @brief Maximum and minimum limits for statistical check of "Poker Test". */
AnnaBridge 145:64910690c574 146 trng_statistical_check_limit_t
AnnaBridge 145:64910690c574 147 frequencyCountLimit; /*!< @brief Maximum and minimum limits for statistical check of entropy sample frequency
AnnaBridge 145:64910690c574 148 count. */
AnnaBridge 145:64910690c574 149 } trng_config_t;
AnnaBridge 145:64910690c574 150
AnnaBridge 145:64910690c574 151 /*******************************************************************************
AnnaBridge 145:64910690c574 152 * API
AnnaBridge 145:64910690c574 153 *******************************************************************************/
AnnaBridge 145:64910690c574 154
AnnaBridge 145:64910690c574 155 #if defined(__cplusplus)
AnnaBridge 145:64910690c574 156 extern "C" {
AnnaBridge 145:64910690c574 157 #endif
AnnaBridge 145:64910690c574 158
AnnaBridge 145:64910690c574 159 /*!
AnnaBridge 145:64910690c574 160 * @brief Initializes user configuration structure to default.
AnnaBridge 145:64910690c574 161 *
AnnaBridge 145:64910690c574 162 * This function initializes the configure structure to default value. the default
AnnaBridge 145:64910690c574 163 * value are:
AnnaBridge 145:64910690c574 164 * @code
AnnaBridge 145:64910690c574 165 * user_config->lock = 0;
AnnaBridge 145:64910690c574 166 * user_config->clockMode = kTRNG_ClockModeRingOscillator;
AnnaBridge 145:64910690c574 167 * user_config->ringOscDiv = kTRNG_RingOscDiv0; Or to other kTRNG_RingOscDiv[2|8] depending on platform.
AnnaBridge 145:64910690c574 168 * user_config->sampleMode = kTRNG_SampleModeRaw;
AnnaBridge 145:64910690c574 169 * user_config->entropyDelay = 3200;
AnnaBridge 145:64910690c574 170 * user_config->sampleSize = 2500;
AnnaBridge 145:64910690c574 171 * user_config->sparseBitLimit = TRNG_USER_CONFIG_DEFAULT_SPARSE_BIT_LIMIT;
AnnaBridge 145:64910690c574 172 * user_config->retryCount = 63;
AnnaBridge 145:64910690c574 173 * user_config->longRunMaxLimit = 34;
AnnaBridge 145:64910690c574 174 * user_config->monobitLimit.maximum = 1384;
AnnaBridge 145:64910690c574 175 * user_config->monobitLimit.minimum = 1116;
AnnaBridge 145:64910690c574 176 * user_config->runBit1Limit.maximum = 405;
AnnaBridge 145:64910690c574 177 * user_config->runBit1Limit.minimum = 227;
AnnaBridge 145:64910690c574 178 * user_config->runBit2Limit.maximum = 220;
AnnaBridge 145:64910690c574 179 * user_config->runBit2Limit.minimum = 98;
AnnaBridge 145:64910690c574 180 * user_config->runBit3Limit.maximum = 125;
AnnaBridge 145:64910690c574 181 * user_config->runBit3Limit.minimum = 37;
AnnaBridge 145:64910690c574 182 * user_config->runBit4Limit.maximum = 75;
AnnaBridge 145:64910690c574 183 * user_config->runBit4Limit.minimum = 11;
AnnaBridge 145:64910690c574 184 * user_config->runBit5Limit.maximum = 47;
AnnaBridge 145:64910690c574 185 * user_config->runBit5Limit.minimum = 1;
AnnaBridge 145:64910690c574 186 * user_config->runBit6PlusLimit.maximum = 47;
AnnaBridge 145:64910690c574 187 * user_config->runBit6PlusLimit.minimum = 1;
AnnaBridge 145:64910690c574 188 * user_config->pokerLimit.maximum = 26912;
AnnaBridge 145:64910690c574 189 * user_config->pokerLimit.minimum = 24445;
AnnaBridge 145:64910690c574 190 * user_config->frequencyCountLimit.maximum = 25600;
AnnaBridge 145:64910690c574 191 * user_config->frequencyCountLimit.minimum = 1600;
AnnaBridge 145:64910690c574 192 * @endcode
AnnaBridge 145:64910690c574 193 *
AnnaBridge 145:64910690c574 194 * @param user_config User configuration structure.
AnnaBridge 145:64910690c574 195 * @return If successful, returns the kStatus_TRNG_Success. Otherwise, it returns an error.
AnnaBridge 145:64910690c574 196 */
AnnaBridge 145:64910690c574 197 status_t TRNG_GetDefaultConfig(trng_config_t *userConfig);
AnnaBridge 145:64910690c574 198
AnnaBridge 145:64910690c574 199 /*!
AnnaBridge 145:64910690c574 200 * @brief Initializes the TRNG.
AnnaBridge 145:64910690c574 201 *
AnnaBridge 145:64910690c574 202 * This function initializes the TRNG.
AnnaBridge 145:64910690c574 203 * When called, the TRNG entropy generation starts immediately.
AnnaBridge 145:64910690c574 204 *
AnnaBridge 145:64910690c574 205 * @param base TRNG base address
AnnaBridge 145:64910690c574 206 * @param userConfig Pointer to initialize configuration structure.
AnnaBridge 145:64910690c574 207 * @return If successful, returns the kStatus_TRNG_Success. Otherwise, it returns an error.
AnnaBridge 145:64910690c574 208 */
AnnaBridge 145:64910690c574 209 status_t TRNG_Init(TRNG_Type *base, const trng_config_t *userConfig);
AnnaBridge 145:64910690c574 210
AnnaBridge 145:64910690c574 211 /*!
AnnaBridge 145:64910690c574 212 * @brief Shuts down the TRNG.
AnnaBridge 145:64910690c574 213 *
AnnaBridge 145:64910690c574 214 * This function shuts down the TRNG.
AnnaBridge 145:64910690c574 215 *
AnnaBridge 145:64910690c574 216 * @param base TRNG base address
AnnaBridge 145:64910690c574 217 */
AnnaBridge 145:64910690c574 218 void TRNG_Deinit(TRNG_Type *base);
AnnaBridge 145:64910690c574 219
AnnaBridge 145:64910690c574 220 /*!
AnnaBridge 145:64910690c574 221 * @brief Gets random data.
AnnaBridge 145:64910690c574 222 *
AnnaBridge 145:64910690c574 223 * This function gets random data from the TRNG.
AnnaBridge 145:64910690c574 224 *
AnnaBridge 145:64910690c574 225 * @param base TRNG base address
AnnaBridge 145:64910690c574 226 * @param data Pointer address used to store random data
AnnaBridge 145:64910690c574 227 * @param dataSize Size of the buffer pointed by the data parameter
AnnaBridge 145:64910690c574 228 * @return random data
AnnaBridge 145:64910690c574 229 */
AnnaBridge 145:64910690c574 230 status_t TRNG_GetRandomData(TRNG_Type *base, void *data, size_t dataSize);
AnnaBridge 145:64910690c574 231
AnnaBridge 145:64910690c574 232 #if defined(__cplusplus)
AnnaBridge 145:64910690c574 233 }
AnnaBridge 145:64910690c574 234 #endif
AnnaBridge 145:64910690c574 235
AnnaBridge 145:64910690c574 236 /*! @}*/
AnnaBridge 145:64910690c574 237
AnnaBridge 145:64910690c574 238 #endif /* FSL_FEATURE_SOC_TRNG_COUNT */
AnnaBridge 145:64910690c574 239 #endif /*_FSL_TRNG_H_*/