1 /**************************************************************************//**
2  * @file     trng.h
3  * @version  V3.00
4  * @brief    TRNG driver header file
5  *
6  * @copyright SPDX-License-Identifier: Apache-2.0
7  * @copyright Copyright (C) 2021 Nuvoton Technology Corp. All rights reserved.
8  ******************************************************************************/
9 #ifndef __TRNG_H__
10 #define __TRNG_H__
11 
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16 
17 /** @addtogroup Standard_Driver Standard Driver
18   @{
19 */
20 
21 /** @addtogroup TRNG_Driver TRNG Driver
22   @{
23 */
24 
25 
26 /** @addtogroup M460_TRNG_EXPORTED_MACROS TRNG Exported Macros
27   @{
28 */
29 
30 /*----------------------------------------------------------------------------------------------*/
31 /*  Macros                                                                                      */
32 /*----------------------------------------------------------------------------------------------*/
33 
34 /**
35   * @brief  Let TRNG engine know the currrent PCLK frequency. The CLKPSC is the peripheral
36   *         clock frequency range for the selected value , the CLKPSC setting must be higher
37   *         than or equal to the actual peripheral clock frequency (for correct random generation).
38   * @param  clkpsc   0: PCLK is 80~100 MHz
39   *                  1: PCLK is 60~80 MHz
40   *                  2: PCLK is 50~60 MHz
41   *                  3: PCLK is 40~50 MHz
42   *                  4: PCLK is 30~40 MHz
43   *                  5: PCLK is 25~30 MHz
44   *                  6: PCLK is 20~25 MHz
45   *                  7: PCLK is 15~20 MHz
46   *                  8: PCLK is 12~15 MHz
47   *                  9: PCLK is 9~12  MHz
48   *
49   * @return None
50   * \hideinitializer
51   */
52 #define TRNG_SET_CLKP(clkpsc) do { TRNG->CTL = (TRNG->CTL&~TRNG_CTL_CLKP_Msk)|((clkpsc & 0xf)<<TRNG_CTL_CLKP_Pos); } while(0);
53 
54 
55 /*@}*/ /* end of group M460_TRNG_EXPORTED_MACROS */
56 
57 
58 /** @addtogroup TRNG_EXPORTED_FUNCTIONS TRNG Exported Functions
59   @{
60 */
61 
62 
63 /*---------------------------------------------------------------------------------------------------------*/
64 /*  Functions                                                                                      */
65 /*---------------------------------------------------------------------------------------------------------*/
66 
67 int32_t TRNG_Open(void);
68 int32_t TRNG_GenWord(uint32_t *u32RndNum);
69 int32_t TRNG_GenBignum(uint8_t u8BigNum[], int32_t i32Len);
70 int32_t TRNG_GenBignumHex(char cBigNumHex[], int32_t i32Len);
71 
72 
73 /*@}*/ /* end of group TRNG_EXPORTED_FUNCTIONS */
74 
75 /*@}*/ /* end of group TRNG_Driver */
76 
77 /*@}*/ /* end of group Standard_Driver */
78 
79 #ifdef __cplusplus
80 }
81 #endif
82 
83 #endif  /* __TRNG_H__ */
84