1 /*
2  * Copyright 2017 - 2021 , 2023 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef _FSL_CLOCK_H_
9 #define _FSL_CLOCK_H_
10 
11 #include "fsl_common.h"
12 
13 /*! @addtogroup clock */
14 /*! @{ */
15 
16 /*! @file */
17 
18 /*******************************************************************************
19  * Definitions
20  *****************************************************************************/
21 
22 /*! @name Driver version */
23 /*@{*/
24 /*! @brief CLOCK driver version 2.3.9. */
25 #define FSL_CLOCK_DRIVER_VERSION (MAKE_VERSION(2, 3, 9))
26 /*@}*/
27 
28 /*! @brief Configure whether driver controls clock
29  *
30  * When set to 0, peripheral drivers will enable clock in initialize function
31  * and disable clock in de-initialize function. When set to 1, peripheral
32  * driver will not control the clock, application could control the clock out of
33  * the driver.
34  *
35  * @note All drivers share this feature switcher. If it is set to 1, application
36  * should handle clock enable and disable for all drivers.
37  */
38 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL))
39 #define FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL 0
40 #endif
41 
42 /*!
43  * @brief User-defined the size of cache for CLOCK_PllGetConfig() function.
44  *
45  * Once define this MACRO to be non-zero value, CLOCK_PllGetConfig() function
46  * would cache the recent calulation and accelerate the execution to get the
47  * right settings.
48  */
49 #ifndef CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT
50 #define CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT 2U
51 #endif
52 
53 /* Definition for delay API in clock driver, users can redefine it to the real application. */
54 #ifndef SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY
55 #define SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY (100000000UL)
56 #endif
57 
58 /*! @brief Clock ip name array for ROM. */
59 #define ROM_CLOCKS \
60     {              \
61         kCLOCK_Rom \
62     }
63 /*! @brief Clock ip name array for SRAM. */
64 #define SRAM_CLOCKS                \
65     {                              \
66         kCLOCK_Sram1, kCLOCK_Sram2 \
67     }
68 /*! @brief Clock ip name array for FLASH. */
69 #define FLASH_CLOCKS \
70     {                \
71         kCLOCK_Flash \
72     }
73 /*! @brief Clock ip name array for FMC. */
74 #define FMC_CLOCKS \
75     {              \
76         kCLOCK_Fmc \
77     }
78 /*! @brief Clock ip name array for INPUTMUX. */
79 #define INPUTMUX_CLOCKS  \
80     {                    \
81         kCLOCK_InputMux0 \
82     }
83 /*! @brief Clock ip name array for IOCON. */
84 #define IOCON_CLOCKS \
85     {                \
86         kCLOCK_Iocon \
87     }
88 /*! @brief Clock ip name array for GPIO. */
89 #define GPIO_CLOCKS                \
90     {                              \
91         kCLOCK_Gpio0, kCLOCK_Gpio1 \
92     }
93 /*! @brief Clock ip name array for PINT. */
94 #define PINT_CLOCKS \
95     {               \
96         kCLOCK_Pint \
97     }
98 /*! @brief Clock ip name array for GINT. */
99 #define GINT_CLOCKS              \
100     {                            \
101         kCLOCK_Gint, kCLOCK_Gint \
102     }
103 /*! @brief Clock ip name array for DMA. */
104 #define DMA_CLOCKS               \
105     {                            \
106         kCLOCK_Dma0, kCLOCK_Dma1 \
107     }
108 /*! @brief Clock ip name array for CRC. */
109 #define CRC_CLOCKS \
110     {              \
111         kCLOCK_Crc \
112     }
113 /*! @brief Clock ip name array for WWDT. */
114 #define WWDT_CLOCKS \
115     {               \
116         kCLOCK_Wwdt \
117     }
118 /*! @brief Clock ip name array for RTC. */
119 #define RTC_CLOCKS \
120     {              \
121         kCLOCK_Rtc \
122     }
123 /*! @brief Clock ip name array for Mailbox. */
124 #define MAILBOX_CLOCKS \
125     {                  \
126         kCLOCK_Mailbox \
127     }
128 /*! @brief Clock ip name array for LPADC. */
129 #define LPADC_CLOCKS \
130     {                \
131         kCLOCK_Adc0  \
132     }
133 /*! @brief Clock ip name array for MRT. */
134 #define MRT_CLOCKS \
135     {              \
136         kCLOCK_Mrt \
137     }
138 /*! @brief Clock ip name array for OSTIMER. */
139 #define OSTIMER_CLOCKS  \
140     {                   \
141         kCLOCK_OsTimer0 \
142     }
143 /*! @brief Clock ip name array for SCT0. */
144 #define SCT_CLOCKS  \
145     {               \
146         kCLOCK_Sct0 \
147     }
148 /*! @brief Clock ip name array for MCAN. */
149 #define MCAN_CLOCKS \
150     {               \
151         kCLOCK_Mcan \
152     }
153 /*! @brief Clock ip name array for UTICK. */
154 #define UTICK_CLOCKS  \
155     {                 \
156         kCLOCK_Utick0 \
157     }
158 /*! @brief Clock ip name array for FLEXCOMM. */
159 #define FLEXCOMM_CLOCKS                                                                                             \
160     {                                                                                                               \
161         kCLOCK_FlexComm0, kCLOCK_FlexComm1, kCLOCK_FlexComm2, kCLOCK_FlexComm3, kCLOCK_FlexComm4, kCLOCK_FlexComm5, \
162             kCLOCK_FlexComm6, kCLOCK_FlexComm7, kCLOCK_Hs_Lspi                                                      \
163     }
164 /*! @brief Clock ip name array for LPUART. */
165 #define LPUART_CLOCKS                                                                                         \
166     {                                                                                                         \
167         kCLOCK_MinUart0, kCLOCK_MinUart1, kCLOCK_MinUart2, kCLOCK_MinUart3, kCLOCK_MinUart4, kCLOCK_MinUart5, \
168             kCLOCK_MinUart6, kCLOCK_MinUart7                                                                  \
169     }
170 
171 /*! @brief Clock ip name array for BI2C. */
172 #define BI2C_CLOCKS                                                                                                    \
173     {                                                                                                                  \
174         kCLOCK_BI2c0, kCLOCK_BI2c1, kCLOCK_BI2c2, kCLOCK_BI2c3, kCLOCK_BI2c4, kCLOCK_BI2c5, kCLOCK_BI2c6, kCLOCK_BI2c7 \
175     }
176 /*! @brief Clock ip name array for LSPI. */
177 #define LPSPI_CLOCKS                                                                                                   \
178     {                                                                                                                  \
179         kCLOCK_LSpi0, kCLOCK_LSpi1, kCLOCK_LSpi2, kCLOCK_LSpi3, kCLOCK_LSpi4, kCLOCK_LSpi5, kCLOCK_LSpi6, kCLOCK_LSpi7 \
180     }
181 /*! @brief Clock ip name array for FLEXI2S. */
182 #define FLEXI2S_CLOCKS                                                                                        \
183     {                                                                                                         \
184         kCLOCK_FlexI2s0, kCLOCK_FlexI2s1, kCLOCK_FlexI2s2, kCLOCK_FlexI2s3, kCLOCK_FlexI2s4, kCLOCK_FlexI2s5, \
185             kCLOCK_FlexI2s6, kCLOCK_FlexI2s7                                                                  \
186     }
187 /*! @brief Clock ip name array for CTIMER. */
188 #define CTIMER_CLOCKS                                                             \
189     {                                                                             \
190         kCLOCK_Timer0, kCLOCK_Timer1, kCLOCK_Timer2, kCLOCK_Timer3, kCLOCK_Timer4 \
191     }
192 /*! @brief Clock ip name array for EZHA */
193 #define EZHA_CLOCKS \
194     {               \
195         kCLOCK_Ezha \
196     }
197 /*! @brief Clock ip name array for EZHB */
198 #define EZHB_CLOCKS \
199     {               \
200         kCLOCK_Ezhb \
201     }
202 /*! @brief Clock ip name array for COMP */
203 #define COMP_CLOCKS \
204     {               \
205         kCLOCK_Comp \
206     }
207 /*! @brief Clock ip name array for USB1CLK. */
208 #define USB1CLK_CLOCKS \
209     {                  \
210         kCLOCK_Usb1Clk \
211     }
212 /*! @brief Clock ip name array for FREQME. */
213 #define FREQME_CLOCKS \
214     {                 \
215         kCLOCK_Freqme \
216     }
217 /*! @brief Clock ip name array for USBRAM. */
218 #define USBRAM_CLOCKS  \
219     {                  \
220         kCLOCK_UsbRam1 \
221     }
222 /*! @brief Clock ip name array for CDOG. */
223 #define CDOG_CLOCKS \
224     {               \
225         kCLOCK_Cdog \
226     }
227 /*! @brief Clock ip name array for RNG. */
228 #define RNG_CLOCKS \
229     {              \
230         kCLOCK_Rng \
231     }
232 /*! @brief Clock ip name array for USBHMR0. */
233 #define USBHMR0_CLOCKS \
234     {                  \
235         kCLOCK_Usbhmr0 \
236     }
237 /*! @brief Clock ip name array for USBHSL0. */
238 #define USBHSL0_CLOCKS \
239     {                  \
240         kCLOCK_Usbhsl0 \
241     }
242 /*! @brief Clock ip name array for HashCrypt. */
243 #define HASHCRYPT_CLOCKS \
244     {                    \
245         kCLOCK_HashCrypt \
246     }
247 /*! @brief Clock ip name array for PLULUT. */
248 #define PLULUT_CLOCKS \
249     {                 \
250         kCLOCK_PluLut \
251     }
252 /*! @brief Clock ip name array for PUF. */
253 #define PUF_CLOCKS \
254     {              \
255         kCLOCK_Puf \
256     }
257 /*! @brief Clock ip name array for CASPER. */
258 #define CASPER_CLOCKS \
259     {                 \
260         kCLOCK_Casper \
261     }
262 /*! @brief Clock ip name array for ANALOGCTRL. */
263 #define ANALOGCTRL_CLOCKS \
264     {                     \
265         kCLOCK_AnalogCtrl \
266     }
267 /*! @brief Clock ip name array for HS_LSPI. */
268 #define HS_LSPI_CLOCKS \
269     {                  \
270         kCLOCK_Hs_Lspi \
271     }
272 /*! @brief Clock ip name array for GPIO_SEC. */
273 #define GPIO_SEC_CLOCKS \
274     {                   \
275         kCLOCK_Gpio_Sec \
276     }
277 /*! @brief Clock ip name array for GPIO_SEC_INT. */
278 #define GPIO_SEC_INT_CLOCKS \
279     {                       \
280         kCLOCK_Gpio_Sec_Int \
281     }
282 /*! @brief Clock ip name array for USBD. */
283 #define USBD_CLOCKS                              \
284     {                                            \
285         kCLOCK_Usbd0, kCLOCK_Usbh1, kCLOCK_Usbd1 \
286     }
287 /*! @brief Clock ip name array for USBH. */
288 #define USBH_CLOCKS  \
289     {                \
290         kCLOCK_Usbh1 \
291     }
292 #define PLU_CLOCKS    \
293     {                 \
294         kCLOCK_PluLut \
295     }
296 #define SYSCTL_CLOCKS \
297     {                 \
298         kCLOCK_Sysctl \
299     }
300 /*! @brief Clock gate name used for CLOCK_EnableClock/CLOCK_DisableClock. */
301 /*------------------------------------------------------------------------------
302  clock_ip_name_t definition:
303 ------------------------------------------------------------------------------*/
304 
305 #define CLK_GATE_REG_OFFSET_SHIFT 8U
306 #define CLK_GATE_REG_OFFSET_MASK  0xFFFFFF00U
307 #define CLK_GATE_BIT_SHIFT_SHIFT  0U
308 #define CLK_GATE_BIT_SHIFT_MASK   0x000000FFU
309 
310 #define CLK_GATE_DEFINE(reg_offset, bit_shift)                                  \
311     ((((reg_offset) << CLK_GATE_REG_OFFSET_SHIFT) & CLK_GATE_REG_OFFSET_MASK) | \
312      (((bit_shift) << CLK_GATE_BIT_SHIFT_SHIFT) & CLK_GATE_BIT_SHIFT_MASK))
313 
314 #define CLK_GATE_ABSTRACT_REG_OFFSET(x) (((uint32_t)(x)&CLK_GATE_REG_OFFSET_MASK) >> CLK_GATE_REG_OFFSET_SHIFT)
315 #define CLK_GATE_ABSTRACT_BITS_SHIFT(x) (((uint32_t)(x)&CLK_GATE_BIT_SHIFT_MASK) >> CLK_GATE_BIT_SHIFT_SHIFT)
316 
317 #define AHB_CLK_CTRL0 0
318 #define AHB_CLK_CTRL1 1
319 #define AHB_CLK_CTRL2 2
320 
321 /*! @brief Clock gate name used for CLOCK_EnableClock/CLOCK_DisableClock. */
322 typedef enum _clock_ip_name
323 {
324     kCLOCK_IpInvalid = 0U,                                   /*!< Invalid Ip Name. */
325     kCLOCK_Rom       = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 1),    /*!< Clock gate name: Rom. */
326 
327     kCLOCK_Sram1 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 3),        /*!< Clock gate name: Sram1. */
328 
329     kCLOCK_Sram2 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 4),        /*!< Clock gate name: Sram2. */
330 
331     kCLOCK_Flash = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 7),        /*!< Clock gate name: Flash. */
332 
333     kCLOCK_Fmc = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 8),          /*!< Clock gate name: Fmc. */
334 
335     kCLOCK_InputMux = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 11),    /*!< Clock gate name: InputMux. */
336 
337     kCLOCK_Iocon = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 13),       /*!< Clock gate name: Iocon. */
338 
339     kCLOCK_Gpio0 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 14),       /*!< Clock gate name: Gpio0. */
340 
341     kCLOCK_Gpio1 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 15),       /*!< Clock gate name: Gpio1. */
342 
343     kCLOCK_Pint = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 18),        /*!< Clock gate name: Pint. */
344 
345     kCLOCK_Gint = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 19),        /*!< Clock gate name: Gint. */
346 
347     kCLOCK_Dma0 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 20),        /*!< Clock gate name: Dma0. */
348 
349     kCLOCK_Crc = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 21),         /*!< Clock gate name: Crc. */
350 
351     kCLOCK_Wwdt = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 22),        /*!< Clock gate name: Wwdt. */
352 
353     kCLOCK_Rtc = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 23),         /*!< Clock gate name: Rtc. */
354 
355     kCLOCK_Mailbox = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 26),     /*!< Clock gate name: Mailbox. */
356 
357     kCLOCK_Adc0 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 27),        /*!< Clock gate name: Adc0. */
358 
359     kCLOCK_Mrt = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 0),          /*!< Clock gate name: Mrt. */
360 
361     kCLOCK_OsTimer0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 1),     /*!< Clock gate name: OsTimer0. */
362 
363     kCLOCK_Sct0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 2),         /*!< Clock gate name: Sct0. */
364 
365     kCLOCK_Mcan = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 7),         /*!< Clock gate name: Mcan. */
366 
367     kCLOCK_Utick0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 10),      /*!< Clock gate name: Utick0. */
368 
369     kCLOCK_FlexComm0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11),   /*!< Clock gate name: FlexComm0. */
370 
371     kCLOCK_FlexComm1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12),   /*!< Clock gate name: FlexComm1. */
372 
373     kCLOCK_FlexComm2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13),   /*!< Clock gate name: FlexComm2. */
374 
375     kCLOCK_FlexComm3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14),   /*!< Clock gate name: FlexComm3. */
376 
377     kCLOCK_FlexComm4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15),   /*!< Clock gate name: FlexComm4. */
378 
379     kCLOCK_FlexComm5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16),   /*!< Clock gate name: FlexComm5. */
380 
381     kCLOCK_FlexComm6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17),   /*!< Clock gate name: FlexComm6. */
382 
383     kCLOCK_FlexComm7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18),   /*!< Clock gate name: FlexComm7. */
384 
385     kCLOCK_MinUart0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11),    /*!< Clock gate name: MinUart0. */
386 
387     kCLOCK_MinUart1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12),    /*!< Clock gate name: MinUart1. */
388 
389     kCLOCK_MinUart2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13),    /*!< Clock gate name: MinUart2. */
390 
391     kCLOCK_MinUart3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14),    /*!< Clock gate name: MinUart3. */
392 
393     kCLOCK_MinUart4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15),    /*!< Clock gate name: MinUart4. */
394 
395     kCLOCK_MinUart5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16),    /*!< Clock gate name: MinUart5. */
396 
397     kCLOCK_MinUart6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17),    /*!< Clock gate name: MinUart6. */
398 
399     kCLOCK_MinUart7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18),    /*!< Clock gate name: MinUart7. */
400 
401     kCLOCK_LSpi0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11),       /*!< Clock gate name: LSpi0. */
402 
403     kCLOCK_LSpi1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12),       /*!< Clock gate name: LSpi1. */
404 
405     kCLOCK_LSpi2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13),       /*!< Clock gate name: LSpi2. */
406 
407     kCLOCK_LSpi3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14),       /*!< Clock gate name: LSpi3. */
408 
409     kCLOCK_LSpi4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15),       /*!< Clock gate name: LSpi4. */
410 
411     kCLOCK_LSpi5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16),       /*!< Clock gate name: LSpi5. */
412 
413     kCLOCK_LSpi6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17),       /*!< Clock gate name: LSpi6. */
414 
415     kCLOCK_LSpi7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18),       /*!< Clock gate name: LSpi7. */
416 
417     kCLOCK_BI2c0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11),       /*!< Clock gate name: BI2c0. */
418 
419     kCLOCK_BI2c1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12),       /*!< Clock gate name: BI2c1. */
420 
421     kCLOCK_BI2c2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13),       /*!< Clock gate name: BI2c2. */
422 
423     kCLOCK_BI2c3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14),       /*!< Clock gate name: BI2c3. */
424 
425     kCLOCK_BI2c4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15),       /*!< Clock gate name: BI2c4. */
426 
427     kCLOCK_BI2c5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16),       /*!< Clock gate name: BI2c5. */
428 
429     kCLOCK_BI2c6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17),       /*!< Clock gate name: BI2c6. */
430 
431     kCLOCK_BI2c7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18),       /*!< Clock gate name: BI2c7. */
432 
433     kCLOCK_FlexI2s0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11),    /*!< Clock gate name: FlexI2s0. */
434 
435     kCLOCK_FlexI2s1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12),    /*!< Clock gate name: FlexI2s1. */
436 
437     kCLOCK_FlexI2s2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13),    /*!< Clock gate name: FlexI2s2. */
438 
439     kCLOCK_FlexI2s3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14),    /*!< Clock gate name: FlexI2s3. */
440 
441     kCLOCK_FlexI2s4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15),    /*!< Clock gate name: FlexI2s4. */
442 
443     kCLOCK_FlexI2s5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16),    /*!< Clock gate name: FlexI2s5. */
444 
445     kCLOCK_FlexI2s6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17),    /*!< Clock gate name: FlexI2s6. */
446 
447     kCLOCK_FlexI2s7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18),    /*!< Clock gate name: FlexI2s7. */
448 
449     kCLOCK_Timer2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 22),      /*!< Clock gate name: Timer2. */
450 
451     kCLOCK_Usbd0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 25),       /*!< Clock gate name: Usbd0. */
452 
453     kCLOCK_Timer0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 26),      /*!< Clock gate name: Timer0. */
454 
455     kCLOCK_Timer1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 27),      /*!< Clock gate name: Timer1. */
456 
457     kCLOCK_Ezha = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 30),        /*!< Clock gate name: Ezha. */
458 
459     kCLOCK_Ezhb = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 31),        /*!< Clock gate name: Ezhb. */
460 
461     kCLOCK_Dma1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 1),         /*!< Clock gate name: Dma1. */
462 
463     kCLOCK_Comp = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 2),         /*!< Clock gate name: Comp. */
464 
465     kCLOCK_Usbh1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 4),        /*!< Clock gate name: Usbh1. */
466 
467     kCLOCK_Usbd1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 5),        /*!< Clock gate name: Usbd1. */
468 
469     kCLOCK_UsbRam1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 6),      /*!< Clock gate name: UsbRam1. */
470 
471     kCLOCK_Usb1Clk = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 7),      /*!< Clock gate name: Usb1Clk. */
472 
473     kCLOCK_Freqme = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 8),       /*!< Clock gate name: Freqme. */
474 
475     kCLOCK_Cdog = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 11),        /*!< Clock gate name: Cdog. */
476 
477     kCLOCK_Rng = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 13),         /*!< Clock gate name: Rng. */
478 
479     kCLOCK_Sysctl = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 15),      /*!< Clock gate name: Sysctl. */
480 
481     kCLOCK_Usbhmr0 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 16),     /*!< Clock gate name: Usbhmr0. */
482 
483     kCLOCK_Usbhsl0 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 17),     /*!< Clock gate name: Usbhsl0. */
484 
485     kCLOCK_HashCrypt = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 18),   /*!< Clock gate name: HashCrypt. */
486 
487     kCLOCK_PluLut = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 20),      /*!< Clock gate name: PluLut. */
488 
489     kCLOCK_Timer3 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 21),      /*!< Clock gate name: Timer3. */
490 
491     kCLOCK_Timer4 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 22),      /*!< Clock gate name: Timer4. */
492 
493     kCLOCK_Puf = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 23),         /*!< Clock gate name: Puf. */
494 
495     kCLOCK_Casper = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 24),      /*!< Clock gate name: Casper. */
496 
497     kCLOCK_AnalogCtrl = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 27),  /*!< Clock gate name: AnalogCtrl. */
498 
499     kCLOCK_Hs_Lspi = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 28),     /*!< Clock gate name: Lspi. */
500 
501     kCLOCK_Gpio_Sec = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 29),    /*!< Clock gate name: GPIO Sec. */
502 
503     kCLOCK_Gpio_Sec_Int = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 30) /*!< Clock gate name: GPIO SEC Int. */
504 } clock_ip_name_t;
505 
506 /*! @brief Peripherals clock source definition. */
507 #define BUS_CLK kCLOCK_BusClk
508 
509 #define I2C0_CLK_SRC BUS_CLK
510 
511 /*! @brief Clock name used to get clock frequency. */
512 typedef enum _clock_name
513 {
514     kCLOCK_CoreSysClk, /*!< Core/system clock  (aka MAIN_CLK)                       */
515     kCLOCK_BusClk,     /*!< Bus clock (AHB clock)                                   */
516     kCLOCK_ClockOut,   /*!< CLOCKOUT                                                */
517     kCLOCK_FroHf,      /*!< FRO48/96                                                */
518     kCLOCK_Pll1Out,    /*!< PLL1 Output                                             */
519     kCLOCK_Mclk,       /*!< MCLK                                                    */
520     kCLOCK_Fro12M,     /*!< FRO12M                                                  */
521     kCLOCK_Fro1M,      /*!< FRO1M                                                   */
522     kCLOCK_ExtClk,     /*!< External Clock                                          */
523     kCLOCK_Pll0Out,    /*!< PLL0 Output                                             */
524     kCLOCK_FlexI2S,    /*!< FlexI2S clock                                           */
525 
526 } clock_name_t;
527 
528 /*! @brief Clock Mux Switches
529  *  The encoding is as follows each connection identified is 32bits wide while 24bits are valuable
530  *  starting from LSB upwards
531  *
532  *  [4 bits for choice, 0 means invalid choice] [8 bits mux ID]*
533  *
534  */
535 
536 #define CLK_ATTACH_ID(mux, sel, pos) \
537     ((((uint32_t)(mux) << 0U) | (((uint32_t)(sel) + 1U) & 0xFU) << 8U) << ((uint32_t)(pos)*12U))
538 #define MUX_A(mux, sel)           CLK_ATTACH_ID((mux), (sel), 0U)
539 #define MUX_B(mux, sel, selector) (CLK_ATTACH_ID((mux), (sel), 1U) | ((selector) << 24U))
540 
541 #define GET_ID_ITEM(connection)      ((connection)&0xFFFU)
542 #define GET_ID_NEXT_ITEM(connection) ((connection) >> 12U)
543 #define GET_ID_ITEM_MUX(connection)  (((uint8_t)connection) & 0xFFU)
544 #define GET_ID_ITEM_SEL(connection)  ((uint8_t)((((uint32_t)(connection)&0xF00U) >> 8U) - 1U))
545 #define GET_ID_SELECTOR(connection)  ((connection)&0xF000000U)
546 
547 #define CM_SYSTICKCLKSEL0 0
548 #define CM_TRACECLKSEL    2
549 #define CM_CTIMERCLKSEL0  3
550 #define CM_CTIMERCLKSEL1  4
551 #define CM_CTIMERCLKSEL2  5
552 #define CM_CTIMERCLKSEL3  6
553 #define CM_CTIMERCLKSEL4  7
554 #define CM_MAINCLKSELA    8
555 #define CM_MAINCLKSELB    9
556 #define CM_CLKOUTCLKSEL   10
557 #define CM_PLL0CLKSEL     12
558 #define CM_PLL1CLKSEL     13
559 #define CM_MCANCLKSEL     16
560 #define CM_ADCASYNCCLKSEL 17
561 #define CM_USB0CLKSEL     18
562 #define CM_CLK32KCLKSEL   19
563 #define CM_FXCOMCLKSEL0   20
564 #define CM_FXCOMCLKSEL1   21
565 #define CM_FXCOMCLKSEL2   22
566 #define CM_FXCOMCLKSEL3   23
567 #define CM_FXCOMCLKSEL4   24
568 #define CM_FXCOMCLKSEL5   25
569 #define CM_FXCOMCLKSEL6   26
570 #define CM_FXCOMCLKSEL7   27
571 #define CM_HSLSPICLKSEL   28
572 #define CM_MCLKCLKSEL     32
573 #define CM_SCTCLKSEL      36
574 
575 #define CM_OSTIMERCLKSEL   (62U)
576 #define CM_RTCOSC32KCLKSEL 63U
577 
578 /*!
579  * @brief The enumerator of clock attach Id.
580  */
581 typedef enum _clock_attach_id
582 {
583 
584     kFRO12M_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 0, 0),  /*!< Attach FRO12M to MAIN_CLK. */
585 
586     kEXT_CLK_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 1) | MUX_B(CM_MAINCLKSELB, 0, 0), /*!< Attach EXT_CLK to MAIN_CLK. */
587 
588     kFRO1M_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 2) | MUX_B(CM_MAINCLKSELB, 0, 0),   /*!< Attach FRO1M to MAIN_CLK. */
589 
590     kFRO_HF_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 3) | MUX_B(CM_MAINCLKSELB, 0, 0),  /*!< Attach FRO_HF to MAIN_CLK. */
591 
592     kPLL0_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 1, 0),    /*!< Attach PLL0 to MAIN_CLK. */
593 
594     kPLL1_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 2, 0),    /*!< Attach PLL1 to MAIN_CLK. */
595 
596     kOSC32K_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 3, 0),  /*!< Attach OSC32K to MAIN_CLK. */
597 
598     kMAIN_CLK_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 0),                               /*!< Attach MAIN_CLK to CLKOUT. */
599 
600     kPLL0_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 1),                                   /*!< Attach PLL0 to CLKOUT. */
601 
602     kEXT_CLK_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 2),                                /*!< Attach EXT_CLK to CLKOUT. */
603 
604     kFRO_HF_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 3),                                 /*!< Attach FRO_HF to CLKOUT. */
605 
606     kFRO1M_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 4),                                  /*!< Attach FRO1M to CLKOUT. */
607 
608     kPLL1_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 5),                                   /*!< Attach PLL1 to CLKOUT. */
609 
610     kOSC32K_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 6),                                 /*!< Attach OSC32K to CLKOUT. */
611 
612     kNONE_to_SYS_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 7),                               /*!< Attach NONE to SYS_CLKOUT. */
613 
614     kFRO12M_to_PLL0 = MUX_A(CM_PLL0CLKSEL, 0),                                     /*!< Attach FRO12M to PLL0. */
615 
616     kEXT_CLK_to_PLL0 = MUX_A(CM_PLL0CLKSEL, 1),                                    /*!< Attach EXT_CLK to PLL0. */
617 
618     kFRO1M_to_PLL0 = MUX_A(CM_PLL0CLKSEL, 2),                                      /*!< Attach FRO1M to PLL0. */
619 
620     kOSC32K_to_PLL0 = MUX_A(CM_PLL0CLKSEL, 3),                                     /*!< Attach OSC32K to PLL0. */
621 
622     kNONE_to_PLL0 = MUX_A(CM_PLL0CLKSEL, 7),                                       /*!< Attach NONE to PLL0. */
623 
624     kMCAN_DIV_to_MCAN = MUX_A(CM_MCANCLKSEL, 0),                                   /*!< Attach MCAN_DIV to MCAN. */
625 
626     kFRO1M_to_MCAN = MUX_A(CM_MCANCLKSEL, 1),                                      /*!< Attach FRO1M to MCAN. */
627 
628     kOSC32K_to_MCAN = MUX_A(CM_MCANCLKSEL, 2),                                     /*!< Attach OSC32K to MCAN. */
629 
630     kNONE_to_MCAN = MUX_A(CM_MCANCLKSEL, 7),                                       /*!< Attach NONE to MCAN. */
631 
632     kMAIN_CLK_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 0),                            /*!< Attach MAIN_CLK to ADC_CLK. */
633 
634     kPLL0_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 1),                                /*!< Attach PLL0 to ADC_CLK. */
635 
636     kFRO_HF_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 2),                              /*!< Attach FRO_HF to ADC_CLK. */
637 
638     kEXT_CLK_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 4),                             /*!< Attach EXT_CLK to ADC_CLK. */
639 
640     kNONE_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 7),                                /*!< Attach NONE to ADC_CLK. */
641 
642     kMAIN_CLK_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 0),                               /*!< Attach MAIN_CLK to USB0_CLK. */
643 
644     kPLL0_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 1),                                   /*!< Attach PLL0 to USB0_CLK. */
645 
646     kFRO_HF_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 3),                                 /*!< Attach FRO_HF to USB0_CLK. */
647 
648     kPLL1_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 5),                                   /*!< Attach PLL1 to USB0_CLK. */
649 
650     kNONE_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 7),                                   /*!< Attach NONE to USB0_CLK. */
651 
652     kOSC32K_to_CLK32K = MUX_A(CM_CLK32KCLKSEL, 0),                                 /*!< Attach OSC32K to CLK32K. */
653 
654     kFRO1MDIV_to_CLK32K = MUX_A(CM_CLK32KCLKSEL, 1),                               /*!< Attach FRO1MDIV to CLK32K. */
655 
656     kNONE_to_CLK32K = MUX_A(CM_CLK32KCLKSEL, 7),                                   /*!< Attach NONE to CLK32K. */
657 
658     kMAIN_CLK_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 0),                            /*!< Attach MAIN_CLK to FLEXCOMM0. */
659 
660     kPLL0_DIV_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 1),                            /*!< Attach PLL0_DIV to FLEXCOMM0. */
661 
662     kFRO12M_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 2),                              /*!< Attach FRO12M to FLEXCOMM0. */
663 
664     kFRO_HF_DIV_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 3),    /*!< Attach FRO_HF_DIV to FLEXCOMM0. */
665 
666     kFRO1M_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 4),         /*!< Attach FRO1M to FLEXCOMM0. */
667 
668     kMCLK_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 5),          /*!< Attach MCLK to FLEXCOMM0. */
669 
670     kOSC32K_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 6),        /*!< Attach OSC32K to FLEXCOMM0. */
671 
672     kNONE_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 7),          /*!< Attach NONE to FLEXCOMM0. */
673 
674     kMAIN_CLK_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 0),      /*!< Attach MAIN_CLK to FLEXCOMM1. */
675 
676     kPLL0_DIV_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 1),      /*!< Attach PLL0_DIV to FLEXCOMM1. */
677 
678     kFRO12M_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 2),        /*!< Attach FRO12M to FLEXCOMM1. */
679 
680     kFRO_HF_DIV_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 3),    /*!< Attach FRO_HF_DIV to FLEXCOMM1. */
681 
682     kFRO1M_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 4),         /*!< Attach FRO1M to FLEXCOMM1. */
683 
684     kMCLK_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 5),          /*!< Attach MCLK to FLEXCOMM1. */
685 
686     kOSC32K_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 6),        /*!< Attach OSC32K to FLEXCOMM1. */
687 
688     kNONE_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 7),          /*!< Attach NONE to FLEXCOMM1. */
689 
690     kMAIN_CLK_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 0),      /*!< Attach MAIN_CLK to FLEXCOMM2. */
691 
692     kPLL0_DIV_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 1),      /*!< Attach PLL0_DIV to FLEXCOMM2. */
693 
694     kFRO12M_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 2),        /*!< Attach FRO12M to FLEXCOMM2. */
695 
696     kFRO_HF_DIV_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 3),    /*!< Attach FRO_HF_DIV to FLEXCOMM2. */
697 
698     kFRO1M_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 4),         /*!< Attach FRO1M to FLEXCOMM2. */
699 
700     kMCLK_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 5),          /*!< Attach MCLK to FLEXCOMM2. */
701 
702     kOSC32K_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 6),        /*!< Attach OSC32K to FLEXCOMM2. */
703 
704     kNONE_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 7),          /*!< Attach NONE to FLEXCOMM2. */
705 
706     kMAIN_CLK_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 0),      /*!< Attach MAIN_CLK to FLEXCOMM3. */
707 
708     kPLL0_DIV_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 1),      /*!< Attach PLL0_DIV to FLEXCOMM3. */
709 
710     kFRO12M_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 2),        /*!< Attach FRO12M to FLEXCOMM3. */
711 
712     kFRO_HF_DIV_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 3),    /*!< Attach FRO_HF_DIV to FLEXCOMM3. */
713 
714     kFRO1M_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 4),         /*!< Attach FRO1M to FLEXCOMM3. */
715 
716     kMCLK_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 5),          /*!< Attach MCLK to FLEXCOMM3. */
717 
718     kOSC32K_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 6),        /*!< Attach OSC32K to FLEXCOMM3. */
719 
720     kNONE_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 7),          /*!< Attach NONE to FLEXCOMM3. */
721 
722     kMAIN_CLK_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 0),      /*!< Attach MAIN_CLK to FLEXCOMM4. */
723 
724     kPLL0_DIV_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 1),      /*!< Attach PLL0_DIV to FLEXCOMM4. */
725 
726     kFRO12M_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 2),        /*!< Attach FRO12M to FLEXCOMM4. */
727 
728     kFRO_HF_DIV_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 3),    /*!< Attach FRO_HF_DIV to FLEXCOMM4. */
729 
730     kFRO1M_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 4),         /*!< Attach FRO1M to FLEXCOMM4. */
731 
732     kMCLK_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 5),          /*!< Attach MCLK to FLEXCOMM4. */
733 
734     kOSC32K_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 6),        /*!< Attach OSC32K to FLEXCOMM4. */
735 
736     kNONE_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 7),          /*!< Attach NONE to FLEXCOMM4. */
737 
738     kMAIN_CLK_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 0),      /*!< Attach MAIN_CLK to FLEXCOMM5. */
739 
740     kPLL0_DIV_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 1),      /*!< Attach PLL0_DIV to FLEXCOMM5. */
741 
742     kFRO12M_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 2),        /*!< Attach FRO12M to FLEXCOMM5. */
743 
744     kFRO_HF_DIV_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 3),    /*!< Attach FRO_HF_DIV to FLEXCOMM5. */
745 
746     kFRO1M_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 4),         /*!< Attach FRO1M to FLEXCOMM5. */
747 
748     kMCLK_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 5),          /*!< Attach MCLK to FLEXCOMM5. */
749 
750     kOSC32K_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 6),        /*!< Attach OSC32K to FLEXCOMM5. */
751 
752     kNONE_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 7),          /*!< Attach NONE to FLEXCOMM5. */
753 
754     kMAIN_CLK_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 0),      /*!< Attach MAIN_CLK to FLEXCOMM6. */
755 
756     kPLL0_DIV_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 1),      /*!< Attach PLL0_DIV to FLEXCOMM6. */
757 
758     kFRO12M_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 2),        /*!< Attach FRO12M to FLEXCOMM6. */
759 
760     kFRO_HF_DIV_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 3),    /*!< Attach FRO_HF_DIV to FLEXCOMM6. */
761 
762     kFRO1M_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 4),         /*!< Attach FRO1M to FLEXCOMM6. */
763 
764     kMCLK_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 5),          /*!< Attach MCLK to FLEXCOMM6. */
765 
766     kOSC32K_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 6),        /*!< Attach OSC32K to FLEXCOMM6. */
767 
768     kNONE_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 7),          /*!< Attach NONE to FLEXCOMM6. */
769 
770     kMAIN_CLK_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 0),      /*!< Attach MAIN_CLK to FLEXCOMM7. */
771 
772     kPLL0_DIV_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 1),      /*!< Attach PLL0_DIV to FLEXCOMM7. */
773 
774     kFRO12M_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 2),        /*!< Attach FRO12M to FLEXCOMM7. */
775 
776     kFRO_HF_DIV_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 3),    /*!< Attach FRO_HF_DIV to FLEXCOMM7. */
777 
778     kFRO1M_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 4),         /*!< Attach FRO1M to FLEXCOMM7. */
779 
780     kMCLK_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 5),          /*!< Attach MCLK to FLEXCOMM7. */
781 
782     kOSC32K_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 6),        /*!< Attach OSC32K to FLEXCOMM7. */
783 
784     kNONE_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 7),          /*!< Attach NONE to FLEXCOMM7. */
785 
786     kMAIN_CLK_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 0),         /*!< Attach MAIN_CLK to HSLSPI. */
787 
788     kPLL0_DIV_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 1),         /*!< Attach PLL0_DIV to HSLSPI. */
789 
790     kFRO12M_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 2),           /*!< Attach FRO12M to HSLSPI. */
791 
792     kFRO_HF_DIV_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 3),       /*!< Attach FRO_HF_DIV to HSLSPI. */
793 
794     kFRO1M_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 4),            /*!< Attach FRO1M to HSLSPI. */
795 
796     kOSC32K_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 6),           /*!< Attach OSC32K to HSLSPI. */
797 
798     kNONE_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 7),             /*!< Attach NONE to HSLSPI. */
799 
800     kFRO_HF_to_MCLK = MUX_A(CM_MCLKCLKSEL, 0),               /*!< Attach FRO_HF to MCLK. */
801 
802     kPLL0_to_MCLK = MUX_A(CM_MCLKCLKSEL, 1),                 /*!< Attach PLL0 to MCLK. */
803 
804     kNONE_to_MCLK = MUX_A(CM_MCLKCLKSEL, 7),                 /*!< Attach NONE to MCLK. */
805 
806     kMAIN_CLK_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 0),           /*!< Attach MAIN_CLK to SCT_CLK. */
807 
808     kPLL0_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 1),               /*!< Attach PLL0 to SCT_CLK. */
809 
810     kEXT_CLK_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 2),            /*!< Attach EXT_CLK to SCT_CLK. */
811 
812     kFRO_HF_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 3),             /*!< Attach FRO_HF to SCT_CLK. */
813 
814     kMCLK_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 5),               /*!< Attach MCLK to SCT_CLK. */
815 
816     kNONE_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 7),               /*!< Attach NONE to SCT_CLK. */
817 
818     kFRO32K_to_OSC32K = MUX_A(CM_RTCOSC32KCLKSEL, 0),        /*!< Attach FRO32K to OSC32K. */
819 
820     kXTAL32K_to_OSC32K = MUX_A(CM_RTCOSC32KCLKSEL, 1),       /*!< Attach XTAL32K to OSC32K. */
821 
822     kOSC32K_to_OSTIMER = MUX_A(CM_OSTIMERCLKSEL, 0),         /*!< Attach OSC32K to OSTIMER. */
823 
824     kFRO1M_to_OSTIMER = MUX_A(CM_OSTIMERCLKSEL, 1),          /*!< Attach FRO1M to OSTIMER. */
825 
826     kMAIN_CLK_to_OSTIMER = MUX_A(CM_OSTIMERCLKSEL, 2),       /*!< Attach MAIN_CLK to OSTIMER. */
827 
828     kTRACE_DIV_to_TRACE = MUX_A(CM_TRACECLKSEL, 0),          /*!< Attach TRACE_DIV to TRACE. */
829 
830     kFRO1M_to_TRACE = MUX_A(CM_TRACECLKSEL, 1),              /*!< Attach FRO1M to TRACE. */
831 
832     kOSC32K_to_TRACE = MUX_A(CM_TRACECLKSEL, 2),             /*!< Attach OSC32K to TRACE. */
833 
834     kNONE_to_TRACE = MUX_A(CM_TRACECLKSEL, 7),               /*!< Attach NONE to TRACE. */
835 
836     kSYSTICK_DIV0_to_SYSTICK0 = MUX_A(CM_SYSTICKCLKSEL0, 0), /*!< Attach SYSTICK_DIV0 to SYSTICK0. */
837 
838     kFRO1M_to_SYSTICK0 = MUX_A(CM_SYSTICKCLKSEL0, 1),        /*!< Attach FRO1M to SYSTICK0. */
839 
840     kOSC32K_to_SYSTICK0 = MUX_A(CM_SYSTICKCLKSEL0, 2),       /*!< Attach OSC32K to SYSTICK0. */
841 
842     kNONE_to_SYSTICK0 = MUX_A(CM_SYSTICKCLKSEL0, 7),         /*!< Attach NONE to SYSTICK0. */
843 
844     kFRO12M_to_PLL1 = MUX_A(CM_PLL1CLKSEL, 0),               /*!< Attach FRO12M to PLL1. */
845 
846     kEXT_CLK_to_PLL1 = MUX_A(CM_PLL1CLKSEL, 1),              /*!< Attach EXT_CLK to PLL1. */
847 
848     kFRO1M_to_PLL1 = MUX_A(CM_PLL1CLKSEL, 2),                /*!< Attach FRO1M to PLL1. */
849 
850     kOSC32K_to_PLL1 = MUX_A(CM_PLL1CLKSEL, 3),               /*!< Attach OSC32K to PLL1. */
851 
852     kNONE_to_PLL1 = MUX_A(CM_PLL1CLKSEL, 7),                 /*!< Attach NONE to PLL1. */
853 
854     kMAIN_CLK_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 0),       /*!< Attach MAIN_CLK to CTIMER0. */
855 
856     kPLL0_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 1),           /*!< Attach PLL0 to CTIMER0. */
857 
858     kFRO_HF_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 3),         /*!< Attach FRO_HF to CTIMER0. */
859 
860     kFRO1M_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 4),          /*!< Attach FRO1M to CTIMER0. */
861 
862     kMCLK_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 5),           /*!< Attach MCLK to CTIMER0. */
863 
864     kOSC32K_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 6),         /*!< Attach OSC32K to CTIMER0. */
865 
866     kNONE_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 7),           /*!< Attach NONE to CTIMER0. */
867 
868     kMAIN_CLK_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 0),       /*!< Attach MAIN_CLK to CTIMER1. */
869 
870     kPLL0_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 1),           /*!< Attach PLL0 to CTIMER1. */
871 
872     kFRO_HF_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 3),         /*!< Attach FRO_HF to CTIMER1. */
873 
874     kFRO1M_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 4),          /*!< Attach FRO1M to CTIMER1. */
875 
876     kMCLK_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 5),           /*!< Attach MCLK to CTIMER1. */
877 
878     kOSC32K_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 6),         /*!< Attach OSC32K to CTIMER1. */
879 
880     kNONE_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 7),           /*!< Attach NONE to CTIMER1. */
881 
882     kMAIN_CLK_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 0),       /*!< Attach MAIN_CLK to CTIMER2. */
883 
884     kPLL0_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 1),           /*!< Attach PLL0 to CTIMER2. */
885 
886     kFRO_HF_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 3),         /*!< Attach FRO_HF to CTIMER2. */
887 
888     kFRO1M_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 4),          /*!< Attach FRO1M to CTIMER2. */
889 
890     kMCLK_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 5),           /*!< Attach MCLK to CTIMER2. */
891 
892     kOSC32K_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 6),         /*!< Attach OSC32K to CTIMER2. */
893 
894     kNONE_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 7),           /*!< Attach NONE to CTIMER2. */
895 
896     kMAIN_CLK_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 0),       /*!< Attach MAIN_CLK to CTIMER3. */
897 
898     kPLL0_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 1),           /*!< Attach PLL0 to CTIMER3. */
899 
900     kFRO_HF_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 3),         /*!< Attach FRO_HF to CTIMER3. */
901 
902     kFRO1M_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 4),          /*!< Attach FRO1M to CTIMER3. */
903 
904     kMCLK_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 5),           /*!< Attach MCLK to CTIMER3. */
905 
906     kOSC32K_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 6),         /*!< Attach OSC32K to CTIMER3. */
907 
908     kNONE_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 7),           /*!< Attach NONE to CTIMER3. */
909 
910     kMAIN_CLK_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 0),       /*!< Attach MAIN_CLK to CTIMER4. */
911 
912     kPLL0_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 1),           /*!< Attach PLL0 to CTIMER4. */
913 
914     kFRO_HF_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 3),         /*!< Attach FRO_HF to CTIMER4. */
915 
916     kFRO1M_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 4),          /*!< Attach FRO1M to CTIMER4. */
917 
918     kMCLK_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 5),           /*!< Attach MCLK to CTIMER4. */
919 
920     kOSC32K_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 6),         /*!< Attach OSC32K to CTIMER4. */
921 
922     kNONE_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 7),           /*!< Attach NONE to CTIMER4. */
923 
924     kNONE_to_NONE = (int)0x80000000U,                        /*!< Attach NONE to NONE. */
925 
926 } clock_attach_id_t;
927 
928 /*! @brief Clock dividers */
929 typedef enum _clock_div_name
930 {
931     kCLOCK_DivSystickClk0 = 0,  /*!< Systick Clk0 Divider. */
932 
933     kCLOCK_DivArmTrClkDiv = 2,  /*!< Arm Tr Clk Div Divider. */
934 
935     kCLOCK_DivCanClk = 3,       /*!< Can Clock Divider. */
936 
937     kCLOCK_DivFlexFrg0 = 8,     /*!< Flex Frg0 Divider. */
938 
939     kCLOCK_DivFlexFrg1 = 9,     /*!< Flex Frg1 Divider. */
940 
941     kCLOCK_DivFlexFrg2 = 10,    /*!< Flex Frg2 Divider. */
942 
943     kCLOCK_DivFlexFrg3 = 11,    /*!< Flex Frg3 Divider. */
944 
945     kCLOCK_DivFlexFrg4 = 12,    /*!< Flex Frg4 Divider. */
946 
947     kCLOCK_DivFlexFrg5 = 13,    /*!< Flex Frg5 Divider. */
948 
949     kCLOCK_DivFlexFrg6 = 14,    /*!< Flex Frg6 Divider. */
950 
951     kCLOCK_DivFlexFrg7 = 15,    /*!< Flex Frg7 Divider. */
952 
953     kCLOCK_DivAhbClk = 32,      /*!< Ahb Clock Divider. */
954 
955     kCLOCK_DivClkOut = 33,      /*!< Clk Out Divider. */
956 
957     kCLOCK_DivFrohfClk = 34,    /*!< Frohf Clock Divider. */
958 
959     kCLOCK_DivWdtClk = 35,      /*!< Wdt Clock Divider. */
960 
961     kCLOCK_DivAdcAsyncClk = 37, /*!< Adc Async Clock Divider. */
962 
963     kCLOCK_DivUsb0Clk = 38,     /*!< Usb0 Clock Divider. */
964 
965     kCLOCK_DivFro1mClk = 40,    /*!< Fro1m Clock Divider. */
966 
967     kCLOCK_DivMClk = 43,        /*!< I2S MCLK Clock Divider. */
968 
969     kCLOCK_DivSctClk = 45,      /*!< Sct Clock Divider. */
970 
971     kCLOCK_DivPll0Clk = 49      /*!< PLL clock divider. */
972 } clock_div_name_t;
973 
974 /*******************************************************************************
975  * API
976  ******************************************************************************/
977 
978 #if defined(__cplusplus)
979 extern "C" {
980 #endif /* __cplusplus */
981 
982 /**
983  * @brief Enable the clock for specific IP.
984  * @param clk : Clock to be enabled.
985  * @return  Nothing
986  */
CLOCK_EnableClock(clock_ip_name_t clk)987 static inline void CLOCK_EnableClock(clock_ip_name_t clk)
988 {
989     uint32_t index               = CLK_GATE_ABSTRACT_REG_OFFSET(clk);
990     SYSCON->AHBCLKCTRLSET[index] = (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT(clk));
991 }
992 /**
993  * @brief Disable the clock for specific IP.
994  * @param clk : Clock to be Disabled.
995  * @return  Nothing
996  */
CLOCK_DisableClock(clock_ip_name_t clk)997 static inline void CLOCK_DisableClock(clock_ip_name_t clk)
998 {
999     uint32_t index               = CLK_GATE_ABSTRACT_REG_OFFSET(clk);
1000     SYSCON->AHBCLKCTRLCLR[index] = (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT(clk));
1001 }
1002 /**
1003  * @brief   Initialize the Core clock to given frequency (12, 48 or 96 MHz).
1004  * Turns on FRO and uses default CCO, if freq is 12000000, then high speed output is off, else high speed output is
1005  * enabled.
1006  * @param   iFreq   : Desired frequency (must be one of CLK_FRO_12MHZ or CLK_FRO_48MHZ or CLK_FRO_96MHZ)
1007  * @return  returns success or fail status.
1008  */
1009 status_t CLOCK_SetupFROClocking(uint32_t iFreq);
1010 /**
1011  * @brief	Set the flash wait states for the input freuqency.
1012  * @param	system_freq_hz	: Input frequency
1013  * @return	Nothing
1014  */
1015 void CLOCK_SetFLASHAccessCyclesForFreq(uint32_t system_freq_hz);
1016 /**
1017  * @brief   Initialize the external osc clock to given frequency.
1018  * @param   iFreq   : Desired frequency (must be equal to exact rate in Hz)
1019  * @return  returns success or fail status.
1020  */
1021 status_t CLOCK_SetupExtClocking(uint32_t iFreq);
1022 /**
1023  * @brief   Initialize the I2S MCLK clock to given frequency.
1024  * @param   iFreq   : Desired frequency (must be equal to exact rate in Hz)
1025  * @return  returns success or fail status.
1026  */
1027 status_t CLOCK_SetupI2SMClkClocking(uint32_t iFreq);
1028 /**
1029  * @brief   Initialize the PLU CLKIN clock to given frequency.
1030  * @param   iFreq   : Desired frequency (must be equal to exact rate in Hz)
1031  * @return  returns success or fail status.
1032  */
1033 status_t CLOCK_SetupPLUClkInClocking(uint32_t iFreq);
1034 /**
1035  * @brief   Configure the clock selection muxes.
1036  * @param   connection  : Clock to be configured.
1037  * @return  Nothing
1038  */
1039 void CLOCK_AttachClk(clock_attach_id_t connection);
1040 /**
1041  * @brief   Get the actual clock attach id.
1042  * This fuction uses the offset in input attach id, then it reads the actual source value in
1043  * the register and combine the offset to obtain an actual attach id.
1044  * @param   attachId  : Clock attach id to get.
1045  * @return  Clock source value.
1046  */
1047 clock_attach_id_t CLOCK_GetClockAttachId(clock_attach_id_t attachId);
1048 /**
1049  * @brief   Setup peripheral clock dividers.
1050  * @param   div_name    : Clock divider name
1051  * @param divided_by_value: Value to be divided
1052  * @param reset :  Whether to reset the divider counter.
1053  * @return  Nothing
1054  */
1055 void CLOCK_SetClkDiv(clock_div_name_t div_name, uint32_t divided_by_value, bool reset);
1056 /**
1057  * @brief   Setup rtc 1khz clock divider.
1058  * @param divided_by_value: Value to be divided
1059  * @return  Nothing
1060  */
1061 void CLOCK_SetRtc1khzClkDiv(uint32_t divided_by_value);
1062 /**
1063  * @brief   Setup rtc 1hz clock divider.
1064  * @param divided_by_value: Value to be divided
1065  * @return  Nothing
1066  */
1067 void CLOCK_SetRtc1hzClkDiv(uint32_t divided_by_value);
1068 
1069 /**
1070  * @brief   Set the flexcomm output frequency.
1071  * @param   id      : flexcomm instance id
1072  * @param   freq    : output frequency
1073  * @return  0   : the frequency range is out of range.
1074  *          1   : switch successfully.
1075  */
1076 uint32_t CLOCK_SetFlexCommClock(uint32_t id, uint32_t freq);
1077 
1078 /*! @brief  Return Frequency of flexcomm input clock
1079  *  @param  id     : flexcomm instance id
1080  *  @return Frequency value
1081  */
1082 uint32_t CLOCK_GetFlexCommInputClock(uint32_t id);
1083 
1084 /*! @brief  Return Frequency of selected clock
1085  *  @return Frequency of selected clock
1086  */
1087 uint32_t CLOCK_GetFreq(clock_name_t clockName);
1088 /*! @brief  Return Frequency of FRO 12MHz
1089  *  @return Frequency of FRO 12MHz
1090  */
1091 uint32_t CLOCK_GetFro12MFreq(void);
1092 /*! @brief  Return Frequency of FRO 1MHz
1093  *  @return Frequency of FRO 1MHz
1094  */
1095 uint32_t CLOCK_GetFro1MFreq(void);
1096 /*! @brief  Return Frequency of ClockOut
1097  *  @return Frequency of ClockOut
1098  */
1099 uint32_t CLOCK_GetClockOutClkFreq(void);
1100 /*! @brief  Return Frequency of Can Clock
1101  *  @return Frequency of Can.
1102  */
1103 uint32_t CLOCK_GetMCanClkFreq(void);
1104 /*! @brief  Return Frequency of Adc Clock
1105  *  @return Frequency of Adc.
1106  */
1107 uint32_t CLOCK_GetAdcClkFreq(void);
1108 /*! @brief  Return Frequency of Usb0 Clock
1109  *  @return Frequency of Usb0 Clock.
1110  */
1111 uint32_t CLOCK_GetUsb0ClkFreq(void);
1112 /*! @brief  Return Frequency of Usb1 Clock
1113  *  @return Frequency of Usb1 Clock.
1114  */
1115 uint32_t CLOCK_GetUsb1ClkFreq(void);
1116 /*! @brief  Return Frequency of MClk Clock
1117  *  @return Frequency of MClk Clock.
1118  */
1119 uint32_t CLOCK_GetMclkClkFreq(void);
1120 /*! @brief  Return Frequency of SCTimer Clock
1121  *  @return Frequency of SCTimer Clock.
1122  */
1123 uint32_t CLOCK_GetSctClkFreq(void);
1124 /*! @brief  Return Frequency of External Clock
1125  *  @return Frequency of External Clock. If no external clock is used returns 0.
1126  */
1127 uint32_t CLOCK_GetExtClkFreq(void);
1128 /*! @brief  Return Frequency of Watchdog
1129  *  @return Frequency of Watchdog
1130  */
1131 uint32_t CLOCK_GetWdtClkFreq(void);
1132 /*! @brief  Return Frequency of High-Freq output of FRO
1133  *  @return Frequency of High-Freq output of FRO
1134  */
1135 uint32_t CLOCK_GetFroHfFreq(void);
1136 /*! @brief  Return Frequency of PLL
1137  *  @return Frequency of PLL
1138  */
1139 uint32_t CLOCK_GetPll0OutFreq(void);
1140 /*! @brief  Return Frequency of USB PLL
1141  *  @return Frequency of PLL
1142  */
1143 uint32_t CLOCK_GetPll1OutFreq(void);
1144 /*! @brief  Return Frequency of 32kHz osc
1145  *  @return Frequency of 32kHz osc
1146  */
1147 uint32_t CLOCK_GetOsc32KFreq(void);
1148 /*! @brief  Return Frequency of Core System
1149  *  @return Frequency of Core System
1150  */
1151 uint32_t CLOCK_GetCoreSysClkFreq(void);
1152 /*! @brief  Return Frequency of I2S MCLK Clock
1153  *  @return Frequency of I2S MCLK Clock
1154  */
1155 uint32_t CLOCK_GetI2SMClkFreq(void);
1156 /*! @brief  Return Frequency of PLU CLKIN Clock
1157  *  @return Frequency of PLU CLKIN Clock
1158  */
1159 uint32_t CLOCK_GetPLUClkInFreq(void);
1160 /*! @brief  Return Frequency of FlexComm Clock
1161  *  @return Frequency of FlexComm Clock
1162  */
1163 uint32_t CLOCK_GetFlexCommClkFreq(uint32_t id);
1164 /*! @brief  Return Frequency of High speed SPI Clock
1165  *  @return Frequency of High speed SPI Clock
1166  */
1167 uint32_t CLOCK_GetHsLspiClkFreq(void);
1168 /*! @brief  Return Frequency of CTimer functional Clock
1169  *  @return Frequency of CTimer functional Clock
1170  */
1171 uint32_t CLOCK_GetCTimerClkFreq(uint32_t id);
1172 /*! @brief  Return Frequency of SystickClock
1173  *  @return Frequency of Systick Clock
1174  */
1175 uint32_t CLOCK_GetSystickClkFreq(uint32_t id);
1176 
1177 /*! @brief    Return  PLL0 input clock rate
1178  *  @return    PLL0 input clock rate
1179  */
1180 uint32_t CLOCK_GetPLL0InClockRate(void);
1181 
1182 /*! @brief    Return  PLL1 input clock rate
1183  *  @return    PLL1 input clock rate
1184  */
1185 uint32_t CLOCK_GetPLL1InClockRate(void);
1186 
1187 /*! @brief    Return  PLL0 output clock rate
1188  *  @param    recompute   : Forces a PLL rate recomputation if true
1189  *  @return    PLL0 output clock rate
1190  *  @note The PLL rate is cached in the driver in a variable as
1191  *  the rate computation function can take some time to perform. It
1192  *  is recommended to use 'false' with the 'recompute' parameter.
1193  */
1194 uint32_t CLOCK_GetPLL0OutClockRate(bool recompute);
1195 
1196 /*! @brief    Return  PLL1 output clock rate
1197  *  @param    recompute   : Forces a PLL rate recomputation if true
1198  *  @return    PLL1 output clock rate
1199  *  @note The PLL rate is cached in the driver in a variable as
1200  *  the rate computation function can take some time to perform. It
1201  *  is recommended to use 'false' with the 'recompute' parameter.
1202  */
1203 uint32_t CLOCK_GetPLL1OutClockRate(bool recompute);
1204 
1205 /*! @brief    Enables and disables PLL0 bypass mode
1206  *  @brief    bypass  : true to bypass PLL0 (PLL0 output = PLL0 input, false to disable bypass
1207  *  @return   PLL0 output clock rate
1208  */
CLOCK_SetBypassPLL0(bool bypass)1209 __STATIC_INLINE void CLOCK_SetBypassPLL0(bool bypass)
1210 {
1211     if (bypass)
1212     {
1213         SYSCON->PLL0CTRL |= (1UL << SYSCON_PLL0CTRL_BYPASSPLL_SHIFT);
1214     }
1215     else
1216     {
1217         SYSCON->PLL0CTRL &= ~(1UL << SYSCON_PLL0CTRL_BYPASSPLL_SHIFT);
1218     }
1219 }
1220 
1221 /*! @brief    Enables and disables PLL1 bypass mode
1222  *  @brief    bypass  : true to bypass PLL1 (PLL1 output = PLL1 input, false to disable bypass
1223  *  @return   PLL1 output clock rate
1224  */
CLOCK_SetBypassPLL1(bool bypass)1225 __STATIC_INLINE void CLOCK_SetBypassPLL1(bool bypass)
1226 {
1227     if (bypass)
1228     {
1229         SYSCON->PLL1CTRL |= (1UL << SYSCON_PLL1CTRL_BYPASSPLL_SHIFT);
1230     }
1231     else
1232     {
1233         SYSCON->PLL1CTRL &= ~(1UL << SYSCON_PLL1CTRL_BYPASSPLL_SHIFT);
1234     }
1235 }
1236 
1237 /*! @brief    Check if PLL is locked or not
1238  *  @return   true if the PLL is locked, false if not locked
1239  */
CLOCK_IsPLL0Locked(void)1240 __STATIC_INLINE bool CLOCK_IsPLL0Locked(void)
1241 {
1242     return (bool)((SYSCON->PLL0STAT & SYSCON_PLL0STAT_LOCK_MASK) != 0UL);
1243 }
1244 
1245 /*! @brief	Check if PLL1 is locked or not
1246  *  @return	true if the PLL1 is locked, false if not locked
1247  */
CLOCK_IsPLL1Locked(void)1248 __STATIC_INLINE bool CLOCK_IsPLL1Locked(void)
1249 {
1250     return (bool)((SYSCON->PLL1STAT & SYSCON_PLL1STAT_LOCK_MASK) != 0UL);
1251 }
1252 
1253 /*! @brief Store the current PLL0 rate
1254  *  @param    rate: Current rate of the PLL0
1255  *  @return   Nothing
1256  **/
1257 void CLOCK_SetStoredPLL0ClockRate(uint32_t rate);
1258 
1259 /*! @brief PLL configuration structure flags for 'flags' field
1260  * These flags control how the PLL configuration function sets up the PLL setup structure.<br>
1261  *
1262  * When the PLL_CONFIGFLAG_USEINRATE flag is selected, the 'InputRate' field in the
1263  * configuration structure must be assigned with the expected PLL frequency. If the
1264  * PLL_CONFIGFLAG_USEINRATE is not used, 'InputRate' is ignored in the configuration
1265  * function and the driver will determine the PLL rate from the currently selected
1266  * PLL source. This flag might be used to configure the PLL input clock more accurately
1267  * when using the WDT oscillator or a more dyanmic CLKIN source.<br>
1268  *
1269  * When the PLL_CONFIGFLAG_FORCENOFRACT flag is selected, the PLL hardware for the
1270  * automatic bandwidth selection, Spread Spectrum (SS) support, and fractional M-divider
1271  * are not used.<br>
1272  */
1273 #define PLL_CONFIGFLAG_USEINRATE    (1U << 0U) /*!< Flag to use InputRate in PLL configuration structure for setup */
1274 #define PLL_CONFIGFLAG_FORCENOFRACT (1U << 2U)
1275 /*!< Force non-fractional output mode, PLL output will not use the fractional, automatic bandwidth, or SS hardware */
1276 
1277 /*! @brief PLL Spread Spectrum (SS) Programmable modulation frequency
1278  * See (MF) field in the PLL0SSCG1 register in the UM.
1279  */
1280 typedef enum _ss_progmodfm
1281 {
1282     kSS_MF_512 = (0U << SYSCON_PLL0SSCG1_MF_SHIFT), /*!< Nss = 512 (fm ? 3.9 - 7.8 kHz) */
1283     kSS_MF_384 = (1U << SYSCON_PLL0SSCG1_MF_SHIFT), /*!< Nss ?= 384 (fm ? 5.2 - 10.4 kHz) */
1284     kSS_MF_256 = (2U << SYSCON_PLL0SSCG1_MF_SHIFT), /*!< Nss = 256 (fm ? 7.8 - 15.6 kHz) */
1285     kSS_MF_128 = (3U << SYSCON_PLL0SSCG1_MF_SHIFT), /*!< Nss = 128 (fm ? 15.6 - 31.3 kHz) */
1286     kSS_MF_64  = (4U << SYSCON_PLL0SSCG1_MF_SHIFT), /*!< Nss = 64 (fm ? 32.3 - 64.5 kHz) */
1287     kSS_MF_32  = (5U << SYSCON_PLL0SSCG1_MF_SHIFT), /*!< Nss = 32 (fm ? 62.5- 125 kHz) */
1288     kSS_MF_24  = (6U << SYSCON_PLL0SSCG1_MF_SHIFT), /*!< Nss ?= 24 (fm ? 83.3- 166.6 kHz) */
1289     kSS_MF_16  = (7U << SYSCON_PLL0SSCG1_MF_SHIFT)  /*!< Nss = 16 (fm ? 125- 250 kHz) */
1290 } ss_progmodfm_t;
1291 
1292 /*! @brief PLL Spread Spectrum (SS) Programmable frequency modulation depth
1293  * See (MR) field in the PLL0SSCG1 register in the UM.
1294  */
1295 typedef enum _ss_progmoddp
1296 {
1297     kSS_MR_K0   = (0U << SYSCON_PLL0SSCG1_MR_SHIFT), /*!< k = 0 (no spread spectrum) */
1298     kSS_MR_K1   = (1U << SYSCON_PLL0SSCG1_MR_SHIFT), /*!< k = 1 */
1299     kSS_MR_K1_5 = (2U << SYSCON_PLL0SSCG1_MR_SHIFT), /*!< k = 1.5 */
1300     kSS_MR_K2   = (3U << SYSCON_PLL0SSCG1_MR_SHIFT), /*!< k = 2 */
1301     kSS_MR_K3   = (4U << SYSCON_PLL0SSCG1_MR_SHIFT), /*!< k = 3 */
1302     kSS_MR_K4   = (5U << SYSCON_PLL0SSCG1_MR_SHIFT), /*!< k = 4 */
1303     kSS_MR_K6   = (6U << SYSCON_PLL0SSCG1_MR_SHIFT), /*!< k = 6 */
1304     kSS_MR_K8   = (7U << SYSCON_PLL0SSCG1_MR_SHIFT)  /*!< k = 8 */
1305 } ss_progmoddp_t;
1306 
1307 /*! @brief PLL Spread Spectrum (SS) Modulation waveform control
1308  * See (MC) field in the PLL0SSCG1 register in the UM.<br>
1309  * Compensation for low pass filtering of the PLL to get a triangular
1310  * modulation at the output of the PLL, giving a flat frequency spectrum.
1311  */
1312 typedef enum _ss_modwvctrl
1313 {
1314     kSS_MC_NOC  = (0U << SYSCON_PLL0SSCG1_MC_SHIFT), /*!< no compensation */
1315     kSS_MC_RECC = (2U << SYSCON_PLL0SSCG1_MC_SHIFT), /*!< recommended setting */
1316     kSS_MC_MAXC = (3U << SYSCON_PLL0SSCG1_MC_SHIFT), /*!< max. compensation */
1317 } ss_modwvctrl_t;
1318 
1319 /*! @brief PLL configuration structure
1320  *
1321  * This structure can be used to configure the settings for a PLL
1322  * setup structure. Fill in the desired configuration for the PLL
1323  * and call the PLL setup function to fill in a PLL setup structure.
1324  */
1325 typedef struct _pll_config
1326 {
1327     uint32_t desiredRate; /*!< Desired PLL rate in Hz */
1328     uint32_t inputRate;   /*!< PLL input clock in Hz, only used if PLL_CONFIGFLAG_USEINRATE flag is set */
1329     uint32_t flags;       /*!< PLL configuration flags, Or'ed value of PLL_CONFIGFLAG_* definitions */
1330     ss_progmodfm_t ss_mf; /*!< SS Programmable modulation frequency, only applicable when not using
1331                              PLL_CONFIGFLAG_FORCENOFRACT flag */
1332     ss_progmoddp_t ss_mr; /*!< SS Programmable frequency modulation depth, only applicable when not using
1333                              PLL_CONFIGFLAG_FORCENOFRACT flag */
1334     ss_modwvctrl_t
1335         ss_mc; /*!< SS Modulation waveform control, only applicable when not using PLL_CONFIGFLAG_FORCENOFRACT flag */
1336     bool mfDither; /*!< false for fixed modulation frequency or true for dithering, only applicable when not using
1337                       PLL_CONFIGFLAG_FORCENOFRACT flag */
1338 
1339 } pll_config_t;
1340 
1341 /*! @brief PLL setup structure flags for 'flags' field
1342  * These flags control how the PLL setup function sets up the PLL
1343  */
1344 #define PLL_SETUPFLAG_POWERUP         (1U << 0U) /*!< Setup will power on the PLL after setup */
1345 #define PLL_SETUPFLAG_WAITLOCK        (1U << 1U) /*!< Setup will wait for PLL lock, implies the PLL will be pwoered on */
1346 #define PLL_SETUPFLAG_ADGVOLT         (1U << 2U) /*!< Optimize system voltage for the new PLL rate */
1347 #define PLL_SETUPFLAG_USEFEEDBACKDIV2 (1U << 3U) /*!< Use feedback divider by 2 in divider path */
1348 
1349 /*! @brief PLL0 setup structure
1350  * This structure can be used to pre-build a PLL setup configuration
1351  * at run-time and quickly set the PLL to the configuration. It can be
1352  * populated with the PLL setup function. If powering up or waiting
1353  * for PLL lock, the PLL input clock source should be configured prior
1354  * to PLL setup.
1355  */
1356 typedef struct _pll_setup
1357 {
1358     uint32_t pllctrl;    /*!< PLL control register PLL0CTRL */
1359     uint32_t pllndec;    /*!< PLL NDEC register PLL0NDEC */
1360     uint32_t pllpdec;    /*!< PLL PDEC register PLL0PDEC */
1361     uint32_t pllmdec;    /*!< PLL MDEC registers PLL0PDEC */
1362     uint32_t pllsscg[2]; /*!< PLL SSCTL registers PLL0SSCG*/
1363     uint32_t pllRate;    /*!< Acutal PLL rate */
1364     uint32_t flags;      /*!< PLL setup flags, Or'ed value of PLL_SETUPFLAG_* definitions */
1365 } pll_setup_t;
1366 
1367 /*! @brief PLL status definitions
1368  */
1369 typedef enum _pll_error
1370 {
1371     kStatus_PLL_Success         = MAKE_STATUS(kStatusGroup_Generic, 0), /*!< PLL operation was successful */
1372     kStatus_PLL_OutputTooLow    = MAKE_STATUS(kStatusGroup_Generic, 1), /*!< PLL output rate request was too low */
1373     kStatus_PLL_OutputTooHigh   = MAKE_STATUS(kStatusGroup_Generic, 2), /*!< PLL output rate request was too high */
1374     kStatus_PLL_InputTooLow     = MAKE_STATUS(kStatusGroup_Generic, 3), /*!< PLL input rate is too low */
1375     kStatus_PLL_InputTooHigh    = MAKE_STATUS(kStatusGroup_Generic, 4), /*!< PLL input rate is too high */
1376     kStatus_PLL_OutsideIntLimit = MAKE_STATUS(kStatusGroup_Generic, 5), /*!< Requested output rate isn't possible */
1377     kStatus_PLL_CCOTooLow       = MAKE_STATUS(kStatusGroup_Generic, 6), /*!< Requested CCO rate isn't possible */
1378     kStatus_PLL_CCOTooHigh      = MAKE_STATUS(kStatusGroup_Generic, 7)  /*!< Requested CCO rate isn't possible */
1379 } pll_error_t;
1380 
1381 /*! @brief USB FS clock source definition. */
1382 typedef enum _clock_usbfs_src
1383 {
1384     kCLOCK_UsbfsSrcFro       = (uint32_t)kCLOCK_FroHf,      /*!< Use FRO 96 MHz. */
1385     kCLOCK_UsbfsSrcPll0      = (uint32_t)kCLOCK_Pll0Out,    /*!< Use PLL0 output. */
1386     kCLOCK_UsbfsSrcMainClock = (uint32_t)kCLOCK_CoreSysClk, /*!< Use Main clock.    */
1387     kCLOCK_UsbfsSrcPll1      = (uint32_t)kCLOCK_Pll1Out,    /*!< Use PLL1 clock.    */
1388 
1389     kCLOCK_UsbfsSrcNone =
1390         SYSCON_USB0CLKSEL_SEL(7) /*!<this may be selected in order to reduce power when no output is needed. */
1391 } clock_usbfs_src_t;
1392 
1393 /*! @brief USBhs clock source definition. */
1394 typedef enum _clock_usbhs_src
1395 {
1396     kCLOCK_UsbSrcUnused = 0xFFFFFFFFU, /*!< Used when the function does not
1397                                             care the clock source. */
1398 } clock_usbhs_src_t;
1399 
1400 /*! @brief Source of the USB HS PHY. */
1401 typedef enum _clock_usb_phy_src
1402 {
1403     kCLOCK_UsbPhySrcExt = 0U, /*!< Use external crystal. */
1404 } clock_usb_phy_src_t;
1405 
1406 /*! @brief    Return PLL0 output clock rate from setup structure
1407  *  @param    pSetup : Pointer to a PLL setup structure
1408  *  @return   System PLL output clock rate the setup structure will generate
1409  */
1410 uint32_t CLOCK_GetPLL0OutFromSetup(pll_setup_t *pSetup);
1411 
1412 /*! @brief    Return PLL1 output clock rate from setup structure
1413  *  @param    pSetup : Pointer to a PLL setup structure
1414  *  @return   PLL0 output clock rate the setup structure will generate
1415  */
1416 uint32_t CLOCK_GetPLL1OutFromSetup(pll_setup_t *pSetup);
1417 
1418 /*! @brief    Set PLL0 output based on the passed PLL setup data
1419  *  @param    pControl    : Pointer to populated PLL control structure to generate setup with
1420  *  @param    pSetup      : Pointer to PLL setup structure to be filled
1421  *  @return   PLL_ERROR_SUCCESS on success, or PLL setup error code
1422  *  @note Actual frequency for setup may vary from the desired frequency based on the
1423  *  accuracy of input clocks, rounding, non-fractional PLL mode, etc.
1424  */
1425 pll_error_t CLOCK_SetupPLL0Data(pll_config_t *pControl, pll_setup_t *pSetup);
1426 
1427 /*! @brief    Set PLL output from PLL setup structure (precise frequency)
1428  * @param pSetup  : Pointer to populated PLL setup structure
1429  * @param flagcfg : Flag configuration for PLL config structure
1430  * @return    PLL_ERROR_SUCCESS on success, or PLL setup error code
1431  * @note  This function will power off the PLL, setup the PLL with the
1432  * new setup data, and then optionally powerup the PLL, wait for PLL lock,
1433  * and adjust system voltages to the new PLL rate. The function will not
1434  * alter any source clocks (ie, main systen clock) that may use the PLL,
1435  * so these should be setup prior to and after exiting the function.
1436  */
1437 pll_error_t CLOCK_SetupPLL0Prec(pll_setup_t *pSetup, uint32_t flagcfg);
1438 
1439 /**
1440  * @brief Set PLL output from PLL setup structure (precise frequency)
1441  * @param pSetup  : Pointer to populated PLL setup structure
1442  * @return    kStatus_PLL_Success on success, or PLL setup error code
1443  * @note  This function will power off the PLL, setup the PLL with the
1444  * new setup data, and then optionally powerup the PLL, wait for PLL lock,
1445  * and adjust system voltages to the new PLL rate. The function will not
1446  * alter any source clocks (ie, main systen clock) that may use the PLL,
1447  * so these should be setup prior to and after exiting the function.
1448  */
1449 pll_error_t CLOCK_SetPLL0Freq(const pll_setup_t *pSetup);
1450 
1451 /**
1452  * @brief Set PLL output from PLL setup structure (precise frequency)
1453  * @param pSetup  : Pointer to populated PLL setup structure
1454  * @return    kStatus_PLL_Success on success, or PLL setup error code
1455  * @note  This function will power off the PLL, setup the PLL with the
1456  * new setup data, and then optionally powerup the PLL, wait for PLL lock,
1457  * and adjust system voltages to the new PLL rate. The function will not
1458  * alter any source clocks (ie, main systen clock) that may use the PLL,
1459  * so these should be setup prior to and after exiting the function.
1460  */
1461 pll_error_t CLOCK_SetPLL1Freq(const pll_setup_t *pSetup);
1462 
1463 /*! @brief    Set PLL0 output based on the multiplier and input frequency
1464  * @param multiply_by : multiplier
1465  * @param input_freq  : Clock input frequency of the PLL
1466  * @return    Nothing
1467  * @note  Unlike the Chip_Clock_SetupSystemPLLPrec() function, this
1468  * function does not disable or enable PLL power, wait for PLL lock,
1469  * or adjust system voltages. These must be done in the application.
1470  * The function will not alter any source clocks (ie, main systen clock)
1471  * that may use the PLL, so these should be setup prior to and after
1472  * exiting the function.
1473  */
1474 void CLOCK_SetupPLL0Mult(uint32_t multiply_by, uint32_t input_freq);
1475 
1476 /*! @brief Disable USB clock.
1477  *
1478  * Disable USB clock.
1479  */
CLOCK_DisableUsbDevicefs0Clock(clock_ip_name_t clk)1480 static inline void CLOCK_DisableUsbDevicefs0Clock(clock_ip_name_t clk)
1481 {
1482     CLOCK_DisableClock(clk);
1483 }
1484 
1485 /*! @brief Enable USB Device FS clock.
1486  * @param src : clock source
1487  * @param freq: clock frequency
1488  * Enable USB Device Full Speed clock.
1489  */
1490 bool CLOCK_EnableUsbfs0DeviceClock(clock_usbfs_src_t src, uint32_t freq);
1491 
1492 /*! @brief Enable USB HOST FS clock.
1493  * @param src : clock source
1494  * @param freq: clock frequency
1495  * Enable USB HOST Full Speed clock.
1496  */
1497 bool CLOCK_EnableUsbfs0HostClock(clock_usbfs_src_t src, uint32_t freq);
1498 
1499 /*! @brief Enable USB phy clock.
1500  * Enable USB phy clock.
1501  */
1502 bool CLOCK_EnableUsbhs0PhyPllClock(clock_usb_phy_src_t src, uint32_t freq);
1503 
1504 /*! @brief Enable USB Device HS clock.
1505  * Enable USB Device High Speed clock.
1506  */
1507 bool CLOCK_EnableUsbhs0DeviceClock(clock_usbhs_src_t src, uint32_t freq);
1508 
1509 /*! @brief Enable USB HOST HS clock.
1510  * Enable USB HOST High Speed clock.
1511  */
1512 bool CLOCK_EnableUsbhs0HostClock(clock_usbhs_src_t src, uint32_t freq);
1513 
1514 /*! @brief Enable the OSTIMER 32k clock.
1515  *  @return  Nothing
1516  */
1517 void CLOCK_EnableOstimer32kClock(void);
1518 
1519 #if defined(__cplusplus)
1520 }
1521 #endif /* __cplusplus */
1522 
1523 /*! @} */
1524 
1525 #endif /* _FSL_CLOCK_H_ */
1526