![]() |
|
|||
File indexing completed on 2025-05-11 08:23:02
0001 /* 0002 * Copyright (c) 2015, Freescale Semiconductor, Inc. 0003 * Copyright 2016-2017, 2020-2022 NXP 0004 * All rights reserved. 0005 * 0006 * SPDX-License-Identifier: BSD-3-Clause 0007 */ 0008 #include "fsl_trng.h" 0009 0010 #if defined(FSL_FEATURE_SOC_TRNG_COUNT) && FSL_FEATURE_SOC_TRNG_COUNT 0011 0012 /******************************************************************************* 0013 * Definitions 0014 *******************************************************************************/ 0015 0016 /* Component ID definition, used by tools. */ 0017 #ifndef FSL_COMPONENT_ID 0018 #define FSL_COMPONENT_ID "platform.drivers.trng" 0019 #endif 0020 0021 /* Default values for user configuration structure.*/ 0022 #if (defined(KW40Z4_SERIES) || defined(KW41Z4_SERIES) || defined(KW31Z4_SERIES) || defined(KW21Z4_SERIES) || \ 0023 defined(MCIMX7U5_M4_SERIES) || defined(KW36Z4_SERIES) || defined(KW37A4_SERIES) || defined(KW37Z4_SERIES) || \ 0024 defined(KW38A4_SERIES) || defined(KW38Z4_SERIES) || defined(KW39A4_SERIES) || defined(KW35Z4_SERIES) || \ 0025 defined(KW36A4_SERIES) || defined(KW35A4_SERIES) || defined(KW34A4_SERIES)) 0026 #define TRNG_USER_CONFIG_DEFAULT_OSC_DIV kTRNG_RingOscDiv8 0027 #elif (defined(KV56F24_SERIES) || defined(KV58F24_SERIES) || defined(KL28Z7_SERIES) || defined(KL81Z7_SERIES) || \ 0028 defined(KL82Z7_SERIES) || defined(K32L2A41A_SERIES)) 0029 #define TRNG_USER_CONFIG_DEFAULT_OSC_DIV kTRNG_RingOscDiv4 0030 #elif (defined(K81F25615_SERIES) || defined(K32L3A60_cm4_SERIES) || defined(K32L3A60_cm0plus_SERIES)) 0031 #define TRNG_USER_CONFIG_DEFAULT_OSC_DIV kTRNG_RingOscDiv2 0032 #else 0033 /* Default value for the TRNG user configuration structure can be optionally 0034 defined by device specific preprocessor macros. */ 0035 #if defined(FSL_FEATURE_TRNG_FORCE_USER_CONFIG_DEFAULT_OSC_DIV) && \ 0036 (FSL_FEATURE_TRNG_FORCE_USER_CONFIG_DEFAULT_OSC_DIV > 0) 0037 #define TRNG_USER_CONFIG_DEFAULT_OSC_DIV (FSL_FEATURE_TRNG_USER_CONFIG_DEFAULT_OSC_DIV_VALUE) 0038 #else 0039 #define TRNG_USER_CONFIG_DEFAULT_OSC_DIV kTRNG_RingOscDiv0 0040 #endif 0041 #endif 0042 0043 #if (defined(RW610_SERIES) || defined(RW612_SERIES)) 0044 0045 /* RW610 specific settings for the TRNG */ 0046 #define TRNG_USER_CONFIG_DEFAULT_LOCK 0 0047 #define TRNG_USER_CONFIG_DEFAULT_ENTROPY_DELAY 3200 0048 #define TRNG_USER_CONFIG_DEFAULT_SAMPLE_SIZE 256 0049 #define TRNG_USER_CONFIG_DEFAULT_SPARSE_BIT_LIMIT 63 0050 #define TRNG_USER_CONFIG_DEFAULT_RETRY_COUNT 1 0051 #define TRNG_USER_CONFIG_DEFAULT_RUN_MAX_LIMIT 34 0052 0053 #define TRNG_USER_CONFIG_DEFAULT_MONOBIT_MAXIMUM 171 0054 #define TRNG_USER_CONFIG_DEFAULT_MONOBIT_MINIMUM (TRNG_USER_CONFIG_DEFAULT_MONOBIT_MAXIMUM - 86) 0055 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT1_MAXIMUM 63 0056 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT1_MINIMUM (TRNG_USER_CONFIG_DEFAULT_RUNBIT1_MAXIMUM - 56) 0057 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT2_MAXIMUM 38 0058 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT2_MINIMUM (TRNG_USER_CONFIG_DEFAULT_RUNBIT2_MAXIMUM - 38) 0059 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT3_MAXIMUM 26 0060 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT3_MINIMUM (TRNG_USER_CONFIG_DEFAULT_RUNBIT3_MAXIMUM - 26) 0061 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT4_MAXIMUM 75 0062 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT4_MINIMUM (TRNG_USER_CONFIG_DEFAULT_RUNBIT4_MAXIMUM - 64) 0063 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT5_MAXIMUM 47 0064 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT5_MINIMUM (TRNG_USER_CONFIG_DEFAULT_RUNBIT5_MAXIMUM - 46) 0065 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT6PLUS_MAXIMUM 47 0066 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT6PLUS_MINIMUM (TRNG_USER_CONFIG_DEFAULT_RUNBIT6PLUS_MAXIMUM - 46) 0067 #define TRNG_USER_CONFIG_DEFAULT_POKER_MAXIMUM 26912 0068 #define TRNG_USER_CONFIG_DEFAULT_POKER_MINIMUM (TRNG_USER_CONFIG_DEFAULT_POKER_MAXIMUM - 2467) 0069 0070 #else 0071 0072 #define TRNG_USER_CONFIG_DEFAULT_LOCK 0 0073 #define TRNG_USER_CONFIG_DEFAULT_ENTROPY_DELAY 3200 0074 #define TRNG_USER_CONFIG_DEFAULT_SAMPLE_SIZE 512 0075 #define TRNG_USER_CONFIG_DEFAULT_SPARSE_BIT_LIMIT 63 0076 #define TRNG_USER_CONFIG_DEFAULT_RETRY_COUNT 1 0077 #define TRNG_USER_CONFIG_DEFAULT_RUN_MAX_LIMIT 32 0078 0079 #define TRNG_USER_CONFIG_DEFAULT_MONOBIT_MAXIMUM 317 0080 #define TRNG_USER_CONFIG_DEFAULT_MONOBIT_MINIMUM (TRNG_USER_CONFIG_DEFAULT_MONOBIT_MAXIMUM - 122) 0081 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT1_MAXIMUM 107 0082 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT1_MINIMUM (TRNG_USER_CONFIG_DEFAULT_RUNBIT1_MAXIMUM - 80) 0083 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT2_MAXIMUM 62 0084 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT2_MINIMUM (TRNG_USER_CONFIG_DEFAULT_RUNBIT2_MAXIMUM - 55) 0085 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT3_MAXIMUM 39 0086 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT3_MINIMUM (TRNG_USER_CONFIG_DEFAULT_RUNBIT3_MAXIMUM - 39) 0087 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT4_MAXIMUM 26 0088 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT4_MINIMUM (TRNG_USER_CONFIG_DEFAULT_RUNBIT4_MAXIMUM - 26) 0089 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT5_MAXIMUM 18 0090 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT5_MINIMUM (TRNG_USER_CONFIG_DEFAULT_RUNBIT5_MAXIMUM - 18) 0091 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT6PLUS_MAXIMUM 17 0092 #define TRNG_USER_CONFIG_DEFAULT_RUNBIT6PLUS_MINIMUM (TRNG_USER_CONFIG_DEFAULT_RUNBIT6PLUS_MAXIMUM - 17) 0093 #define TRNG_USER_CONFIG_DEFAULT_POKER_MAXIMUM 1600 0094 #define TRNG_USER_CONFIG_DEFAULT_POKER_MINIMUM (TRNG_USER_CONFIG_DEFAULT_POKER_MAXIMUM - 570) 0095 0096 #endif 0097 0098 #if defined(FSL_FEATURE_TRNG_FORCE_USER_CONFIG_DEFAULT_FREQUENCY_MAXIMUM) && \ 0099 (FSL_FEATURE_TRNG_FORCE_USER_CONFIG_DEFAULT_FREQUENCY_MAXIMUM > 0) 0100 #define TRNG_USER_CONFIG_DEFAULT_FREQUENCY_MAXIMUM (FSL_FEATURE_TRNG_USER_CONFIG_DEFAULT_FREQUENCY_MAXIMUM_VALUE) 0101 #else 0102 #define TRNG_USER_CONFIG_DEFAULT_FREQUENCY_MAXIMUM 30000 0103 #endif 0104 0105 #if defined(FSL_FEATURE_TRNG_FORCE_USER_CONFIG_DEFAULT_FREQUENCY_MINIMUM) && \ 0106 (FSL_FEATURE_TRNG_FORCE_USER_CONFIG_DEFAULT_FREQUENCY_MINIMUM > 0) 0107 #define TRNG_USER_CONFIG_DEFAULT_FREQUENCY_MINIMUM (FSL_FEATURE_TRNG_USER_CONFIG_DEFAULT_FREQUENCY_MINIMUM_VALUE) 0108 #else 0109 #define TRNG_USER_CONFIG_DEFAULT_FREQUENCY_MINIMUM 1600 0110 #endif 0111 0112 /*! @brief TRNG work mode */ 0113 typedef enum _trng_work_mode 0114 { 0115 kTRNG_WorkModeRun = 0U, /*!< Run Mode. */ 0116 kTRNG_WorkModeProgram = 1U /*!< Program Mode. */ 0117 } trng_work_mode_t; 0118 0119 /*! @brief TRNG statistical check type*/ 0120 typedef enum _trng_statistical_check 0121 { 0122 kTRNG_StatisticalCheckMonobit = 0123 1U, /*!< Statistical check of number of ones/zero detected during entropy generation. */ 0124 kTRNG_StatisticalCheckRunBit1, /*!< Statistical check of number of runs of length 1 detected during entropy 0125 generation. */ 0126 kTRNG_StatisticalCheckRunBit2, /*!< Statistical check of number of runs of length 2 detected during entropy 0127 generation. */ 0128 kTRNG_StatisticalCheckRunBit3, /*!< Statistical check of number of runs of length 3 detected during entropy 0129 generation. */ 0130 kTRNG_StatisticalCheckRunBit4, /*!< Statistical check of number of runs of length 4 detected during entropy 0131 generation. */ 0132 kTRNG_StatisticalCheckRunBit5, /*!< Statistical check of number of runs of length 5 detected during entropy 0133 generation. */ 0134 kTRNG_StatisticalCheckRunBit6Plus, /*!< Statistical check of number of runs of length 6 or more detected during 0135 entropy generation. */ 0136 kTRNG_StatisticalCheckPoker, /*!< Statistical check of "Poker Test". */ 0137 kTRNG_StatisticalCheckFrequencyCount /*!< Statistical check of entropy sample frequency count. */ 0138 } trng_statistical_check_t; 0139 0140 /******************************************************************************* 0141 * TRNG_SCMISC - RNG Statistical Check Miscellaneous Register 0142 ******************************************************************************/ 0143 /*! 0144 * @name Register TRNG_SCMISC, field RTY_CT[19:16] (RW) 0145 * 0146 * RETRY COUNT. If a statistical check fails during the TRNG Entropy Generation, 0147 * the RTY_CT value indicates the number of times a retry should occur before 0148 * generating an error. This field is writable only if MCTL[PRGM] bit is 1. This 0149 * field will read zeroes if MCTL[PRGM] = 0. This field is cleared to 1h by writing 0150 * the MCTL[RST_DEF] bit to 1. 0151 */ 0152 /*@{*/ 0153 /*! @brief Read current value of the TRNG_SCMISC_RTY_CT field. */ 0154 #define TRNG_RD_SCMISC_RTY_CT(base) ((TRNG_SCMISC_REG(base) & TRNG_SCMISC_RTY_CT_MASK) >> TRNG_SCMISC_RTY_CT_SHIFT) 0155 0156 /*! @brief Set the RTY_CT field to a new value. */ 0157 #define TRNG_WR_SCMISC_RTY_CT(base, value) (TRNG_RMW_SCMISC(base, TRNG_SCMISC_RTY_CT_MASK, TRNG_SCMISC_RTY_CT(value))) 0158 /*@}*/ 0159 0160 /******************************************************************************* 0161 * TRNG_SCML - RNG Statistical Check Monobit Limit Register 0162 ******************************************************************************/ 0163 /*! 0164 * @brief TRNG_SCML - RNG Statistical Check Monobit Limit Register (RW) 0165 * 0166 * Reset value: 0x010C0568U 0167 * 0168 * The RNG Statistical Check Monobit Limit Register defines the allowable 0169 * maximum and minimum number of ones/zero detected during entropy generation. To pass 0170 * the test, the number of ones/zeroes generated must be less than the programmed 0171 * maximum value, and the number of ones/zeroes generated must be greater than 0172 * (maximum - range). If this test fails, the Retry Counter in SCMISC will be 0173 * decremented, and a retry will occur if the Retry Count has not reached zero. If 0174 * the Retry Count has reached zero, an error will be generated. Note that this 0175 * offset (0xBASE_0620) is used as SCML only if MCTL[PRGM] is 1. If MCTL[PRGM] is 0, 0176 * this offset is used as SCMC readback register. 0177 */ 0178 /*! 0179 * @name Constants and macros for entire TRNG_SCML register 0180 */ 0181 /*@{*/ 0182 #define TRNG_SCML_REG(base) ((base)->SCML) 0183 #define TRNG_RD_SCML(base) (TRNG_SCML_REG(base)) 0184 #define TRNG_WR_SCML(base, value) (TRNG_SCML_REG(base) = (value)) 0185 #define TRNG_RMW_SCML(base, mask, value) (TRNG_WR_SCML(base, (TRNG_RD_SCML(base) & ~(mask)) | (value))) 0186 /*@}*/ 0187 /*! 0188 * @name Register TRNG_SCML, field MONO_MAX[15:0] (RW) 0189 * 0190 * Monobit Maximum Limit. Defines the maximum allowable count taken during 0191 * entropy generation. The number of ones/zeroes detected during entropy generation 0192 * must be less than MONO_MAX, else a retry or error will occur. This register is 0193 * cleared to 00056Bh (decimal 1387) by writing the MCTL[RST_DEF] bit to 1. 0194 */ 0195 /*@{*/ 0196 /*! @brief Read current value of the TRNG_SCML_MONO_MAX field. */ 0197 #define TRNG_RD_SCML_MONO_MAX(base) ((TRNG_SCML_REG(base) & TRNG_SCML_MONO_MAX_MASK) >> TRNG_SCML_MONO_MAX_SHIFT) 0198 0199 /*! @brief Set the MONO_MAX field to a new value. */ 0200 #define TRNG_WR_SCML_MONO_MAX(base, value) (TRNG_RMW_SCML(base, TRNG_SCML_MONO_MAX_MASK, TRNG_SCML_MONO_MAX(value))) 0201 /*@}*/ 0202 /*! 0203 * @name Register TRNG_SCML, field MONO_RNG[31:16] (RW) 0204 * 0205 * Monobit Range. The number of ones/zeroes detected during entropy generation 0206 * must be greater than MONO_MAX - MONO_RNG, else a retry or error will occur. 0207 * This register is cleared to 000112h (decimal 274) by writing the MCTL[RST_DEF] 0208 * bit to 1. 0209 */ 0210 /*@{*/ 0211 /*! @brief Read current value of the TRNG_SCML_MONO_RNG field. */ 0212 #define TRNG_RD_SCML_MONO_RNG(base) ((TRNG_SCML_REG(base) & TRNG_SCML_MONO_RNG_MASK) >> TRNG_SCML_MONO_RNG_SHIFT) 0213 0214 /*! @brief Set the MONO_RNG field to a new value. */ 0215 #define TRNG_WR_SCML_MONO_RNG(base, value) (TRNG_RMW_SCML(base, TRNG_SCML_MONO_RNG_MASK, TRNG_SCML_MONO_RNG(value))) 0216 /*@}*/ 0217 0218 /******************************************************************************* 0219 * TRNG_SCR1L - RNG Statistical Check Run Length 1 Limit Register 0220 ******************************************************************************/ 0221 0222 /*! 0223 * @brief TRNG_SCR1L - RNG Statistical Check Run Length 1 Limit Register (RW) 0224 * 0225 * Reset value: 0x00B20195U 0226 * 0227 * The RNG Statistical Check Run Length 1 Limit Register defines the allowable 0228 * maximum and minimum number of runs of length 1 detected during entropy 0229 * generation. To pass the test, the number of runs of length 1 (for samples of both 0 0230 * and 1) must be less than the programmed maximum value, and the number of runs of 0231 * length 1 must be greater than (maximum - range). If this test fails, the 0232 * Retry Counter in SCMISC will be decremented, and a retry will occur if the Retry 0233 * Count has not reached zero. If the Retry Count has reached zero, an error will 0234 * be generated. Note that this address (0xBASE_0624) is used as SCR1L only if 0235 * MCTL[PRGM] is 1. If MCTL[PRGM] is 0, this address is used as SCR1C readback 0236 * register. 0237 */ 0238 /*! 0239 * @name Constants and macros for entire TRNG_SCR1L register 0240 */ 0241 /*@{*/ 0242 #define TRNG_SCR1L_REG(base) ((base)->SCR1L) 0243 #define TRNG_RD_SCR1L(base) (TRNG_SCR1L_REG(base)) 0244 #define TRNG_WR_SCR1L(base, value) (TRNG_SCR1L_REG(base) = (value)) 0245 #define TRNG_RMW_SCR1L(base, mask, value) (TRNG_WR_SCR1L(base, (TRNG_RD_SCR1L(base) & ~(mask)) | (value))) 0246 /*@}*/ 0247 0248 /*! 0249 * @name Register TRNG_SCR1L, field RUN1_MAX[14:0] (RW) 0250 * 0251 * Run Length 1 Maximum Limit. Defines the maximum allowable runs of length 1 0252 * (for both 0 and 1) detected during entropy generation. The number of runs of 0253 * length 1 detected during entropy generation must be less than RUN1_MAX, else a 0254 * retry or error will occur. This register is cleared to 01E5h (decimal 485) by 0255 * writing the MCTL[RST_DEF] bit to 1. 0256 */ 0257 /*@{*/ 0258 /*! @brief Read current value of the TRNG_SCR1L_RUN1_MAX field. */ 0259 #define TRNG_RD_SCR1L_RUN1_MAX(base) ((TRNG_SCR1L_REG(base) & TRNG_SCR1L_RUN1_MAX_MASK) >> TRNG_SCR1L_RUN1_MAX_SHIFT) 0260 0261 /*! @brief Set the RUN1_MAX field to a new value. */ 0262 #define TRNG_WR_SCR1L_RUN1_MAX(base, value) (TRNG_RMW_SCR1L(base, TRNG_SCR1L_RUN1_MAX_MASK, TRNG_SCR1L_RUN1_MAX(value))) 0263 /*@}*/ 0264 0265 /*! 0266 * @name Register TRNG_SCR1L, field RUN1_RNG[30:16] (RW) 0267 * 0268 * Run Length 1 Range. The number of runs of length 1 (for both 0 and 1) 0269 * detected during entropy generation must be greater than RUN1_MAX - RUN1_RNG, else a 0270 * retry or error will occur. This register is cleared to 0102h (decimal 258) by 0271 * writing the MCTL[RST_DEF] bit to 1. 0272 */ 0273 /*@{*/ 0274 /*! @brief Read current value of the TRNG_SCR1L_RUN1_RNG field. */ 0275 #define TRNG_RD_SCR1L_RUN1_RNG(base) ((TRNG_SCR1L_REG(base) & TRNG_SCR1L_RUN1_RNG_MASK) >> TRNG_SCR1L_RUN1_RNG_SHIFT) 0276 0277 /*! @brief Set the RUN1_RNG field to a new value. */ 0278 #define TRNG_WR_SCR1L_RUN1_RNG(base, value) (TRNG_RMW_SCR1L(base, TRNG_SCR1L_RUN1_RNG_MASK, TRNG_SCR1L_RUN1_RNG(value))) 0279 /*@}*/ 0280 0281 /******************************************************************************* 0282 * TRNG_SCR2L - RNG Statistical Check Run Length 2 Limit Register 0283 ******************************************************************************/ 0284 0285 /*! 0286 * @brief TRNG_SCR2L - RNG Statistical Check Run Length 2 Limit Register (RW) 0287 * 0288 * Reset value: 0x007A00DCU 0289 * 0290 * The RNG Statistical Check Run Length 2 Limit Register defines the allowable 0291 * maximum and minimum number of runs of length 2 detected during entropy 0292 * generation. To pass the test, the number of runs of length 2 (for samples of both 0 0293 * and 1) must be less than the programmed maximum value, and the number of runs of 0294 * length 2 must be greater than (maximum - range). If this test fails, the 0295 * Retry Counter in SCMISC will be decremented, and a retry will occur if the Retry 0296 * Count has not reached zero. If the Retry Count has reached zero, an error will 0297 * be generated. Note that this address (0xBASE_0628) is used as SCR2L only if 0298 * MCTL[PRGM] is 1. If MCTL[PRGM] is 0, this address is used as SCR2C readback 0299 * register. 0300 */ 0301 /*! 0302 * @name Constants and macros for entire TRNG_SCR2L register 0303 */ 0304 /*@{*/ 0305 #define TRNG_SCR2L_REG(base) ((base)->SCR2L) 0306 #define TRNG_RD_SCR2L(base) (TRNG_SCR2L_REG(base)) 0307 #define TRNG_WR_SCR2L(base, value) (TRNG_SCR2L_REG(base) = (value)) 0308 #define TRNG_RMW_SCR2L(base, mask, value) (TRNG_WR_SCR2L(base, (TRNG_RD_SCR2L(base) & ~(mask)) | (value))) 0309 /*@}*/ 0310 0311 /* 0312 * Constants & macros for individual TRNG_SCR2L bitfields 0313 */ 0314 0315 /*! 0316 * @name Register TRNG_SCR2L, field RUN2_MAX[13:0] (RW) 0317 * 0318 * Run Length 2 Maximum Limit. Defines the maximum allowable runs of length 2 0319 * (for both 0 and 1) detected during entropy generation. The number of runs of 0320 * length 2 detected during entropy generation must be less than RUN2_MAX, else a 0321 * retry or error will occur. This register is cleared to 00DCh (decimal 220) by 0322 * writing the MCTL[RST_DEF] bit to 1. 0323 */ 0324 /*@{*/ 0325 /*! @brief Read current value of the TRNG_SCR2L_RUN2_MAX field. */ 0326 #define TRNG_RD_SCR2L_RUN2_MAX(base) ((TRNG_SCR2L_REG(base) & TRNG_SCR2L_RUN2_MAX_MASK) >> TRNG_SCR2L_RUN2_MAX_SHIFT) 0327 0328 /*! @brief Set the RUN2_MAX field to a new value. */ 0329 #define TRNG_WR_SCR2L_RUN2_MAX(base, value) (TRNG_RMW_SCR2L(base, TRNG_SCR2L_RUN2_MAX_MASK, TRNG_SCR2L_RUN2_MAX(value))) 0330 /*@}*/ 0331 0332 /*! 0333 * @name Register TRNG_SCR2L, field RUN2_RNG[29:16] (RW) 0334 * 0335 * Run Length 2 Range. The number of runs of length 2 (for both 0 and 1) 0336 * detected during entropy generation must be greater than RUN2_MAX - RUN2_RNG, else a 0337 * retry or error will occur. This register is cleared to 007Ah (decimal 122) by 0338 * writing the MCTL[RST_DEF] bit to 1. 0339 */ 0340 /*@{*/ 0341 /*! @brief Read current value of the TRNG_SCR2L_RUN2_RNG field. */ 0342 #define TRNG_RD_SCR2L_RUN2_RNG(base) ((TRNG_SCR2L_REG(base) & TRNG_SCR2L_RUN2_RNG_MASK) >> TRNG_SCR2L_RUN2_RNG_SHIFT) 0343 0344 /*! @brief Set the RUN2_RNG field to a new value. */ 0345 #define TRNG_WR_SCR2L_RUN2_RNG(base, value) (TRNG_RMW_SCR2L(base, TRNG_SCR2L_RUN2_RNG_MASK, TRNG_SCR2L_RUN2_RNG(value))) 0346 /*@}*/ 0347 0348 /******************************************************************************* 0349 * TRNG_SCR3L - RNG Statistical Check Run Length 3 Limit Register 0350 ******************************************************************************/ 0351 0352 /*! 0353 * @brief TRNG_SCR3L - RNG Statistical Check Run Length 3 Limit Register (RW) 0354 * 0355 * Reset value: 0x0058007DU 0356 * 0357 * The RNG Statistical Check Run Length 3 Limit Register defines the allowable 0358 * maximum and minimum number of runs of length 3 detected during entropy 0359 * generation. To pass the test, the number of runs of length 3 (for samples of both 0 0360 * and 1) must be less than the programmed maximum value, and the number of runs of 0361 * length 3 must be greater than (maximum - range). If this test fails, the 0362 * Retry Counter in SCMISC will be decremented, and a retry will occur if the Retry 0363 * Count has not reached zero. If the Retry Count has reached zero, an error will 0364 * be generated. Note that this address (0xBASE_062C) is used as SCR3L only if 0365 * MCTL[PRGM] is 1. If MCTL[PRGM] is 0, this address is used as SCR3C readback 0366 * register. 0367 */ 0368 /*! 0369 * @name Constants and macros for entire TRNG_SCR3L register 0370 */ 0371 /*@{*/ 0372 #define TRNG_SCR3L_REG(base) ((base)->SCR3L) 0373 #define TRNG_RD_SCR3L(base) (TRNG_SCR3L_REG(base)) 0374 #define TRNG_WR_SCR3L(base, value) (TRNG_SCR3L_REG(base) = (value)) 0375 #define TRNG_RMW_SCR3L(base, mask, value) (TRNG_WR_SCR3L(base, (TRNG_RD_SCR3L(base) & ~(mask)) | (value))) 0376 /*@}*/ 0377 0378 /* 0379 * Constants & macros for individual TRNG_SCR3L bitfields 0380 */ 0381 0382 /*! 0383 * @name Register TRNG_SCR3L, field RUN3_MAX[12:0] (RW) 0384 * 0385 * Run Length 3 Maximum Limit. Defines the maximum allowable runs of length 3 0386 * (for both 0 and 1) detected during entropy generation. The number of runs of 0387 * length 3 detected during entropy generation must be less than RUN3_MAX, else a 0388 * retry or error will occur. This register is cleared to 007Dh (decimal 125) by 0389 * writing the MCTL[RST_DEF] bit to 1. 0390 */ 0391 /*@{*/ 0392 /*! @brief Read current value of the TRNG_SCR3L_RUN3_MAX field. */ 0393 #define TRNG_RD_SCR3L_RUN3_MAX(base) ((TRNG_SCR3L_REG(base) & TRNG_SCR3L_RUN3_MAX_MASK) >> TRNG_SCR3L_RUN3_MAX_SHIFT) 0394 0395 /*! @brief Set the RUN3_MAX field to a new value. */ 0396 #define TRNG_WR_SCR3L_RUN3_MAX(base, value) (TRNG_RMW_SCR3L(base, TRNG_SCR3L_RUN3_MAX_MASK, TRNG_SCR3L_RUN3_MAX(value))) 0397 /*@}*/ 0398 0399 /*! 0400 * @name Register TRNG_SCR3L, field RUN3_RNG[28:16] (RW) 0401 * 0402 * Run Length 3 Range. The number of runs of length 3 (for both 0 and 1) 0403 * detected during entropy generation must be greater than RUN3_MAX - RUN3_RNG, else a 0404 * retry or error will occur. This register is cleared to 0058h (decimal 88) by 0405 * writing the MCTL[RST_DEF] bit to 1. 0406 */ 0407 /*@{*/ 0408 /*! @brief Read current value of the TRNG_SCR3L_RUN3_RNG field. */ 0409 #define TRNG_RD_SCR3L_RUN3_RNG(base) ((TRNG_SCR3L_REG(base) & TRNG_SCR3L_RUN3_RNG_MASK) >> TRNG_SCR3L_RUN3_RNG_SHIFT) 0410 0411 /*! @brief Set the RUN3_RNG field to a new value. */ 0412 #define TRNG_WR_SCR3L_RUN3_RNG(base, value) (TRNG_RMW_SCR3L(base, TRNG_SCR3L_RUN3_RNG_MASK, TRNG_SCR3L_RUN3_RNG(value))) 0413 /*@}*/ 0414 0415 /******************************************************************************* 0416 * TRNG_SCR4L - RNG Statistical Check Run Length 4 Limit Register 0417 ******************************************************************************/ 0418 0419 #if !(defined(FSL_FEATURE_TRNG_HAS_NO_TRNG_SCR4L) && FSL_FEATURE_TRNG_HAS_NO_TRNG_SCR4L) 0420 /*! 0421 * @brief TRNG_SCR4L - RNG Statistical Check Run Length 4 Limit Register (RW) 0422 * 0423 * Reset value: 0x0040004BU 0424 * 0425 * The RNG Statistical Check Run Length 4 Limit Register defines the allowable 0426 * maximum and minimum number of runs of length 4 detected during entropy 0427 * generation. To pass the test, the number of runs of length 4 (for samples of both 0 0428 * and 1) must be less than the programmed maximum value, and the number of runs of 0429 * length 4 must be greater than (maximum - range). If this test fails, the 0430 * Retry Counter in SCMISC will be decremented, and a retry will occur if the Retry 0431 * Count has not reached zero. If the Retry Count has reached zero, an error will 0432 * be generated. Note that this address (0xBASE_0630) is used as SCR4L only if 0433 * MCTL[PRGM] is 1. If MCTL[PRGM] is 0, this address is used as SCR4C readback 0434 * register. 0435 */ 0436 /*! 0437 * @name Constants and macros for entire TRNG_SCR4L register 0438 */ 0439 /*@{*/ 0440 #define TRNG_SCR4L_REG(base) ((base)->SCR4L) 0441 #define TRNG_RD_SCR4L(base) (TRNG_SCR4L_REG(base)) 0442 #define TRNG_WR_SCR4L(base, value) (TRNG_SCR4L_REG(base) = (value)) 0443 #define TRNG_RMW_SCR4L(base, mask, value) (TRNG_WR_SCR4L(base, (TRNG_RD_SCR4L(base) & ~(mask)) | (value))) 0444 /*@}*/ 0445 0446 /* 0447 * Constants & macros for individual TRNG_SCR4L bitfields 0448 */ 0449 0450 /*! 0451 * @name Register TRNG_SCR4L, field RUN4_MAX[11:0] (RW) 0452 * 0453 * Run Length 4 Maximum Limit. Defines the maximum allowable runs of length 4 0454 * (for both 0 and 1) detected during entropy generation. The number of runs of 0455 * length 4 detected during entropy generation must be less than RUN4_MAX, else a 0456 * retry or error will occur. This register is cleared to 004Bh (decimal 75) by 0457 * writing the MCTL[RST_DEF] bit to 1. 0458 */ 0459 /*@{*/ 0460 /*! @brief Read current value of the TRNG_SCR4L_RUN4_MAX field. */ 0461 #define TRNG_RD_SCR4L_RUN4_MAX(base) ((TRNG_SCR4L_REG(base) & TRNG_SCR4L_RUN4_MAX_MASK) >> TRNG_SCR4L_RUN4_MAX_SHIFT) 0462 0463 /*! @brief Set the RUN4_MAX field to a new value. */ 0464 #define TRNG_WR_SCR4L_RUN4_MAX(base, value) (TRNG_RMW_SCR4L(base, TRNG_SCR4L_RUN4_MAX_MASK, TRNG_SCR4L_RUN4_MAX(value))) 0465 /*@}*/ 0466 0467 /*! 0468 * @name Register TRNG_SCR4L, field RUN4_RNG[27:16] (RW) 0469 * 0470 * Run Length 4 Range. The number of runs of length 4 (for both 0 and 1) 0471 * detected during entropy generation must be greater than RUN4_MAX - RUN4_RNG, else a 0472 * retry or error will occur. This register is cleared to 0040h (decimal 64) by 0473 * writing the MCTL[RST_DEF] bit to 1. 0474 */ 0475 /*@{*/ 0476 /*! @brief Read current value of the TRNG_SCR4L_RUN4_RNG field. */ 0477 #define TRNG_RD_SCR4L_RUN4_RNG(base) ((TRNG_SCR4L_REG(base) & TRNG_SCR4L_RUN4_RNG_MASK) >> TRNG_SCR4L_RUN4_RNG_SHIFT) 0478 0479 /*! @brief Set the RUN4_RNG field to a new value. */ 0480 #define TRNG_WR_SCR4L_RUN4_RNG(base, value) (TRNG_RMW_SCR4L(base, TRNG_SCR4L_RUN4_RNG_MASK, TRNG_SCR4L_RUN4_RNG(value))) 0481 /*@}*/ 0482 #endif /* FSL_FEATURE_TRNG_HAS_NO_TRNG_SCR4L */ 0483 0484 /******************************************************************************* 0485 * TRNG_SCR5L - RNG Statistical Check Run Length 5 Limit Register 0486 ******************************************************************************/ 0487 0488 #if !(defined(FSL_FEATURE_TRNG_HAS_NO_TRNG_SCR5L) && FSL_FEATURE_TRNG_HAS_NO_TRNG_SCR5L) 0489 /*! 0490 * @brief TRNG_SCR5L - RNG Statistical Check Run Length 5 Limit Register (RW) 0491 * 0492 * Reset value: 0x002E002FU 0493 * 0494 * The RNG Statistical Check Run Length 5 Limit Register defines the allowable 0495 * maximum and minimum number of runs of length 5 detected during entropy 0496 * generation. To pass the test, the number of runs of length 5 (for samples of both 0 0497 * and 1) must be less than the programmed maximum value, and the number of runs of 0498 * length 5 must be greater than (maximum - range). If this test fails, the 0499 * Retry Counter in SCMISC will be decremented, and a retry will occur if the Retry 0500 * Count has not reached zero. If the Retry Count has reached zero, an error will 0501 * be generated. Note that this address (0xBASE_0634) is used as SCR5L only if 0502 * MCTL[PRGM] is 1. If MCTL[PRGM] is 0, this address is used as SCR5C readback 0503 * register. 0504 */ 0505 /*! 0506 * @name Constants and macros for entire TRNG_SCR5L register 0507 */ 0508 /*@{*/ 0509 #define TRNG_SCR5L_REG(base) ((base)->SCR5L) 0510 #define TRNG_RD_SCR5L(base) (TRNG_SCR5L_REG(base)) 0511 #define TRNG_WR_SCR5L(base, value) (TRNG_SCR5L_REG(base) = (value)) 0512 #define TRNG_RMW_SCR5L(base, mask, value) (TRNG_WR_SCR5L(base, (TRNG_RD_SCR5L(base) & ~(mask)) | (value))) 0513 /*@}*/ 0514 0515 /* 0516 * Constants & macros for individual TRNG_SCR5L bitfields 0517 */ 0518 0519 /*! 0520 * @name Register TRNG_SCR5L, field RUN5_MAX[10:0] (RW) 0521 * 0522 * Run Length 5 Maximum Limit. Defines the maximum allowable runs of length 5 0523 * (for both 0 and 1) detected during entropy generation. The number of runs of 0524 * length 5 detected during entropy generation must be less than RUN5_MAX, else a 0525 * retry or error will occur. This register is cleared to 002Fh (decimal 47) by 0526 * writing the MCTL[RST_DEF] bit to 1. 0527 */ 0528 /*@{*/ 0529 /*! @brief Read current value of the TRNG_SCR5L_RUN5_MAX field. */ 0530 #define TRNG_RD_SCR5L_RUN5_MAX(base) ((TRNG_SCR5L_REG(base) & TRNG_SCR5L_RUN5_MAX_MASK) >> TRNG_SCR5L_RUN5_MAX_SHIFT) 0531 0532 /*! @brief Set the RUN5_MAX field to a new value. */ 0533 #define TRNG_WR_SCR5L_RUN5_MAX(base, value) (TRNG_RMW_SCR5L(base, TRNG_SCR5L_RUN5_MAX_MASK, TRNG_SCR5L_RUN5_MAX(value))) 0534 /*@}*/ 0535 0536 /*! 0537 * @name Register TRNG_SCR5L, field RUN5_RNG[26:16] (RW) 0538 * 0539 * Run Length 5 Range. The number of runs of length 5 (for both 0 and 1) 0540 * detected during entropy generation must be greater than RUN5_MAX - RUN5_RNG, else a 0541 * retry or error will occur. This register is cleared to 002Eh (decimal 46) by 0542 * writing the MCTL[RST_DEF] bit to 1. 0543 */ 0544 /*@{*/ 0545 /*! @brief Read current value of the TRNG_SCR5L_RUN5_RNG field. */ 0546 #define TRNG_RD_SCR5L_RUN5_RNG(base) ((TRNG_SCR5L_REG(base) & TRNG_SCR5L_RUN5_RNG_MASK) >> TRNG_SCR5L_RUN5_RNG_SHIFT) 0547 0548 /*! @brief Set the RUN5_RNG field to a new value. */ 0549 #define TRNG_WR_SCR5L_RUN5_RNG(base, value) (TRNG_RMW_SCR5L(base, TRNG_SCR5L_RUN5_RNG_MASK, TRNG_SCR5L_RUN5_RNG(value))) 0550 /*@}*/ 0551 #endif /* FSL_FEATURE_TRNG_HAS_NO_TRNG_SCR5L */ 0552 0553 /******************************************************************************* 0554 * TRNG_SCR6PL - RNG Statistical Check Run Length 6+ Limit Register 0555 ******************************************************************************/ 0556 0557 #if !(defined(FSL_FEATURE_TRNG_HAS_NO_TRNG_SCR6L) && FSL_FEATURE_TRNG_HAS_NO_TRNG_SCR6L) 0558 /*! 0559 * @brief TRNG_SCR6PL - RNG Statistical Check Run Length 6+ Limit Register (RW) 0560 * 0561 * Reset value: 0x002E002FU 0562 * 0563 * The RNG Statistical Check Run Length 6+ Limit Register defines the allowable 0564 * maximum and minimum number of runs of length 6 or more detected during entropy 0565 * generation. To pass the test, the number of runs of length 6 or more (for 0566 * samples of both 0 and 1) must be less than the programmed maximum value, and the 0567 * number of runs of length 6 or more must be greater than (maximum - range). If 0568 * this test fails, the Retry Counter in SCMISC will be decremented, and a retry 0569 * will occur if the Retry Count has not reached zero. If the Retry Count has 0570 * reached zero, an error will be generated. Note that this offset (0xBASE_0638) is 0571 * used as SCR6PL only if MCTL[PRGM] is 1. If MCTL[PRGM] is 0, this offset is 0572 * used as SCR6PC readback register. 0573 */ 0574 /*! 0575 * @name Constants and macros for entire TRNG_SCR6PL register 0576 */ 0577 /*@{*/ 0578 #define TRNG_SCR6PL_REG(base) ((base)->SCR6PL) 0579 #define TRNG_RD_SCR6PL(base) (TRNG_SCR6PL_REG(base)) 0580 #define TRNG_WR_SCR6PL(base, value) (TRNG_SCR6PL_REG(base) = (value)) 0581 #define TRNG_RMW_SCR6PL(base, mask, value) (TRNG_WR_SCR6PL(base, (TRNG_RD_SCR6PL(base) & ~(mask)) | (value))) 0582 /*@}*/ 0583 0584 /* 0585 * Constants & macros for individual TRNG_SCR6PL bitfields 0586 */ 0587 0588 /*! 0589 * @name Register TRNG_SCR6PL, field RUN6P_MAX[10:0] (RW) 0590 * 0591 * Run Length 6+ Maximum Limit. Defines the maximum allowable runs of length 6 0592 * or more (for both 0 and 1) detected during entropy generation. The number of 0593 * runs of length 6 or more detected during entropy generation must be less than 0594 * RUN6P_MAX, else a retry or error will occur. This register is cleared to 002Fh 0595 * (decimal 47) by writing the MCTL[RST_DEF] bit to 1. 0596 */ 0597 /*@{*/ 0598 /*! @brief Read current value of the TRNG_SCR6PL_RUN6P_MAX field. */ 0599 #define TRNG_RD_SCR6PL_RUN6P_MAX(base) \ 0600 ((TRNG_SCR6PL_REG(base) & TRNG_SCR6PL_RUN6P_MAX_MASK) >> TRNG_SCR6PL_RUN6P_MAX_SHIFT) 0601 0602 /*! @brief Set the RUN6P_MAX field to a new value. */ 0603 #define TRNG_WR_SCR6PL_RUN6P_MAX(base, value) \ 0604 (TRNG_RMW_SCR6PL(base, TRNG_SCR6PL_RUN6P_MAX_MASK, TRNG_SCR6PL_RUN6P_MAX(value))) 0605 /*@}*/ 0606 0607 /*! 0608 * @name Register TRNG_SCR6PL, field RUN6P_RNG[26:16] (RW) 0609 * 0610 * Run Length 6+ Range. The number of runs of length 6 or more (for both 0 and 0611 * 1) detected during entropy generation must be greater than RUN6P_MAX - 0612 * RUN6P_RNG, else a retry or error will occur. This register is cleared to 002Eh 0613 * (decimal 46) by writing the MCTL[RST_DEF] bit to 1. 0614 */ 0615 /*@{*/ 0616 /*! @brief Read current value of the TRNG_SCR6PL_RUN6P_RNG field. */ 0617 #define TRNG_RD_SCR6PL_RUN6P_RNG(base) \ 0618 ((TRNG_SCR6PL_REG(base) & TRNG_SCR6PL_RUN6P_RNG_MASK) >> TRNG_SCR6PL_RUN6P_RNG_SHIFT) 0619 0620 /*! @brief Set the RUN6P_RNG field to a new value. */ 0621 #define TRNG_WR_SCR6PL_RUN6P_RNG(base, value) \ 0622 (TRNG_RMW_SCR6PL(base, TRNG_SCR6PL_RUN6P_RNG_MASK, TRNG_SCR6PL_RUN6P_RNG(value))) 0623 /*@}*/ 0624 #endif /* FSL_FEATURE_TRNG_HAS_NO_TRNG_SCR6L */ 0625 0626 /******************************************************************************* 0627 * TRNG_PKRMAX - RNG Poker Maximum Limit Register 0628 ******************************************************************************/ 0629 0630 #if !(defined(FSL_FEATURE_TRNG_HAS_NO_TRNG_PKRMAX) && FSL_FEATURE_TRNG_HAS_NO_TRNG_PKRMAX) 0631 /*! 0632 * @brief TRNG_PKRMAX - RNG Poker Maximum Limit Register (RW) 0633 * 0634 * Reset value: 0x00006920U 0635 * 0636 * The RNG Poker Maximum Limit Register defines Maximum Limit allowable during 0637 * the TRNG Statistical Check Poker Test. Note that this offset (0xBASE_060C) is 0638 * used as PKRMAX only if MCTL[PRGM] is 1. If MCTL[PRGM] is 0, this offset is used 0639 * as the PKRSQ readback register. 0640 */ 0641 /*! 0642 * @name Constants and macros for entire TRNG_PKRMAX register 0643 */ 0644 /*@{*/ 0645 #define TRNG_PKRMAX_REG(base) ((base)->PKRMAX) 0646 #define TRNG_RD_PKRMAX(base) (TRNG_PKRMAX_REG(base)) 0647 #define TRNG_WR_PKRMAX(base, value) (TRNG_PKRMAX_REG(base) = (value)) 0648 #define TRNG_RMW_PKRMAX(base, mask, value) (TRNG_WR_PKRMAX(base, (TRNG_RD_PKRMAX(base) & ~(mask)) | (value))) 0649 /*@}*/ 0650 0651 /* 0652 * Constants & macros for individual TRNG_PKRMAX bitfields 0653 */ 0654 0655 /*! 0656 * @name Register TRNG_PKRMAX, field PKR_MAX[23:0] (RW) 0657 * 0658 * Poker Maximum Limit. During the TRNG Statistical Checks, a "Poker Test" is 0659 * run which requires a maximum and minimum limit. The maximum allowable result is 0660 * programmed in the PKRMAX[PKR_MAX] register. This field is writable only if 0661 * MCTL[PRGM] bit is 1. This register is cleared to 006920h (decimal 26912) by 0662 * writing the MCTL[RST_DEF] bit to 1. Note that the PKRMAX and PKRRNG registers 0663 * combined are used to define the minimum allowable Poker result, which is PKR_MAX - 0664 * PKR_RNG + 1. Note that if MCTL[PRGM] bit is 0, this register address is used 0665 * to read the Poker Test Square Calculation result in register PKRSQ, as defined 0666 * in the following section. 0667 */ 0668 /*@{*/ 0669 /*! @brief Read current value of the TRNG_PKRMAX_PKR_MAX field. */ 0670 #define TRNG_RD_PKRMAX_PKR_MAX(base) ((TRNG_PKRMAX_REG(base) & TRNG_PKRMAX_PKR_MAX_MASK) >> TRNG_PKRMAX_PKR_MAX_SHIFT) 0671 0672 /*! @brief Set the PKR_MAX field to a new value. */ 0673 #define TRNG_WR_PKRMAX_PKR_MAX(base, value) \ 0674 (TRNG_RMW_PKRMAX(base, TRNG_PKRMAX_PKR_MAX_MASK, TRNG_PKRMAX_PKR_MAX(value))) 0675 /*@}*/ 0676 #endif /* FSL_FEATURE_TRNG_HAS_NO_TRNG_PKRMAX */ 0677 0678 /******************************************************************************* 0679 * TRNG_PKRRNG - RNG Poker Range Register 0680 ******************************************************************************/ 0681 0682 /*! 0683 * @brief TRNG_PKRRNG - RNG Poker Range Register (RW) 0684 * 0685 * Reset value: 0x000009A3U 0686 * 0687 * The RNG Poker Range Register defines the difference between the TRNG Poker 0688 * Maximum Limit and the minimum limit. These limits are used during the TRNG 0689 * Statistical Check Poker Test. 0690 */ 0691 /*! 0692 * @name Constants and macros for entire TRNG_PKRRNG register 0693 */ 0694 /*@{*/ 0695 #define TRNG_PKRRNG_REG(base) ((base)->PKRRNG) 0696 #define TRNG_RD_PKRRNG(base) (TRNG_PKRRNG_REG(base)) 0697 #define TRNG_WR_PKRRNG(base, value) (TRNG_PKRRNG_REG(base) = (value)) 0698 #define TRNG_RMW_PKRRNG(base, mask, value) (TRNG_WR_PKRRNG(base, (TRNG_RD_PKRRNG(base) & ~(mask)) | (value))) 0699 /*@}*/ 0700 0701 /* 0702 * Constants & macros for individual TRNG_PKRRNG bitfields 0703 */ 0704 0705 /*! 0706 * @name Register TRNG_PKRRNG, field PKR_RNG[15:0] (RW) 0707 * 0708 * Poker Range. During the TRNG Statistical Checks, a "Poker Test" is run which 0709 * requires a maximum and minimum limit. The maximum is programmed in the 0710 * RTPKRMAX[PKR_MAX] register, and the minimum is derived by subtracting the PKR_RNG 0711 * value from the programmed maximum value. This field is writable only if 0712 * MCTL[PRGM] bit is 1. This field will read zeroes if MCTL[PRGM] = 0. This field is 0713 * cleared to 09A3h (decimal 2467) by writing the MCTL[RST_DEF] bit to 1. Note that 0714 * the minimum allowable Poker result is PKR_MAX - PKR_RNG + 1. 0715 */ 0716 /*@{*/ 0717 /*! @brief Read current value of the TRNG_PKRRNG_PKR_RNG field. */ 0718 #define TRNG_RD_PKRRNG_PKR_RNG(base) ((TRNG_PKRRNG_REG(base) & TRNG_PKRRNG_PKR_RNG_MASK) >> TRNG_PKRRNG_PKR_RNG_SHIFT) 0719 0720 /*! @brief Set the PKR_RNG field to a new value. */ 0721 #define TRNG_WR_PKRRNG_PKR_RNG(base, value) \ 0722 (TRNG_RMW_PKRRNG(base, TRNG_PKRRNG_PKR_RNG_MASK, TRNG_PKRRNG_PKR_RNG(value))) 0723 /*@}*/ 0724 0725 /******************************************************************************* 0726 * TRNG_FRQMAX - RNG Frequency Count Maximum Limit Register 0727 ******************************************************************************/ 0728 0729 /*! 0730 * @brief TRNG_FRQMAX - RNG Frequency Count Maximum Limit Register (RW) 0731 * 0732 * Reset value: 0x00006400U 0733 * 0734 * The RNG Frequency Count Maximum Limit Register defines the maximum allowable 0735 * count taken by the Entropy sample counter during each Entropy sample. During 0736 * any sample period, if the count is greater than this programmed maximum, a 0737 * Frequency Count Fail is flagged in MCTL[FCT_FAIL] and an error is generated. Note 0738 * that this address (061C) is used as FRQMAX only if MCTL[PRGM] is 1. If 0739 * MCTL[PRGM] is 0, this address is used as FRQCNT readback register. 0740 */ 0741 /*! 0742 * @name Constants and macros for entire TRNG_FRQMAX register 0743 */ 0744 /*@{*/ 0745 #define TRNG_FRQMAX_REG(base) ((base)->FRQMAX) 0746 #define TRNG_RD_FRQMAX(base) (TRNG_FRQMAX_REG(base)) 0747 #define TRNG_WR_FRQMAX(base, value) (TRNG_FRQMAX_REG(base) = (value)) 0748 #define TRNG_RMW_FRQMAX(base, mask, value) (TRNG_WR_FRQMAX(base, (TRNG_RD_FRQMAX(base) & ~(mask)) | (value))) 0749 /*@}*/ 0750 0751 /* 0752 * Constants & macros for individual TRNG_FRQMAX bitfields 0753 */ 0754 0755 /*! 0756 * @name Register TRNG_FRQMAX, field FRQ_MAX[21:0] (RW) 0757 * 0758 * Frequency Counter Maximum Limit. Defines the maximum allowable count taken 0759 * during each entropy sample. This field is writable only if MCTL[PRGM] bit is 1. 0760 * This register is cleared to 000640h by writing the MCTL[RST_DEF] bit to 1. 0761 * Note that if MCTL[PRGM] bit is 0, this register address is used to read the 0762 * Frequency Count result in register FRQCNT, as defined in the following section. 0763 */ 0764 /*@{*/ 0765 /*! @brief Read current value of the TRNG_FRQMAX_FRQ_MAX field. */ 0766 #define TRNG_RD_FRQMAX_FRQ_MAX(base) ((TRNG_FRQMAX_REG(base) & TRNG_FRQMAX_FRQ_MAX_MASK) >> TRNG_FRQMAX_FRQ_MAX_SHIFT) 0767 0768 /*! @brief Set the FRQ_MAX field to a new value. */ 0769 #define TRNG_WR_FRQMAX_FRQ_MAX(base, value) \ 0770 (TRNG_RMW_FRQMAX(base, TRNG_FRQMAX_FRQ_MAX_MASK, TRNG_FRQMAX_FRQ_MAX(value))) 0771 /*@}*/ 0772 0773 /******************************************************************************* 0774 * TRNG_FRQMIN - RNG Frequency Count Minimum Limit Register 0775 ******************************************************************************/ 0776 0777 /*! 0778 * @brief TRNG_FRQMIN - RNG Frequency Count Minimum Limit Register (RW) 0779 * 0780 * Reset value: 0x00000640U 0781 * 0782 * The RNG Frequency Count Minimum Limit Register defines the minimum allowable 0783 * count taken by the Entropy sample counter during each Entropy sample. During 0784 * any sample period, if the count is less than this programmed minimum, a 0785 * Frequency Count Fail is flagged in MCTL[FCT_FAIL] and an error is generated. 0786 */ 0787 /*! 0788 * @name Constants and macros for entire TRNG_FRQMIN register 0789 */ 0790 /*@{*/ 0791 #define TRNG_FRQMIN_REG(base) ((base)->FRQMIN) 0792 #define TRNG_RD_FRQMIN(base) (TRNG_FRQMIN_REG(base)) 0793 #define TRNG_WR_FRQMIN(base, value) (TRNG_FRQMIN_REG(base) = (value)) 0794 #define TRNG_RMW_FRQMIN(base, mask, value) (TRNG_WR_FRQMIN(base, (TRNG_RD_FRQMIN(base) & ~(mask)) | (value))) 0795 /*@}*/ 0796 0797 /* 0798 * Constants & macros for individual TRNG_FRQMIN bitfields 0799 */ 0800 0801 /*! 0802 * @name Register TRNG_FRQMIN, field FRQ_MIN[21:0] (RW) 0803 * 0804 * Frequency Count Minimum Limit. Defines the minimum allowable count taken 0805 * during each entropy sample. This field is writable only if MCTL[PRGM] bit is 1. 0806 * This field will read zeroes if MCTL[PRGM] = 0. This field is cleared to 0000h64 0807 * by writing the MCTL[RST_DEF] bit to 1. 0808 */ 0809 /*@{*/ 0810 /*! @brief Read current value of the TRNG_FRQMIN_FRQ_MIN field. */ 0811 #define TRNG_RD_FRQMIN_FRQ_MIN(base) ((TRNG_FRQMIN_REG(base) & TRNG_FRQMIN_FRQ_MIN_MASK) >> TRNG_FRQMIN_FRQ_MIN_SHIFT) 0812 0813 /*! @brief Set the FRQ_MIN field to a new value. */ 0814 #define TRNG_WR_FRQMIN_FRQ_MIN(base, value) \ 0815 (TRNG_RMW_FRQMIN(base, TRNG_FRQMIN_FRQ_MIN_MASK, TRNG_FRQMIN_FRQ_MIN(value))) 0816 /*@}*/ 0817 0818 /******************************************************************************* 0819 * TRNG_MCTL - RNG Miscellaneous Control Register 0820 ******************************************************************************/ 0821 0822 /*! 0823 * @brief TRNG_MCTL - RNG Miscellaneous Control Register (RW) 0824 * 0825 * Reset value: 0x00012001U 0826 * 0827 * This register is intended to be used for programming, configuring and testing 0828 * the RNG. It is the main register to read/write, in order to enable Entropy 0829 * generation, to stop entropy generation and to block access to entropy registers. 0830 * This is done via the special TRNG_ACC and PRGM bits below. The RNG 0831 * Miscellaneous Control Register is a read/write register used to control the RNG's True 0832 * Random Number Generator (TRNG) access, operation and test. Note that in many 0833 * cases two RNG registers share the same address, and a particular register at the 0834 * shared address is selected based upon the value in the PRGM field of the MCTL 0835 * register. 0836 */ 0837 /*! 0838 * @name Constants and macros for entire TRNG_MCTL register 0839 */ 0840 /*@{*/ 0841 #define TRNG_MCTL_REG(base) ((base)->MCTL) 0842 #define TRNG_RD_MCTL(base) (TRNG_MCTL_REG(base)) 0843 #define TRNG_WR_MCTL(base, value) (TRNG_MCTL_REG(base) = (value)) 0844 #define TRNG_RMW_MCTL(base, mask, value) (TRNG_WR_MCTL(base, (TRNG_RD_MCTL(base) & ~(mask)) | (value))) 0845 /*@}*/ 0846 0847 /*! 0848 * @name Register TRNG_MCTL, field FOR_SCLK[7] (RW) 0849 * 0850 * Force System Clock. If set, the system clock is used to operate the TRNG, 0851 * instead of the ring oscillator. This is for test use only, and indeterminate 0852 * results may occur. This bit is writable only if PRGM bit is 1, or PRGM bit is 0853 * being written to 1 simultaneously to writing this bit. This bit is cleared by 0854 * writing the RST_DEF bit to 1. 0855 */ 0856 /*@{*/ 0857 /*! @brief Read current value of the TRNG_MCTL_FOR_SCLK field. */ 0858 #define TRNG_RD_MCTL_FOR_SCLK(base) ((TRNG_MCTL_REG(base) & TRNG_MCTL_FOR_SCLK_MASK) >> TRNG_MCTL_FOR_SCLK_SHIFT) 0859 0860 /*! @brief Set the FOR_SCLK field to a new value. */ 0861 #define TRNG_WR_MCTL_FOR_SCLK(base, value) \ 0862 (TRNG_RMW_MCTL(base, (TRNG_MCTL_FOR_SCLK_MASK | TRNG_MCTL_ERR_MASK), TRNG_MCTL_FOR_SCLK(value))) 0863 /*@}*/ 0864 0865 /*! 0866 * @name Register TRNG_MCTL, field OSC_DIV[3:2] (RW) 0867 * 0868 * Oscillator Divide. Determines the amount of dividing done to the ring 0869 * oscillator before it is used by the TRNG.This field is writable only if PRGM bit is 0870 * 1, or PRGM bit is being written to 1 simultaneously to writing this field. This 0871 * field is cleared to 00 by writing the RST_DEF bit to 1. 0872 * 0873 * Values: 0874 * - 0b00 - use ring oscillator with no divide 0875 * - 0b01 - use ring oscillator divided-by-2 0876 * - 0b10 - use ring oscillator divided-by-4 0877 * - 0b11 - use ring oscillator divided-by-8 0878 */ 0879 /*@{*/ 0880 /*! @brief Read current value of the TRNG_MCTL_OSC_DIV field. */ 0881 #define TRNG_RD_MCTL_OSC_DIV(base) ((TRNG_MCTL_REG(base) & TRNG_MCTL_OSC_DIV_MASK) >> TRNG_MCTL_OSC_DIV_SHIFT) 0882 0883 /*! @brief Set the OSC_DIV field to a new value. */ 0884 #define TRNG_WR_MCTL_OSC_DIV(base, value) \ 0885 (TRNG_RMW_MCTL(base, (TRNG_MCTL_OSC_DIV_MASK | TRNG_MCTL_ERR_MASK), TRNG_MCTL_OSC_DIV(value))) 0886 /*@}*/ 0887 0888 #if !(defined(FSL_FEATURE_TRNG_HAS_NO_TRNG_MCTL_SAMP_MODE) && FSL_FEATURE_TRNG_HAS_NO_TRNG_MCTL_SAMP_MODE) 0889 /*! 0890 * @name Register TRNG_MCTL, field SAMP_MODE[1:0] (RW) 0891 * 0892 * Sample Mode. Determines the method of sampling the ring oscillator while 0893 * generating the Entropy value:This field is writable only if PRGM bit is 1, or PRGM 0894 * bit is being written to 1 simultaneously with writing this field. This field 0895 * is cleared to 01 by writing the RST_DEF bit to 1. 0896 * 0897 * Values: 0898 * - 0b00 - use Von Neumann data into both Entropy shifter and Statistical 0899 * Checker 0900 * - 0b01 - use raw data into both Entropy shifter and Statistical Checker 0901 * - 0b10 - use Von Neumann data into Entropy shifter. Use raw data into 0902 * Statistical Checker 0903 * - 0b11 - reserved. 0904 */ 0905 /*@{*/ 0906 /*! @brief Read current value of the TRNG_MCTL_SAMP_MODE field. */ 0907 #define TRNG_RD_MCTL_SAMP_MODE(base) ((TRNG_MCTL_REG(base) & TRNG_MCTL_SAMP_MODE_MASK) >> TRNG_MCTL_SAMP_MODE_SHIFT) 0908 0909 /*! @brief Set the SAMP_MODE field to a new value. */ 0910 #define TRNG_WR_MCTL_SAMP_MODE(base, value) \ 0911 (TRNG_RMW_MCTL(base, (TRNG_MCTL_SAMP_MODE_MASK | TRNG_MCTL_ERR_MASK), TRNG_MCTL_SAMP_MODE(value))) 0912 /*@}*/ 0913 #endif /* FSL_FEATURE_TRNG_HAS_NO_TRNG_MCTL_SAMP_MODE */ 0914 0915 /*! 0916 * @name Register TRNG_MCTL, field PRGM[16] (RW) 0917 * 0918 * Programming Mode Select. When this bit is 1, the TRNG is in Program Mode, 0919 * otherwise it is in Run Mode. No Entropy value will be generated while the TRNG is 0920 * in Program Mode. Note that different RNG registers are accessible at the same 0921 * address depending on whether PRGM is set to 1 or 0. This is noted in the RNG 0922 * register descriptions. 0923 */ 0924 /*@{*/ 0925 /*! @brief Read current value of the TRNG_MCTL_PRGM field. */ 0926 #define TRNG_RD_MCTL_PRGM(base) ((TRNG_MCTL_REG(base) & TRNG_MCTL_PRGM_MASK) >> TRNG_MCTL_PRGM_SHIFT) 0927 0928 /*! @brief Set the PRGM field to a new value. */ 0929 #define TRNG_WR_MCTL_PRGM(base, value) \ 0930 (TRNG_RMW_MCTL(base, (TRNG_MCTL_PRGM_MASK | TRNG_MCTL_ERR_MASK), TRNG_MCTL_PRGM(value))) 0931 /*@}*/ 0932 0933 /*! 0934 * @name Register TRNG_MCTL, field RST_DEF[6] (WO) 0935 * 0936 * Reset Defaults. Writing a 1 to this bit clears various TRNG registers, and 0937 * bits within registers, to their default state. This bit is writable only if PRGM 0938 * bit is 1, or PRGM bit is being written to 1 simultaneously to writing this 0939 * bit. Reading this bit always produces a 0. 0940 */ 0941 /*@{*/ 0942 /*! @brief Set the RST_DEF field to a new value. */ 0943 #define TRNG_WR_MCTL_RST_DEF(base, value) \ 0944 (TRNG_RMW_MCTL(base, (TRNG_MCTL_RST_DEF_MASK | TRNG_MCTL_ERR_MASK), TRNG_MCTL_RST_DEF(value))) 0945 /*@}*/ 0946 0947 #if !(defined(FSL_FEATURE_TRNG_HAS_NO_TRNG_ACC) && (FSL_FEATURE_TRNG_HAS_NO_TRNG_ACC > 0)) 0948 /*! 0949 * @name Register TRNG_MCTL, field TRNG_ACC[5] (RW) 0950 * 0951 * TRNG Access Mode. If this bit is set to 1, the TRNG will generate an Entropy 0952 * value that can be read via the ENT0-ENT15 registers. The Entropy value may be 0953 * read once the ENT VAL bit is asserted. Also see ENTa register descriptions 0954 * (For a = 0 to 15). 0955 */ 0956 /*@{*/ 0957 /*! @brief Read current value of the TRNG_MCTL_TRNG_ACC field. */ 0958 #define TRNG_RD_MCTL_TRNG_ACC(base) ((TRNG_MCTL_REG(base) & TRNG_MCTL_TRNG_ACC_MASK) >> TRNG_MCTL_TRNG_ACC_SHIFT) 0959 0960 /*! @brief Set the TRNG_ACC field to a new value. */ 0961 #define TRNG_WR_MCTL_TRNG_ACC(base, value) \ 0962 (TRNG_RMW_MCTL(base, (TRNG_MCTL_TRNG_ACC_MASK | TRNG_MCTL_ERR_MASK), TRNG_MCTL_TRNG_ACC(value))) 0963 /*@}*/ 0964 #endif /* FSL_FEATURE_TRNG_HAS_NO_TRNG_ACC */ 0965 0966 /*! 0967 * @name Register TRNG_MCTL, field TSTOP_OK[13] (RO) 0968 * 0969 * TRNG_OK_TO_STOP. Software should check that this bit is a 1 before 0970 * transitioning RNG to low power mode (RNG clock stopped). RNG turns on the TRNG 0971 * free-running ring oscillator whenever new entropy is being generated and turns off the 0972 * ring oscillator when entropy generation is complete. If the RNG clock is 0973 * stopped while the TRNG ring oscillator is running, the oscillator will continue 0974 * running even though the RNG clock is stopped. TSTOP_OK is asserted when the TRNG 0975 * ring oscillator is not running. and therefore it is ok to stop the RNG clock. 0976 */ 0977 /*@{*/ 0978 /*! @brief Read current value of the TRNG_MCTL_TSTOP_OK field. */ 0979 #define TRNG_RD_MCTL_TSTOP_OK(base) ((TRNG_MCTL_REG(base) & TRNG_MCTL_TSTOP_OK_MASK) >> TRNG_MCTL_TSTOP_OK_SHIFT) 0980 /*@}*/ 0981 0982 /*! 0983 * @name Register TRNG_MCTL, field ENT_VAL[10] (RO) 0984 * 0985 * Read only: Entropy Valid. Will assert only if TRNG ACC bit is set, and then 0986 * after an entropy value is generated. Will be cleared when ENT15 is read. (ENT0 0987 * through ENT14 should be read before reading ENT15). 0988 */ 0989 /*@{*/ 0990 /*! @brief Read current value of the TRNG_MCTL_ENT_VAL field. */ 0991 #define TRNG_RD_MCTL_ENT_VAL(base) ((TRNG_MCTL_REG(base) & TRNG_MCTL_ENT_VAL_MASK) >> TRNG_MCTL_ENT_VAL_SHIFT) 0992 /*@}*/ 0993 0994 /*! 0995 * @name Register TRNG_MCTL, field ERR[12] (W1C) 0996 * 0997 * Read: Error status. 1 = error detected. 0 = no error.Write: Write 1 to clear 0998 * errors. Writing 0 has no effect. 0999 */ 1000 /*@{*/ 1001 /*! @brief Read current value of the TRNG_MCTL_ERR field. */ 1002 #define TRNG_RD_MCTL_ERR(base) ((TRNG_MCTL_REG(base) & TRNG_MCTL_ERR_MASK) >> TRNG_MCTL_ERR_SHIFT) 1003 1004 /*! @brief Set the ERR field to a new value. */ 1005 #define TRNG_WR_MCTL_ERR(base, value) (TRNG_RMW_MCTL(base, TRNG_MCTL_ERR_MASK, TRNG_MCTL_ERR(value))) 1006 /*@}*/ 1007 1008 /******************************************************************************* 1009 * TRNG_SDCTL - RNG Seed Control Register 1010 ******************************************************************************/ 1011 1012 /*! 1013 * @brief TRNG_SDCTL - RNG Seed Control Register (RW) 1014 * 1015 * Reset value: 0x0C8009C4U 1016 * 1017 * The RNG Seed Control Register contains two fields. One field defines the 1018 * length (in system clocks) of each Entropy sample (ENT_DLY), and the other field 1019 * indicates the number of samples that will taken during each TRNG Entropy 1020 * generation (SAMP_SIZE). 1021 */ 1022 /*! 1023 * @name Constants and macros for entire TRNG_SDCTL register 1024 */ 1025 /*@{*/ 1026 #define TRNG_SDCTL_REG(base) ((base)->SDCTL) 1027 #define TRNG_RD_SDCTL(base) (TRNG_SDCTL_REG(base)) 1028 #define TRNG_WR_SDCTL(base, value) (TRNG_SDCTL_REG(base) = (value)) 1029 #define TRNG_RMW_SDCTL(base, mask, value) (TRNG_WR_SDCTL(base, (TRNG_RD_SDCTL(base) & ~(mask)) | (value))) 1030 /*@}*/ 1031 1032 /* 1033 * Constants & macros for individual TRNG_SDCTL bitfields 1034 */ 1035 1036 /*! 1037 * @name Register TRNG_SDCTL, field SAMP_SIZE[15:0] (RW) 1038 * 1039 * Sample Size. Defines the total number of Entropy samples that will be taken 1040 * during Entropy generation. This field is writable only if MCTL[PRGM] bit is 1. 1041 * This field will read zeroes if MCTL[PRGM] = 0. This field is cleared to 09C4h 1042 * (decimal 2500) by writing the MCTL[RST_DEF] bit to 1. 1043 */ 1044 /*@{*/ 1045 /*! @brief Read current value of the TRNG_SDCTL_SAMP_SIZE field. */ 1046 #define TRNG_RD_SDCTL_SAMP_SIZE(base) ((TRNG_SDCTL_REG(base) & TRNG_SDCTL_SAMP_SIZE_MASK) >> TRNG_SDCTL_SAMP_SIZE_SHIFT) 1047 1048 /*! @brief Set the SAMP_SIZE field to a new value. */ 1049 #define TRNG_WR_SDCTL_SAMP_SIZE(base, value) \ 1050 (TRNG_RMW_SDCTL(base, TRNG_SDCTL_SAMP_SIZE_MASK, TRNG_SDCTL_SAMP_SIZE(value))) 1051 /*@}*/ 1052 1053 /*! 1054 * @name Register TRNG_SDCTL, field ENT_DLY[31:16] (RW) 1055 * 1056 * Entropy Delay. Defines the length (in system clocks) of each Entropy sample 1057 * taken. This field is writable only if MCTL[PRGM] bit is 1. This field will read 1058 * zeroes if MCTL[PRGM] = 0. This field is cleared to 0C80h (decimal 3200) by 1059 * writing the MCTL[RST_DEF] bit to 1. 1060 */ 1061 /*@{*/ 1062 /*! @brief Read current value of the TRNG_SDCTL_ENT_DLY field. */ 1063 #define TRNG_RD_SDCTL_ENT_DLY(base) ((TRNG_SDCTL_REG(base) & TRNG_SDCTL_ENT_DLY_MASK) >> TRNG_SDCTL_ENT_DLY_SHIFT) 1064 1065 /*! @brief Set the ENT_DLY field to a new value. */ 1066 #define TRNG_WR_SDCTL_ENT_DLY(base, value) (TRNG_RMW_SDCTL(base, TRNG_SDCTL_ENT_DLY_MASK, TRNG_SDCTL_ENT_DLY(value))) 1067 /*@}*/ 1068 1069 /******************************************************************************* 1070 * TRNG_SBLIM - RNG Sparse Bit Limit Register 1071 ******************************************************************************/ 1072 1073 #if !(defined(FSL_FEATURE_TRNG_HAS_NO_TRNG_SBLIM) && (FSL_FEATURE_TRNG_HAS_NO_TRNG_SBLIM > 0)) 1074 /*! 1075 * @brief TRNG_SBLIM - RNG Sparse Bit Limit Register (RW) 1076 * 1077 * Reset value: 0x0000003FU 1078 * 1079 * The RNG Sparse Bit Limit Register is used when Von Neumann sampling is 1080 * selected during Entropy Generation. It defines the maximum number of consecutive Von 1081 * Neumann samples which may be discarded before an error is generated. Note 1082 * that this address (0xBASE_0614) is used as SBLIM only if MCTL[PRGM] is 1. If 1083 * MCTL[PRGM] is 0, this address is used as TOTSAM readback register. 1084 */ 1085 /*! 1086 * @name Constants and macros for entire TRNG_SBLIM register 1087 */ 1088 /*@{*/ 1089 #define TRNG_SBLIM_REG(base) ((base)->SBLIM) 1090 #define TRNG_RD_SBLIM(base) (TRNG_SBLIM_REG(base)) 1091 #define TRNG_WR_SBLIM(base, value) (TRNG_SBLIM_REG(base) = (value)) 1092 #define TRNG_RMW_SBLIM(base, mask, value) (TRNG_WR_SBLIM(base, (TRNG_RD_SBLIM(base) & ~(mask)) | (value))) 1093 /*@}*/ 1094 1095 /* 1096 * Constants & macros for individual TRNG_SBLIM bitfields 1097 */ 1098 1099 /*! 1100 * @name Register TRNG_SBLIM, field SB_LIM[9:0] (RW) 1101 * 1102 * Sparse Bit Limit. During Von Neumann sampling (if enabled by MCTL[SAMP_MODE], 1103 * samples are discarded if two consecutive raw samples are both 0 or both 1. If 1104 * this discarding occurs for a long period of time, it indicates that there is 1105 * insufficient Entropy. The Sparse Bit Limit defines the maximum number of 1106 * consecutive samples that may be discarded before an error is generated. This field 1107 * is writable only if MCTL[PRGM] bit is 1. This register is cleared to 03hF by 1108 * writing the MCTL[RST_DEF] bit to 1. Note that if MCTL[PRGM] bit is 0, this 1109 * register address is used to read the Total Samples count in register TOTSAM, as 1110 * defined in the following section. 1111 */ 1112 /*@{*/ 1113 /*! @brief Read current value of the TRNG_SBLIM_SB_LIM field. */ 1114 #define TRNG_RD_SBLIM_SB_LIM(base) ((TRNG_SBLIM_REG(base) & TRNG_SBLIM_SB_LIM_MASK) >> TRNG_SBLIM_SB_LIM_SHIFT) 1115 1116 /*! @brief Set the SB_LIM field to a new value. */ 1117 #define TRNG_WR_SBLIM_SB_LIM(base, value) (TRNG_RMW_SBLIM(base, TRNG_SBLIM_SB_LIM_MASK, TRNG_SBLIM_SB_LIM(value))) 1118 /*@}*/ 1119 #endif /* FSL_FEATURE_TRNG_HAS_NO_TRNG_SBLIM */ 1120 1121 /******************************************************************************* 1122 * TRNG_SCMISC - RNG Statistical Check Miscellaneous Register 1123 ******************************************************************************/ 1124 1125 /*! 1126 * @brief TRNG_SCMISC - RNG Statistical Check Miscellaneous Register (RW) 1127 * 1128 * Reset value: 0x0001001FU 1129 * 1130 * The RNG Statistical Check Miscellaneous Register contains the Long Run 1131 * Maximum Limit value and the Retry Count value. This register is accessible only when 1132 * the MCTL[PRGM] bit is 1, otherwise this register will read zeroes, and cannot 1133 * be written. 1134 */ 1135 /*! 1136 * @name Constants and macros for entire TRNG_SCMISC register 1137 */ 1138 /*@{*/ 1139 #define TRNG_SCMISC_REG(base) ((base)->SCMISC) 1140 #define TRNG_RD_SCMISC(base) (TRNG_SCMISC_REG(base)) 1141 #define TRNG_WR_SCMISC(base, value) (TRNG_SCMISC_REG(base) = (value)) 1142 #define TRNG_RMW_SCMISC(base, mask, value) (TRNG_WR_SCMISC(base, (TRNG_RD_SCMISC(base) & ~(mask)) | (value))) 1143 /*@}*/ 1144 1145 /* 1146 * Constants & macros for individual TRNG_SCMISC bitfields 1147 */ 1148 1149 /*! 1150 * @name Register TRNG_SCMISC, field LRUN_MAX[7:0] (RW) 1151 * 1152 * LONG RUN MAX LIMIT. This value is the largest allowable number of consecutive 1153 * samples of all 1, or all 0, that is allowed during the Entropy generation. 1154 * This field is writable only if MCTL[PRGM] bit is 1. This field will read zeroes 1155 * if MCTL[PRGM] = 0. This field is cleared to 22h by writing the MCTL[RST_DEF] 1156 * bit to 1. 1157 */ 1158 /*@{*/ 1159 /*! @brief Read current value of the TRNG_SCMISC_LRUN_MAX field. */ 1160 #define TRNG_RD_SCMISC_LRUN_MAX(base) \ 1161 ((TRNG_SCMISC_REG(base) & TRNG_SCMISC_LRUN_MAX_MASK) >> TRNG_SCMISC_LRUN_MAX_SHIFT) 1162 1163 /*! @brief Set the LRUN_MAX field to a new value. */ 1164 #define TRNG_WR_SCMISC_LRUN_MAX(base, value) \ 1165 (TRNG_RMW_SCMISC(base, TRNG_SCMISC_LRUN_MAX_MASK, TRNG_SCMISC_LRUN_MAX(value))) 1166 /*@}*/ 1167 1168 /******************************************************************************* 1169 * TRNG_ENT - RNG TRNG Entropy Read Register 1170 ******************************************************************************/ 1171 1172 /*! 1173 * @brief TRNG_ENT - RNG TRNG Entropy Read Register (RO) 1174 * 1175 * Reset value: 0x00000000U 1176 * 1177 * The RNG TRNG can be programmed to generate an entropy value that is readable 1178 * via the SkyBlue bus. To do this, set the MCTL[TRNG_ACC] bit to 1. Once the 1179 * entropy value has been generated, the MCTL[ENT_VAL] bit will be set to 1. At this 1180 * point, ENT0 through ENT15 may be read to retrieve the 512-bit entropy value. 1181 * Note that once ENT15 is read, the entropy value will be cleared and a new 1182 * value will begin generation, so it is important that ENT15 be read last. These 1183 * registers are readable only when MCTL[PRGM] = 0 (Run Mode), MCTL[TRNG_ACC] = 1 1184 * (TRNG access mode) and MCTL[ENT_VAL] = 1, otherwise zeroes will be read. 1185 */ 1186 /*! 1187 * @name Constants and macros for entire TRNG_ENT register 1188 */ 1189 /*@{*/ 1190 #define TRNG_ENT_REG(base, index) ((base)->ENT[index]) 1191 #define TRNG_RD_ENT(base, index) (TRNG_ENT_REG(base, index)) 1192 /*@}*/ 1193 1194 /******************************************************************************* 1195 * TRNG_SEC_CFG - RNG Security Configuration Register 1196 ******************************************************************************/ 1197 1198 /*! 1199 * @brief TRNG_SEC_CFG - RNG Security Configuration Register (RW) 1200 * 1201 * Reset value: 0x00000000U 1202 * 1203 * The RNG Security Configuration Register is a read/write register used to 1204 * control the test mode, programmability and state modes of the RNG. Many bits are 1205 * place holders for this version. More configurability will be added here. Clears 1206 * on asynchronous reset. For SA-TRNG releases before 2014/July/01, offsets 0xA0 1207 * to 0xAC used to be 0xB0 to 0xBC respectively. So, update newer tests that use 1208 * these registers, if hard coded. 1209 */ 1210 /*! 1211 * @name Constants and macros for entire TRNG_SEC_CFG register 1212 */ 1213 /*@{*/ 1214 #define TRNG_SEC_CFG_REG(base) ((base)->SEC_CFG) 1215 #define TRNG_RD_SEC_CFG(base) (TRNG_SEC_CFG_REG(base)) 1216 #define TRNG_WR_SEC_CFG(base, value) (TRNG_SEC_CFG_REG(base) = (value)) 1217 #define TRNG_RMW_SEC_CFG(base, mask, value) (TRNG_WR_SEC_CFG(base, (TRNG_RD_SEC_CFG(base) & ~(mask)) | (value))) 1218 /*@}*/ 1219 1220 /*! 1221 * @name Register TRNG_SEC_CFG, field NO_PRGM[1] (RW) 1222 * 1223 * If set the TRNG registers cannot be programmed. That is, regardless of the 1224 * TRNG access mode in the SA-TRNG Miscellaneous Control Register. 1225 * 1226 * Values: 1227 * - 0b0 - Programability of registers controlled only by the RNG Miscellaneous 1228 * Control Register's access mode bit. 1229 * - 0b1 - Overides RNG Miscellaneous Control Register access mode and prevents 1230 * TRNG register programming. 1231 */ 1232 /*@{*/ 1233 /*! @brief Read current value of the TRNG_SEC_CFG_NO_PRGM field. */ 1234 #define TRNG_RD_SEC_CFG_NO_PRGM(base) \ 1235 ((TRNG_SEC_CFG_REG(base) & TRNG_SEC_CFG_NO_PRGM_MASK) >> TRNG_SEC_CFG_NO_PRGM_SHIFT) 1236 1237 /*! @brief Set the NO_PRGM field to a new value. */ 1238 #define TRNG_WR_SEC_CFG_NO_PRGM(base, value) \ 1239 (TRNG_RMW_SEC_CFG(base, TRNG_SEC_CFG_NO_PRGM_MASK, TRNG_SEC_CFG_NO_PRGM(value))) 1240 /*@}*/ 1241 1242 /*! @brief Array to map TRNG instance number to base pointer. */ 1243 static TRNG_Type *const s_trngBases[] = TRNG_BASE_PTRS; 1244 1245 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) 1246 /*! @brief Clock array name */ 1247 static const clock_ip_name_t s_trngClock[] = TRNG_CLOCKS; 1248 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */ 1249 1250 #if defined(FSL_FEATURE_TRNG_HAS_RSTCTL) && (FSL_FEATURE_TRNG_HAS_RSTCTL > 0) 1251 static const reset_ip_name_t trng_reset = TRNG_RSTS; 1252 #endif /* FSL_FEATURE_TRNG_HAS_RSTCTL */ 1253 1254 /******************************************************************************* 1255 * Prototypes 1256 *******************************************************************************/ 1257 static status_t trng_ApplyUserConfig(TRNG_Type *base, const trng_config_t *userConfig); 1258 static status_t trng_SetRetryCount(TRNG_Type *base, uint8_t retry_count); 1259 static status_t trng_SetMonobitLimit(TRNG_Type *base, uint32_t range, uint32_t limit_maximum); 1260 static status_t trng_SetRunBit1Limit(TRNG_Type *base, uint32_t range, uint32_t limit_maximum); 1261 static status_t trng_SetRunBit2Limit(TRNG_Type *base, uint32_t range, uint32_t limit_maximum); 1262 static status_t trng_SetRunBit3Limit(TRNG_Type *base, uint32_t range, uint32_t limit_maximum); 1263 static status_t trng_SetRunBit4Limit(TRNG_Type *base, uint32_t range, uint32_t limit_maximum); 1264 static status_t trng_SetRunBit5Limit(TRNG_Type *base, uint32_t range, uint32_t limit_maximum); 1265 static status_t trng_SetRunBit6Limit(TRNG_Type *base, uint32_t range, uint32_t limit_maximum); 1266 static status_t trng_SetPokerMaxLimit(TRNG_Type *base, uint32_t range, uint32_t limit_maximum); 1267 static status_t trng_SetFrequencyCountMaxLimit(TRNG_Type *base, uint32_t limit_minimum, uint32_t limit_maximum); 1268 static status_t trng_SetStatisticalCheckLimit(TRNG_Type *base, 1269 trng_statistical_check_t statistical_check, 1270 const trng_statistical_check_limit_t *limit); 1271 static uint32_t trng_ReadEntropy(TRNG_Type *base, uint32_t index); 1272 static uint32_t trng_GetInstance(TRNG_Type *base); 1273 1274 /******************************************************************************* 1275 * Code 1276 ******************************************************************************/ 1277 1278 static uint32_t trng_GetInstance(TRNG_Type *base) 1279 { 1280 uint32_t instance; 1281 1282 /* Find the instance index from base address mappings. */ 1283 for (instance = 0; instance < ARRAY_SIZE(s_trngBases); instance++) 1284 { 1285 if (s_trngBases[instance] == base) 1286 { 1287 break; 1288 } 1289 } 1290 1291 assert(instance < ARRAY_SIZE(s_trngBases)); 1292 1293 return instance; 1294 } 1295 1296 /*FUNCTION********************************************************************* 1297 * 1298 * Function Name : TRNG_InitUserConfigDefault 1299 * Description : Initializes user configuration structure to default settings. 1300 * 1301 *END*************************************************************************/ 1302 /*! 1303 * brief Initializes the user configuration structure to default values. 1304 * 1305 * This function initializes the configuration structure to default values. The default 1306 * values are as follows. 1307 * code 1308 * userConfig->lock = 0; 1309 * userConfig->clockMode = kTRNG_ClockModeRingOscillator; 1310 * userConfig->ringOscDiv = kTRNG_RingOscDiv0; Or to other kTRNG_RingOscDiv[2|8] depending on the platform. 1311 * userConfig->sampleMode = kTRNG_SampleModeRaw; 1312 * userConfig->entropyDelay = 3200; 1313 * userConfig->sampleSize = 2500; 1314 * userConfig->sparseBitLimit = TRNG_USER_CONFIG_DEFAULT_SPARSE_BIT_LIMIT; 1315 * userConfig->retryCount = 63; 1316 * userConfig->longRunMaxLimit = 34; 1317 * userConfig->monobitLimit.maximum = 1384; 1318 * userConfig->monobitLimit.minimum = 1116; 1319 * userConfig->runBit1Limit.maximum = 405; 1320 * userConfig->runBit1Limit.minimum = 227; 1321 * userConfig->runBit2Limit.maximum = 220; 1322 * userConfig->runBit2Limit.minimum = 98; 1323 * userConfig->runBit3Limit.maximum = 125; 1324 * userConfig->runBit3Limit.minimum = 37; 1325 * userConfig->runBit4Limit.maximum = 75; 1326 * userConfig->runBit4Limit.minimum = 11; 1327 * userConfig->runBit5Limit.maximum = 47; 1328 * userConfig->runBit5Limit.minimum = 1; 1329 * userConfig->runBit6PlusLimit.maximum = 47; 1330 * userConfig->runBit6PlusLimit.minimum = 1; 1331 * userConfig->pokerLimit.maximum = 26912; 1332 * userConfig->pokerLimit.minimum = 24445; 1333 * userConfig->frequencyCountLimit.maximum = 25600; 1334 * userConfig->frequencyCountLimit.minimum = 1600; 1335 * endcode 1336 * 1337 * param userConfig User configuration structure. 1338 * return If successful, returns the kStatus_TRNG_Success. Otherwise, it returns an error. 1339 */ 1340 status_t TRNG_GetDefaultConfig(trng_config_t *userConfig) 1341 { 1342 status_t result; 1343 1344 if (userConfig != NULL) 1345 { 1346 /* Initializes the configuration structure to default values. */ 1347 1348 /* Lock programmability of TRNG registers. */ 1349 userConfig->lock = (bool)TRNG_USER_CONFIG_DEFAULT_LOCK; 1350 /* Clock settings */ 1351 userConfig->clockMode = kTRNG_ClockModeRingOscillator; 1352 userConfig->ringOscDiv = TRNG_USER_CONFIG_DEFAULT_OSC_DIV; 1353 userConfig->sampleMode = kTRNG_SampleModeRaw; 1354 /* Seed control*/ 1355 userConfig->entropyDelay = TRNG_USER_CONFIG_DEFAULT_ENTROPY_DELAY; 1356 userConfig->sampleSize = TRNG_USER_CONFIG_DEFAULT_SAMPLE_SIZE; 1357 userConfig->sparseBitLimit = TRNG_USER_CONFIG_DEFAULT_SPARSE_BIT_LIMIT; 1358 1359 /* Statistical Check Parameters.*/ 1360 userConfig->retryCount = TRNG_USER_CONFIG_DEFAULT_RETRY_COUNT; 1361 userConfig->longRunMaxLimit = TRNG_USER_CONFIG_DEFAULT_RUN_MAX_LIMIT; 1362 1363 userConfig->monobitLimit.maximum = TRNG_USER_CONFIG_DEFAULT_MONOBIT_MAXIMUM; 1364 userConfig->monobitLimit.minimum = TRNG_USER_CONFIG_DEFAULT_MONOBIT_MINIMUM; 1365 userConfig->runBit1Limit.maximum = TRNG_USER_CONFIG_DEFAULT_RUNBIT1_MAXIMUM; 1366 userConfig->runBit1Limit.minimum = TRNG_USER_CONFIG_DEFAULT_RUNBIT1_MINIMUM; 1367 userConfig->runBit2Limit.maximum = TRNG_USER_CONFIG_DEFAULT_RUNBIT2_MAXIMUM; 1368 userConfig->runBit2Limit.minimum = TRNG_USER_CONFIG_DEFAULT_RUNBIT2_MINIMUM; 1369 userConfig->runBit3Limit.maximum = TRNG_USER_CONFIG_DEFAULT_RUNBIT3_MAXIMUM; 1370 userConfig->runBit3Limit.minimum = TRNG_USER_CONFIG_DEFAULT_RUNBIT3_MINIMUM; 1371 userConfig->runBit4Limit.maximum = TRNG_USER_CONFIG_DEFAULT_RUNBIT4_MAXIMUM; 1372 userConfig->runBit4Limit.minimum = TRNG_USER_CONFIG_DEFAULT_RUNBIT4_MINIMUM; 1373 userConfig->runBit5Limit.maximum = TRNG_USER_CONFIG_DEFAULT_RUNBIT5_MAXIMUM; 1374 userConfig->runBit5Limit.minimum = TRNG_USER_CONFIG_DEFAULT_RUNBIT5_MINIMUM; 1375 userConfig->runBit6PlusLimit.maximum = TRNG_USER_CONFIG_DEFAULT_RUNBIT6PLUS_MAXIMUM; 1376 userConfig->runBit6PlusLimit.minimum = TRNG_USER_CONFIG_DEFAULT_RUNBIT6PLUS_MINIMUM; 1377 /* Limits for statistical check of "Poker Test". */ 1378 userConfig->pokerLimit.maximum = TRNG_USER_CONFIG_DEFAULT_POKER_MAXIMUM; 1379 userConfig->pokerLimit.minimum = TRNG_USER_CONFIG_DEFAULT_POKER_MINIMUM; 1380 /* Limits for statistical check of entropy sample frequency count. */ 1381 userConfig->frequencyCountLimit.maximum = TRNG_USER_CONFIG_DEFAULT_FREQUENCY_MAXIMUM; 1382 userConfig->frequencyCountLimit.minimum = TRNG_USER_CONFIG_DEFAULT_FREQUENCY_MINIMUM; 1383 1384 result = kStatus_Success; 1385 } 1386 else 1387 { 1388 result = kStatus_InvalidArgument; 1389 } 1390 1391 return result; 1392 } 1393 1394 /*! 1395 * @brief Sets the TRNG retry count. 1396 * 1397 * This function sets the retry counter which defines the number of times a 1398 * statistical check may fails during the TRNG Entropy Generation before 1399 * generating an error. 1400 */ 1401 static status_t trng_SetRetryCount(TRNG_Type *base, uint8_t retry_count) 1402 { 1403 status_t status; 1404 1405 if ((retry_count >= 1u) && (retry_count <= 15u)) 1406 { 1407 /* Set retry count.*/ 1408 TRNG_WR_SCMISC_RTY_CT(base, retry_count); 1409 status = kStatus_Success; 1410 } 1411 else 1412 { 1413 status = kStatus_InvalidArgument; 1414 } 1415 return status; 1416 } 1417 1418 /*! 1419 * @brief Sets statistical Check Monobit Limit Register . 1420 * 1421 * This function set register TRNG_SCML - Statistical Check Monobit Limit Register 1422 */ 1423 static status_t trng_SetMonobitLimit(TRNG_Type *base, uint32_t range, uint32_t limit_maximum) 1424 { 1425 status_t status; 1426 1427 /* Check input parameters*/ 1428 if ((range <= 0xffffu) && (limit_maximum <= 0xffffu)) 1429 1430 { 1431 /* Set TRNG_SCML register */ 1432 TRNG_WR_SCML_MONO_MAX(base, limit_maximum); 1433 TRNG_WR_SCML_MONO_RNG(base, range); 1434 status = kStatus_Success; 1435 } 1436 else 1437 { 1438 status = kStatus_InvalidArgument; 1439 } 1440 return status; 1441 } 1442 1443 /*! 1444 * @brief Sets statistical Statistical Check Run Length 1 Limit Register . 1445 * 1446 * This function set register TRNG_SCR1L - Statistical Check Run Length 1 Limit Register 1447 */ 1448 static status_t trng_SetRunBit1Limit(TRNG_Type *base, uint32_t range, uint32_t limit_maximum) 1449 { 1450 status_t status; 1451 1452 /* Check input parameters*/ 1453 if ((range <= 0x7fffu) && (limit_maximum <= 0x7fffu)) 1454 { 1455 /* Set TRNG_SCR1L register */ 1456 TRNG_WR_SCR1L_RUN1_MAX(base, limit_maximum); 1457 TRNG_WR_SCR1L_RUN1_RNG(base, range); 1458 status = kStatus_Success; 1459 } 1460 else 1461 { 1462 status = kStatus_InvalidArgument; 1463 } 1464 return status; 1465 } 1466 1467 /*! 1468 * @brief Sets statistical Statistical Check Run Length 2 Limit Register . 1469 * 1470 * This function set register TRNG_SCR2L - Statistical Check Run Length 2 Limit Register 1471 */ 1472 static status_t trng_SetRunBit2Limit(TRNG_Type *base, uint32_t range, uint32_t limit_maximum) 1473 { 1474 status_t status; 1475 1476 /* Check input parameters*/ 1477 if ((range <= 0x3fffu) && (limit_maximum <= 0x3fffu)) 1478 { 1479 /* Set TRNG_SCR2L register */ 1480 TRNG_WR_SCR2L_RUN2_MAX(base, limit_maximum); 1481 TRNG_WR_SCR2L_RUN2_RNG(base, range); 1482 status = kStatus_Success; 1483 } 1484 else 1485 { 1486 status = kStatus_InvalidArgument; 1487 } 1488 return status; 1489 } 1490 1491 /*! 1492 * @brief Sets statistical Statistical Check Run Length 3 Limit Register . 1493 * 1494 * This function set register TRNG_SCR3L - Statistical Check Run Length 3 Limit Register 1495 */ 1496 static status_t trng_SetRunBit3Limit(TRNG_Type *base, uint32_t range, uint32_t limit_maximum) 1497 { 1498 status_t status; 1499 1500 /* Check input parameters*/ 1501 if ((range <= 0x1fffu) && (limit_maximum <= 0x1fffu)) 1502 { 1503 /* Set TRNG_SCR3L register */ 1504 TRNG_WR_SCR3L_RUN3_MAX(base, limit_maximum); 1505 TRNG_WR_SCR3L_RUN3_RNG(base, range); 1506 status = kStatus_Success; 1507 } 1508 else 1509 { 1510 status = kStatus_InvalidArgument; 1511 } 1512 return status; 1513 } 1514 1515 /*! 1516 * @brief Sets statistical Statistical Check Run Length 4 Limit Register . 1517 * This function set register TRNG_SCR4L - Statistical Check Run Length 4 Limit Register 1518 */ 1519 static status_t trng_SetRunBit4Limit(TRNG_Type *base, uint32_t range, uint32_t limit_maximum) 1520 { 1521 status_t status; 1522 1523 /* Check input parameters*/ 1524 if ((range <= 0xfffu) && (limit_maximum <= 0xfffu)) 1525 { 1526 #if !(defined(FSL_FEATURE_TRNG_HAS_NO_TRNG_SCR4L) && FSL_FEATURE_TRNG_HAS_NO_TRNG_SCR4L) 1527 /* Set TRNG_SCR4L register */ 1528 TRNG_WR_SCR4L_RUN4_MAX(base, limit_maximum); 1529 TRNG_WR_SCR4L_RUN4_RNG(base, range); 1530 #endif /* FSL_FEATURE_TRNG_HAS_NO_TRNG_SCR4L */ 1531 status = kStatus_Success; 1532 } 1533 else 1534 { 1535 status = kStatus_InvalidArgument; 1536 } 1537 return status; 1538 } 1539 1540 /*! 1541 * @brief Sets statistical Statistical Check Run Length 5 Limit Register . 1542 * This function set register TRNG_SCR5L - Statistical Check Run Length 5 Limit Register 1543 */ 1544 static status_t trng_SetRunBit5Limit(TRNG_Type *base, uint32_t range, uint32_t limit_maximum) 1545 { 1546 status_t status; 1547 1548 /* Check input parameters*/ 1549 if ((range <= 0x7ffu) && (limit_maximum <= 0x7ffu)) 1550 { 1551 #if !(defined(FSL_FEATURE_TRNG_HAS_NO_TRNG_SCR5L) && FSL_FEATURE_TRNG_HAS_NO_TRNG_SCR5L) 1552 /* Set TRNG_SCR5L register */ 1553 TRNG_WR_SCR5L_RUN5_MAX(base, limit_maximum); 1554 TRNG_WR_SCR5L_RUN5_RNG(base, range); 1555 #endif /* FSL_FEATURE_TRNG_HAS_NO_TRNG_SCR5L */ 1556 status = kStatus_Success; 1557 } 1558 else 1559 { 1560 status = kStatus_InvalidArgument; 1561 } 1562 return status; 1563 } 1564 1565 /*! 1566 * @brief Sets statistical Statistical Check Run Length 6 Limit Register . 1567 * This function set register TRNG_SCR6L - Statistical Check Run Length 6 Limit Register 1568 */ 1569 static status_t trng_SetRunBit6Limit(TRNG_Type *base, uint32_t range, uint32_t limit_maximum) 1570 { 1571 status_t status; 1572 1573 /* Check input parameters*/ 1574 if ((range <= 0x7ffu) && (limit_maximum <= 0x7ffu)) 1575 { 1576 #if !(defined(FSL_FEATURE_TRNG_HAS_NO_TRNG_SCR6L) && FSL_FEATURE_TRNG_HAS_NO_TRNG_SCR6L) 1577 /* Set TRNG_SCR6L register */ 1578 TRNG_WR_SCR6PL_RUN6P_MAX(base, limit_maximum); 1579 TRNG_WR_SCR6PL_RUN6P_RNG(base, range); 1580 #endif /* FSL_FEATURE_TRNG_HAS_NO_TRNG_SCR6L */ 1581 status = kStatus_Success; 1582 } 1583 else 1584 { 1585 status = kStatus_InvalidArgument; 1586 } 1587 return status; 1588 } 1589 1590 /*! 1591 * @brief Sets statistical Poker Maximum Limit Register. 1592 * This function set register TRNG_PKRMAX - Poker Maximum Limit Register 1593 */ 1594 static status_t trng_SetPokerMaxLimit(TRNG_Type *base, uint32_t range, uint32_t limit_maximum) 1595 { 1596 status_t status; 1597 1598 /* Check input parameters*/ 1599 if ((range <= 0xffffu) && (limit_maximum <= 0xffffffu)) 1600 { 1601 #if !(defined(FSL_FEATURE_TRNG_HAS_NO_TRNG_PKRMAX) && FSL_FEATURE_TRNG_HAS_NO_TRNG_PKRMAX) 1602 /* Set TRNG_PKRMAX register */ 1603 TRNG_WR_PKRMAX_PKR_MAX(base, limit_maximum); 1604 TRNG_WR_PKRRNG_PKR_RNG(base, range); 1605 #endif /* FSL_FEATURE_TRNG_HAS_NO_TRNG_PKRMAX */ 1606 status = kStatus_Success; 1607 } 1608 else 1609 { 1610 status = kStatus_InvalidArgument; 1611 } 1612 return status; 1613 } 1614 1615 /*! 1616 * @brief Sets statistical Frequency Count Maximum Limit Register. 1617 * This function set register TRNG_FRQMAX - Frequency Count Maximum Limit Register 1618 */ 1619 static status_t trng_SetFrequencyCountMaxLimit(TRNG_Type *base, uint32_t limit_minimum, uint32_t limit_maximum) 1620 { 1621 status_t status; 1622 1623 /* Check input parameters*/ 1624 if ((limit_minimum <= 0x3fffffu) && (limit_maximum <= 0x3fffffu)) 1625 { 1626 /* Set FRQMAX register */ 1627 TRNG_WR_FRQMAX_FRQ_MAX(base, limit_maximum); 1628 TRNG_WR_FRQMIN_FRQ_MIN(base, limit_minimum); 1629 status = kStatus_Success; 1630 } 1631 else 1632 { 1633 status = kStatus_InvalidArgument; 1634 } 1635 return status; 1636 } 1637 1638 /*! 1639 * @brief Sets statistical check limits. 1640 * 1641 * This function is used to set minimum and maximum limits of statistical checks. 1642 * 1643 */ 1644 static status_t trng_SetStatisticalCheckLimit(TRNG_Type *base, 1645 trng_statistical_check_t statistical_check, 1646 const trng_statistical_check_limit_t *limit) 1647 { 1648 uint32_t range; 1649 status_t status = kStatus_Success; 1650 1651 if ((NULL != limit) && (limit->maximum > limit->minimum)) 1652 { 1653 range = limit->maximum - limit->minimum; /* Registers use range instead of minimum value.*/ 1654 1655 if (statistical_check == kTRNG_StatisticalCheckMonobit) /* Allowable maximum and minimum number of ones/zero 1656 detected during entropy generation. */ 1657 { 1658 status = trng_SetMonobitLimit(base, range, limit->maximum); 1659 } 1660 else if (statistical_check == kTRNG_StatisticalCheckRunBit1) /* Allowable maximum and minimum number of runs of 1661 length 1 detected during entropy generation. */ 1662 { 1663 status = trng_SetRunBit1Limit(base, range, limit->maximum); 1664 } 1665 else if (statistical_check == kTRNG_StatisticalCheckRunBit2) /* Allowable maximum and minimum number of runs of 1666 length 2 detected during entropy generation. */ 1667 { 1668 status = trng_SetRunBit2Limit(base, range, limit->maximum); 1669 } 1670 else if (statistical_check == kTRNG_StatisticalCheckRunBit3) /* Allowable maximum and minimum number of runs of 1671 length 3 detected during entropy generation. */ 1672 { 1673 status = trng_SetRunBit3Limit(base, range, limit->maximum); 1674 } 1675 else if (statistical_check == kTRNG_StatisticalCheckRunBit4) /* Allowable maximum and minimum number of runs of 1676 length 4 detected during entropy generation. */ 1677 { 1678 status = trng_SetRunBit4Limit(base, range, limit->maximum); 1679 } 1680 else if (statistical_check == kTRNG_StatisticalCheckRunBit5) /* Allowable maximum and minimum number of runs of 1681 length 5 detected during entropy generation. */ 1682 { 1683 status = trng_SetRunBit5Limit(base, range, limit->maximum); 1684 } 1685 else if (statistical_check == kTRNG_StatisticalCheckRunBit6Plus) /* Allowable maximum and minimum number of 1686 length 6 or more detected during entropy 1687 generation */ 1688 { 1689 status = trng_SetRunBit6Limit(base, range, limit->maximum); 1690 } 1691 else if (statistical_check == kTRNG_StatisticalCheckPoker) /* Allowable maximum and minimum limit of "Poker 1692 Test" detected during entropy generation . */ 1693 { 1694 status = trng_SetPokerMaxLimit(base, range, limit->maximum); 1695 } 1696 else if (statistical_check == kTRNG_StatisticalCheckFrequencyCount) /* Allowable maximum and minimum limit of 1697 entropy sample frquency count during 1698 entropy generation . */ 1699 { 1700 status = trng_SetFrequencyCountMaxLimit(base, limit->minimum, limit->maximum); 1701 } 1702 else 1703 { 1704 status = kStatus_InvalidArgument; 1705 } 1706 } 1707 1708 return status; 1709 } 1710 1711 /*FUNCTION********************************************************************* 1712 * 1713 * Function Name : trng_ApplyUserConfig 1714 * Description : Apply user configuration settings to TRNG module. 1715 * 1716 *END*************************************************************************/ 1717 static status_t trng_ApplyUserConfig(TRNG_Type *base, const trng_config_t *userConfig) 1718 { 1719 status_t status; 1720 1721 /* Set retry count */ 1722 status = trng_SetRetryCount(base, userConfig->retryCount); 1723 1724 /* Set statistical check limit */ 1725 if (kStatus_Success == status) 1726 { 1727 status = trng_SetStatisticalCheckLimit(base, kTRNG_StatisticalCheckMonobit, &userConfig->monobitLimit); 1728 } 1729 1730 if (kStatus_Success == status) 1731 { 1732 status = trng_SetStatisticalCheckLimit(base, kTRNG_StatisticalCheckRunBit1, &userConfig->runBit1Limit); 1733 } 1734 1735 if (kStatus_Success == status) 1736 { 1737 status = trng_SetStatisticalCheckLimit(base, kTRNG_StatisticalCheckRunBit2, &userConfig->runBit2Limit); 1738 } 1739 1740 if (kStatus_Success == status) 1741 { 1742 status = trng_SetStatisticalCheckLimit(base, kTRNG_StatisticalCheckRunBit3, &userConfig->runBit3Limit); 1743 } 1744 1745 if (kStatus_Success == status) 1746 { 1747 status = trng_SetStatisticalCheckLimit(base, kTRNG_StatisticalCheckRunBit4, &userConfig->runBit4Limit); 1748 } 1749 1750 if (kStatus_Success == status) 1751 { 1752 status = trng_SetStatisticalCheckLimit(base, kTRNG_StatisticalCheckRunBit5, &userConfig->runBit5Limit); 1753 } 1754 1755 if (kStatus_Success == status) 1756 { 1757 status = trng_SetStatisticalCheckLimit(base, kTRNG_StatisticalCheckRunBit6Plus, &userConfig->runBit6PlusLimit); 1758 } 1759 1760 if (kStatus_Success == status) 1761 { 1762 status = trng_SetStatisticalCheckLimit(base, kTRNG_StatisticalCheckPoker, &userConfig->pokerLimit); 1763 } 1764 1765 if (kStatus_Success == status) 1766 { 1767 status = 1768 trng_SetStatisticalCheckLimit(base, kTRNG_StatisticalCheckFrequencyCount, &userConfig->frequencyCountLimit); 1769 } 1770 1771 if (kStatus_Success == status) 1772 { 1773 /* Set clock mode used to operate TRNG */ 1774 TRNG_WR_MCTL_FOR_SCLK(base, userConfig->clockMode); 1775 /* Set ring oscillator divider used by TRNG */ 1776 TRNG_WR_MCTL_OSC_DIV(base, userConfig->ringOscDiv); 1777 #if !(defined(FSL_FEATURE_TRNG_HAS_NO_TRNG_MCTL_SAMP_MODE) && FSL_FEATURE_TRNG_HAS_NO_TRNG_MCTL_SAMP_MODE) 1778 /* Set sample mode of the TRNG ring oscillator. */ 1779 TRNG_WR_MCTL_SAMP_MODE(base, userConfig->sampleMode); 1780 #endif /* FSL_FEATURE_TRNG_HAS_NO_TRNG_MCTL_SAMP_MODE */ 1781 /* Set length of each Entropy sample taken */ 1782 TRNG_WR_SDCTL_ENT_DLY(base, userConfig->entropyDelay); 1783 /* Set number of entropy samples that will be taken during Entropy generation */ 1784 TRNG_WR_SDCTL_SAMP_SIZE(base, userConfig->sampleSize); 1785 #if !(defined(FSL_FEATURE_TRNG_HAS_NO_TRNG_SBLIM) && (FSL_FEATURE_TRNG_HAS_NO_TRNG_SBLIM > 0)) 1786 /* Set Sparse Bit Limit */ 1787 TRNG_WR_SBLIM_SB_LIM(base, userConfig->sparseBitLimit); 1788 #endif /* FSL_FEATURE_TRNG_HAS_NO_TRNG_SBLIM */ 1789 TRNG_WR_SCMISC_LRUN_MAX(base, userConfig->longRunMaxLimit); 1790 } 1791 1792 return status; 1793 } 1794 1795 /*! 1796 * @brief Gets a entry data from the TRNG. 1797 * 1798 * This function gets an entropy data from TRNG. 1799 * Entropy data is spread over TRNG_ENT_COUNT registers. 1800 * Read register number is defined by index parameter. 1801 */ 1802 static uint32_t trng_ReadEntropy(TRNG_Type *base, uint32_t index) 1803 { 1804 uint32_t data; 1805 1806 index = index % TRNG_ENT_COUNT; /* This way we can use incremental index without limit control from application.*/ 1807 1808 data = TRNG_RD_ENT(base, index); 1809 1810 if (index == (TRNG_ENT_COUNT - 1u)) 1811 { 1812 /* Dummy read. Defect workaround. 1813 * TRNG could not clear ENT_VAL flag automatically, application 1814 * had to do a dummy reading operation for anyone TRNG register 1815 * to clear it firstly, then to read the RTENT0 to RTENT15 again */ 1816 index = TRNG_RD_ENT(base, 0); 1817 } 1818 1819 return data; 1820 } 1821 1822 /*! 1823 * brief Initializes the TRNG. 1824 * 1825 * This function initializes the TRNG. 1826 * When called, the TRNG entropy generation starts immediately. 1827 * 1828 * param base TRNG base address 1829 * param userConfig Pointer to the initialization configuration structure. 1830 * return If successful, returns the kStatus_TRNG_Success. Otherwise, it returns an error. 1831 */ 1832 status_t TRNG_Init(TRNG_Type *base, const trng_config_t *userConfig) 1833 { 1834 status_t result; 1835 1836 /* Check input parameters.*/ 1837 if ((base != NULL) && (userConfig != NULL)) 1838 { 1839 #if defined(FSL_FEATURE_TRNG_HAS_RSTCTL) && (FSL_FEATURE_TRNG_HAS_RSTCTL > 0) 1840 /* Reset TRNG peripheral */ 1841 SYSCTL2->TRNG_PIN_CTRL |= SYSCTL2_TRNG_PIN_CTRL_ENABLE_MASK; 1842 RESET_PeripheralReset(trng_reset); 1843 #endif /* FSL_FEATURE_TRNG_HAS_RSTCTL */ 1844 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) 1845 /* Enable the clock gate. */ 1846 CLOCK_EnableClock(s_trngClock[trng_GetInstance(base)]); 1847 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */ 1848 1849 /* Clear pending errors, set program mode and reset the registers to default values.*/ 1850 /* MCTL[PRGM] = 1 (kTRNG_WorkModeProgram); MCTL[ERR] = 1; MCTL[RST_DEF] = 1 */ 1851 TRNG_RMW_MCTL(base, (TRNG_MCTL_PRGM_MASK | TRNG_MCTL_ERR_MASK | TRNG_MCTL_RST_DEF_MASK), 1852 TRNG_MCTL_PRGM(kTRNG_WorkModeProgram) | TRNG_MCTL_ERR(1) | TRNG_MCTL_RST_DEF(1)); 1853 1854 /* Set configuration.*/ 1855 if ((result = trng_ApplyUserConfig(base, userConfig)) == kStatus_Success) 1856 { 1857 /* Start entropy generation.*/ 1858 /* Set to Run mode.*/ 1859 TRNG_WR_MCTL_PRGM(base, kTRNG_WorkModeRun); 1860 #if !(defined(FSL_FEATURE_TRNG_HAS_NO_TRNG_ACC) && (FSL_FEATURE_TRNG_HAS_NO_TRNG_ACC > 0)) 1861 /* Enable TRNG Access Mode. To generate an Entropy 1862 * value that can be read via the true0-true15 registers.*/ 1863 TRNG_WR_MCTL_TRNG_ACC(base, 1); 1864 #endif /* !FSL_FEATURE_TRNG_HAS_NO_TRNG_ACC */ 1865 1866 (void)trng_ReadEntropy(base, (TRNG_ENT_COUNT - 1u)); 1867 1868 if (true == userConfig->lock) /* Disable programmability of TRNG registers. */ 1869 { 1870 TRNG_WR_SEC_CFG_NO_PRGM(base, 1); 1871 } 1872 1873 result = kStatus_Success; 1874 } 1875 } 1876 else 1877 { 1878 result = kStatus_InvalidArgument; 1879 } 1880 1881 return result; 1882 } 1883 1884 /*! 1885 * brief Shuts down the TRNG. 1886 * 1887 * This function shuts down the TRNG. 1888 * 1889 * param base TRNG base address. 1890 */ 1891 void TRNG_Deinit(TRNG_Type *base) 1892 { 1893 /* Check input parameters.*/ 1894 if (NULL != base) 1895 { 1896 /* Move to program mode. Stop entropy generation.*/ 1897 TRNG_WR_MCTL_PRGM(base, kTRNG_WorkModeProgram); 1898 1899 /* Check before clock stop. 1900 TRNG turns on the TRNG free-running ring oscillator whenever new entropy 1901 is being generated and turns off the ring oscillator when entropy generation 1902 is complete. If the TRNG clock is stopped while the TRNG ring oscillator 1903 is running, the oscillator continues running though the RNG clock. 1904 is stopped. */ 1905 while (TRNG_RD_MCTL_TSTOP_OK(base) == 0u) 1906 { 1907 } 1908 1909 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) 1910 /* Disable Clock*/ 1911 CLOCK_DisableClock(s_trngClock[trng_GetInstance(base)]); 1912 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */ 1913 } 1914 } 1915 1916 /*! 1917 * brief Gets random data. 1918 * 1919 * This function gets random data from the TRNG. 1920 * 1921 * param base TRNG base address. 1922 * param data Pointer address used to store random data. 1923 * param dataSize Size of the buffer pointed by the data parameter. 1924 * return random data 1925 */ 1926 status_t TRNG_GetRandomData(TRNG_Type *base, void *data, size_t dataSize) 1927 { 1928 status_t result = kStatus_Success; 1929 uint32_t random_32; 1930 uint8_t *random_p; 1931 uint32_t random_size; 1932 uint8_t *data_p = (uint8_t *)data; 1933 uint32_t i; 1934 uint32_t tmpValidFlag; 1935 uint32_t tmpErrorFlag; 1936 1937 int index = 0; 1938 1939 /* Check input parameters.*/ 1940 if ((NULL != base) && (NULL != data) && (0U != dataSize)) 1941 { 1942 /* After a deepsleep exit some errors bits are set in MCTL and must be cleared before processing further. 1943 Also, trigger new 512 bits entropy generation to be sure we will have fresh bits.*/ 1944 if (0U != TRNG_RD_MCTL_ERR(base)) 1945 { 1946 /* clear errors bits */ 1947 TRNG_WR_MCTL_ERR(base, 1); 1948 /* restart new entropy generation */ 1949 (void)trng_ReadEntropy(base, (TRNG_ENT_COUNT - 1u)); 1950 } 1951 1952 do 1953 { 1954 /* Wait for Valid or Error flag*/ 1955 tmpValidFlag = TRNG_RD_MCTL_ENT_VAL(base); 1956 tmpErrorFlag = TRNG_RD_MCTL_ERR(base); 1957 while ((tmpValidFlag == 0u) && (tmpErrorFlag == 0u)) 1958 { 1959 tmpValidFlag = TRNG_RD_MCTL_ENT_VAL(base); 1960 tmpErrorFlag = TRNG_RD_MCTL_ERR(base); 1961 } 1962 1963 /* Check HW error.*/ 1964 if (0U != TRNG_RD_MCTL_ERR(base)) 1965 { 1966 result = kStatus_Fail; /* TRNG module error occurred */ 1967 /* Clear error.*/ 1968 TRNG_WR_MCTL_ERR(base, 1); 1969 break; /* No sense stay here.*/ 1970 } 1971 1972 /* Read Entropy.*/ 1973 random_32 = trng_ReadEntropy(base, (uint32_t)index++); 1974 1975 random_p = (uint8_t *)&random_32; 1976 1977 if (dataSize < sizeof(random_32)) 1978 { 1979 random_size = dataSize; 1980 } 1981 else 1982 { 1983 random_size = sizeof(random_32); 1984 } 1985 1986 for (i = 0U; i < random_size; i++) 1987 { 1988 *data_p++ = *random_p++; 1989 } 1990 1991 dataSize -= random_size; 1992 } while (dataSize > 0u); 1993 1994 /* Start a new entropy generation. 1995 It is done by reading of the last entropy register.*/ 1996 if (((unsigned)index % TRNG_ENT_COUNT) != 0U) 1997 { 1998 (void)trng_ReadEntropy(base, (TRNG_ENT_COUNT - 1u)); 1999 } 2000 } 2001 else 2002 { 2003 result = kStatus_InvalidArgument; 2004 } 2005 2006 return result; 2007 } 2008 2009 #endif /* FSL_FEATURE_SOC_TRNG_COUNT */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |