1 /******************************************************************************
2 * @file  rsi_rom_rng.h
3 *******************************************************************************
4 * # License
5 * <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b>
6 *******************************************************************************
7 *
8 * SPDX-License-Identifier: Zlib
9 *
10 * The licensor of this software is Silicon Laboratories Inc.
11 *
12 * This software is provided 'as-is', without any express or implied
13 * warranty. In no event will the authors be held liable for any damages
14 * arising from the use of this software.
15 *
16 * Permission is granted to anyone to use this software for any purpose,
17 * including commercial applications, and to alter it and redistribute it
18 * freely, subject to the following restrictions:
19 *
20 * 1. The origin of this software must not be misrepresented; you must not
21 *    claim that you wrote the original software. If you use this software
22 *    in a product, an acknowledgment in the product documentation would be
23 *    appreciated but is not required.
24 * 2. Altered source versions must be plainly marked as such, and must not be
25 *    misrepresented as being the original software.
26 * 3. This notice may not be removed or altered from any source distribution.
27 *
28 ******************************************************************************/
29 
30 #ifndef __RSI_ROM_RNG_H__
31 #define __RSI_ROM_RNG_H__
32 
33 /**
34  * \ingroup   RSI_SPECIFIC_DRIVERS
35  * \defgroup RNG_DRIVERS
36  *  @{
37  *
38  */
39 #include "rsi_ccp_user_config.h"
40 #include "rsi_packing.h"
41 #if defined(A11_ROM)
42 #include "rsi_rom_table_si91x.h"
43 #else
44 #include "rsi_rom_table_RS1xxxx.h"
45 #endif
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 /**
52  * @fn           STATIC INLINE uint32_t  RSI_RNG_Start(HWRNG_Type *pRNG, uint8_t rngMode)
53  * @brief        This API is used to start the Random Number Generation
54  * @param[in]    pRNG		 : Random Number Generator handler
55  * @param[in]    rngMode : mode of the Random Number Generator
56  *               			- \ref RNG_TRUE_RANDOM   - For True RNG
57  *               			- \ref RNG_PSEUDO_RANDOM - For Psudo RNG
58  * @return       returns 0 \ref RSI_OK on success ,non zero on failure
59  *
60  */
RSI_RNG_Start(HWRNG_Type * pRNG,uint8_t rngMode)61 STATIC INLINE uint32_t RSI_RNG_Start(HWRNG_Type *pRNG, uint8_t rngMode)
62 {
63 #if defined(RNG_ROMDRIVER_PRESENT)
64   return ROMAPI_RNG_API->rng_start(pRNG, rngMode);
65 #else
66   return rng_start(pRNG, rngMode);
67 #endif
68 }
69 
70 /**
71  * @fn           STATIC INLINE void  RSI_RNG_Stop(HWRNG_Type *pRNG)
72  * @brief        This API is used to stop the Random Number Generation
73  * @param[in]    pRNG  : Random Number Generator handler
74  * @return       none
75  */
RSI_RNG_Stop(HWRNG_Type * pRNG)76 STATIC INLINE void RSI_RNG_Stop(HWRNG_Type *pRNG)
77 {
78 #if defined(RNG_ROMDRIVER_PRESENT)
79   ROMAPI_RNG_API->rng_stop(pRNG);
80 #else
81   rng_stop(pRNG);
82 #endif
83 }
84 
85 /**
86  * @fn           STATIC INLINE void  RSI_RNG_GetBytes(HWRNG_Type *pRNG, uint32_t *randomBytes, uint32_t numberOfBytes)
87  * @brief        This API is used to get the random number bytes
88  * @param[in]    pRNG	         : Random Number Generator handler
89  * @param[in]    numberOfBytes : Number of bytes to generate
90  * @param[out]   randomBytes	 : variable or array to store generated random bytes
91  * @return       none
92  */
RSI_RNG_GetBytes(HWRNG_Type * pRNG,uint32_t * randomBytes,uint32_t numberOfBytes)93 STATIC INLINE void RSI_RNG_GetBytes(HWRNG_Type *pRNG, uint32_t *randomBytes, uint32_t numberOfBytes)
94 {
95 #if defined(RNG_ROMDRIVER_PRESENT)
96   ROMAPI_RNG_API->rng_get_bytes(pRNG, randomBytes, numberOfBytes);
97 #else
98   rng_get_bytes(pRNG, randomBytes, numberOfBytes);
99 #endif
100 }
101 
102 #ifdef __cplusplus
103 }
104 #endif
105 
106 #endif
107 
108 /* @} end of RSI_RNG_DRIVERS */
109