1 /******************************************************************************
2  *
3  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
4  * Analog Devices, Inc.),
5  * Copyright (C) 2023-2024 Analog Devices, Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************************/
20 
21 /* **** Includes **** */
22 #include <stdint.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include "mxc_errors.h"
26 #include "mxc_sys.h"
27 #include "trng.h"
28 #include "trng_reva.h"
29 
30 /* **** MACROS **** */
31 #define WORD 3
32 #define BYTE 4
33 
34 /* **** Functions **** */
35 
36 // *********************************************************************
MXC_TRNG_Init(void)37 int MXC_TRNG_Init(void)
38 {
39 #ifndef MSDK_NO_GPIO_CLK_INIT
40     MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_TRNG);
41 #endif
42 
43     return MXC_TRNG_RevA_Init();
44 }
45 
46 // *********************************************************************
MXC_TRNG_EnableInt(void)47 void MXC_TRNG_EnableInt(void)
48 {
49     MXC_TRNG_RevA_EnableInt((mxc_trng_reva_regs_t *)MXC_TRNG);
50 }
51 
52 // *********************************************************************
MXC_TRNG_DisableInt(void)53 void MXC_TRNG_DisableInt(void)
54 {
55     MXC_TRNG_RevA_DisableInt((mxc_trng_reva_regs_t *)MXC_TRNG);
56 }
57 
58 // *********************************************************************
MXC_TRNG_Shutdown(void)59 int MXC_TRNG_Shutdown(void)
60 {
61     MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_TRNG);
62 
63     return MXC_TRNG_RevA_Shutdown();
64 }
65 
66 // *********************************************************************
MXC_TRNG_Handler(void)67 void MXC_TRNG_Handler(void)
68 {
69     MXC_TRNG_RevA_Handler((mxc_trng_reva_regs_t *)MXC_TRNG);
70 }
71 
72 // *********************************************************************
MXC_TRNG_RandomInt(void)73 int MXC_TRNG_RandomInt(void)
74 {
75     return MXC_TRNG_RevA_RandomInt((mxc_trng_reva_regs_t *)MXC_TRNG);
76 }
77 
78 // *********************************************************************
MXC_TRNG_Random(uint8_t * data,uint32_t len)79 int MXC_TRNG_Random(uint8_t *data, uint32_t len)
80 {
81     return MXC_TRNG_RevA_Random(data, len);
82 }
83 
84 // *********************************************************************
MXC_TRNG_RandomAsync(uint8_t * data,uint32_t len,mxc_trng_complete_t callback)85 void MXC_TRNG_RandomAsync(uint8_t *data, uint32_t len, mxc_trng_complete_t callback)
86 {
87     MXC_TRNG_RevA_RandomAsync((mxc_trng_reva_regs_t *)MXC_TRNG, data, len, callback);
88 }
89 
90 // *********************************************************************
MXC_TRNG_GenerateKey(void)91 void MXC_TRNG_GenerateKey(void)
92 {
93     MXC_TRNG_RevA_GenerateKey((mxc_trng_reva_regs_t *)MXC_TRNG);
94 }
95