1 /*
2  * Copyright 2017, 2019, 2021 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef _FSL_RNG_DRIVER_H_
9 #define _FSL_RNG_DRIVER_H_
10 
11 #include "fsl_common.h"
12 
13 /*!
14  * @addtogroup rng
15  * @{
16  */
17 
18 /*******************************************************************************
19  * Definitions
20  *******************************************************************************/
21 
22 /*! @name Driver version */
23 /*@{*/
24 /*! @brief RNG driver version. Version 2.0.3.
25  *
26  * Current version: 2.0.3
27  *
28  * Change log:
29  * - Version 2.0.0
30  *   - Initial version
31  *
32  * - Version 2.0.1
33  *   - Fix MISRA C-2012 issue.
34  *
35  * - Version 2.0.2
36  *   - Add RESET_PeripheralReset function inside RNG_Init and RNG_Deinit functions.
37  *
38  * - Version 2.0.3
39  *   - Modified RNG_Init and RNG_GetRandomData functions, added rng_accumulateEntropy and rng_readEntropy functions.
40  *   - These changes are reflecting recommended usage of RNG according to device UM.
41  */
42 #define FSL_RNG_DRIVER_VERSION (MAKE_VERSION(2, 0, 3))
43 /*@}*/
44 
45 /*******************************************************************************
46  * API
47  *******************************************************************************/
48 
49 #if defined(__cplusplus)
50 extern "C" {
51 #endif
52 
53 /*!
54  * @brief Initializes the RNG.
55  *
56  * This function initializes the RNG.
57  * When called, the RNG module and ring oscillator is enabled.
58  *
59  * @param base  RNG base address
60  * @return If successful, returns the kStatus_RNG_Success. Otherwise, it returns an error.
61  */
62 void RNG_Init(RNG_Type *base);
63 
64 /*!
65  * @brief Shuts down the RNG.
66  *
67  * This function shuts down the RNG.
68  *
69  * @param base  RNG base address.
70  */
71 void RNG_Deinit(RNG_Type *base);
72 
73 /*!
74  * @brief Gets random data.
75  *
76  * This function gets random data from the RNG.
77  *
78  * @param base  RNG base address.
79  * @param data  Pointer address used to store random data.
80  * @param dataSize  Size of the buffer pointed by the data parameter.
81  * @return random data
82  */
83 status_t RNG_GetRandomData(RNG_Type *base, void *data, size_t dataSize);
84 
85 /*!
86  * @brief Returns random 32-bit number.
87  *
88  * This function gets random number from the RNG.
89  *
90  * @param base  RNG base address.
91  * @return random number
92  */
RNG_GetRandomWord(RNG_Type * base)93 static inline uint32_t RNG_GetRandomWord(RNG_Type *base)
94 {
95     return base->RANDOM_NUMBER;
96 }
97 
98 #if defined(__cplusplus)
99 }
100 #endif
101 
102 /*! @}*/
103 
104 #endif /*_FSL_RNG_H_*/
105