1 /*
2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
3 * Copyright 2016 - 2021, NXP
4 * All rights reserved.
5 *
6 *
7 * SPDX-License-Identifier: BSD-3-Clause
8 */
9
10 #ifndef _FSL_CLOCK_H_
11 #define _FSL_CLOCK_H_
12
13 #include "fsl_common.h"
14
15 /*! @addtogroup clock */
16 /*! @{ */
17
18 /*! @file */
19
20 /*******************************************************************************
21 * Definitions
22 *****************************************************************************/
23
24 /*! @name Driver version */
25 /*@{*/
26 /*! @brief CLOCK driver version 2.3.3. */
27 #define FSL_CLOCK_DRIVER_VERSION (MAKE_VERSION(2, 3, 3))
28 /*@}*/
29
30 /*! @brief Configure whether driver controls clock
31 *
32 * When set to 0, peripheral drivers will enable clock in initialize function
33 * and disable clock in de-initialize function. When set to 1, peripheral
34 * driver will not control the clock, application could control the clock out of
35 * the driver.
36 *
37 * @note All drivers share this feature switcher. If it is set to 1, application
38 * should handle clock enable and disable for all drivers.
39 */
40 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL))
41 #define FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL 0
42 #endif
43
44 /*!
45 * @brief User-defined the size of cache for CLOCK_PllGetConfig() function.
46 *
47 * Once define this MACRO to be non-zero value, CLOCK_PllGetConfig() function
48 * would cache the recent calulation and accelerate the execution to get the
49 * right settings.
50 */
51 #ifndef CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT
52 #define CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT 2U
53 #endif
54
55 /* Definition for delay API in clock driver, users can redefine it to the real application. */
56 #ifndef SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY
57 #define SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY (180000000UL)
58 #endif
59
60 /*! @brief Clock ip name array for ADC. */
61 #define ADC_CLOCKS \
62 { \
63 kCLOCK_Adc0 \
64 }
65 /*! @brief Clock ip name array for ROM. */
66 #define ROM_CLOCKS \
67 { \
68 kCLOCK_Rom \
69 }
70 /*! @brief Clock ip name array for SRAM. */
71 #define SRAM_CLOCKS \
72 { \
73 kCLOCK_Sram1, kCLOCK_Sram2, kCLOCK_Sram3 \
74 }
75 /*! @brief Clock ip name array for FLASH. */
76 #define FLASH_CLOCKS \
77 { \
78 kCLOCK_Flash \
79 }
80 /*! @brief Clock ip name array for FMC. */
81 #define FMC_CLOCKS \
82 { \
83 kCLOCK_Fmc \
84 }
85 /*! @brief Clock ip name array for EEPROM. */
86 #define EEPROM_CLOCKS \
87 { \
88 kCLOCK_Eeprom \
89 }
90 /*! @brief Clock ip name array for SPIFI. */
91 #define SPIFI_CLOCKS \
92 { \
93 kCLOCK_Spifi \
94 }
95 /*! @brief Clock ip name array for INPUTMUX. */
96 #define INPUTMUX_CLOCKS \
97 { \
98 kCLOCK_InputMux \
99 }
100 /*! @brief Clock ip name array for IOCON. */
101 #define IOCON_CLOCKS \
102 { \
103 kCLOCK_Iocon \
104 }
105 /*! @brief Clock ip name array for GPIO. */
106 #define GPIO_CLOCKS \
107 { \
108 kCLOCK_Gpio0, kCLOCK_Gpio1, kCLOCK_Gpio2, kCLOCK_Gpio3, kCLOCK_Gpio4, kCLOCK_Gpio5 \
109 }
110 /*! @brief Clock ip name array for PINT. */
111 #define PINT_CLOCKS \
112 { \
113 kCLOCK_Pint \
114 }
115 /*! @brief Clock ip name array for GINT. */
116 #define GINT_CLOCKS \
117 { \
118 kCLOCK_Gint, kCLOCK_Gint \
119 }
120 /*! @brief Clock ip name array for DMA. */
121 #define DMA_CLOCKS \
122 { \
123 kCLOCK_Dma \
124 }
125 /*! @brief Clock ip name array for CRC. */
126 #define CRC_CLOCKS \
127 { \
128 kCLOCK_Crc \
129 }
130 /*! @brief Clock ip name array for WWDT. */
131 #define WWDT_CLOCKS \
132 { \
133 kCLOCK_Wwdt \
134 }
135 /*! @brief Clock ip name array for RTC. */
136 #define RTC_CLOCKS \
137 { \
138 kCLOCK_Rtc \
139 }
140 /*! @brief Clock ip name array for ADC0. */
141 #define ADC0_CLOCKS \
142 { \
143 kCLOCK_Adc0 \
144 }
145 /*! @brief Clock ip name array for MRT. */
146 #define MRT_CLOCKS \
147 { \
148 kCLOCK_Mrt \
149 }
150 /*! @brief Clock ip name array for RIT. */
151 #define RIT_CLOCKS \
152 { \
153 kCLOCK_Rit \
154 }
155 /*! @brief Clock ip name array for SCT0. */
156 #define SCT_CLOCKS \
157 { \
158 kCLOCK_Sct0 \
159 }
160 /*! @brief Clock ip name array for MCAN. */
161 #define MCAN_CLOCKS \
162 { \
163 kCLOCK_Mcan0, kCLOCK_Mcan1 \
164 }
165 /*! @brief Clock ip name array for UTICK. */
166 #define UTICK_CLOCKS \
167 { \
168 kCLOCK_Utick \
169 }
170 /*! @brief Clock ip name array for FLEXCOMM. */
171 #define FLEXCOMM_CLOCKS \
172 { \
173 kCLOCK_FlexComm0, kCLOCK_FlexComm1, kCLOCK_FlexComm2, kCLOCK_FlexComm3, kCLOCK_FlexComm4, kCLOCK_FlexComm5, \
174 kCLOCK_FlexComm6, kCLOCK_FlexComm7, kCLOCK_FlexComm8, kCLOCK_FlexComm9, kCLOCK_FlexComm10 \
175 }
176 /*! @brief Clock ip name array for LPUART. */
177 #define LPUART_CLOCKS \
178 { \
179 kCLOCK_MinUart0, kCLOCK_MinUart1, kCLOCK_MinUart2, kCLOCK_MinUart3, kCLOCK_MinUart4, kCLOCK_MinUart5, \
180 kCLOCK_MinUart6, kCLOCK_MinUart7, kCLOCK_MinUart8, kCLOCK_MinUart9 \
181 }
182
183 /*! @brief Clock ip name array for BI2C. */
184 #define BI2C_CLOCKS \
185 { \
186 kCLOCK_BI2c0, kCLOCK_BI2c1, kCLOCK_BI2c2, kCLOCK_BI2c3, kCLOCK_BI2c4, kCLOCK_BI2c5, kCLOCK_BI2c6, \
187 kCLOCK_BI2c7, kCLOCK_BI2c8, kCLOCK_BI2c9 \
188 }
189 /*! @brief Clock ip name array for LSPI. */
190 #define LPSI_CLOCKS \
191 { \
192 kCLOCK_LSpi0, kCLOCK_LSpi1, kCLOCK_LSpi2, kCLOCK_LSpi3, kCLOCK_LSpi4, kCLOCK_LSpi5, kCLOCK_LSpi6, \
193 kCLOCK_LSpi7, kCLOCK_LSpi8, kCLOCK_LSpi9 \
194 }
195 /*! @brief Clock ip name array for FLEXI2S. */
196 #define FLEXI2S_CLOCKS \
197 { \
198 kCLOCK_FlexI2s0, kCLOCK_FlexI2s1, kCLOCK_FlexI2s2, kCLOCK_FlexI2s3, kCLOCK_FlexI2s4, kCLOCK_FlexI2s5, \
199 kCLOCK_FlexI2s6, kCLOCK_FlexI2s7, kCLOCK_FlexI2s8, kCLOCK_FlexI2s9 \
200 }
201 /*! @brief Clock ip name array for DMIC. */
202 #define DMIC_CLOCKS \
203 { \
204 kCLOCK_DMic \
205 }
206 /*! @brief Clock ip name array for CT32B. */
207 #define CTIMER_CLOCKS \
208 { \
209 kCLOCK_Ct32b0, kCLOCK_Ct32b1, kCLOCK_Ct32b2, kCLOCK_Ct32b3, kCLOCK_Ct32b4 \
210 }
211 /*! @brief Clock ip name array for LCD. */
212 #define LCD_CLOCKS \
213 { \
214 kCLOCK_Lcd \
215 }
216 /*! @brief Clock ip name array for SDIO. */
217 #define SDIO_CLOCKS \
218 { \
219 kCLOCK_Sdio \
220 }
221 /*! @brief Clock ip name array for USBRAM. */
222 #define USBRAM_CLOCKS \
223 { \
224 kCLOCK_UsbRam1 \
225 }
226 /*! @brief Clock ip name array for EMC. */
227 #define EMC_CLOCKS \
228 { \
229 kCLOCK_Emc \
230 }
231 /*! @brief Clock ip name array for ETH. */
232 #define ETH_CLOCKS \
233 { \
234 kCLOCK_Eth \
235 }
236 /*! @brief Clock ip name array for AES. */
237 #define AES_CLOCKS \
238 { \
239 kCLOCK_Aes \
240 }
241 /*! @brief Clock ip name array for OTP. */
242 #define OTP_CLOCKS \
243 { \
244 kCLOCK_Otp \
245 }
246 /*! @brief Clock ip name array for RNG. */
247 #define RNG_CLOCKS \
248 { \
249 kCLOCK_Rng \
250 }
251 /*! @brief Clock ip name array for USBHMR0. */
252 #define USBHMR0_CLOCKS \
253 { \
254 kCLOCK_Usbhmr0 \
255 }
256 /*! @brief Clock ip name array for USBHSL0. */
257 #define USBHSL0_CLOCKS \
258 { \
259 kCLOCK_Usbhsl0 \
260 }
261 /*! @brief Clock ip name array for SHA0. */
262 #define SHA0_CLOCKS \
263 { \
264 kCLOCK_Sha0 \
265 }
266 /*! @brief Clock ip name array for SMARTCARD. */
267 #define SMARTCARD_CLOCKS \
268 { \
269 kCLOCK_SmartCard0, kCLOCK_SmartCard1 \
270 }
271 /*! @brief Clock ip name array for USBD. */
272 #define USBD_CLOCKS \
273 { \
274 kCLOCK_Usbd0, kCLOCK_Usbh1, kCLOCK_Usbd1 \
275 }
276 /*! @brief Clock ip name array for USBH. */
277 #define USBH_CLOCKS \
278 { \
279 kCLOCK_Usbh1 \
280 }
281 /*! @brief Clock gate name used for CLOCK_EnableClock/CLOCK_DisableClock. */
282 /*------------------------------------------------------------------------------
283 clock_ip_name_t definition:
284 ------------------------------------------------------------------------------*/
285
286 #define CLK_GATE_REG_OFFSET_SHIFT 8U
287 #define CLK_GATE_REG_OFFSET_MASK 0xFFFFFF00U
288 #define CLK_GATE_BIT_SHIFT_SHIFT 0U
289 #define CLK_GATE_BIT_SHIFT_MASK 0x000000FFU
290
291 #define CLK_GATE_DEFINE(reg_offset, bit_shift) \
292 ((((reg_offset) << CLK_GATE_REG_OFFSET_SHIFT) & CLK_GATE_REG_OFFSET_MASK) | \
293 (((bit_shift) << CLK_GATE_BIT_SHIFT_SHIFT) & CLK_GATE_BIT_SHIFT_MASK))
294
295 #define CLK_GATE_ABSTRACT_REG_OFFSET(x) (((uint32_t)(x)&CLK_GATE_REG_OFFSET_MASK) >> CLK_GATE_REG_OFFSET_SHIFT)
296 #define CLK_GATE_ABSTRACT_BITS_SHIFT(x) (((uint32_t)(x)&CLK_GATE_BIT_SHIFT_MASK) >> CLK_GATE_BIT_SHIFT_SHIFT)
297
298 #define AHB_CLK_CTRL0 0
299 #define AHB_CLK_CTRL1 1
300 #define AHB_CLK_CTRL2 2
301 #define ASYNC_CLK_CTRL0 3
302
303 /*! @brief Clock gate name used for CLOCK_EnableClock/CLOCK_DisableClock. */
304 typedef enum _clock_ip_name
305 {
306 kCLOCK_IpInvalid = 0U, /*!< Invalid Ip Name. */
307 kCLOCK_Rom = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 1), /*!< Clock gate name: Rom. */
308
309 kCLOCK_Sram1 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 3), /*!< Clock gate name: Sram1. */
310
311 kCLOCK_Sram2 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 4), /*!< Clock gate name: Sram2. */
312
313 kCLOCK_Sram3 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 5), /*!< Clock gate name: Sram3. */
314
315 kCLOCK_Spifi = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 10), /*!< Clock gate name: Spifi. */
316
317 kCLOCK_InputMux = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 11), /*!< Clock gate name: InputMux. */
318
319 kCLOCK_Iocon = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 13), /*!< Clock gate name: Iocon. */
320
321 kCLOCK_Gpio0 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 14), /*!< Clock gate name: Gpio0. */
322
323 kCLOCK_Gpio1 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 15), /*!< Clock gate name: Gpio1. */
324
325 kCLOCK_Gpio2 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 16), /*!< Clock gate name: Gpio2. */
326
327 kCLOCK_Gpio3 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 17), /*!< Clock gate name: Gpio3. */
328
329 kCLOCK_Pint = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 18), /*!< Clock gate name: Pint. */
330
331 kCLOCK_Gint = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 19), /*!< Clock gate name: Gint. */
332
333 kCLOCK_Dma = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 20), /*!< Clock gate name: Dma. */
334
335 kCLOCK_Crc = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 21), /*!< Clock gate name: Crc. */
336
337 kCLOCK_Wwdt = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 22), /*!< Clock gate name: Wwdt. */
338
339 kCLOCK_Rtc = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 23), /*!< Clock gate name: Rtc. */
340
341 kCLOCK_Adc0 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 27), /*!< Clock gate name: Adc0. */
342
343 kCLOCK_Mrt = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 0), /*!< Clock gate name: Mrt. */
344
345 kCLOCK_Rit = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 1), /*!< Clock gate name: Rit. */
346
347 kCLOCK_Sct0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 2), /*!< Clock gate name: Sct0. */
348
349 kCLOCK_Mcan0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 7), /*!< Clock gate name: Mcan0. */
350
351 kCLOCK_Mcan1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 8), /*!< Clock gate name: Mcan1. */
352
353 kCLOCK_Utick = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 10), /*!< Clock gate name: Utick. */
354
355 kCLOCK_FlexComm0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11), /*!< Clock gate name: FlexComm0. */
356
357 kCLOCK_FlexComm1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12), /*!< Clock gate name: FlexComm1. */
358
359 kCLOCK_FlexComm2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13), /*!< Clock gate name: FlexComm2. */
360
361 kCLOCK_FlexComm3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14), /*!< Clock gate name: FlexComm3. */
362
363 kCLOCK_FlexComm4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15), /*!< Clock gate name: FlexComm4. */
364
365 kCLOCK_FlexComm5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16), /*!< Clock gate name: FlexComm5. */
366
367 kCLOCK_FlexComm6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17), /*!< Clock gate name: FlexComm6. */
368
369 kCLOCK_FlexComm7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18), /*!< Clock gate name: FlexComm7. */
370
371 kCLOCK_MinUart0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11), /*!< Clock gate name: MinUart0. */
372
373 kCLOCK_MinUart1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12), /*!< Clock gate name: MinUart1. */
374
375 kCLOCK_MinUart2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13), /*!< Clock gate name: MinUart2. */
376
377 kCLOCK_MinUart3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14), /*!< Clock gate name: MinUart3. */
378
379 kCLOCK_MinUart4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15), /*!< Clock gate name: MinUart4. */
380
381 kCLOCK_MinUart5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16), /*!< Clock gate name: MinUart5. */
382
383 kCLOCK_MinUart6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17), /*!< Clock gate name: MinUart6. */
384
385 kCLOCK_MinUart7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18), /*!< Clock gate name: MinUart7. */
386
387 kCLOCK_LSpi0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11), /*!< Clock gate name: LSpi0. */
388
389 kCLOCK_LSpi1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12), /*!< Clock gate name: LSpi1. */
390
391 kCLOCK_LSpi2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13), /*!< Clock gate name: LSpi2. */
392
393 kCLOCK_LSpi3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14), /*!< Clock gate name: LSpi3. */
394
395 kCLOCK_LSpi4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15), /*!< Clock gate name: LSpi4. */
396
397 kCLOCK_LSpi5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16), /*!< Clock gate name: LSpi5. */
398
399 kCLOCK_LSpi6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17), /*!< Clock gate name: LSpi6. */
400
401 kCLOCK_LSpi7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18), /*!< Clock gate name: LSpi7. */
402
403 kCLOCK_BI2c0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11), /*!< Clock gate name: BI2c0. */
404
405 kCLOCK_BI2c1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12), /*!< Clock gate name: BI2c1. */
406
407 kCLOCK_BI2c2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13), /*!< Clock gate name: BI2c2. */
408
409 kCLOCK_BI2c3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14), /*!< Clock gate name: BI2c3. */
410
411 kCLOCK_BI2c4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15), /*!< Clock gate name: BI2c4. */
412
413 kCLOCK_BI2c5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16), /*!< Clock gate name: BI2c5. */
414
415 kCLOCK_BI2c6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17), /*!< Clock gate name: BI2c6. */
416
417 kCLOCK_BI2c7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18), /*!< Clock gate name: BI2c7. */
418
419 kCLOCK_FlexI2s0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11), /*!< Clock gate name: FlexI2s0. */
420
421 kCLOCK_FlexI2s1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12), /*!< Clock gate name: FlexI2s1. */
422
423 kCLOCK_FlexI2s2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13), /*!< Clock gate name: FlexI2s2. */
424
425 kCLOCK_FlexI2s3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14), /*!< Clock gate name: FlexI2s3. */
426
427 kCLOCK_FlexI2s4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15), /*!< Clock gate name: FlexI2s4. */
428
429 kCLOCK_FlexI2s5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16), /*!< Clock gate name: FlexI2s5. */
430
431 kCLOCK_FlexI2s6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17), /*!< Clock gate name: FlexI2s6. */
432
433 kCLOCK_FlexI2s7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18), /*!< Clock gate name: FlexI2s7. */
434
435 kCLOCK_DMic = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 19), /*!< Clock gate name: DMic. */
436
437 kCLOCK_Ct32b2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 22), /*!< Clock gate name: Ct32b2. */
438
439 kCLOCK_Usbd0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 25), /*!< Clock gate name: Usbd0. */
440
441 kCLOCK_Ct32b0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 26), /*!< Clock gate name: Ct32b0. */
442
443 kCLOCK_Ct32b1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 27), /*!< Clock gate name: Ct32b1. */
444
445 kCLOCK_BodyBias0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 29), /*!< Clock gate name: BodyBias0. */
446
447 kCLOCK_EzhArchB0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 31), /*!< Clock gate name: EzhArchB0. */
448
449 kCLOCK_Lcd = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 2), /*!< Clock gate name: Lcd. */
450
451 kCLOCK_Sdio = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 3), /*!< Clock gate name: Sdio. */
452
453 kCLOCK_Usbh1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 4), /*!< Clock gate name: Usbh1. */
454
455 kCLOCK_Usbd1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 5), /*!< Clock gate name: Usbd1. */
456
457 kCLOCK_UsbRam1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 6), /*!< Clock gate name: UsbRam1. */
458
459 kCLOCK_Emc = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 7), /*!< Clock gate name: Emc. */
460
461 kCLOCK_Eth = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 8), /*!< Clock gate name: Eth. */
462
463 kCLOCK_Gpio4 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 9), /*!< Clock gate name: Gpio4. */
464
465 kCLOCK_Gpio5 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 10), /*!< Clock gate name: Gpio5. */
466
467 kCLOCK_Aes = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 11), /*!< Clock gate name: Aes. */
468
469 kCLOCK_Otp = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 12), /*!< Clock gate name: Otp. */
470
471 kCLOCK_Rng = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 13), /*!< Clock gate name: Rng. */
472
473 kCLOCK_FlexComm8 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 14), /*!< Clock gate name: FlexComm8. */
474
475 kCLOCK_FlexComm9 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 15), /*!< Clock gate name: FlexComm9. */
476
477 kCLOCK_MinUart8 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 14), /*!< Clock gate name: MinUart8. */
478
479 kCLOCK_MinUart9 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 15), /*!< Clock gate name: MinUart9. */
480
481 kCLOCK_LSpi8 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 14), /*!< Clock gate name: LSpi8. */
482
483 kCLOCK_LSpi9 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 15), /*!< Clock gate name: LSpi9. */
484
485 kCLOCK_BI2c8 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 14), /*!< Clock gate name: BI2c8. */
486
487 kCLOCK_BI2c9 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 15), /*!< Clock gate name: BI2c9. */
488
489 kCLOCK_FlexI2s8 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 14), /*!< Clock gate name: FlexI2s8. */
490
491 kCLOCK_FlexI2s9 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 15), /*!< Clock gate name: FlexI2s9. */
492
493 kCLOCK_Usbhmr0 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 16), /*!< Clock gate name: Usbhmr0. */
494
495 kCLOCK_Usbhsl0 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 17), /*!< Clock gate name: Usbhsl0. */
496
497 kCLOCK_Sha0 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 18), /*!< Clock gate name: Sha0. */
498
499 kCLOCK_SmartCard0 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 19), /*!< Clock gate name: SmartCard0. */
500
501 kCLOCK_SmartCard1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 20), /*!< Clock gate name: SmartCard1. */
502
503 kCLOCK_FlexComm10 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 21), /*!< Clock gate name: FlexComm10. */
504
505 kCLOCK_Puf = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 23), /*!< Clock gate name: Puf. */
506
507 kCLOCK_Ct32b3 = CLK_GATE_DEFINE(ASYNC_CLK_CTRL0, 13), /*!< Clock gate name: Ct32b3. */
508
509 kCLOCK_Ct32b4 = CLK_GATE_DEFINE(ASYNC_CLK_CTRL0, 14) /*!< Clock gate name: Ct32b4. */
510 } clock_ip_name_t;
511
512 /*! @brief Clock name used to get clock frequency. */
513 typedef enum _clock_name
514 {
515 kCLOCK_CoreSysClk, /*!< Core/system clock (aka MAIN_CLK) */
516 kCLOCK_BusClk, /*!< Bus clock (AHB clock) */
517 kCLOCK_ClockOut, /*!< CLOCKOUT */
518 kCLOCK_FroHf, /*!< FRO48/96 */
519 kCLOCK_UsbPll, /*!< USB1 PLL */
520 kCLOCK_Mclk, /*!< MCLK */
521 kCLOCK_Fro12M, /*!< FRO12M */
522 kCLOCK_ExtClk, /*!< External Clock */
523 kCLOCK_PllOut, /*!< PLL Output */
524 kCLOCK_UsbClk, /*!< USB input */
525 kCLOCK_WdtOsc, /*!< Watchdog Oscillator */
526 kCLOCK_Frg, /*!< Frg Clock */
527 kCLOCK_AsyncApbClk, /*!< Async APB clock */
528 } clock_name_t;
529
530 /**
531 * @brief Clock source selections for the asynchronous APB clock
532 */
533 typedef enum _async_clock_src
534 {
535 kCLOCK_AsyncMainClk = 0, /*!< Main System clock */
536 kCLOCK_AsyncFro12Mhz, /*!< 12MHz FRO */
537 kCLOCK_AsyncAudioPllClk, /*!< Async Audio PLL clock. */
538 kCLOCK_AsyncI2cClkFc6, /*!< Async I2C clock. */
539
540 } async_clock_src_t;
541
542 /*! @brief Clock Mux Switches
543 * The encoding is as follows each connection identified is 32bits wide while 24bits are valuable
544 * starting from LSB upwards
545 *
546 * [4 bits for choice, 0 means invalid choice] [8 bits mux ID]*
547 *
548 */
549
550 #define CLK_ATTACH_ID(mux, sel, pos) ((((uint32_t)(mux) << 0U) | (((uint32_t)(sel) + 1U) & 0xFU) << 8U) << ((pos)*12U))
551 #define MUX_A_OFFSET(mux) ((mux) << 0U)
552 #define MUX_A(mux, sel) CLK_ATTACH_ID((mux), (sel), 0U)
553 #define MUX_B(mux, sel, selector) (CLK_ATTACH_ID((mux), (sel), 1U) | ((selector) << 24U))
554
555 #define GET_ID_ITEM(connection) ((connection)&0xFFFU)
556 #define GET_ID_NEXT_ITEM(connection) ((connection) >> 12U)
557 #define GET_ID_ITEM_MUX(connection) ((uint8_t)((connection)&0xFFU))
558 #define GET_ID_ITEM_SEL(connection) ((uint8_t)((((connection)&0xF00U) >> 8U) - 1U))
559 #define GET_ID_SELECTOR(connection) ((connection)&0xF000000U)
560 #define CLR_ID_ITEM_SEL(connection) ((connection) &= 0xFFFFF0FFU)
561
562 #define CM_STICKCLKSEL 0
563 #define CM_MAINCLKSELA 1
564 #define CM_MAINCLKSELB 2
565 #define CM_CLKOUTCLKSELA 3
566 #define CM_SYSPLLCLKSEL 5
567 #define CM_AUDPLLCLKSEL 7
568 #define CM_SPIFICLKSEL 9
569 #define CM_ADCASYNCCLKSEL 10
570 #define CM_USB0CLKSEL 11
571 #define CM_USB1CLKSEL 12
572 #define CM_FXCOMCLKSEL0 13
573 #define CM_FXCOMCLKSEL1 14
574 #define CM_FXCOMCLKSEL2 15
575 #define CM_FXCOMCLKSEL3 16
576 #define CM_FXCOMCLKSEL4 17
577 #define CM_FXCOMCLKSEL5 18
578 #define CM_FXCOMCLKSEL6 19
579 #define CM_FXCOMCLKSEL7 20
580 #define CM_FXCOMCLKSEL8 21
581 #define CM_FXCOMCLKSEL9 22
582 #define CM_FXCOMCLKSEL10 23
583 #define CM_MCLKCLKSEL 25
584 #define CM_FRGCLKSEL 27
585 #define CM_DMICCLKSEL 28
586 #define CM_SCTCLKSEL 29
587 #define CM_LCDCLKSEL 30
588 #define CM_SDIOCLKSEL 31
589
590 #define CM_ASYNCAPB 32U
591
592 /*!
593 * @brief The enumerator of clock attach Id.
594 */
595 typedef enum _clock_attach_id
596 {
597
598 kSYSTICK_DIV_CLK_to_SYSTICKCLK = MUX_A(CM_STICKCLKSEL, 0), /*!< Attach SYSTICK_DIV_CLK to SYSTICKCLK. */
599
600 kWDT_OSC_to_SYSTICKCLK = MUX_A(CM_STICKCLKSEL, 1), /*!< Attach WDT_OSC to SYSTICKCLK. */
601
602 kOSC32K_to_SYSTICKCLK = MUX_A(CM_STICKCLKSEL, 2), /*!< Attach OSC32K to SYSTICKCLK. */
603
604 kFRO12M_to_SYSTICKCLK = MUX_A(CM_STICKCLKSEL, 3), /*!< Attach FRO12M to SYSTICKCLK. */
605
606 kNONE_to_SYSTICKCLK = MUX_A(CM_STICKCLKSEL, 7), /*!< Attach NONE to SYSTICKCLK. */
607
608 kFRO12M_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 0, 0), /*!< Attach FRO12M to MAIN_CLK. */
609
610 kEXT_CLK_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 1) | MUX_B(CM_MAINCLKSELB, 0, 0), /*!< Attach EXT_CLK to MAIN_CLK. */
611
612 kWDT_OSC_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 2) | MUX_B(CM_MAINCLKSELB, 0, 0), /*!< Attach WDT_OSC to MAIN_CLK. */
613
614 kFRO_HF_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 3) | MUX_B(CM_MAINCLKSELB, 0, 0), /*!< Attach FRO_HF to MAIN_CLK. */
615
616 kSYS_PLL_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 2, 0), /*!< Attach SYS_PLL to MAIN_CLK. */
617
618 kOSC32K_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 3, 0), /*!< Attach OSC32K to MAIN_CLK. */
619
620 kMAIN_CLK_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 0), /*!< Attach MAIN_CLK to CLKOUT. */
621
622 kEXT_CLK_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 1), /*!< Attach EXT_CLK to CLKOUT. */
623
624 kWDT_OSC_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 2), /*!< Attach WDT_OSC to CLKOUT. */
625
626 kFRO_HF_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 3), /*!< Attach FRO_HF to CLKOUT. */
627
628 kSYS_PLL_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 4), /*!< Attach SYS_PLL to CLKOUT. */
629
630 kUSB_PLL_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 5), /*!< Attach USB_PLL to CLKOUT. */
631
632 kAUDIO_PLL_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 6), /*!< Attach AUDIO_PLL to CLKOUT. */
633
634 kOSC32K_OSC_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 7), /*!< Attach OSC32K_OSC to CLKOUT. */
635
636 kFRO12M_to_SYS_PLL = MUX_A(CM_SYSPLLCLKSEL, 0), /*!< Attach FRO12M to SYS_PLL. */
637
638 kEXT_CLK_to_SYS_PLL = MUX_A(CM_SYSPLLCLKSEL, 1), /*!< Attach EXT_CLK to SYS_PLL. */
639
640 kWDT_OSC_to_SYS_PLL = MUX_A(CM_SYSPLLCLKSEL, 2), /*!< Attach WDT_OSC to SYS_PLL. */
641
642 kOSC32K_to_SYS_PLL = MUX_A(CM_SYSPLLCLKSEL, 3), /*!< Attach OSC32K to SYS_PLL. */
643
644 kNONE_to_SYS_PLL = MUX_A(CM_SYSPLLCLKSEL, 7), /*!< Attach NONE to SYS_PLL. */
645
646 kFRO12M_to_AUDIO_PLL = MUX_A(CM_AUDPLLCLKSEL, 0), /*!< Attach FRO12M to AUDIO_PLL. */
647
648 kEXT_CLK_to_AUDIO_PLL = MUX_A(CM_AUDPLLCLKSEL, 1), /*!< Attach EXT_CLK to AUDIO_PLL. */
649
650 kNONE_to_AUDIO_PLL = MUX_A(CM_AUDPLLCLKSEL, 7), /*!< Attach NONE to AUDIO_PLL. */
651
652 kMAIN_CLK_to_SPIFI_CLK = MUX_A(CM_SPIFICLKSEL, 0), /*!< Attach MAIN_CLK to SPIFI_CLK. */
653
654 kSYS_PLL_to_SPIFI_CLK = MUX_A(CM_SPIFICLKSEL, 1), /*!< Attach SYS_PLL to SPIFI_CLK. */
655
656 kUSB_PLL_to_SPIFI_CLK = MUX_A(CM_SPIFICLKSEL, 2), /*!< Attach USB_PLL to SPIFI_CLK. */
657
658 kFRO_HF_to_SPIFI_CLK = MUX_A(CM_SPIFICLKSEL, 3), /*!< Attach FRO_HF to SPIFI_CLK. */
659
660 kAUDIO_PLL_to_SPIFI_CLK = MUX_A(CM_SPIFICLKSEL, 4), /*!< Attach AUDIO_PLL to SPIFI_CLK. */
661
662 kNONE_to_SPIFI_CLK = MUX_A(CM_SPIFICLKSEL, 7), /*!< Attach NONE to SPIFI_CLK. */
663
664 kFRO_HF_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 0), /*!< Attach FRO_HF to ADC_CLK. */
665
666 kSYS_PLL_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 1), /*!< Attach SYS_PLL to ADC_CLK. */
667
668 kUSB_PLL_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 2), /*!< Attach USB_PLL to ADC_CLK. */
669
670 kAUDIO_PLL_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 3), /*!< Attach AUDIO_PLL to ADC_CLK. */
671
672 kNONE_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 7), /*!< Attach NONE to ADC_CLK. */
673
674 kFRO_HF_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 0), /*!< Attach FRO_HF to USB0_CLK. */
675
676 kSYS_PLL_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 1), /*!< Attach SYS_PLL to USB0_CLK. */
677
678 kUSB_PLL_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 2), /*!< Attach USB_PLL to USB0_CLK. */
679
680 kNONE_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 7), /*!< Attach NONE to USB0_CLK. */
681
682 kFRO_HF_to_USB1_CLK = MUX_A(CM_USB1CLKSEL, 0), /*!< Attach FRO_HF to USB1_CLK. */
683
684 kSYS_PLL_to_USB1_CLK = MUX_A(CM_USB1CLKSEL, 1), /*!< Attach SYS_PLL to USB1_CLK. */
685
686 kUSB_PLL_to_USB1_CLK = MUX_A(CM_USB1CLKSEL, 2), /*!< Attach USB_PLL to USB1_CLK. */
687
688 kNONE_to_USB1_CLK = MUX_A(CM_USB1CLKSEL, 7), /*!< Attach NONE to USB1_CLK. */
689
690 kFRO12M_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 0), /*!< Attach FRO12M to FLEXCOMM0. */
691
692 kFRO_HF_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 1), /*!< Attach FRO_HF to FLEXCOMM0. */
693
694 kAUDIO_PLL_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 2), /*!< Attach AUDIO_PLL to FLEXCOMM0. */
695
696 kMCLK_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 3), /*!< Attach MCLK to FLEXCOMM0. */
697
698 kFRG_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 4), /*!< Attach FRG to FLEXCOMM0. */
699
700 kNONE_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 7), /*!< Attach NONE to FLEXCOMM0. */
701
702 kFRO12M_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 0), /*!< Attach FRO12M to FLEXCOMM1. */
703
704 kFRO_HF_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 1), /*!< Attach FRO_HF to FLEXCOMM1. */
705
706 kAUDIO_PLL_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 2), /*!< Attach AUDIO_PLL to FLEXCOMM1. */
707
708 kMCLK_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 3), /*!< Attach MCLK to FLEXCOMM1. */
709
710 kFRG_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 4), /*!< Attach FRG to FLEXCOMM1. */
711
712 kNONE_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 7), /*!< Attach NONE to FLEXCOMM1. */
713
714 kFRO12M_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 0), /*!< Attach FRO12M to FLEXCOMM2. */
715
716 kFRO_HF_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 1), /*!< Attach FRO_HF to FLEXCOMM2. */
717
718 kAUDIO_PLL_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 2), /*!< Attach AUDIO_PLL to FLEXCOMM2. */
719
720 kMCLK_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 3), /*!< Attach MCLK to FLEXCOMM2. */
721
722 kFRG_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 4), /*!< Attach FRG to FLEXCOMM2. */
723
724 kNONE_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 7), /*!< Attach NONE to FLEXCOMM2. */
725
726 kFRO12M_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 0), /*!< Attach FRO12M to FLEXCOMM3. */
727
728 kFRO_HF_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 1), /*!< Attach FRO_HF to FLEXCOMM3. */
729
730 kAUDIO_PLL_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 2), /*!< Attach AUDIO_PLL to FLEXCOMM3. */
731
732 kMCLK_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 3), /*!< Attach MCLK to FLEXCOMM3. */
733
734 kFRG_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 4), /*!< Attach FRG to FLEXCOMM3. */
735
736 kNONE_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 7), /*!< Attach NONE to FLEXCOMM3. */
737
738 kFRO12M_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 0), /*!< Attach FRO12M to FLEXCOMM4. */
739
740 kFRO_HF_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 1), /*!< Attach FRO_HF to FLEXCOMM4. */
741
742 kAUDIO_PLL_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 2), /*!< Attach AUDIO_PLL to FLEXCOMM4. */
743
744 kMCLK_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 3), /*!< Attach MCLK to FLEXCOMM4. */
745
746 kFRG_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 4), /*!< Attach FRG to FLEXCOMM4. */
747
748 kNONE_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 7), /*!< Attach NONE to FLEXCOMM4. */
749
750 kFRO12M_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 0), /*!< Attach FRO12M to FLEXCOMM5. */
751
752 kFRO_HF_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 1), /*!< Attach FRO_HF to FLEXCOMM5. */
753
754 kAUDIO_PLL_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 2), /*!< Attach AUDIO_PLL to FLEXCOMM5. */
755
756 kMCLK_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 3), /*!< Attach MCLK to FLEXCOMM5. */
757
758 kFRG_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 4), /*!< Attach FRG to FLEXCOMM5. */
759
760 kNONE_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 7), /*!< Attach NONE to FLEXCOMM5. */
761
762 kFRO12M_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 0), /*!< Attach FRO12M to FLEXCOMM6. */
763
764 kFRO_HF_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 1), /*!< Attach FRO_HF to FLEXCOMM6. */
765
766 kAUDIO_PLL_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 2), /*!< Attach AUDIO_PLL to FLEXCOMM6. */
767
768 kMCLK_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 3), /*!< Attach MCLK to FLEXCOMM6. */
769
770 kFRG_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 4), /*!< Attach FRG to FLEXCOMM6. */
771
772 kNONE_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 7), /*!< Attach NONE to FLEXCOMM6. */
773
774 kFRO12M_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 0), /*!< Attach FRO12M to FLEXCOMM7. */
775
776 kFRO_HF_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 1), /*!< Attach FRO_HF to FLEXCOMM7. */
777
778 kAUDIO_PLL_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 2), /*!< Attach AUDIO_PLL to FLEXCOMM7. */
779
780 kMCLK_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 3), /*!< Attach MCLK to FLEXCOMM7. */
781
782 kFRG_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 4), /*!< Attach FRG to FLEXCOMM7. */
783
784 kNONE_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 7), /*!< Attach NONE to FLEXCOMM7. */
785
786 kFRO12M_to_FLEXCOMM8 = MUX_A(CM_FXCOMCLKSEL8, 0), /*!< Attach FRO12M to FLEXCOMM8. */
787
788 kFRO_HF_to_FLEXCOMM8 = MUX_A(CM_FXCOMCLKSEL8, 1), /*!< Attach FRO_HF to FLEXCOMM8. */
789
790 kAUDIO_PLL_to_FLEXCOMM8 = MUX_A(CM_FXCOMCLKSEL8, 2), /*!< Attach AUDIO_PLL to FLEXCOMM8. */
791
792 kMCLK_to_FLEXCOMM8 = MUX_A(CM_FXCOMCLKSEL8, 3), /*!< Attach MCLK to FLEXCOMM8. */
793
794 kFRG_to_FLEXCOMM8 = MUX_A(CM_FXCOMCLKSEL8, 4), /*!< Attach FRG to FLEXCOMM8. */
795
796 kNONE_to_FLEXCOMM8 = MUX_A(CM_FXCOMCLKSEL8, 7), /*!< Attach NONE to FLEXCOMM8. */
797
798 kFRO12M_to_FLEXCOMM9 = MUX_A(CM_FXCOMCLKSEL9, 0), /*!< Attach FRO12M to FLEXCOMM9. */
799
800 kFRO_HF_to_FLEXCOMM9 = MUX_A(CM_FXCOMCLKSEL9, 1), /*!< Attach FRO_HF to FLEXCOMM9. */
801
802 kAUDIO_PLL_to_FLEXCOMM9 = MUX_A(CM_FXCOMCLKSEL9, 2), /*!< Attach AUDIO_PLL to FLEXCOMM9. */
803
804 kMCLK_to_FLEXCOMM9 = MUX_A(CM_FXCOMCLKSEL9, 3), /*!< Attach MCLK to FLEXCOMM9. */
805
806 kFRG_to_FLEXCOMM9 = MUX_A(CM_FXCOMCLKSEL9, 4), /*!< Attach FRG to FLEXCOMM9. */
807
808 kNONE_to_FLEXCOMM9 = MUX_A(CM_FXCOMCLKSEL9, 7), /*!< Attach NONE to FLEXCOMM9. */
809
810 kMAIN_CLK_to_FLEXCOMM10 = MUX_A(CM_FXCOMCLKSEL10, 0), /*!< Attach MAIN_CLK to FLEXCOMM10. */
811
812 kSYS_PLL_to_FLEXCOMM10 = MUX_A(CM_FXCOMCLKSEL10, 1), /*!< Attach SYS_PLL to FLEXCOMM10. */
813
814 kUSB_PLL_to_FLEXCOMM10 = MUX_A(CM_FXCOMCLKSEL10, 2), /*!< Attach USB_PLL to FLEXCOMM10. */
815
816 kFRO_HF_to_FLEXCOMM10 = MUX_A(CM_FXCOMCLKSEL10, 3), /*!< Attach FRO_HF to FLEXCOMM10. */
817
818 kAUDIO_PLL_to_FLEXCOMM10 = MUX_A(CM_FXCOMCLKSEL10, 4), /*!< Attach AUDIO_PLL to FLEXCOMM10. */
819
820 kNONE_to_FLEXCOMM10 = MUX_A(CM_FXCOMCLKSEL10, 7), /*!< Attach NONE to FLEXCOMM10. */
821
822 kFRO_HF_to_MCLK = MUX_A(CM_MCLKCLKSEL, 0), /*!< Attach FRO_HF to MCLK. */
823
824 kAUDIO_PLL_to_MCLK = MUX_A(CM_MCLKCLKSEL, 1), /*!< Attach AUDIO_PLL to MCLK. */
825
826 kNONE_to_MCLK = MUX_A(CM_MCLKCLKSEL, 7), /*!< Attach NONE to MCLK. */
827
828 kMAIN_CLK_to_FRG = MUX_A(CM_FRGCLKSEL, 0), /*!< Attach MAIN_CLK to FRG. */
829
830 kSYS_PLL_to_FRG = MUX_A(CM_FRGCLKSEL, 1), /*!< Attach SYS_PLL to FRG. */
831
832 kFRO12M_to_FRG = MUX_A(CM_FRGCLKSEL, 2), /*!< Attach FRO12M to FRG. */
833
834 kFRO_HF_to_FRG = MUX_A(CM_FRGCLKSEL, 3), /*!< Attach FRO_HF to FRG. */
835
836 kNONE_to_FRG = MUX_A(CM_FRGCLKSEL, 7), /*!< Attach NONE to FRG. */
837
838 kFRO12M_to_DMIC = MUX_A(CM_DMICCLKSEL, 0), /*!< Attach FRO12M to DMIC. */
839
840 kFRO_HF_DIV_to_DMIC = MUX_A(CM_DMICCLKSEL, 1), /*!< Attach FRO_HF_DIV to DMIC. */
841
842 kAUDIO_PLL_to_DMIC = MUX_A(CM_DMICCLKSEL, 2), /*!< Attach AUDIO_PLL to DMIC. */
843
844 kMCLK_to_DMIC = MUX_A(CM_DMICCLKSEL, 3), /*!< Attach MCLK to DMIC. */
845
846 kMAIN_CLK_to_DMIC = MUX_A(CM_DMICCLKSEL, 4), /*!< Attach MAIN_CLK to DMIC. */
847
848 kWDT_OSC_to_DMIC = MUX_A(CM_DMICCLKSEL, 5), /*!< Attach WDT_OSC to DMIC. */
849
850 kNONE_to_DMIC = MUX_A(CM_DMICCLKSEL, 7), /*!< Attach NONE to DMIC. */
851
852 kMAIN_CLK_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 0), /*!< Attach MAIN_CLK to SCT_CLK. */
853
854 kSYS_PLL_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 1), /*!< Attach SYS_PLL to SCT_CLK. */
855
856 kFRO_HF_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 2), /*!< Attach FRO_HF to SCT_CLK. */
857
858 kAUDIO_PLL_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 3), /*!< Attach AUDIO_PLL to SCT_CLK. */
859
860 kNONE_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 7), /*!< Attach NONE to SCT_CLK. */
861
862 kMAIN_CLK_to_LCD_CLK = MUX_A(CM_LCDCLKSEL, 0), /*!< Attach MAIN_CLK to LCD_CLK. */
863
864 kLCDCLKIN_to_LCD_CLK = MUX_A(CM_LCDCLKSEL, 1), /*!< Attach LCDCLKIN to LCD_CLK. */
865
866 kFRO_HF_to_LCD_CLK = MUX_A(CM_LCDCLKSEL, 2), /*!< Attach FRO_HF to LCD_CLK. */
867
868 kNONE_to_LCD_CLK = MUX_A(CM_LCDCLKSEL, 3), /*!< Attach NONE to LCD_CLK. */
869
870 kMAIN_CLK_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 0), /*!< Attach MAIN_CLK to SDIO_CLK. */
871
872 kSYS_PLL_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 1), /*!< Attach SYS_PLL to SDIO_CLK. */
873
874 kUSB_PLL_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 2), /*!< Attach USB_PLL to SDIO_CLK. */
875
876 kFRO_HF_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 3), /*!< Attach FRO_HF to SDIO_CLK. */
877
878 kAUDIO_PLL_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 4), /*!< Attach AUDIO_PLL to SDIO_CLK. */
879
880 kNONE_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 7), /*!< Attach NONE to SDIO_CLK. */
881
882 kMAIN_CLK_to_ASYNC_APB = MUX_A(CM_ASYNCAPB, 0), /*!< Attach MAIN_CLK to ASYNC_APB. */
883
884 kFRO12M_to_ASYNC_APB = MUX_A(CM_ASYNCAPB, 1), /*!< Attach FRO12M to ASYNC_APB. */
885
886 kAUDIO_PLL_to_ASYNC_APB = MUX_A(CM_ASYNCAPB, 2), /*!< Attach AUDIO_PLL to ASYNC_APB. */
887
888 kI2C_CLK_FC6_to_ASYNC_APB = MUX_A(CM_ASYNCAPB, 3), /*!< Attach I2C_CLK_FC6 to ASYNC_APB. */
889
890 kNONE_to_NONE = (int)0x80000000U, /*!< Attach NONE to NONE. */
891
892 } clock_attach_id_t;
893
894 /*! @brief Clock dividers */
895 typedef enum _clock_div_name
896 {
897 kCLOCK_DivSystickClk = 0, /*!< Systick Clock Divider. */
898
899 kCLOCK_DivArmTrClkDiv = 1, /*!< Arm Tr Clk Div Divider. */
900
901 kCLOCK_DivCan0Clk = 2, /*!< Can0 Clock Divider. */
902
903 kCLOCK_DivCan1Clk = 3, /*!< Can1 Clock Divider. */
904
905 kCLOCK_DivSmartCard0Clk = 4, /*!< Smart Card0 Clock Divider. */
906
907 kCLOCK_DivSmartCard1Clk = 5, /*!< Smart Card1 Clock Divider. */
908
909 kCLOCK_DivAhbClk = 32, /*!< Ahb Clock Divider. */
910
911 kCLOCK_DivClkOut = 33, /*!< Clk Out Divider. */
912
913 kCLOCK_DivFrohfClk = 34, /*!< Frohf Clock Divider. */
914
915 kCLOCK_DivSpifiClk = 36, /*!< Spifi Clock Divider. */
916
917 kCLOCK_DivAdcAsyncClk = 37, /*!< Adc Async Clock Divider. */
918
919 kCLOCK_DivUsb0Clk = 38, /*!< Usb0 Clock Divider. */
920
921 kCLOCK_DivUsb1Clk = 39, /*!< Usb1 Clock Divider. */
922
923 kCLOCK_DivFrg = 40, /*!< Frg Divider. */
924
925 kCLOCK_DivDmicClk = 42, /*!< Dmic Clock Divider. */
926
927 kCLOCK_DivMClk = 43, /*!< Main Clock Divider. */
928
929 kCLOCK_DivLcdClk = 44, /*!< Lcd Clock Divider. */
930
931 kCLOCK_DivSctClk = 45, /*!< Sct Clock Divider. */
932
933 kCLOCK_DivEmcClk = 46, /*!< Emc Clock Divider. */
934
935 kCLOCK_DivSdioClk = 47 /*!< Sdio clock divider. */
936 } clock_div_name_t;
937
938 /*******************************************************************************
939 * API
940 ******************************************************************************/
941
942 #if defined(__cplusplus)
943 extern "C" {
944 #endif /* __cplusplus */
945
CLOCK_EnableClock(clock_ip_name_t clk)946 static inline void CLOCK_EnableClock(clock_ip_name_t clk)
947 {
948 uint32_t index = CLK_GATE_ABSTRACT_REG_OFFSET(clk);
949 if (index < 3UL)
950 {
951 SYSCON->AHBCLKCTRLSET[index] = (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT(clk));
952 }
953 else
954 {
955 SYSCON->ASYNCAPBCTRL = SYSCON_ASYNCAPBCTRL_ENABLE(1);
956 ASYNC_SYSCON->ASYNCAPBCLKCTRLSET = (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT(clk));
957 }
958 }
959
CLOCK_DisableClock(clock_ip_name_t clk)960 static inline void CLOCK_DisableClock(clock_ip_name_t clk)
961 {
962 uint32_t index = CLK_GATE_ABSTRACT_REG_OFFSET(clk);
963 if (index < 3UL)
964 {
965 SYSCON->AHBCLKCTRLCLR[index] = (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT(clk));
966 }
967 else
968 {
969 ASYNC_SYSCON->ASYNCAPBCLKCTRLCLR = (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT(clk));
970 SYSCON->ASYNCAPBCTRL = SYSCON_ASYNCAPBCTRL_ENABLE(0);
971 }
972 }
973
974 /**
975 * @brief
976 * Initialize the Core clock to given frequency (12, 48 or 96 MHz), this API is implememnt in ROM code.
977 * Turns on FRO and uses default CCO, if freq is 12000000, then high speed output is off, else high speed
978 * output is enabled.
979 * Usage: CLOCK_SetupFROClocking(frequency), (frequency must be one of 12, 48 or 96 MHz)
980 * Note: Need to make sure ROM and OTP has power(PDRUNCFG0[17,29]= 0U) before calling this API since this API is
981 * implemented in ROM code and the FROHF TRIM value is stored in OTP
982 *
983 * @param froFreq target fro frequency.
984 * @return Nothing
985 */
986
987 void CLOCK_SetupFROClocking(uint32_t froFreq);
988
989 /**
990 * @brief Configure the clock selection muxes.
991 * @param connection : Clock to be configured.
992 * @return Nothing
993 */
994 void CLOCK_AttachClk(clock_attach_id_t connection);
995 /**
996 * @brief Get the actual clock attach id.
997 * This fuction uses the offset in input attach id, then it reads the actual source value in
998 * the register and combine the offset to obtain an actual attach id.
999 * @param attachId : Clock attach id to get.
1000 * @return Clock source value.
1001 */
1002 clock_attach_id_t CLOCK_GetClockAttachId(clock_attach_id_t attachId);
1003 /**
1004 * @brief Setup peripheral clock dividers.
1005 * @param div_name : Clock divider name
1006 * @param divided_by_value: Value to be divided
1007 * @param reset : Whether to reset the divider counter.
1008 * @return Nothing
1009 */
1010 void CLOCK_SetClkDiv(clock_div_name_t div_name, uint32_t divided_by_value, bool reset);
1011
1012 /*! @brief Return Frequency of selected clock
1013 * @return Frequency of selected clock
1014 */
1015 uint32_t CLOCK_GetFreq(clock_name_t clockName);
1016 /*! @brief Return Frequency of FRO 12MHz
1017 * @return Frequency of FRO 12MHz
1018 */
1019 uint32_t CLOCK_GetFro12MFreq(void);
1020 /*! @brief Return Frequency of ClockOut
1021 * @return Frequency of ClockOut
1022 */
1023 uint32_t CLOCK_GetClockOutClkFreq(void);
1024 /*! @brief Return Frequency of Spifi Clock
1025 * @return Frequency of Spifi.
1026 */
1027 uint32_t CLOCK_GetSpifiClkFreq(void);
1028 /*! @brief Return Frequency of Adc Clock
1029 * @return Frequency of Adc Clock.
1030 */
1031 uint32_t CLOCK_GetAdcClkFreq(void);
1032 /*! brief Return Frequency of MCAN Clock
1033 * param MCanSel : 0U: MCAN0; 1U: MCAN1
1034 * return Frequency of MCAN Clock
1035 */
1036 uint32_t CLOCK_GetMCanClkFreq(uint32_t MCanSel);
1037 /*! @brief Return Frequency of Usb0 Clock
1038 * @return Frequency of Usb0 Clock.
1039 */
1040 uint32_t CLOCK_GetUsb0ClkFreq(void);
1041 /*! @brief Return Frequency of Usb1 Clock
1042 * @return Frequency of Usb1 Clock.
1043 */
1044 uint32_t CLOCK_GetUsb1ClkFreq(void);
1045 /*! @brief Return Frequency of MClk Clock
1046 * @return Frequency of MClk Clock.
1047 */
1048 uint32_t CLOCK_GetMclkClkFreq(void);
1049 /*! @brief Return Frequency of SCTimer Clock
1050 * @return Frequency of SCTimer Clock.
1051 */
1052 uint32_t CLOCK_GetSctClkFreq(void);
1053 /*! @brief Return Frequency of SDIO Clock
1054 * @return Frequency of SDIO Clock.
1055 */
1056 uint32_t CLOCK_GetSdioClkFreq(void);
1057 /*! @brief Return Frequency of LCD Clock
1058 * @return Frequency of LCD Clock.
1059 */
1060 uint32_t CLOCK_GetLcdClkFreq(void);
1061 /*! @brief Return Frequency of LCD CLKIN Clock
1062 * @return Frequency of LCD CLKIN Clock.
1063 */
1064 uint32_t CLOCK_GetLcdClkIn(void);
1065 /*! @brief Return Frequency of External Clock
1066 * @return Frequency of External Clock. If no external clock is used returns 0.
1067 */
1068 uint32_t CLOCK_GetExtClkFreq(void);
1069 /*! @brief Return Frequency of Watchdog Oscillator
1070 * @return Frequency of Watchdog Oscillator
1071 */
1072 uint32_t CLOCK_GetWdtOscFreq(void);
1073 /*! @brief Return Frequency of High-Freq output of FRO
1074 * @return Frequency of High-Freq output of FRO
1075 */
1076 uint32_t CLOCK_GetFroHfFreq(void);
1077 /*! @brief Return Frequency of frg
1078 * @return Frequency of FRG
1079 */
1080 uint32_t CLOCK_GetFrgClkFreq(void);
1081 /*! @brief Return Frequency of dmic
1082 * @return Frequency of DMIC
1083 */
1084 uint32_t CLOCK_GetDmicClkFreq(void);
1085
1086 /*!
1087 * @brief Set FRG Clk
1088 * @return
1089 * 1: if set FRG CLK successfully.
1090 * 0: if set FRG CLK fail.
1091 */
1092 uint32_t CLOCK_SetFRGClock(uint32_t freq);
1093
1094 /*! @brief Return Frequency of PLL
1095 * @return Frequency of PLL
1096 */
1097 uint32_t CLOCK_GetPllOutFreq(void);
1098 /*! @brief Return Frequency of USB PLL
1099 * @return Frequency of PLL
1100 */
1101 uint32_t CLOCK_GetUsbPllOutFreq(void);
1102 /*! @brief Return Frequency of AUDIO PLL
1103 * @return Frequency of PLL
1104 */
1105 uint32_t CLOCK_GetAudioPllOutFreq(void);
1106 /*! @brief Return Frequency of 32kHz osc
1107 * @return Frequency of 32kHz osc
1108 */
1109 uint32_t CLOCK_GetOsc32KFreq(void);
1110 /*! @brief Return Frequency of Core System
1111 * @return Frequency of Core System
1112 */
1113 uint32_t CLOCK_GetCoreSysClkFreq(void);
1114 /*! @brief Return Frequency of I2S MCLK Clock
1115 * @return Frequency of I2S MCLK Clock
1116 */
1117 uint32_t CLOCK_GetI2SMClkFreq(void);
1118 /*! @brief Return Frequency of Flexcomm functional Clock
1119 * @return Frequency of Flexcomm functional Clock
1120 */
1121 uint32_t CLOCK_GetFlexCommClkFreq(uint32_t id);
1122
1123 /*! @brief return FRG Clk
1124 * @return Frequency of FRG CLK.
1125 */
1126 uint32_t CLOCK_GetFRGInputClock(void);
1127 /*! @brief Return Asynchronous APB Clock source
1128 * @return Asynchronous APB CLock source
1129 */
CLOCK_GetAsyncApbClkSrc(void)1130 __STATIC_INLINE async_clock_src_t CLOCK_GetAsyncApbClkSrc(void)
1131 {
1132 return (async_clock_src_t)(uint32_t)(ASYNC_SYSCON->ASYNCAPBCLKSELA & 0x3U);
1133 }
1134 /*! @brief Return Frequency of Asynchronous APB Clock
1135 * @return Frequency of Asynchronous APB Clock Clock
1136 */
1137 uint32_t CLOCK_GetAsyncApbClkFreq(void);
1138 /*! @brief Return EMC source
1139 * @return EMC source
1140 */
CLOCK_GetEmcClkFreq(void)1141 __STATIC_INLINE uint32_t CLOCK_GetEmcClkFreq(void)
1142 {
1143 uint32_t freqtmp;
1144
1145 freqtmp = CLOCK_GetCoreSysClkFreq() / ((SYSCON->AHBCLKDIV & 0xffU) + 1U);
1146 return freqtmp / ((SYSCON->EMCCLKDIV & 0xffU) + 1U);
1147 }
1148 /*! @brief Return Audio PLL input clock rate
1149 * @return Audio PLL input clock rate
1150 */
1151 uint32_t CLOCK_GetAudioPLLInClockRate(void);
1152 /*! @brief Return System PLL input clock rate
1153 * @return System PLL input clock rate
1154 */
1155 uint32_t CLOCK_GetSystemPLLInClockRate(void);
1156
1157 /*! @brief Return System PLL output clock rate
1158 * @param recompute : Forces a PLL rate recomputation if true
1159 * @return System PLL output clock rate
1160 * @note The PLL rate is cached in the driver in a variable as
1161 * the rate computation function can take some time to perform. It
1162 * is recommended to use 'false' with the 'recompute' parameter.
1163 */
1164 uint32_t CLOCK_GetSystemPLLOutClockRate(bool recompute);
1165
1166 /*! @brief Return System AUDIO PLL output clock rate
1167 * @param recompute : Forces a AUDIO PLL rate recomputation if true
1168 * @return System AUDIO PLL output clock rate
1169 * @note The AUDIO PLL rate is cached in the driver in a variable as
1170 * the rate computation function can take some time to perform. It
1171 * is recommended to use 'false' with the 'recompute' parameter.
1172 */
1173 uint32_t CLOCK_GetAudioPLLOutClockRate(bool recompute);
1174
1175 /*! @brief Return System USB PLL output clock rate
1176 * @param recompute : Forces a USB PLL rate recomputation if true
1177 * @return System USB PLL output clock rate
1178 * @note The USB PLL rate is cached in the driver in a variable as
1179 * the rate computation function can take some time to perform. It
1180 * is recommended to use 'false' with the 'recompute' parameter.
1181 */
1182 uint32_t CLOCK_GetUsbPLLOutClockRate(bool recompute);
1183
1184 /*! @brief Enables and disables PLL bypass mode
1185 * @brief bypass : true to bypass PLL (PLL output = PLL input, false to disable bypass
1186 * @return System PLL output clock rate
1187 */
CLOCK_SetBypassPLL(bool bypass)1188 __STATIC_INLINE void CLOCK_SetBypassPLL(bool bypass)
1189 {
1190 if (bypass)
1191 {
1192 SYSCON->SYSPLLCTRL |= (1UL << SYSCON_SYSPLLCTRL_BYPASS_SHIFT);
1193 }
1194 else
1195 {
1196 SYSCON->SYSPLLCTRL &= ~(1UL << SYSCON_SYSPLLCTRL_BYPASS_SHIFT);
1197 }
1198 }
1199
1200 /*! @brief Check if PLL is locked or not
1201 * @return true if the PLL is locked, false if not locked
1202 */
CLOCK_IsSystemPLLLocked(void)1203 __STATIC_INLINE bool CLOCK_IsSystemPLLLocked(void)
1204 {
1205 return (bool)((SYSCON->SYSPLLSTAT & SYSCON_SYSPLLSTAT_LOCK_MASK) != 0U);
1206 }
1207
1208 /*! @brief Check if USB PLL is locked or not
1209 * @return true if the USB PLL is locked, false if not locked
1210 */
CLOCK_IsUsbPLLLocked(void)1211 __STATIC_INLINE bool CLOCK_IsUsbPLLLocked(void)
1212 {
1213 return (bool)((SYSCON->USBPLLSTAT & SYSCON_USBPLLSTAT_LOCK_MASK) != 0U);
1214 }
1215
1216 /*! @brief Check if AUDIO PLL is locked or not
1217 * @return true if the AUDIO PLL is locked, false if not locked
1218 */
CLOCK_IsAudioPLLLocked(void)1219 __STATIC_INLINE bool CLOCK_IsAudioPLLLocked(void)
1220 {
1221 return (bool)((SYSCON->AUDPLLSTAT & SYSCON_AUDPLLSTAT_LOCK_MASK) != 0U);
1222 }
1223
1224 /*! @brief Enables and disables SYS OSC
1225 * @brief enable : true to enable SYS OSC, false to disable SYS OSC
1226 */
CLOCK_Enable_SysOsc(bool enable)1227 __STATIC_INLINE void CLOCK_Enable_SysOsc(bool enable)
1228 {
1229 if (enable)
1230 {
1231 SYSCON->PDRUNCFGCLR[0] |= SYSCON_PDRUNCFG_PDEN_VD2_ANA_MASK;
1232 SYSCON->PDRUNCFGCLR[1] |= SYSCON_PDRUNCFG_PDEN_SYSOSC_MASK;
1233 }
1234
1235 else
1236 {
1237 SYSCON->PDRUNCFGSET[0] = SYSCON_PDRUNCFG_PDEN_VD2_ANA_MASK;
1238 SYSCON->PDRUNCFGSET[1] = SYSCON_PDRUNCFG_PDEN_SYSOSC_MASK;
1239 }
1240 }
1241
1242 /*! @brief Store the current PLL rate
1243 * @param rate: Current rate of the PLL
1244 * @return Nothing
1245 **/
1246 void CLOCK_SetStoredPLLClockRate(uint32_t rate);
1247
1248 /*! @brief Store the current AUDIO PLL rate
1249 * @param rate: Current rate of the PLL
1250 * @return Nothing
1251 **/
1252 void CLOCK_SetStoredAudioPLLClockRate(uint32_t rate);
1253
1254 /*! @brief PLL configuration structure flags for 'flags' field
1255 * These flags control how the PLL configuration function sets up the PLL setup structure.<br>
1256 *
1257 * When the PLL_CONFIGFLAG_USEINRATE flag is selected, the 'InputRate' field in the
1258 * configuration structure must be assigned with the expected PLL frequency. If the
1259 * PLL_CONFIGFLAG_USEINRATE is not used, 'InputRate' is ignored in the configuration
1260 * function and the driver will determine the PLL rate from the currently selected
1261 * PLL source. This flag might be used to configure the PLL input clock more accurately
1262 * when using the WDT oscillator or a more dyanmic CLKIN source.<br>
1263 *
1264 * When the PLL_CONFIGFLAG_FORCENOFRACT flag is selected, the PLL hardware for the
1265 * automatic bandwidth selection, Spread Spectrum (SS) support, and fractional M-divider
1266 * are not used.<br>
1267 */
1268 #define PLL_CONFIGFLAG_USEINRATE (1U << 0U) /*!< Flag to use InputRate in PLL configuration structure for setup */
1269 #define PLL_CONFIGFLAG_FORCENOFRACT \
1270 (1U << 2U) /*!< Force non-fractional output mode, PLL output will not use the fractional, automatic bandwidth, or \
1271 SS hardware */
1272
1273 /*! @brief PLL configuration structure
1274 *
1275 * This structure can be used to configure the settings for a PLL
1276 * setup structure. Fill in the desired configuration for the PLL
1277 * and call the PLL setup function to fill in a PLL setup structure.
1278 */
1279 typedef struct _pll_config
1280 {
1281 uint32_t desiredRate; /*!< Desired PLL rate in Hz */
1282 uint32_t inputRate; /*!< PLL input clock in Hz, only used if PLL_CONFIGFLAG_USEINRATE flag is set */
1283 uint32_t flags; /*!< PLL configuration flags, Or'ed value of PLL_CONFIGFLAG_* definitions */
1284 } pll_config_t;
1285
1286 /*! @brief PLL setup structure flags for 'flags' field
1287 * These flags control how the PLL setup function sets up the PLL
1288 */
1289 #define PLL_SETUPFLAG_POWERUP (1U << 0U) /*!< Setup will power on the PLL after setup */
1290 #define PLL_SETUPFLAG_WAITLOCK (1U << 1U) /*!< Setup will wait for PLL lock, implies the PLL will be pwoered on */
1291 #define PLL_SETUPFLAG_ADGVOLT (1U << 2U) /*!< Optimize system voltage for the new PLL rate */
1292
1293 /*! @brief PLL setup structure
1294 * This structure can be used to pre-build a PLL setup configuration
1295 * at run-time and quickly set the PLL to the configuration. It can be
1296 * populated with the PLL setup function. If powering up or waiting
1297 * for PLL lock, the PLL input clock source should be configured prior
1298 * to PLL setup.
1299 */
1300 typedef struct _pll_setup
1301 {
1302 uint32_t pllctrl; /*!< PLL control register SYSPLLCTRL */
1303 uint32_t pllndec; /*!< PLL NDEC register SYSPLLNDEC */
1304 uint32_t pllpdec; /*!< PLL PDEC register SYSPLLPDEC */
1305 uint32_t pllmdec; /*!< PLL MDEC registers SYSPLLPDEC */
1306 uint32_t pllRate; /*!< Acutal PLL rate */
1307 uint32_t audpllfrac; /*!< only aduio PLL has this function*/
1308 uint32_t flags; /*!< PLL setup flags, Or'ed value of PLL_SETUPFLAG_* definitions */
1309 } pll_setup_t;
1310
1311 /*! @brief PLL status definitions
1312 */
1313 typedef enum _pll_error
1314 {
1315 kStatus_PLL_Success = MAKE_STATUS(kStatusGroup_Generic, 0), /*!< PLL operation was successful */
1316 kStatus_PLL_OutputTooLow = MAKE_STATUS(kStatusGroup_Generic, 1), /*!< PLL output rate request was too low */
1317 kStatus_PLL_OutputTooHigh = MAKE_STATUS(kStatusGroup_Generic, 2), /*!< PLL output rate request was too high */
1318 kStatus_PLL_InputTooLow = MAKE_STATUS(kStatusGroup_Generic, 3), /*!< PLL input rate is too low */
1319 kStatus_PLL_InputTooHigh = MAKE_STATUS(kStatusGroup_Generic, 4), /*!< PLL input rate is too high */
1320 kStatus_PLL_OutsideIntLimit = MAKE_STATUS(kStatusGroup_Generic, 5), /*!< Requested output rate isn't possible */
1321 kStatus_PLL_CCOTooLow = MAKE_STATUS(kStatusGroup_Generic, 6), /*!< Requested CCO rate isn't possible */
1322 kStatus_PLL_CCOTooHigh = MAKE_STATUS(kStatusGroup_Generic, 7) /*!< Requested CCO rate isn't possible */
1323 } pll_error_t;
1324
1325 /*! @brief USB clock source definition. */
1326 typedef enum _clock_usb_src
1327 {
1328 kCLOCK_UsbSrcFro = (uint32_t)kCLOCK_FroHf, /*!< Use FRO 96 or 48 MHz. */
1329 kCLOCK_UsbSrcSystemPll = (uint32_t)kCLOCK_PllOut, /*!< Use System PLL output. */
1330 kCLOCK_UsbSrcMainClock = (uint32_t)kCLOCK_CoreSysClk, /*!< Use Main clock. */
1331 kCLOCK_UsbSrcUsbPll = (uint32_t)kCLOCK_UsbPll, /*!< Use USB PLL clock. */
1332
1333 kCLOCK_UsbSrcNone = SYSCON_USB0CLKSEL_SEL(
1334 7U) /*!< Use None, this may be selected in order to reduce power when no output is needed. */
1335 } clock_usb_src_t;
1336
1337 /*! @brief USB PDEL Divider. */
1338 typedef enum _usb_pll_psel
1339 {
1340 pSel_Divide_1 = 0U,
1341 pSel_Divide_2,
1342 pSel_Divide_4,
1343 pSel_Divide_8
1344 } usb_pll_psel;
1345
1346 /*! @brief PLL setup structure
1347 * This structure can be used to pre-build a USB PLL setup configuration
1348 * at run-time and quickly set the usb PLL to the configuration. It can be
1349 * populated with the USB PLL setup function. If powering up or waiting
1350 * for USB PLL lock, the PLL input clock source should be configured prior
1351 * to USB PLL setup.
1352 */
1353 typedef struct _usb_pll_setup
1354 {
1355 uint8_t msel; /*!< USB PLL control register msel:1U-256U */
1356 uint8_t psel; /*!< USB PLL control register psel:only support inter 1U 2U 4U 8U */
1357 uint8_t nsel; /*!< USB PLL control register nsel:only suppoet inter 1U 2U 3U 4U */
1358 bool direct; /*!< USB PLL CCO output control */
1359 bool bypass; /*!< USB PLL inout clock bypass control */
1360 bool fbsel; /*!< USB PLL ineter mode and non-integer mode control*/
1361 uint32_t inputRate; /*!< USB PLL input rate */
1362 } usb_pll_setup_t;
1363
1364 /*! @brief Return System PLL output clock rate from setup structure
1365 * @param pSetup : Pointer to a PLL setup structure
1366 * @return System PLL output clock rate the setup structure will generate
1367 */
1368 uint32_t CLOCK_GetSystemPLLOutFromSetup(pll_setup_t *pSetup);
1369
1370 /*! @brief Return System AUDIO PLL output clock rate from setup structure
1371 * @param pSetup : Pointer to a PLL setup structure
1372 * @return System PLL output clock rate the setup structure will generate
1373 */
1374 uint32_t CLOCK_GetAudioPLLOutFromSetup(pll_setup_t *pSetup);
1375
1376 /*! @brief Return System AUDIO PLL output clock rate from audio fractioanl setup structure
1377 * @param pSetup : Pointer to a PLL setup structure
1378 * @return System PLL output clock rate the setup structure will generate
1379 */
1380 uint32_t CLOCK_GetAudioPLLOutFromFractSetup(pll_setup_t *pSetup);
1381
1382 /*! @brief Return System USB PLL output clock rate from setup structure
1383 * @param pSetup : Pointer to a PLL setup structure
1384 * @return System PLL output clock rate the setup structure will generate
1385 */
1386 uint32_t CLOCK_GetUsbPLLOutFromSetup(const usb_pll_setup_t *pSetup);
1387
1388 /*! @brief Set PLL output based on the passed PLL setup data
1389 * @param pControl : Pointer to populated PLL control structure to generate setup with
1390 * @param pSetup : Pointer to PLL setup structure to be filled
1391 * @return PLL_ERROR_SUCCESS on success, or PLL setup error code
1392 * @note Actual frequency for setup may vary from the desired frequency based on the
1393 * accuracy of input clocks, rounding, non-fractional PLL mode, etc.
1394 */
1395 pll_error_t CLOCK_SetupPLLData(pll_config_t *pControl, pll_setup_t *pSetup);
1396
1397 /*! @brief Set AUDIO PLL output based on the passed AUDIO PLL setup data
1398 * @param pControl : Pointer to populated PLL control structure to generate setup with
1399 * @param pSetup : Pointer to PLL setup structure to be filled
1400 * @return PLL_ERROR_SUCCESS on success, or PLL setup error code
1401 * @note Actual frequency for setup may vary from the desired frequency based on the
1402 * accuracy of input clocks, rounding, non-fractional PLL mode, etc.
1403 */
1404 pll_error_t CLOCK_SetupAudioPLLData(pll_config_t *pControl, pll_setup_t *pSetup);
1405
1406 /*! @brief Set PLL output from PLL setup structure (precise frequency)
1407 * @param pSetup : Pointer to populated PLL setup structure
1408 * @param flagcfg : Flag configuration for PLL config structure
1409 * @return PLL_ERROR_SUCCESS on success, or PLL setup error code
1410 * @note This function will power off the PLL, setup the PLL with the
1411 * new setup data, and then optionally powerup the PLL, wait for PLL lock,
1412 * and adjust system voltages to the new PLL rate. The function will not
1413 * alter any source clocks (ie, main systen clock) that may use the PLL,
1414 * so these should be setup prior to and after exiting the function.
1415 */
1416 pll_error_t CLOCK_SetupSystemPLLPrec(pll_setup_t *pSetup, uint32_t flagcfg);
1417
1418 /*! @brief Set AUDIO PLL output from AUDIOPLL setup structure (precise frequency)
1419 * @param pSetup : Pointer to populated PLL setup structure
1420 * @param flagcfg : Flag configuration for PLL config structure
1421 * @return PLL_ERROR_SUCCESS on success, or PLL setup error code
1422 * @note This function will power off the PLL, setup the PLL with the
1423 * new setup data, and then optionally powerup the AUDIO PLL, wait for PLL lock,
1424 * and adjust system voltages to the new AUDIOPLL rate. The function will not
1425 * alter any source clocks (ie, main systen clock) that may use the AUDIO PLL,
1426 * so these should be setup prior to and after exiting the function.
1427 */
1428 pll_error_t CLOCK_SetupAudioPLLPrec(pll_setup_t *pSetup, uint32_t flagcfg);
1429
1430 /*! @brief Set AUDIO PLL output from AUDIOPLL setup structure using the Audio Fractional divider register(precise
1431 * frequency)
1432 * @param pSetup : Pointer to populated PLL setup structure
1433 * @param flagcfg : Flag configuration for PLL config structure
1434 * @return PLL_ERROR_SUCCESS on success, or PLL setup error code
1435 * @note This function will power off the PLL, setup the PLL with the
1436 * new setup data, and then optionally powerup the AUDIO PLL, wait for PLL lock,
1437 * and adjust system voltages to the new AUDIOPLL rate. The function will not
1438 * alter any source clocks (ie, main systen clock) that may use the AUDIO PLL,
1439 * so these should be setup prior to and after exiting the function.
1440 */
1441 pll_error_t CLOCK_SetupAudioPLLPrecFract(pll_setup_t *pSetup, uint32_t flagcfg);
1442
1443 /**
1444 * @brief Set PLL output from PLL setup structure (precise frequency)
1445 * @param pSetup : Pointer to populated PLL setup structure
1446 * @return kStatus_PLL_Success on success, or PLL setup error code
1447 * @note This function will power off the PLL, setup the PLL with the
1448 * new setup data, and then optionally powerup the PLL, wait for PLL lock,
1449 * and adjust system voltages to the new PLL rate. The function will not
1450 * alter any source clocks (ie, main systen clock) that may use the PLL,
1451 * so these should be setup prior to and after exiting the function.
1452 */
1453 pll_error_t CLOCK_SetPLLFreq(const pll_setup_t *pSetup);
1454
1455 /**
1456 * @brief Set Audio PLL output from Audio PLL setup structure (precise frequency)
1457 * @param pSetup : Pointer to populated PLL setup structure
1458 * @return kStatus_PLL_Success on success, or Audio PLL setup error code
1459 * @note This function will power off the PLL, setup the Audio PLL with the
1460 * new setup data, and then optionally powerup the PLL, wait for Audio PLL lock,
1461 * and adjust system voltages to the new PLL rate. The function will not
1462 * alter any source clocks (ie, main systen clock) that may use the Audio PLL,
1463 * so these should be setup prior to and after exiting the function.
1464 */
1465 pll_error_t CLOCK_SetAudioPLLFreq(const pll_setup_t *pSetup);
1466
1467 /**
1468 * @brief Set USB PLL output from USB PLL setup structure (precise frequency)
1469 * @param pSetup : Pointer to populated USB PLL setup structure
1470 * @return kStatus_PLL_Success on success, or USB PLL setup error code
1471 * @note This function will power off the USB PLL, setup the PLL with the
1472 * new setup data, and then optionally powerup the USB PLL, wait for USB PLL lock,
1473 * and adjust system voltages to the new USB PLL rate. The function will not
1474 * alter any source clocks (ie, usb pll clock) that may use the USB PLL,
1475 * so these should be setup prior to and after exiting the function.
1476 */
1477 pll_error_t CLOCK_SetUsbPLLFreq(const usb_pll_setup_t *pSetup);
1478
1479 /*! @brief Set PLL output based on the multiplier and input frequency
1480 * @param multiply_by : multiplier
1481 * @param input_freq : Clock input frequency of the PLL
1482 * @return Nothing
1483 * @note Unlike the Chip_Clock_SetupSystemPLLPrec() function, this
1484 * function does not disable or enable PLL power, wait for PLL lock,
1485 * or adjust system voltages. These must be done in the application.
1486 * The function will not alter any source clocks (ie, main systen clock)
1487 * that may use the PLL, so these should be setup prior to and after
1488 * exiting the function.
1489 */
1490 void CLOCK_SetupSystemPLLMult(uint32_t multiply_by, uint32_t input_freq);
1491
1492 /*! @brief Disable USB clock.
1493 *
1494 * Disable USB clock.
1495 */
CLOCK_DisableUsbDevicefs0Clock(clock_ip_name_t clk)1496 static inline void CLOCK_DisableUsbDevicefs0Clock(clock_ip_name_t clk)
1497 {
1498 CLOCK_DisableClock(clk);
1499 }
1500
1501 /*! @brief Enable USB Device FS clock.
1502 * @param src : clock source
1503 * @param freq: clock frequency
1504 * Enable USB Device Full Speed clock.
1505 */
1506 bool CLOCK_EnableUsbfs0DeviceClock(clock_usb_src_t src, uint32_t freq);
1507
1508 /*! @brief Enable USB HOST FS clock.
1509 * @param src : clock source
1510 * @param freq: clock frequency
1511 * Enable USB HOST Full Speed clock.
1512 */
1513 bool CLOCK_EnableUsbfs0HostClock(clock_usb_src_t src, uint32_t freq);
1514
1515 /*! @brief Set the current Usb PLL Rate
1516 */
1517 void CLOCK_SetStoredUsbPLLClockRate(uint32_t rate);
1518
1519 /*! @brief Enable USB Device HS clock.
1520 * @param src : clock source
1521 * @param freq: clock frequency
1522 * Enable USB Device High Speed clock.
1523 */
1524 bool CLOCK_EnableUsbhs0DeviceClock(clock_usb_src_t src, uint32_t freq);
1525
1526 /*! @brief Enable USB HOST HS clock.
1527 * @param src : clock source
1528 * @param freq: clock frequency
1529 * Enable USB HOST High Speed clock.
1530 */
1531 bool CLOCK_EnableUsbhs0HostClock(clock_usb_src_t src, uint32_t freq);
1532
1533 #if defined(__cplusplus)
1534 }
1535 #endif /* __cplusplus */
1536
1537 /*! @} */
1538
1539 #endif /* _FSL_CLOCK_H_ */
1540