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 #include "mxc_device.h"
22 #include "mxc_errors.h"
23 #include "mxc_assert.h"
24 #include "mxc_sys.h"
25 #include "trng_revb.h"
26 #include "trng.h"
27
28 /* ************************************************************************* */
29 /* Global Control/Configuration functions */
30 /* ************************************************************************* */
31
32 /********************************************************/
33
MXC_TRNG_Init(void)34 int MXC_TRNG_Init(void)
35 {
36 #ifndef MSDK_NO_GPIO_CLK_INIT
37 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_TRNG);
38 #endif
39
40 MXC_TRNG_RevB_Init();
41
42 return E_NO_ERROR;
43 }
44
MXC_TRNG_EnableInt(void)45 void MXC_TRNG_EnableInt(void)
46 {
47 MXC_TRNG_RevB_EnableInt();
48 }
49
MXC_TRNG_DisableInt(void)50 void MXC_TRNG_DisableInt(void)
51 {
52 MXC_TRNG_RevB_DisableInt();
53 }
54
MXC_TRNG_Shutdown(void)55 int MXC_TRNG_Shutdown(void)
56 {
57 int error = MXC_TRNG_RevB_Shutdown();
58
59 MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_TRNG);
60
61 return error;
62 }
63
MXC_TRNG_Handler(void)64 void MXC_TRNG_Handler(void)
65 {
66 MXC_TRNG_RevB_Handler();
67 }
68
69 /* ************************************************************************* */
70 /* True Random Number Generator (TRNG) functions */
71 /* ************************************************************************* */
72
MXC_TRNG_RandomInt(void)73 int MXC_TRNG_RandomInt(void)
74 {
75 return MXC_TRNG_RevB_RandomInt();
76 }
77
MXC_TRNG_Random(uint8_t * data,uint32_t len)78 int MXC_TRNG_Random(uint8_t *data, uint32_t len)
79 {
80 return MXC_TRNG_RevB_Random(data, len);
81 }
82
MXC_TRNG_RandomAsync(uint8_t * data,uint32_t len,mxc_trng_complete_t callback)83 void MXC_TRNG_RandomAsync(uint8_t *data, uint32_t len, mxc_trng_complete_t callback)
84 {
85 MXC_TRNG_RevB_RandomAsync(data, len, callback);
86 }
87
MXC_TRNG_HealthTest(void)88 int MXC_TRNG_HealthTest(void)
89 {
90 return E_NOT_SUPPORTED;
91 }
92