1 /**
2  * @file    trng.h
3  * @brief   Random number generator driver.
4  */
5 
6 /******************************************************************************
7  *
8  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
9  * Analog Devices, Inc.),
10  * Copyright (C) 2023-2024 Analog Devices, Inc.
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  *     http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  ******************************************************************************/
25 
26 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78002_TRNG_H_
27 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78002_TRNG_H_
28 
29 /***** Includes *****/
30 #include "trng_regs.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /**
37  * @defgroup trng TRNG
38  * @ingroup periphlibs
39  * @{
40  */
41 
42 /* IN ADDITION TO THIS HEADER, FCL WILL BE SUPPORTED AND PROVIDED IN BINARY FORM */
43 
44 /***** Function Prototypes *****/
45 typedef void (*mxc_trng_complete_t)(void *req, int result);
46 
47 /* ************************************************************************* */
48 /* Global Control/Configuration functions                                    */
49 /* ************************************************************************* */
50 
51 /**
52  * @brief   Enable portions of the TRNG
53  *
54  * @return  Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
55  */
56 int MXC_TRNG_Init(void);
57 
58 /**
59  * @brief   Enable TRNG Interrupts
60  *
61  */
62 void MXC_TRNG_EnableInt(void);
63 
64 /**
65  * @brief   Disable TRNG Interrupts
66  *
67  */
68 void MXC_TRNG_DisableInt(void);
69 
70 /**
71  * @brief   Disable and reset portions of the TRNG
72  *
73  * @return  Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
74  */
75 int MXC_TRNG_Shutdown(void);
76 
77 /**
78  * @brief   This function should be called from the TRNG ISR Handler
79  *          when using Async functions
80  */
81 void MXC_TRNG_Handler(void);
82 
83 /* ************************************************************************* */
84 /* True Random Number Generator (TRNG) functions                             */
85 /* ************************************************************************* */
86 
87 /**
88  * @brief   Get a random number
89  *
90  * @return  A random 32-bit number
91  */
92 int MXC_TRNG_RandomInt(void);
93 
94 /**
95  * @brief   Get a random number of length len
96  *
97  * @param   data    Pointer to a location to store the number
98  * @param   len     Length of random number in bytes
99  *
100  * @return  Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
101  */
102 int MXC_TRNG_Random(uint8_t *data, uint32_t len);
103 
104 /**
105  * @brief   Get a random number of length len, do not block while generating data
106  * @note    The user must call MXC_TRNG_Handler() in the ISR
107  *
108  * @param   data      Pointer to a location to store the number
109  * @param   len       Length of random number in bytes
110  * @param   callback  Function that will be called when all data has been generated
111  *
112  */
113 void MXC_TRNG_RandomAsync(uint8_t *data, uint32_t len, mxc_trng_complete_t callback);
114 
115 /**
116  * @brief   Generate an AES key and transfer to the AES block
117  */
118 void MXC_TRNG_GenerateKey(void);
119 
120 /**
121  * @brief   Perform health test of the TRNG entropy source
122  *
123  * @return  E_NOT_SUPPORTED (-17)
124  */
125 int MXC_TRNG_HealthTest(void);
126 
127 #ifdef __cplusplus
128 }
129 #endif
130 /**@} end of group trng */
131 
132 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78002_TRNG_H_
133