1 /******************************************************************************
2 *
3 * Copyright (C) 2023-2025 Analog Devices, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 #ifndef LIBRARIES_ZEPHYR_MAX_INCLUDE_WRAP_MAX32_SYS_H_
20 #define LIBRARIES_ZEPHYR_MAX_INCLUDE_WRAP_MAX32_SYS_H_
21
22 /***** Includes *****/
23 #include <mxc_sys.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 /*
30 * Apply preinit configuration for the target
31 */
32 void max32xx_system_init(void);
33
34 /*
35 * MAX32665, MAX32666 related mapping
36 */
37 #if defined(CONFIG_SOC_MAX32665) || defined(CONFIG_SOC_MAX32666) || \
38 defined(CONFIG_SOC_MAX32650)
39
40 #define ADI_MAX32_CLK_IPO MXC_SYS_CLOCK_HIRC96
41 #define ADI_MAX32_CLK_IBRO MXC_SYS_CLOCK_HIRC8
42 #if !defined(CONFIG_SOC_MAX32650)
43 #define ADI_MAX32_CLK_ERFO MXC_SYS_CLOCK_XTAL32M
44 #define ADI_MAX32_CLK_ISO MXC_SYS_CLOCK_HIRC
45 #define ADI_MAX32_CLK_INRO MXC_SYS_CLOCK_LIRC8K
46 #define ADI_MAX32_CLK_ERTCO MXC_SYS_CLOCK_XTAL32K
47 #else
48 #define ADI_MAX32_CLK_ISO MXC_SYS_CLOCK_HFXIN
49 #define ADI_MAX32_CLK_INRO MXC_SYS_CLOCK_NANORING
50 #define ADI_MAX32_CLK_ERTCO MXC_SYS_CLOCK_X32K
51 #endif
52
53 #define z_sysclk_prescaler(v) MXC_SYS_SYSTEM_DIV_##v
54 #define sysclk_prescaler(v) z_sysclk_prescaler(v)
55
Wrap_MXC_SYS_SetClockDiv(int div)56 static inline void Wrap_MXC_SYS_SetClockDiv(int div)
57 {
58 MXC_SYS_Clock_Div((mxc_sys_system_div_t)div);
59 }
60
Wrap_MXC_SYS_GetUSN(uint8_t * usn)61 static inline int Wrap_MXC_SYS_GetUSN(uint8_t *usn)
62 {
63 #if defined(CONFIG_SOC_MAX32650)
64 return MXC_SYS_GetUSN(usn, MXC_SYS_USN_LEN);
65 #else
66 uint8_t checksum[MXC_SYS_USN_CHECKSUM_LEN];
67 return MXC_SYS_GetUSN(usn, checksum);
68 #endif
69 }
70
71 /*
72 * MAX32690, MAX32655 related mapping
73 */
74 #elif defined(CONFIG_SOC_MAX32690) || defined(CONFIG_SOC_MAX32655) || \
75 defined(CONFIG_SOC_MAX32670) || defined(CONFIG_SOC_MAX32672) || \
76 defined(CONFIG_SOC_MAX32662) || defined(CONFIG_SOC_MAX32675) || \
77 defined(CONFIG_SOC_MAX32680) || defined(CONFIG_SOC_MAX32657) || \
78 defined(CONFIG_SOC_MAX78002) || defined(CONFIG_SOC_MAX78000) || defined(CONFIG_SOC_MAX32660)
79
80 #if !defined(CONFIG_SOC_MAX32660)
81 #define ADI_MAX32_CLK_IPO MXC_SYS_CLOCK_IPO
82 #if defined(CONFIG_SOC_MAX78002)
83 #define ADI_MAX32_CLK_IPLL MXC_SYS_CLOCK_IPLL
84 #define ADI_MAX32_CLK_EBO MXC_SYS_CLOCK_EBO
85 #elif !defined(CONFIG_SOC_MAX78000)
86 #define ADI_MAX32_CLK_ERFO MXC_SYS_CLOCK_ERFO
87 #endif
88 #define ADI_MAX32_CLK_IBRO MXC_SYS_CLOCK_IBRO
89 #define ADI_MAX32_CLK_INRO MXC_SYS_CLOCK_INRO
90 #define ADI_MAX32_CLK_ERTCO MXC_SYS_CLOCK_ERTCO
91 #define ADI_MAX32_CLK_EXTCLK MXC_SYS_CLOCK_EXTCLK
92 #if !(defined(CONFIG_SOC_MAX32670) || (CONFIG_SOC_MAX32672) || (CONFIG_SOC_MAX32662) || \
93 (CONFIG_SOC_MAX32675))
94 #define ADI_MAX32_CLK_ISO MXC_SYS_CLOCK_ISO
95 #endif
96 #else
97 #define ADI_MAX32_CLK_IPO MXC_SYS_CLOCK_HIRC
98 #define ADI_MAX32_CLK_INRO MXC_SYS_CLOCK_NANORING
99 #define ADI_MAX32_CLK_ERTCO MXC_SYS_CLOCK_HFXIN
100 #endif
101
102 #define z_sysclk_prescaler(v) MXC_SYS_CLOCK_DIV_##v
103 #define sysclk_prescaler(v) z_sysclk_prescaler(v)
104
Wrap_MXC_SYS_SetClockDiv(int div)105 static inline void Wrap_MXC_SYS_SetClockDiv(int div)
106 {
107 MXC_SYS_SetClockDiv((mxc_sys_system_clock_div_t)div);
108 }
109
Wrap_MXC_SYS_GetUSN(uint8_t * usn)110 static inline int Wrap_MXC_SYS_GetUSN(uint8_t *usn)
111 {
112 #if defined(CONFIG_SOC_MAX32660)
113 return MXC_SYS_GetUSN(usn, MXC_SYS_USN_LEN, 0);
114 #else
115 uint8_t checksum[MXC_SYS_USN_CHECKSUM_LEN];
116
117 return MXC_SYS_GetUSN(usn, checksum);
118 #endif
119 }
120
121 #endif // part number
122
123 #ifdef __cplusplus
124 }
125 #endif
126
127 #endif // LIBRARIES_ZEPHYR_MAX_INCLUDE_WRAP_MAX32_SYS_H_
128