1 /**
2 * @file
3 * @brief Trust Protection Unit 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 #include "mxc_device.h"
27 #include "mxc_errors.h"
28 #include "mxc_assert.h"
29 #include "mxc_sys.h"
30 #include "trng_revb.h"
31 #include "trng.h"
32
33 /* ************************************************************************* */
34 /* Global Control/Configuration functions */
35 /* ************************************************************************* */
36
37 /********************************************************/
38
MXC_TRNG_Init(void)39 int MXC_TRNG_Init(void)
40 {
41 #ifndef MSDK_NO_GPIO_CLK_INIT
42 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_TRNG);
43 #endif
44
45 MXC_TRNG_RevB_Init();
46
47 return E_NO_ERROR;
48 }
49
MXC_TRNG_EnableInt(void)50 void MXC_TRNG_EnableInt(void)
51 {
52 MXC_TRNG_RevB_EnableInt((mxc_trng_revb_regs_t *)MXC_TRNG);
53 }
54
MXC_TRNG_DisableInt(void)55 void MXC_TRNG_DisableInt(void)
56 {
57 MXC_TRNG_RevB_DisableInt((mxc_trng_revb_regs_t *)MXC_TRNG);
58 }
59
MXC_TRNG_Shutdown(void)60 int MXC_TRNG_Shutdown(void)
61 {
62 int error = MXC_TRNG_RevB_Shutdown();
63
64 MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_TRNG);
65
66 return error;
67 }
68
MXC_TRNG_Handler(void)69 void MXC_TRNG_Handler(void)
70 {
71 MXC_TRNG_RevB_Handler((mxc_trng_revb_regs_t *)MXC_TRNG);
72 }
73
74 /* ************************************************************************* */
75 /* True Random Number Generator (TRNG) functions */
76 /* ************************************************************************* */
77
MXC_TRNG_RandomInt(void)78 int MXC_TRNG_RandomInt(void)
79 {
80 return MXC_TRNG_RevB_RandomInt((mxc_trng_revb_regs_t *)MXC_TRNG);
81 }
82
MXC_TRNG_Random(uint8_t * data,uint32_t len)83 int MXC_TRNG_Random(uint8_t *data, uint32_t len)
84 {
85 return MXC_TRNG_RevB_Random(data, len);
86 }
87
MXC_TRNG_RandomAsync(uint8_t * data,uint32_t len,mxc_trng_complete_t callback)88 void MXC_TRNG_RandomAsync(uint8_t *data, uint32_t len, mxc_trng_complete_t callback)
89 {
90 MXC_TRNG_RevB_RandomAsync((mxc_trng_revb_regs_t *)MXC_TRNG, data, len, callback);
91 }
92
MXC_TRNG_HealthTest(void)93 int MXC_TRNG_HealthTest(void)
94 {
95 if ((MXC_SYS_GetRevision() & 0xF0) == 0xA0) { // ME17 Rev. A does not support health tests.
96 return E_NOT_SUPPORTED;
97 }
98
99 return MXC_TRNG_RevB_HealthTest((mxc_trng_revb_regs_t *)MXC_TRNG);
100 }
101