aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/ext/mcux-sdk/devices/MK28FA15/drivers/fsl_clock.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/devices/MK28FA15/drivers/fsl_clock.h')
-rw-r--r--lib/chibios-contrib/ext/mcux-sdk/devices/MK28FA15/drivers/fsl_clock.h1754
1 files changed, 1754 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/devices/MK28FA15/drivers/fsl_clock.h b/lib/chibios-contrib/ext/mcux-sdk/devices/MK28FA15/drivers/fsl_clock.h
new file mode 100644
index 000000000..d5caee78e
--- /dev/null
+++ b/lib/chibios-contrib/ext/mcux-sdk/devices/MK28FA15/drivers/fsl_clock.h
@@ -0,0 +1,1754 @@
1/*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * Copyright 2016 - 2020, NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#ifndef _FSL_CLOCK_H_
10#define _FSL_CLOCK_H_
11
12#include "fsl_common.h"
13
14/*! @addtogroup clock */
15/*! @{ */
16
17/*! @file */
18
19/*******************************************************************************
20 * Configurations
21 ******************************************************************************/
22
23/*! @brief Configures whether to check a parameter in a function.
24 *
25 * Some MCG settings must be changed with conditions, for example:
26 * 1. MCGIRCLK settings, such as the source, divider, and the trim value should not change when
27 * MCGIRCLK is used as a system clock source.
28 * 2. MCG_C7[OSCSEL] should not be changed when the external reference clock is used
29 * as a system clock source. For example, in FBE/BLPE/PBE modes.
30 * 3. The users should only switch between the supported clock modes.
31 *
32 * MCG functions check the parameter and MCG status before setting, if not allowed
33 * to change, the functions return error. The parameter checking increases code size,
34 * if code size is a critical requirement, change #MCG_CONFIG_CHECK_PARAM to 0 to
35 * disable parameter checking.
36 */
37#ifndef MCG_CONFIG_CHECK_PARAM
38#define MCG_CONFIG_CHECK_PARAM 0U
39#endif
40
41/*! @brief Configure whether driver controls clock
42 *
43 * When set to 0, peripheral drivers will enable clock in initialize function
44 * and disable clock in de-initialize function. When set to 1, peripheral
45 * driver will not control the clock, application could control the clock out of
46 * the driver.
47 *
48 * @note All drivers share this feature switcher. If it is set to 1, application
49 * should handle clock enable and disable for all drivers.
50 */
51#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL))
52#define FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL 0
53#endif
54
55/*******************************************************************************
56 * Definitions
57 ******************************************************************************/
58
59/*! @name Driver version */
60/*@{*/
61/*! @brief CLOCK driver version 2.5.2. */
62#define FSL_CLOCK_DRIVER_VERSION (MAKE_VERSION(2, 5, 2))
63/*@}*/
64
65/*! @brief External XTAL0 (OSC0) clock frequency.
66 *
67 * The XTAL0/EXTAL0 (OSC0) clock frequency in Hz. When the clock is set up, use the
68 * function CLOCK_SetXtal0Freq to set the value in the clock driver. For example,
69 * if XTAL0 is 8 MHz:
70 * @code
71 * Set up the OSC0
72 * CLOCK_InitOsc0(...);
73 * Set the XTAL0 value to the clock driver.
74 * CLOCK_SetXtal0Freq(80000000);
75 * @endcode
76 *
77 * This is important for the multicore platforms where only one core needs to set up the
78 * OSC0 using the CLOCK_InitOsc0. All other cores need to call the CLOCK_SetXtal0Freq
79 * to get a valid clock frequency.
80 */
81extern volatile uint32_t g_xtal0Freq;
82
83/*! @brief External XTAL32/EXTAL32/RTC_CLKIN clock frequency.
84 *
85 * The XTAL32/EXTAL32/RTC_CLKIN clock frequency in Hz. When the clock is set up, use the
86 * function CLOCK_SetXtal32Freq to set the value in the clock driver.
87 *
88 * This is important for the multicore platforms where only one core needs to set up
89 * the clock. All other cores need to call the CLOCK_SetXtal32Freq
90 * to get a valid clock frequency.
91 */
92extern volatile uint32_t g_xtal32Freq;
93
94/*! @brief IRC48M clock frequency in Hz. */
95#define MCG_INTERNAL_IRC_48M 48000000U
96
97#if (defined(OSC) && !(defined(OSC0)))
98#define OSC0 OSC
99#endif
100
101/* Definition for delay API in clock driver, users can redefine it to the real application. */
102#ifndef SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY
103#define SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY (150000000UL)
104#endif
105/*! @brief Clock ip name array for DMAMUX. */
106#define DMAMUX_CLOCKS \
107 { \
108 kCLOCK_Dmamux0 \
109 }
110
111/*! @brief Clock ip name array for RTC. */
112#define RTC_CLOCKS \
113 { \
114 kCLOCK_Rtc0 \
115 }
116
117/*! @brief Clock ip name array for SAI. */
118#define SAI_CLOCKS \
119 { \
120 kCLOCK_Sai0, kCLOCK_Sai1 \
121 }
122
123/*! @brief Clock ip name array for PORT. */
124#define PORT_CLOCKS \
125 { \
126 kCLOCK_PortA, kCLOCK_PortB, kCLOCK_PortC, kCLOCK_PortD, kCLOCK_PortE \
127 }
128
129/*! @brief Clock ip name array for FLEXBUS. */
130#define FLEXBUS_CLOCKS \
131 { \
132 kCLOCK_Flexbus0 \
133 }
134
135/*! @brief Clock ip name array for EWM. */
136#define EWM_CLOCKS \
137 { \
138 kCLOCK_Ewm0 \
139 }
140
141/*! @brief Clock ip name array for PIT. */
142#define PIT_CLOCKS \
143 { \
144 kCLOCK_Pit0 \
145 }
146
147/*! @brief Clock ip name array for DSPI. */
148#define DSPI_CLOCKS \
149 { \
150 kCLOCK_Spi0, kCLOCK_Spi1, kCLOCK_Spi2, kCLOCK_Spi3 \
151 }
152
153/*! @brief Clock ip name array for QSPI. */
154#define QSPI_CLOCKS \
155 { \
156 kCLOCK_Qspi0 \
157 }
158
159/*! @brief Clock ip name array for LPTMR. */
160#define LPTMR_CLOCKS \
161 { \
162 kCLOCK_Lptmr0, kCLOCK_Lptmr1 \
163 }
164
165/*! @brief Clock ip name array for SDHC. */
166#define SDHC_CLOCKS \
167 { \
168 kCLOCK_Sdhc0 \
169 }
170
171/*! @brief Clock ip name array for FTM. */
172#define FTM_CLOCKS \
173 { \
174 kCLOCK_Ftm0, kCLOCK_Ftm1, kCLOCK_Ftm2, kCLOCK_Ftm3 \
175 }
176
177/*! @brief Clock ip name array for EDMA. */
178#define EDMA_CLOCKS \
179 { \
180 kCLOCK_Dma0 \
181 }
182
183/*! @brief Clock ip name array for LPUART. */
184#define LPUART_CLOCKS \
185 { \
186 kCLOCK_Lpuart0, kCLOCK_Lpuart1, kCLOCK_Lpuart2, kCLOCK_Lpuart3, kCLOCK_Lpuart4 \
187 }
188
189/*! @brief Clock ip name array for DAC. */
190#define DAC_CLOCKS \
191 { \
192 kCLOCK_Dac0 \
193 }
194
195/*! @brief Clock ip name array for ADC16. */
196#define ADC16_CLOCKS \
197 { \
198 kCLOCK_Adc0 \
199 }
200
201/*! @brief Clock ip name array for SDRAM. */
202#define SDRAM_CLOCKS \
203 { \
204 kCLOCK_Sdramc0 \
205 }
206
207/*! @brief Clock ip name array for TRNG. */
208#define TRNG_CLOCKS \
209 { \
210 kCLOCK_Trng0 \
211 }
212
213/*! @brief Clock ip name array for USBHS. */
214#define USBHS_CLOCKS \
215 { \
216 kCLOCK_Usbhs \
217 }
218
219/*! @brief Clock ip name array for USBHSPHY. */
220#define USBHSPHY_CLOCKS \
221 { \
222 kCLOCK_Usbhsphy \
223 }
224
225/*! @brief Clock ip name array for USBHSDCD. */
226#define USBHSDCD_CLOCKS \
227 { \
228 kCLOCK_Usbhsdcd \
229 }
230
231/*! @brief Clock ip name array for MPU. */
232#define SYSMPU_CLOCKS \
233 { \
234 kCLOCK_Sysmpu0 \
235 }
236
237/*! @brief Clock ip name array for FLEXIO. */
238#define FLEXIO_CLOCKS \
239 { \
240 kCLOCK_Flexio0 \
241 }
242
243/*! @brief Clock ip name array for VREF. */
244#define VREF_CLOCKS \
245 { \
246 kCLOCK_Vref0 \
247 }
248
249/*! @brief Clock ip name array for CMT. */
250#define CMT_CLOCKS \
251 { \
252 kCLOCK_Cmt0 \
253 }
254
255/*! @brief Clock ip name array for TPM. */
256#define TPM_CLOCKS \
257 { \
258 kCLOCK_IpInvalid, kCLOCK_Tpm1, kCLOCK_Tpm2 \
259 }
260
261/*! @brief Clock ip name array for TSI. */
262#define TSI_CLOCKS \
263 { \
264 kCLOCK_Tsi0 \
265 }
266
267/*! @brief Clock ip name array for CRC. */
268#define CRC_CLOCKS \
269 { \
270 kCLOCK_Crc0 \
271 }
272
273/*! @brief Clock ip name array for I2C. */
274#define I2C_CLOCKS \
275 { \
276 kCLOCK_I2c0, kCLOCK_I2c1, kCLOCK_I2c2, kCLOCK_I2c3 \
277 }
278
279/*! @brief Clock ip name array for PDB. */
280#define PDB_CLOCKS \
281 { \
282 kCLOCK_Pdb0 \
283 }
284
285/*! @brief Clock ip name array for FTF. */
286#define FTF_CLOCKS \
287 { \
288 kCLOCK_Ftf0 \
289 }
290
291/*! @brief Clock ip name array for CMP. */
292#define CMP_CLOCKS \
293 { \
294 kCLOCK_Cmp0, kCLOCK_Cmp1 \
295 }
296
297/*!
298 * @brief LPO clock frequency.
299 */
300#define LPO_CLK_FREQ 1000U
301
302/*! @brief Peripherals clock source definition. */
303#define SYS_CLK kCLOCK_CoreSysClk
304#define BUS_CLK kCLOCK_BusClk
305
306#define I2C0_CLK_SRC BUS_CLK
307#define I2C1_CLK_SRC BUS_CLK
308#define I2C2_CLK_SRC BUS_CLK
309#define I2C3_CLK_SRC BUS_CLK
310#define DSPI0_CLK_SRC BUS_CLK
311#define DSPI1_CLK_SRC BUS_CLK
312#define DSPI2_CLK_SRC BUS_CLK
313#define DSPI3_CLK_SRC BUS_CLK
314
315/*! @brief Clock name used to get clock frequency. */
316typedef enum _clock_name
317{
318
319 /* ----------------------------- System layer clock -------------------------------*/
320 kCLOCK_CoreSysClk, /*!< Core/system clock */
321 kCLOCK_PlatClk, /*!< Platform clock */
322 kCLOCK_BusClk, /*!< Bus clock */
323 kCLOCK_FlexBusClk, /*!< FlexBus clock */
324 kCLOCK_FlashClk, /*!< Flash clock */
325 kCLOCK_FastPeriphClk, /*!< Fast peripheral clock */
326 kCLOCK_PllFllSelClk, /*!< The clock after SIM[PLLFLLSEL]. */
327
328 /* ---------------------------------- OSC clock -----------------------------------*/
329 kCLOCK_Er32kClk, /*!< External reference 32K clock (ERCLK32K) */
330 kCLOCK_Osc0ErClk, /*!< OSC0 external reference clock (OSC0ERCLK) */
331 kCLOCK_Osc1ErClk, /*!< OSC1 external reference clock (OSC1ERCLK) */
332 kCLOCK_Osc0ErClkUndiv, /*!< OSC0 external reference undivided clock(OSC0ERCLK_UNDIV). */
333
334 /* ----------------------------- MCG and MCG-Lite clock ---------------------------*/
335 kCLOCK_McgFixedFreqClk, /*!< MCG fixed frequency clock (MCGFFCLK) */
336 kCLOCK_McgInternalRefClk, /*!< MCG internal reference clock (MCGIRCLK) */
337 kCLOCK_McgFllClk, /*!< MCGFLLCLK */
338 kCLOCK_McgPll0Clk, /*!< MCGPLL0CLK */
339 kCLOCK_McgPll1Clk, /*!< MCGPLL1CLK */
340 kCLOCK_McgExtPllClk, /*!< EXT_PLLCLK */
341 kCLOCK_McgPeriphClk, /*!< MCG peripheral clock (MCGPCLK) */
342 kCLOCK_McgIrc48MClk, /*!< MCG IRC48M clock */
343
344 /* --------------------------------- Other clock ----------------------------------*/
345 kCLOCK_LpoClk, /*!< LPO clock */
346
347} clock_name_t;
348
349/*! @brief USB clock source definition. */
350typedef enum _clock_usb_src
351{
352 kCLOCK_UsbSrcPll0 = SIM_SOPT2_USBSRC(1U) | SIM_SOPT2_PLLFLLSEL(1U), /*!< Use PLL0. */
353 kCLOCK_UsbSrcUsbPfd = SIM_SOPT2_USBSRC(1U) | SIM_SOPT2_PLLFLLSEL(2U), /*!< Use USBPFDCLK. */
354 kCLOCK_UsbSrcIrc48M = SIM_SOPT2_USBSRC(1U) | SIM_SOPT2_PLLFLLSEL(3U), /*!< Use IRC48M. */
355 kCLOCK_UsbSrcExt = SIM_SOPT2_USBSRC(0U), /*!< Use USB_CLKIN. */
356 kCLOCK_UsbSrcUnused = (int)0xFFFFFFFFU, /*!< Used when the function does not
357 care the clock source. */
358} clock_usb_src_t;
359/*------------------------------------------------------------------------------
360
361 clock_gate_t definition:
362
363 31 16 0
364 -----------------------------------------------------------------
365 | SIM_SCGC register offset | control bit offset in SCGC |
366 -----------------------------------------------------------------
367
368 For example, the SDHC clock gate is controlled by SIM_SCGC3[17], the
369 SIM_SCGC3 offset in SIM is 0x1030, then kClockGateSdhc0 is defined as
370
371 kClockGateSdhc0 = (0x1030 << 16) | 17;
372
373------------------------------------------------------------------------------*/
374
375#define CLK_GATE_REG_OFFSET_SHIFT 16U
376#define CLK_GATE_REG_OFFSET_MASK 0xFFFF0000U
377#define CLK_GATE_BIT_SHIFT_SHIFT 0U
378#define CLK_GATE_BIT_SHIFT_MASK 0x0000FFFFU
379
380#define CLK_GATE_DEFINE(reg_offset, bit_shift) \
381 ((((reg_offset) << CLK_GATE_REG_OFFSET_SHIFT) & CLK_GATE_REG_OFFSET_MASK) | \
382 (((bit_shift) << CLK_GATE_BIT_SHIFT_SHIFT) & CLK_GATE_BIT_SHIFT_MASK))
383
384#define CLK_GATE_ABSTRACT_REG_OFFSET(x) (((x)&CLK_GATE_REG_OFFSET_MASK) >> CLK_GATE_REG_OFFSET_SHIFT)
385#define CLK_GATE_ABSTRACT_BITS_SHIFT(x) (((x)&CLK_GATE_BIT_SHIFT_MASK) >> CLK_GATE_BIT_SHIFT_SHIFT)
386
387/*! @brief Clock gate name used for CLOCK_EnableClock/CLOCK_DisableClock. */
388typedef enum _clock_ip_name
389{
390 kCLOCK_IpInvalid = 0U,
391 kCLOCK_I2c2 = CLK_GATE_DEFINE(0x1028U, 6U),
392 kCLOCK_I2c3 = CLK_GATE_DEFINE(0x1028U, 7U),
393
394 kCLOCK_Lpuart0 = CLK_GATE_DEFINE(0x102CU, 4U),
395 kCLOCK_Lpuart1 = CLK_GATE_DEFINE(0x102CU, 5U),
396 kCLOCK_Lpuart2 = CLK_GATE_DEFINE(0x102CU, 6U),
397 kCLOCK_Lpuart3 = CLK_GATE_DEFINE(0x102CU, 7U),
398 kCLOCK_Tpm1 = CLK_GATE_DEFINE(0x102CU, 9U),
399 kCLOCK_Tpm2 = CLK_GATE_DEFINE(0x102CU, 10U),
400 kCLOCK_Dac0 = CLK_GATE_DEFINE(0x102CU, 12U),
401 kCLOCK_Lpuart4 = CLK_GATE_DEFINE(0x102CU, 22U),
402 kCLOCK_Qspi0 = CLK_GATE_DEFINE(0x102CU, 26U),
403 kCLOCK_Flexio0 = CLK_GATE_DEFINE(0x102CU, 31U),
404
405 kCLOCK_Trng0 = CLK_GATE_DEFINE(0x1030U, 0U),
406 kCLOCK_Usbhs = CLK_GATE_DEFINE(0x1030U, 1U),
407 kCLOCK_Usbhsphy = CLK_GATE_DEFINE(0x1030U, 2U),
408 kCLOCK_Usbhsdcd = CLK_GATE_DEFINE(0x1030U, 3U),
409 kCLOCK_Spi2 = CLK_GATE_DEFINE(0x1030U, 12U),
410 kCLOCK_Spi3 = CLK_GATE_DEFINE(0x1030U, 13U),
411 kCLOCK_Sai1 = CLK_GATE_DEFINE(0x1030U, 15U),
412 kCLOCK_Sdhc0 = CLK_GATE_DEFINE(0x1030U, 17U),
413 kCLOCK_Ftm2 = CLK_GATE_DEFINE(0x1030U, 24U),
414 kCLOCK_Ftm3 = CLK_GATE_DEFINE(0x1030U, 25U),
415
416 kCLOCK_Ewm0 = CLK_GATE_DEFINE(0x1034U, 1U),
417 kCLOCK_Cmt0 = CLK_GATE_DEFINE(0x1034U, 2U),
418 kCLOCK_I2c0 = CLK_GATE_DEFINE(0x1034U, 6U),
419 kCLOCK_I2c1 = CLK_GATE_DEFINE(0x1034U, 7U),
420 kCLOCK_Usbfs0 = CLK_GATE_DEFINE(0x1034U, 18U),
421 kCLOCK_Cmp0 = CLK_GATE_DEFINE(0x1034U, 19U),
422 kCLOCK_Cmp1 = CLK_GATE_DEFINE(0x1034U, 19U),
423 kCLOCK_Vref0 = CLK_GATE_DEFINE(0x1034U, 20U),
424
425 kCLOCK_Lptmr0 = CLK_GATE_DEFINE(0x1038U, 0U),
426 kCLOCK_Lptmr1 = CLK_GATE_DEFINE(0x1038U, 4U),
427 kCLOCK_Tsi0 = CLK_GATE_DEFINE(0x1038U, 5U),
428 kCLOCK_PortA = CLK_GATE_DEFINE(0x1038U, 9U),
429 kCLOCK_PortB = CLK_GATE_DEFINE(0x1038U, 10U),
430 kCLOCK_PortC = CLK_GATE_DEFINE(0x1038U, 11U),
431 kCLOCK_PortD = CLK_GATE_DEFINE(0x1038U, 12U),
432 kCLOCK_PortE = CLK_GATE_DEFINE(0x1038U, 13U),
433
434 kCLOCK_Ftf0 = CLK_GATE_DEFINE(0x103CU, 0U),
435 kCLOCK_Dmamux0 = CLK_GATE_DEFINE(0x103CU, 1U),
436 kCLOCK_Spi0 = CLK_GATE_DEFINE(0x103CU, 12U),
437 kCLOCK_Spi1 = CLK_GATE_DEFINE(0x103CU, 13U),
438 kCLOCK_Sai0 = CLK_GATE_DEFINE(0x103CU, 15U),
439 kCLOCK_Crc0 = CLK_GATE_DEFINE(0x103CU, 18U),
440 kCLOCK_Usbdcd0 = CLK_GATE_DEFINE(0x103CU, 21U),
441 kCLOCK_Pdb0 = CLK_GATE_DEFINE(0x103CU, 22U),
442 kCLOCK_Pit0 = CLK_GATE_DEFINE(0x103CU, 23U),
443 kCLOCK_Ftm0 = CLK_GATE_DEFINE(0x103CU, 24U),
444 kCLOCK_Ftm1 = CLK_GATE_DEFINE(0x103CU, 25U),
445 kCLOCK_Adc0 = CLK_GATE_DEFINE(0x103CU, 27U),
446 kCLOCK_Rtc0 = CLK_GATE_DEFINE(0x103CU, 29U),
447
448 kCLOCK_Flexbus0 = CLK_GATE_DEFINE(0x1040U, 0U),
449 kCLOCK_Dma0 = CLK_GATE_DEFINE(0x1040U, 1U),
450 kCLOCK_Sysmpu0 = CLK_GATE_DEFINE(0x1040U, 2U),
451 kCLOCK_Sdramc0 = CLK_GATE_DEFINE(0x1040U, 3U),
452} clock_ip_name_t;
453
454/*! @brief Source of the USB HS PHY. */
455typedef enum _clock_usb_phy_src
456{
457 kCLOCK_UsbPhySrcExt = 0U, /*!< Use external crystal. */
458} clock_usb_phy_src_t;
459
460/*! @brief Source of the USB HS PFD clock (USB1PFDCLK) */
461typedef enum _clock_usb_pfd_src
462{
463 kCLOCK_UsbPfdSrcExt = 0U, /*!< Use external crystal. */
464 kCLOCK_UsbPfdSrcFracDivBy4 = 1U, /*!< Use PFD_FRAC output divided by 4. */
465 kCLOCK_UsbPfdSrcFracDivBy2 = 2U, /*!< Use PFD_FRAC output divided by 2. */
466 kCLOCK_UsbPfdSrcFrac = 3U, /*!< Use PFD_FRAC output. */
467} clock_usb_pfd_src_t;
468
469/*!@brief SIM configuration structure for clock setting. */
470typedef struct _sim_clock_config
471{
472 uint8_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
473 uint8_t pllFllDiv; /*!< PLLFLLSEL clock divider divisor. */
474 uint8_t pllFllFrac; /*!< PLLFLLSEL clock divider fraction. */
475 uint8_t er32kSrc; /*!< ERCLK32K source selection. */
476 uint32_t clkdiv1; /*!< SIM_CLKDIV1. */
477} sim_clock_config_t;
478
479/*! @brief OSC work mode. */
480typedef enum _osc_mode
481{
482 kOSC_ModeExt = 0U, /*!< Use an external clock. */
483#if (defined(MCG_C2_EREFS_MASK) && !(defined(MCG_C2_EREFS0_MASK)))
484 kOSC_ModeOscLowPower = MCG_C2_EREFS_MASK, /*!< Oscillator low power. */
485#else
486 kOSC_ModeOscLowPower = MCG_C2_EREFS0_MASK, /*!< Oscillator low power. */
487#endif
488 kOSC_ModeOscHighGain = 0U
489#if (defined(MCG_C2_EREFS_MASK) && !(defined(MCG_C2_EREFS0_MASK)))
490 | MCG_C2_EREFS_MASK
491#else
492 | MCG_C2_EREFS0_MASK
493#endif
494#if (defined(MCG_C2_HGO_MASK) && !(defined(MCG_C2_HGO0_MASK)))
495 | MCG_C2_HGO_MASK, /*!< Oscillator high gain. */
496#else
497 | MCG_C2_HGO0_MASK, /*!< Oscillator high gain. */
498#endif
499} osc_mode_t;
500
501/*! @brief Oscillator capacitor load setting.*/
502enum _osc_cap_load
503{
504 kOSC_Cap2P = OSC_CR_SC2P_MASK, /*!< 2 pF capacitor load */
505 kOSC_Cap4P = OSC_CR_SC4P_MASK, /*!< 4 pF capacitor load */
506 kOSC_Cap8P = OSC_CR_SC8P_MASK, /*!< 8 pF capacitor load */
507 kOSC_Cap16P = OSC_CR_SC16P_MASK /*!< 16 pF capacitor load */
508};
509
510/*! @brief OSCERCLK enable mode. */
511enum _oscer_enable_mode
512{
513 kOSC_ErClkEnable = OSC_CR_ERCLKEN_MASK, /*!< Enable. */
514 kOSC_ErClkEnableInStop = OSC_CR_EREFSTEN_MASK /*!< Enable in stop mode. */
515};
516
517/*! @brief OSC configuration for OSCERCLK. */
518typedef struct _oscer_config
519{
520 uint8_t enableMode; /*!< OSCERCLK enable mode. OR'ed value of @ref _oscer_enable_mode. */
521
522 uint8_t erclkDiv; /*!< Divider for OSCERCLK.*/
523} oscer_config_t;
524
525/*!
526 * @brief OSC Initialization Configuration Structure
527 *
528 * Defines the configuration data structure to initialize the OSC.
529 * When porting to a new board, set the following members
530 * according to the board setting:
531 * 1. freq: The external frequency.
532 * 2. workMode: The OSC module mode.
533 */
534typedef struct _osc_config
535{
536 uint32_t freq; /*!< External clock frequency. */
537 uint8_t capLoad; /*!< Capacitor load setting. */
538 osc_mode_t workMode; /*!< OSC work mode setting. */
539 oscer_config_t oscerConfig; /*!< Configuration for OSCERCLK. */
540} osc_config_t;
541
542/*! @brief MCG FLL reference clock source select. */
543typedef enum _mcg_fll_src
544{
545 kMCG_FllSrcExternal, /*!< External reference clock is selected */
546 kMCG_FllSrcInternal /*!< The slow internal reference clock is selected */
547} mcg_fll_src_t;
548
549/*! @brief MCG internal reference clock select */
550typedef enum _mcg_irc_mode
551{
552 kMCG_IrcSlow, /*!< Slow internal reference clock selected */
553 kMCG_IrcFast /*!< Fast internal reference clock selected */
554} mcg_irc_mode_t;
555
556/*! @brief MCG DCO Maximum Frequency with 32.768 kHz Reference */
557typedef enum _mcg_dmx32
558{
559 kMCG_Dmx32Default, /*!< DCO has a default range of 25% */
560 kMCG_Dmx32Fine /*!< DCO is fine-tuned for maximum frequency with 32.768 kHz reference */
561} mcg_dmx32_t;
562
563/*! @brief MCG DCO range select */
564typedef enum _mcg_drs
565{
566 kMCG_DrsLow, /*!< Low frequency range */
567 kMCG_DrsMid, /*!< Mid frequency range */
568 kMCG_DrsMidHigh, /*!< Mid-High frequency range */
569 kMCG_DrsHigh /*!< High frequency range */
570} mcg_drs_t;
571
572/*! @brief MCG PLL reference clock select */
573typedef enum _mcg_pll_ref_src
574{
575 kMCG_PllRefOsc0, /*!< Selects OSC0 as PLL reference clock */
576 kMCG_PllRefOsc1 /*!< Selects OSC1 as PLL reference clock */
577} mcg_pll_ref_src_t;
578
579/*! @brief MCGOUT clock source. */
580typedef enum _mcg_clkout_src
581{
582 kMCG_ClkOutSrcOut, /*!< Output of the FLL is selected (reset default) */
583 kMCG_ClkOutSrcInternal, /*!< Internal reference clock is selected */
584 kMCG_ClkOutSrcExternal, /*!< External reference clock is selected */
585} mcg_clkout_src_t;
586
587/*! @brief MCG Automatic Trim Machine Select */
588typedef enum _mcg_atm_select
589{
590 kMCG_AtmSel32k, /*!< 32 kHz Internal Reference Clock selected */
591 kMCG_AtmSel4m /*!< 4 MHz Internal Reference Clock selected */
592} mcg_atm_select_t;
593
594/*! @brief MCG OSC Clock Select */
595typedef enum _mcg_oscsel
596{
597 kMCG_OscselOsc, /*!< Selects System Oscillator (OSCCLK) */
598 kMCG_OscselRtc, /*!< Selects 32 kHz RTC Oscillator */
599 kMCG_OscselIrc /*!< Selects 48 MHz IRC Oscillator */
600} mcg_oscsel_t;
601
602/*! @brief MCG PLLCS select */
603typedef enum _mcg_pll_clk_select
604{
605 kMCG_PllClkSelPll0, /*!< PLL0 output clock is selected */
606 kMCG_PllClkSelExtPll /* The external PLL clock is selected */
607} mcg_pll_clk_select_t;
608
609/*! @brief MCG clock monitor mode. */
610typedef enum _mcg_monitor_mode
611{
612 kMCG_MonitorNone, /*!< Clock monitor is disabled. */
613 kMCG_MonitorInt, /*!< Trigger interrupt when clock lost. */
614 kMCG_MonitorReset /*!< System reset when clock lost. */
615} mcg_monitor_mode_t;
616
617/*! @brief MCG status. */
618enum
619{
620 kStatus_MCG_ModeUnreachable = MAKE_STATUS(kStatusGroup_MCG, 0U), /*!< Can't switch to target mode. */
621 kStatus_MCG_ModeInvalid = MAKE_STATUS(kStatusGroup_MCG, 1U), /*!< Current mode invalid for the specific
622 function. */
623 kStatus_MCG_AtmBusClockInvalid = MAKE_STATUS(kStatusGroup_MCG, 2U), /*!< Invalid bus clock for ATM. */
624 kStatus_MCG_AtmDesiredFreqInvalid = MAKE_STATUS(kStatusGroup_MCG, 3U), /*!< Invalid desired frequency for ATM. */
625 kStatus_MCG_AtmIrcUsed = MAKE_STATUS(kStatusGroup_MCG, 4U), /*!< IRC is used when using ATM. */
626 kStatus_MCG_AtmHardwareFail = MAKE_STATUS(kStatusGroup_MCG, 5U), /*!< Hardware fail occurs during ATM. */
627 kStatus_MCG_SourceUsed = MAKE_STATUS(kStatusGroup_MCG, 6U) /*!< Can't change the clock source because
628 it is in use. */
629};
630
631/*! @brief MCG status flags. */
632enum
633{
634 kMCG_Osc0LostFlag = (1U << 0U), /*!< OSC0 lost. */
635 kMCG_Osc0InitFlag = (1U << 1U), /*!< OSC0 crystal initialized. */
636 kMCG_RtcOscLostFlag = (1U << 4U), /*!< RTC OSC lost. */
637 kMCG_Pll0LostFlag = (1U << 5U), /*!< PLL0 lost. */
638 kMCG_Pll0LockFlag = (1U << 6U), /*!< PLL0 locked. */
639 kMCG_ExtPllLostFlag = (1U << 9U), /*!< External PLL lost. */
640};
641
642/*! @brief MCG internal reference clock (MCGIRCLK) enable mode definition. */
643enum
644{
645 kMCG_IrclkEnable = MCG_C1_IRCLKEN_MASK, /*!< MCGIRCLK enable. */
646 kMCG_IrclkEnableInStop = MCG_C1_IREFSTEN_MASK /*!< MCGIRCLK enable in stop mode. */
647};
648
649/*! @brief MCG PLL clock enable mode definition. */
650enum
651{
652 kMCG_PllEnableIndependent = MCG_C5_PLLCLKEN0_MASK, /*!< MCGPLLCLK enable independent of the
653 MCG clock mode. Generally, the PLL
654 is disabled in FLL modes
655 (FEI/FBI/FEE/FBE). Setting the PLL clock
656 enable independent, enables the
657 PLL in the FLL modes. */
658 kMCG_PllEnableInStop = MCG_C5_PLLSTEN0_MASK /*!< MCGPLLCLK enable in STOP mode. */
659};
660
661/*! @brief MCG mode definitions */
662typedef enum _mcg_mode
663{
664 kMCG_ModeFEI = 0U, /*!< FEI - FLL Engaged Internal */
665 kMCG_ModeFBI, /*!< FBI - FLL Bypassed Internal */
666 kMCG_ModeBLPI, /*!< BLPI - Bypassed Low Power Internal */
667 kMCG_ModeFEE, /*!< FEE - FLL Engaged External */
668 kMCG_ModeFBE, /*!< FBE - FLL Bypassed External */
669 kMCG_ModeBLPE, /*!< BLPE - Bypassed Low Power External */
670 kMCG_ModePBE, /*!< PBE - PLL Bypassed External */
671 kMCG_ModePEE, /*!< PEE - PLL Engaged External */
672 kMCG_ModeError /*!< Unknown mode */
673} mcg_mode_t;
674
675/*! @brief MCG PLL configuration. */
676typedef struct _mcg_pll_config
677{
678 uint8_t enableMode; /*!< Enable mode. OR'ed value of _mcg_pll_enable_mode. */
679 uint8_t prdiv; /*!< Reference divider PRDIV. */
680 uint8_t vdiv; /*!< VCO divider VDIV. */
681} mcg_pll_config_t;
682
683/*! @brief MCG mode change configuration structure
684 *
685 * When porting to a new board, set the following members
686 * according to the board setting:
687 * 1. frdiv: If the FLL uses the external reference clock, set this
688 * value to ensure that the external reference clock divided by frdiv is
689 * in the 31.25 kHz to 39.0625 kHz range.
690 * 2. The PLL reference clock divider PRDIV: PLL reference clock frequency after
691 * PRDIV should be in the FSL_FEATURE_MCG_PLL_REF_MIN to
692 * FSL_FEATURE_MCG_PLL_REF_MAX range.
693 */
694typedef struct _mcg_config
695{
696 mcg_mode_t mcgMode; /*!< MCG mode. */
697
698 /* ----------------------- MCGIRCCLK settings ------------------------ */
699 uint8_t irclkEnableMode; /*!< MCGIRCLK enable mode. */
700 mcg_irc_mode_t ircs; /*!< Source, MCG_C2[IRCS]. */
701 uint8_t fcrdiv; /*!< Divider, MCG_SC[FCRDIV]. */
702
703 /* ------------------------ MCG FLL settings ------------------------- */
704 uint8_t frdiv; /*!< Divider MCG_C1[FRDIV]. */
705 mcg_drs_t drs; /*!< DCO range MCG_C4[DRST_DRS]. */
706 mcg_dmx32_t dmx32; /*!< MCG_C4[DMX32]. */
707 mcg_oscsel_t oscsel; /*!< OSC select MCG_C7[OSCSEL]. */
708
709 /* ------------------------ MCG PLL settings ------------------------- */
710 mcg_pll_config_t pll0Config; /*!< MCGPLL0CLK configuration. */
711
712 mcg_pll_clk_select_t pllcs; /*!< PLL select as output, PLLCS.*/
713
714} mcg_config_t;
715
716/*******************************************************************************
717 * API
718 ******************************************************************************/
719
720#if defined(__cplusplus)
721extern "C" {
722#endif /* __cplusplus */
723
724/*!
725 * @brief Enable the clock for specific IP.
726 *
727 * @param name Which clock to enable, see \ref clock_ip_name_t.
728 */
729static inline void CLOCK_EnableClock(clock_ip_name_t name)
730{
731 uint32_t regAddr = SIM_BASE + CLK_GATE_ABSTRACT_REG_OFFSET((uint32_t)name);
732 (*(volatile uint32_t *)regAddr) |= (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT((uint32_t)name));
733}
734
735/*!
736 * @brief Disable the clock for specific IP.
737 *
738 * @param name Which clock to disable, see \ref clock_ip_name_t.
739 */
740static inline void CLOCK_DisableClock(clock_ip_name_t name)
741{
742 uint32_t regAddr = SIM_BASE + CLK_GATE_ABSTRACT_REG_OFFSET((uint32_t)name);
743 (*(volatile uint32_t *)regAddr) &= ~(1UL << CLK_GATE_ABSTRACT_BITS_SHIFT((uint32_t)name));
744}
745
746/*!
747 * @brief Set ERCLK32K source.
748 *
749 * @param src The value to set ERCLK32K clock source.
750 */
751static inline void CLOCK_SetEr32kClock(uint32_t src)
752{
753 SIM->SOPT1 = ((SIM->SOPT1 & ~SIM_SOPT1_OSC32KSEL_MASK) | SIM_SOPT1_OSC32KSEL(src));
754}
755
756/*!
757 * @brief Set SDHC0 clock source.
758 *
759 * @param src The value to set SDHC0 clock source.
760 */
761static inline void CLOCK_SetSdhc0Clock(uint32_t src)
762{
763 SIM->SOPT2 = ((SIM->SOPT2 & ~SIM_SOPT2_SDHCSRC_MASK) | SIM_SOPT2_SDHCSRC(src));
764}
765
766/*!
767 * @brief Set LPUART clock source.
768 *
769 * @param src The value to set LPUART clock source.
770 */
771static inline void CLOCK_SetLpuartClock(uint32_t src)
772{
773 SIM->SOPT2 = ((SIM->SOPT2 & ~SIM_SOPT2_LPUARTSRC_MASK) | SIM_SOPT2_LPUARTSRC(src));
774}
775
776/*!
777 * @brief Set TPM clock source.
778 *
779 * @param src The value to set TPM clock source.
780 */
781static inline void CLOCK_SetTpmClock(uint32_t src)
782{
783 SIM->SOPT2 = ((SIM->SOPT2 & ~SIM_SOPT2_TPMSRC_MASK) | SIM_SOPT2_TPMSRC(src));
784}
785
786/*!
787 * @brief Set FLEXIO clock source.
788 *
789 * @param src The value to set FLEXIO clock source.
790 */
791static inline void CLOCK_SetFlexio0Clock(uint32_t src)
792{
793 SIM->SOPT2 = ((SIM->SOPT2 & ~SIM_SOPT2_FLEXIOSRC_MASK) | SIM_SOPT2_FLEXIOSRC(src));
794}
795
796/*!
797 * @brief Set USB clock source.
798 *
799 * @param src The value to set USB clock source.
800 */
801static inline void CLOCK_SetUsbClock(uint32_t src)
802{
803 SIM->SOPT2 = ((SIM->SOPT2 & ~SIM_SOPT2_USBSRC_MASK) | SIM_SOPT2_USBSRC(src));
804}
805
806/*!
807 * @brief Set debug trace clock source.
808 *
809 * @param src The value to set debug trace clock source.
810 * @param divValue
811 * @param fracValue
812 */
813static inline void CLOCK_SetTraceClock(uint32_t src, uint32_t divValue, uint32_t fracValue)
814{
815 SIM->SOPT2 = ((SIM->SOPT2 & ~SIM_SOPT2_TRACECLKSEL_MASK) | SIM_SOPT2_TRACECLKSEL(src));
816 SIM->CLKDIV4 = SIM_CLKDIV4_TRACEDIV(divValue) | SIM_CLKDIV4_TRACEFRAC(fracValue);
817}
818
819/*!
820 * @brief Set PLLFLLSEL clock source.
821 *
822 * @param src The value to set PLLFLLSEL clock source.
823 * @param divValue
824 * @param fracValue
825 */
826static inline void CLOCK_SetPllFllSelClock(uint32_t src, uint32_t divValue, uint32_t fracValue)
827{
828 SIM->SOPT2 = ((SIM->SOPT2 & ~SIM_SOPT2_PLLFLLSEL_MASK) | SIM_SOPT2_PLLFLLSEL(src));
829 SIM->CLKDIV3 = SIM_CLKDIV3_PLLFLLDIV(divValue) | SIM_CLKDIV3_PLLFLLFRAC(fracValue);
830}
831
832/*!
833 * @brief Set CLKOUT source.
834 *
835 * @param src The value to set CLKOUT source.
836 */
837static inline void CLOCK_SetClkOutClock(uint32_t src)
838{
839 SIM->SOPT2 = ((SIM->SOPT2 & ~SIM_SOPT2_CLKOUTSEL_MASK) | SIM_SOPT2_CLKOUTSEL(src));
840}
841
842/*!
843 * @brief Set RTC_CLKOUT source.
844 *
845 * @param src The value to set RTC_CLKOUT source.
846 */
847static inline void CLOCK_SetRtcClkOutClock(uint32_t src)
848{
849 SIM->SOPT2 = ((SIM->SOPT2 & ~SIM_SOPT2_RTCCLKOUTSEL_MASK) | SIM_SOPT2_RTCCLKOUTSEL(src));
850}
851
852/*! @brief Enable USB HS clock.
853 *
854 * @param src USB HS clock source.
855 * @param freq The frequency specified by src.
856 * @retval true The clock is set successfully.
857 * @retval false The clock source is invalid to get proper USB HS clock.
858 */
859bool CLOCK_EnableUsbhs0Clock(clock_usb_src_t src, uint32_t freq);
860
861/*! @brief Disable USB HS clock.
862 *
863 * Disable USB HS clock.
864 *
865 */
866void CLOCK_DisableUsbhs0Clock(void);
867
868/*! @ brief Disable USB hs0 Phy Pll Clock
869 *
870 * Disable USB hs0 Phy Pll Clock
871 */
872void CLOCK_DisableUsbhs0PhyPllClock(void);
873
874/*! Enable USB hs0 Pfd clock
875 *
876 * @param src USB hs0 clock source.
877 * @param frac
878 *
879 */
880void CLOCK_EnableUsbhs0PfdClock(uint8_t frac, clock_usb_pfd_src_t src);
881
882/*! @ brief Disable USB hs0 Pfd Pll Clock
883 *
884 * Disable USB hs0 Pfd Pll Clock
885 */
886void CLOCK_DisableUsbhs0PfdClock(void);
887
888/*! @brief Enable USB FS clock.
889 *
890 * @param src USB FS clock source.
891 * @param freq The frequency specified by src.
892 * @retval true The clock is set successfully.
893 * @retval false The clock source is invalid to get proper USB FS clock.
894 */
895bool CLOCK_EnableUsbfs0Clock(clock_usb_src_t src, uint32_t freq);
896
897/*! @brief Enable USB hs0PhyPll clock.
898 *
899 * @param src USB HS clock source.
900 * @param freq The frequency specified by src.
901 * @retval true The clock is set successfully.
902 * @retval false The clock source is invalid to get proper USB HS clock.
903 */
904bool CLOCK_EnableUsbhs0PhyPllClock(clock_usb_phy_src_t src, uint32_t freq);
905
906/*! @brief Disable USB FS clock.
907 *
908 * Disable USB FS clock.
909 */
910static inline void CLOCK_DisableUsbfs0Clock(void)
911{
912 CLOCK_DisableClock(kCLOCK_Usbfs0);
913}
914
915/*!
916 * @brief System clock divider
917 *
918 * Set the SIM_CLKDIV1[OUTDIV1], SIM_CLKDIV1[OUTDIV2], SIM_CLKDIV1[OUTDIV3], SIM_CLKDIV1[OUTDIV4].
919 *
920 * @param outdiv1 Clock 1 output divider value.
921 *
922 * @param outdiv2 Clock 2 output divider value.
923 *
924 * @param outdiv3 Clock 3 output divider value.
925 *
926 * @param outdiv4 Clock 4 output divider value.
927 */
928static inline void CLOCK_SetOutDiv(uint32_t outdiv1, uint32_t outdiv2, uint32_t outdiv3, uint32_t outdiv4)
929{
930 SIM->CLKDIV1 = SIM_CLKDIV1_OUTDIV1(outdiv1) | SIM_CLKDIV1_OUTDIV2(outdiv2) | SIM_CLKDIV1_OUTDIV3(outdiv3) |
931 SIM_CLKDIV1_OUTDIV4(outdiv4);
932}
933
934/*!
935 * @brief Gets the clock frequency for a specific clock name.
936 *
937 * This function checks the current clock configurations and then calculates
938 * the clock frequency for a specific clock name defined in clock_name_t.
939 * The MCG must be properly configured before using this function.
940 *
941 * @param clockName Clock names defined in clock_name_t
942 * @return Clock frequency value in Hertz
943 */
944uint32_t CLOCK_GetFreq(clock_name_t clockName);
945
946/*!
947 * @brief Get the core clock or system clock frequency.
948 *
949 * @return Clock frequency in Hz.
950 */
951uint32_t CLOCK_GetCoreSysClkFreq(void);
952
953/*!
954 * @brief Get the platform clock frequency.
955 *
956 * @return Clock frequency in Hz.
957 */
958uint32_t CLOCK_GetPlatClkFreq(void);
959
960/*!
961 * @brief Get the bus clock frequency.
962 *
963 * @return Clock frequency in Hz.
964 */
965uint32_t CLOCK_GetBusClkFreq(void);
966
967/*!
968 * @brief Get the flexbus clock frequency.
969 *
970 * @return Clock frequency in Hz.
971 */
972uint32_t CLOCK_GetFlexBusClkFreq(void);
973
974/*!
975 * @brief Get the flash clock frequency.
976 *
977 * @return Clock frequency in Hz.
978 */
979uint32_t CLOCK_GetFlashClkFreq(void);
980
981/*!
982 * @brief Get the output clock frequency selected by SIM[PLLFLLSEL].
983 *
984 * @return Clock frequency in Hz.
985 */
986uint32_t CLOCK_GetPllFllSelClkFreq(void);
987
988/*!
989 * @brief Get the external reference 32K clock frequency (ERCLK32K).
990 *
991 * @return Clock frequency in Hz.
992 */
993uint32_t CLOCK_GetEr32kClkFreq(void);
994
995/*!
996 * @brief Get the OSC0 external reference undivided clock frequency (OSC0ERCLK_UNDIV).
997 *
998 * @return Clock frequency in Hz.
999 */
1000uint32_t CLOCK_GetOsc0ErClkUndivFreq(void);
1001
1002/*!
1003 * @brief Get the OSC0 external reference divided clock frequency (OSC0ERCLK_UNDIV).
1004 *
1005 * @return Clock frequency
1006 */
1007uint32_t CLOCK_GetOsc0ErClkDivFreq(void);
1008
1009/*!
1010 * @brief Get the OSC0 external reference clock frequency (OSC0ERCLK).
1011 *
1012 * @return Clock frequency in Hz.
1013 */
1014uint32_t CLOCK_GetOsc0ErClkFreq(void);
1015
1016/*!
1017 * @brief Set the clock configure in SIM module.
1018 *
1019 * This function sets system layer clock settings in SIM module.
1020 */
1021void CLOCK_SetSimConfig(sim_clock_config_t const *config);
1022
1023/*!
1024 * @brief Set the system clock dividers in SIM to safe value.
1025 *
1026 * The system level clocks (core clock, bus clock, flexbus clock and flash clock)
1027 * must be in allowed ranges. During MCG clock mode switch, the MCG output clock
1028 * changes then the system level clocks may be out of range. This function could
1029 * be used before MCG mode change, to make sure system level clocks are in allowed
1030 * range.
1031 *
1032 */
1033static inline void CLOCK_SetSimSafeDivs(void)
1034{
1035 SIM->CLKDIV1 = 0x02260000U;
1036}
1037
1038/*! @name MCG frequency functions. */
1039/*@{*/
1040
1041/*!
1042 * @brief Gets the MCG output clock (MCGOUTCLK) frequency.
1043 *
1044 * This function gets the MCG output clock frequency in Hz based on the current MCG
1045 * register value.
1046 *
1047 * @return The frequency of MCGOUTCLK.
1048 */
1049uint32_t CLOCK_GetOutClkFreq(void);
1050
1051/*!
1052 * @brief Gets the MCG FLL clock (MCGFLLCLK) frequency.
1053 *
1054 * This function gets the MCG FLL clock frequency in Hz based on the current MCG
1055 * register value. The FLL is enabled in FEI/FBI/FEE/FBE mode and
1056 * disabled in low power state in other modes.
1057 *
1058 * @return The frequency of MCGFLLCLK.
1059 */
1060uint32_t CLOCK_GetFllFreq(void);
1061
1062/*!
1063 * @brief Gets the MCG internal reference clock (MCGIRCLK) frequency.
1064 *
1065 * This function gets the MCG internal reference clock frequency in Hz based
1066 * on the current MCG register value.
1067 *
1068 * @return The frequency of MCGIRCLK.
1069 */
1070uint32_t CLOCK_GetInternalRefClkFreq(void);
1071
1072/*!
1073 * @brief Gets the MCG fixed frequency clock (MCGFFCLK) frequency.
1074 *
1075 * This function gets the MCG fixed frequency clock frequency in Hz based
1076 * on the current MCG register value.
1077 *
1078 * @return The frequency of MCGFFCLK.
1079 */
1080uint32_t CLOCK_GetFixedFreqClkFreq(void);
1081
1082/*!
1083 * @brief Gets the MCG PLL0 clock (MCGPLL0CLK) frequency.
1084 *
1085 * This function gets the MCG PLL0 clock frequency in Hz based on the current MCG
1086 * register value.
1087 *
1088 * @return The frequency of MCGPLL0CLK.
1089 */
1090uint32_t CLOCK_GetPll0Freq(void);
1091
1092/*!
1093 * @brief Gets the MCG external PLL frequency.
1094 *
1095 * This function gets the MCG external PLL frequency in Hz.
1096 *
1097 * @return The frequency of the MCG external PLL.
1098 */
1099uint32_t CLOCK_GetExtPllFreq(void);
1100
1101/*!
1102 * @brief Sets the MCG external PLL frequency.
1103 *
1104 * This function sets the MCG external PLL frequency in Hz. The MCG external PLL
1105 * frequency is passed to the MCG driver using this function. Call this
1106 * function after the external PLL frequency is changed. Otherwise, the APIs, which are used to get
1107 * the frequency, may return an incorrect value.
1108 *
1109 * @param freq The frequency of MCG external PLL.
1110 */
1111void CLOCK_SetExtPllFreq(uint32_t freq);
1112
1113/*@}*/
1114
1115/*! @name MCG clock configuration. */
1116/*@{*/
1117
1118/*!
1119 * @brief Enables or disables the MCG low power.
1120 *
1121 * Enabling the MCG low power disables the PLL and FLL in bypass modes. In other words,
1122 * in FBE and PBE modes, enabling low power sets the MCG to BLPE mode. In FBI and
1123 * PBI modes, enabling low power sets the MCG to BLPI mode.
1124 * When disabling the MCG low power, the PLL or FLL are enabled based on MCG settings.
1125 *
1126 * @param enable True to enable MCG low power, false to disable MCG low power.
1127 */
1128static inline void CLOCK_SetLowPowerEnable(bool enable)
1129{
1130 if (enable)
1131 {
1132 MCG->C2 |= MCG_C2_LP_MASK;
1133 }
1134 else
1135 {
1136 MCG->C2 &= ~(uint8_t)MCG_C2_LP_MASK;
1137 }
1138}
1139
1140/*!
1141 * @brief Configures the Internal Reference clock (MCGIRCLK).
1142 *
1143 * This function sets the \c MCGIRCLK base on parameters. It also selects the IRC
1144 * source. If the fast IRC is used, this function sets the fast IRC divider.
1145 * This function also sets whether the \c MCGIRCLK is enabled in stop mode.
1146 * Calling this function in FBI/PBI/BLPI modes may change the system clock. As a result,
1147 * using the function in these modes it is not allowed.
1148 *
1149 * @param enableMode MCGIRCLK enable mode, OR'ed value of _mcg_irclk_enable_mode.
1150 * @param ircs MCGIRCLK clock source, choose fast or slow.
1151 * @param fcrdiv Fast IRC divider setting (\c FCRDIV).
1152 * @retval kStatus_MCG_SourceUsed Because the internal reference clock is used as a clock source,
1153 * the configuration should not be changed. Otherwise, a glitch occurs.
1154 * @retval kStatus_Success MCGIRCLK configuration finished successfully.
1155 */
1156status_t CLOCK_SetInternalRefClkConfig(uint8_t enableMode, mcg_irc_mode_t ircs, uint8_t fcrdiv);
1157
1158/*!
1159 * @brief Selects the MCG external reference clock.
1160 *
1161 * Selects the MCG external reference clock source, changes the MCG_C7[OSCSEL],
1162 * and waits for the clock source to be stable. Because the external reference
1163 * clock should not be changed in FEE/FBE/BLPE/PBE/PEE modes, do not call this function in these modes.
1164 *
1165 * @param oscsel MCG external reference clock source, MCG_C7[OSCSEL].
1166 * @retval kStatus_MCG_SourceUsed Because the external reference clock is used as a clock source,
1167 * the configuration should not be changed. Otherwise, a glitch occurs.
1168 * @retval kStatus_Success External reference clock set successfully.
1169 */
1170status_t CLOCK_SetExternalRefClkConfig(mcg_oscsel_t oscsel);
1171
1172/*!
1173 * @brief Set the FLL external reference clock divider value.
1174 *
1175 * Sets the FLL external reference clock divider value, the register MCG_C1[FRDIV].
1176 *
1177 * @param frdiv The FLL external reference clock divider value, MCG_C1[FRDIV].
1178 */
1179static inline void CLOCK_SetFllExtRefDiv(uint8_t frdiv)
1180{
1181 MCG->C1 = (uint8_t)((MCG->C1 & ~MCG_C1_FRDIV_MASK) | MCG_C1_FRDIV(frdiv));
1182}
1183
1184/*!
1185 * @brief Enables the PLL0 in FLL mode.
1186 *
1187 * This function sets us the PLL0 in FLL mode and reconfigures
1188 * the PLL0. Ensure that the PLL reference
1189 * clock is enabled before calling this function and that the PLL0 is not used as a clock source.
1190 * The function CLOCK_CalcPllDiv gets the correct PLL
1191 * divider values.
1192 *
1193 * @param config Pointer to the configuration structure.
1194 */
1195void CLOCK_EnablePll0(mcg_pll_config_t const *config);
1196
1197/*!
1198 * @brief Disables the PLL0 in FLL mode.
1199 *
1200 * This function disables the PLL0 in FLL mode. It should be used together with the
1201 * @ref CLOCK_EnablePll0.
1202 */
1203static inline void CLOCK_DisablePll0(void)
1204{
1205 MCG->C5 &= (uint8_t)(~(MCG_C5_PLLCLKEN0_MASK | MCG_C5_PLLSTEN0_MASK));
1206}
1207
1208/*!
1209 * @brief Calculates the PLL divider setting for a desired output frequency.
1210 *
1211 * This function calculates the correct reference clock divider (\c PRDIV) and
1212 * VCO divider (\c VDIV) to generate a desired PLL output frequency. It returns the
1213 * closest frequency match with the corresponding \c PRDIV/VDIV
1214 * returned from parameters. If a desired frequency is not valid, this function
1215 * returns 0.
1216 *
1217 * @param refFreq PLL reference clock frequency.
1218 * @param desireFreq Desired PLL output frequency.
1219 * @param prdiv PRDIV value to generate desired PLL frequency.
1220 * @param vdiv VDIV value to generate desired PLL frequency.
1221 * @return Closest frequency match that the PLL was able generate.
1222 */
1223uint32_t CLOCK_CalcPllDiv(uint32_t refFreq, uint32_t desireFreq, uint8_t *prdiv, uint8_t *vdiv);
1224
1225/*!
1226 * @brief Set the PLL selection.
1227 *
1228 * This function sets the PLL selection between PLL0/PLL1/EXTPLL, and waits for
1229 * change finished.
1230 *
1231 * @param pllcs The PLL to select.
1232 */
1233void CLOCK_SetPllClkSel(mcg_pll_clk_select_t pllcs);
1234
1235/*@}*/
1236
1237/*! @name MCG clock lock monitor functions. */
1238/*@{*/
1239
1240/*!
1241 * @brief Sets the OSC0 clock monitor mode.
1242 *
1243 * This function sets the OSC0 clock monitor mode. See @ref mcg_monitor_mode_t for details.
1244 *
1245 * @param mode Monitor mode to set.
1246 */
1247void CLOCK_SetOsc0MonitorMode(mcg_monitor_mode_t mode);
1248
1249/*!
1250 * @brief Sets the RTC OSC clock monitor mode.
1251 *
1252 * This function sets the RTC OSC clock monitor mode. See @ref mcg_monitor_mode_t for details.
1253 *
1254 * @param mode Monitor mode to set.
1255 */
1256void CLOCK_SetRtcOscMonitorMode(mcg_monitor_mode_t mode);
1257
1258/*!
1259 * @brief Sets the PLL0 clock monitor mode.
1260 *
1261 * This function sets the PLL0 clock monitor mode. See @ref mcg_monitor_mode_t for details.
1262 *
1263 * @param mode Monitor mode to set.
1264 */
1265void CLOCK_SetPll0MonitorMode(mcg_monitor_mode_t mode);
1266
1267/*!
1268 * @brief Sets the external PLL clock monitor mode.
1269 *
1270 * This function ets the external PLL clock monitor mode. See @ref mcg_monitor_mode_t
1271 * for details.
1272 *
1273 * @param mode Monitor mode to set.
1274 */
1275void CLOCK_SetExtPllMonitorMode(mcg_monitor_mode_t mode);
1276
1277/*!
1278 * @brief Gets the MCG status flags.
1279 *
1280 * This function gets the MCG clock status flags. All status flags are
1281 * returned as a logical OR of the enumeration _mcg_status_flags_t. To
1282 * check a specific flag, compare the return value with the flag.
1283 *
1284 * Example:
1285 * @code
1286 * To check the clock lost lock status of OSC0 and PLL0.
1287 * uint32_t mcgFlags;
1288 *
1289 * mcgFlags = CLOCK_GetStatusFlags();
1290 *
1291 * if (mcgFlags & kMCG_Osc0LostFlag)
1292 * {
1293 * OSC0 clock lock lost. Do something.
1294 * }
1295 * if (mcgFlags & kMCG_Pll0LostFlag)
1296 * {
1297 * PLL0 clock lock lost. Do something.
1298 * }
1299 * @endcode
1300 *
1301 * @return Logical OR value of the _mcg_status_flags_t.
1302 */
1303uint32_t CLOCK_GetStatusFlags(void);
1304
1305/*!
1306 * @brief Clears the MCG status flags.
1307 *
1308 * This function clears the MCG clock lock lost status. The parameter is a logical
1309 * OR value of the flags to clear. See _mcg_status_flags_t.
1310 *
1311 * Example:
1312 * @code
1313 * To clear the clock lost lock status flags of OSC0 and PLL0.
1314 *
1315 * CLOCK_ClearStatusFlags(kMCG_Osc0LostFlag | kMCG_Pll0LostFlag);
1316 * @endcode
1317 *
1318 * @param mask The status flags to clear. This is a logical OR of members of the
1319 * enumeration _mcg_status_flags_t.
1320 */
1321void CLOCK_ClearStatusFlags(uint32_t mask);
1322
1323/*@}*/
1324
1325/*!
1326 * @name OSC configuration
1327 * @{
1328 */
1329
1330/*!
1331 * @brief Configures the OSC external reference clock (OSCERCLK).
1332 *
1333 * This function configures the OSC external reference clock (OSCERCLK).
1334 * This is an example to enable the OSCERCLK in normal and stop modes and also set
1335 * the output divider to 1:
1336 *
1337 @code
1338 oscer_config_t config =
1339 {
1340 .enableMode = kOSC_ErClkEnable | kOSC_ErClkEnableInStop,
1341 .erclkDiv = 1U,
1342 };
1343
1344 OSC_SetExtRefClkConfig(OSC, &config);
1345 @endcode
1346 *
1347 * @param base OSC peripheral address.
1348 * @param config Pointer to the configuration structure.
1349 */
1350static inline void OSC_SetExtRefClkConfig(OSC_Type *base, oscer_config_t const *config)
1351{
1352 uint8_t reg = base->CR;
1353
1354 reg &= (uint8_t)(~(OSC_CR_ERCLKEN_MASK | OSC_CR_EREFSTEN_MASK));
1355 reg |= config->enableMode;
1356
1357 base->CR = reg;
1358
1359 base->DIV = OSC_DIV_ERPS(config->erclkDiv);
1360}
1361
1362/*!
1363 * @brief Sets the capacitor load configuration for the oscillator.
1364 *
1365 * This function sets the specified capacitors configuration for the oscillator.
1366 * This should be done in the early system level initialization function call
1367 * based on the system configuration.
1368 *
1369 * @param base OSC peripheral address.
1370 * @param capLoad OR'ed value for the capacitor load option, see \ref _osc_cap_load.
1371 *
1372 * Example:
1373 @code
1374 To enable only 2 pF and 8 pF capacitor load, please use like this.
1375 OSC_SetCapLoad(OSC, kOSC_Cap2P | kOSC_Cap8P);
1376 @endcode
1377 */
1378static inline void OSC_SetCapLoad(OSC_Type *base, uint8_t capLoad)
1379{
1380 uint8_t reg = base->CR;
1381
1382 reg &= (uint8_t)(~(OSC_CR_SC2P_MASK | OSC_CR_SC4P_MASK | OSC_CR_SC8P_MASK | OSC_CR_SC16P_MASK));
1383 reg |= capLoad;
1384
1385 base->CR = reg;
1386}
1387
1388/*!
1389 * @brief Initializes the OSC0.
1390 *
1391 * This function initializes the OSC0 according to the board configuration.
1392 *
1393 * @param config Pointer to the OSC0 configuration structure.
1394 */
1395void CLOCK_InitOsc0(osc_config_t const *config);
1396
1397/*!
1398 * @brief Deinitializes the OSC0.
1399 *
1400 * This function deinitializes the OSC0.
1401 */
1402void CLOCK_DeinitOsc0(void);
1403
1404/* @} */
1405
1406/*!
1407 * @name External clock frequency
1408 * @{
1409 */
1410
1411/*!
1412 * @brief Sets the XTAL0 frequency based on board settings.
1413 *
1414 * @param freq The XTAL0/EXTAL0 input clock frequency in Hz.
1415 */
1416static inline void CLOCK_SetXtal0Freq(uint32_t freq)
1417{
1418 g_xtal0Freq = freq;
1419}
1420
1421/*!
1422 * @brief Sets the XTAL32/RTC_CLKIN frequency based on board settings.
1423 *
1424 * @param freq The XTAL32/EXTAL32/RTC_CLKIN input clock frequency in Hz.
1425 */
1426static inline void CLOCK_SetXtal32Freq(uint32_t freq)
1427{
1428 g_xtal32Freq = freq;
1429}
1430/* @} */
1431
1432/*!
1433 * @name IRCs frequency
1434 * @{
1435 */
1436
1437/*!
1438 * @brief Set the Slow IRC frequency based on the trimmed value
1439 *
1440 * @param freq The Slow IRC frequency input clock frequency in Hz.
1441 */
1442void CLOCK_SetSlowIrcFreq(uint32_t freq);
1443
1444/*!
1445 * @brief Set the Fast IRC frequency based on the trimmed value
1446 *
1447 * @param freq The Fast IRC frequency input clock frequency in Hz.
1448 */
1449void CLOCK_SetFastIrcFreq(uint32_t freq);
1450/* @} */
1451
1452/*!
1453 * @name MCG auto-trim machine.
1454 * @{
1455 */
1456
1457/*!
1458 * @brief Auto trims the internal reference clock.
1459 *
1460 * This function trims the internal reference clock by using the external clock. If
1461 * successful, it returns the kStatus_Success and the frequency after
1462 * trimming is received in the parameter @p actualFreq. If an error occurs,
1463 * the error code is returned.
1464 *
1465 * @param extFreq External clock frequency, which should be a bus clock.
1466 * @param desireFreq Frequency to trim to.
1467 * @param actualFreq Actual frequency after trimming.
1468 * @param atms Trim fast or slow internal reference clock.
1469 * @retval kStatus_Success ATM success.
1470 * @retval kStatus_MCG_AtmBusClockInvalid The bus clock is not in allowed range for the ATM.
1471 * @retval kStatus_MCG_AtmDesiredFreqInvalid MCGIRCLK could not be trimmed to the desired frequency.
1472 * @retval kStatus_MCG_AtmIrcUsed Could not trim because MCGIRCLK is used as a bus clock source.
1473 * @retval kStatus_MCG_AtmHardwareFail Hardware fails while trimming.
1474 */
1475status_t CLOCK_TrimInternalRefClk(uint32_t extFreq, uint32_t desireFreq, uint32_t *actualFreq, mcg_atm_select_t atms);
1476/* @} */
1477
1478/*! @name MCG mode functions. */
1479/*@{*/
1480
1481/*!
1482 * @brief Gets the current MCG mode.
1483 *
1484 * This function checks the MCG registers and determines the current MCG mode.
1485 *
1486 * @return Current MCG mode or error code; See @ref mcg_mode_t.
1487 */
1488mcg_mode_t CLOCK_GetMode(void);
1489
1490/*!
1491 * @brief Sets the MCG to FEI mode.
1492 *
1493 * This function sets the MCG to FEI mode. If setting to FEI mode fails
1494 * from the current mode, this function returns an error.
1495 *
1496 * @param dmx32 DMX32 in FEI mode.
1497 * @param drs The DCO range selection.
1498 * @param fllStableDelay Delay function to ensure that the FLL is stable. Passing
1499 * NULL does not cause a delay.
1500 * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
1501 * @retval kStatus_Success Switched to the target mode successfully.
1502 * @note If @p dmx32 is set to kMCG_Dmx32Fine, the slow IRC must not be trimmed
1503 * to a frequency above 32768 Hz.
1504 */
1505status_t CLOCK_SetFeiMode(mcg_dmx32_t dmx32, mcg_drs_t drs, void (*fllStableDelay)(void));
1506
1507/*!
1508 * @brief Sets the MCG to FEE mode.
1509 *
1510 * This function sets the MCG to FEE mode. If setting to FEE mode fails
1511 * from the current mode, this function returns an error.
1512 *
1513 * @param frdiv FLL reference clock divider setting, FRDIV.
1514 * @param dmx32 DMX32 in FEE mode.
1515 * @param drs The DCO range selection.
1516 * @param fllStableDelay Delay function to make sure FLL is stable. Passing
1517 * NULL does not cause a delay.
1518 *
1519 * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
1520 * @retval kStatus_Success Switched to the target mode successfully.
1521 */
1522status_t CLOCK_SetFeeMode(uint8_t frdiv, mcg_dmx32_t dmx32, mcg_drs_t drs, void (*fllStableDelay)(void));
1523
1524/*!
1525 * @brief Sets the MCG to FBI mode.
1526 *
1527 * This function sets the MCG to FBI mode. If setting to FBI mode fails
1528 * from the current mode, this function returns an error.
1529 *
1530 * @param dmx32 DMX32 in FBI mode.
1531 * @param drs The DCO range selection.
1532 * @param fllStableDelay Delay function to make sure FLL is stable. If the FLL
1533 * is not used in FBI mode, this parameter can be NULL. Passing
1534 * NULL does not cause a delay.
1535 * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
1536 * @retval kStatus_Success Switched to the target mode successfully.
1537 * @note If @p dmx32 is set to kMCG_Dmx32Fine, the slow IRC must not be trimmed
1538 * to frequency above 32768 Hz.
1539 */
1540status_t CLOCK_SetFbiMode(mcg_dmx32_t dmx32, mcg_drs_t drs, void (*fllStableDelay)(void));
1541
1542/*!
1543 * @brief Sets the MCG to FBE mode.
1544 *
1545 * This function sets the MCG to FBE mode. If setting to FBE mode fails
1546 * from the current mode, this function returns an error.
1547 *
1548 * @param frdiv FLL reference clock divider setting, FRDIV.
1549 * @param dmx32 DMX32 in FBE mode.
1550 * @param drs The DCO range selection.
1551 * @param fllStableDelay Delay function to make sure FLL is stable. If the FLL
1552 * is not used in FBE mode, this parameter can be NULL. Passing NULL
1553 * does not cause a delay.
1554 * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
1555 * @retval kStatus_Success Switched to the target mode successfully.
1556 */
1557status_t CLOCK_SetFbeMode(uint8_t frdiv, mcg_dmx32_t dmx32, mcg_drs_t drs, void (*fllStableDelay)(void));
1558
1559/*!
1560 * @brief Sets the MCG to BLPI mode.
1561 *
1562 * This function sets the MCG to BLPI mode. If setting to BLPI mode fails
1563 * from the current mode, this function returns an error.
1564 *
1565 * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
1566 * @retval kStatus_Success Switched to the target mode successfully.
1567 */
1568status_t CLOCK_SetBlpiMode(void);
1569
1570/*!
1571 * @brief Sets the MCG to BLPE mode.
1572 *
1573 * This function sets the MCG to BLPE mode. If setting to BLPE mode fails
1574 * from the current mode, this function returns an error.
1575 *
1576 * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
1577 * @retval kStatus_Success Switched to the target mode successfully.
1578 */
1579status_t CLOCK_SetBlpeMode(void);
1580
1581/*!
1582 * @brief Sets the MCG to PBE mode.
1583 *
1584 * This function sets the MCG to PBE mode. If setting to PBE mode fails
1585 * from the current mode, this function returns an error.
1586 *
1587 * @param pllcs The PLL selection, PLLCS.
1588 * @param config Pointer to the PLL configuration.
1589 * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
1590 * @retval kStatus_Success Switched to the target mode successfully.
1591 *
1592 * @note
1593 * 1. The parameter \c pllcs selects the PLL. For platforms with
1594 * only one PLL, the parameter pllcs is kept for interface compatibility.
1595 * 2. The parameter \c config is the PLL configuration structure. On some
1596 * platforms, it is possible to choose the external PLL directly, which renders the
1597 * configuration structure not necessary. In this case, pass in NULL.
1598 * For example: CLOCK_SetPbeMode(kMCG_OscselOsc, kMCG_PllClkSelExtPll, NULL);
1599 */
1600status_t CLOCK_SetPbeMode(mcg_pll_clk_select_t pllcs, mcg_pll_config_t const *config);
1601
1602/*!
1603 * @brief Sets the MCG to PEE mode.
1604 *
1605 * This function sets the MCG to PEE mode.
1606 *
1607 * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
1608 * @retval kStatus_Success Switched to the target mode successfully.
1609 *
1610 * @note This function only changes the CLKS to use the PLL/FLL output. If the
1611 * PRDIV/VDIV are different than in the PBE mode, set them up
1612 * in PBE mode and wait. When the clock is stable, switch to PEE mode.
1613 */
1614status_t CLOCK_SetPeeMode(void);
1615
1616/*!
1617 * @brief Switches the MCG to FBE mode from the external mode.
1618 *
1619 * This function switches the MCG from external modes (PEE/PBE/BLPE/FEE) to the FBE mode quickly.
1620 * The external clock is used as the system clock source and PLL is disabled. However,
1621 * the FLL settings are not configured. This is a lite function with a small code size, which is useful
1622 * during the mode switch. For example, to switch from PEE mode to FEI mode:
1623 *
1624 * @code
1625 * CLOCK_ExternalModeToFbeModeQuick();
1626 * CLOCK_SetFeiMode(...);
1627 * @endcode
1628 *
1629 * @retval kStatus_Success Switched successfully.
1630 * @retval kStatus_MCG_ModeInvalid If the current mode is not an external mode, do not call this function.
1631 */
1632status_t CLOCK_ExternalModeToFbeModeQuick(void);
1633
1634/*!
1635 * @brief Switches the MCG to FBI mode from internal modes.
1636 *
1637 * This function switches the MCG from internal modes (PEI/PBI/BLPI/FEI) to the FBI mode quickly.
1638 * The MCGIRCLK is used as the system clock source and PLL is disabled. However,
1639 * FLL settings are not configured. This is a lite function with a small code size, which is useful
1640 * during the mode switch. For example, to switch from PEI mode to FEE mode:
1641 *
1642 * @code
1643 * CLOCK_InternalModeToFbiModeQuick();
1644 * CLOCK_SetFeeMode(...);
1645 * @endcode
1646 *
1647 * @retval kStatus_Success Switched successfully.
1648 * @retval kStatus_MCG_ModeInvalid If the current mode is not an internal mode, do not call this function.
1649 */
1650status_t CLOCK_InternalModeToFbiModeQuick(void);
1651
1652/*!
1653 * @brief Sets the MCG to FEI mode during system boot up.
1654 *
1655 * This function sets the MCG to FEI mode from the reset mode. It can also be used to
1656 * set up MCG during system boot up.
1657 *
1658 * @param dmx32 DMX32 in FEI mode.
1659 * @param drs The DCO range selection.
1660 * @param fllStableDelay Delay function to ensure that the FLL is stable.
1661 *
1662 * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
1663 * @retval kStatus_Success Switched to the target mode successfully.
1664 * @note If @p dmx32 is set to kMCG_Dmx32Fine, the slow IRC must not be trimmed
1665 * to frequency above 32768 Hz.
1666 */
1667status_t CLOCK_BootToFeiMode(mcg_dmx32_t dmx32, mcg_drs_t drs, void (*fllStableDelay)(void));
1668
1669/*!
1670 * @brief Sets the MCG to FEE mode during system bootup.
1671 *
1672 * This function sets MCG to FEE mode from the reset mode. It can also be used to
1673 * set up the MCG during system boot up.
1674 *
1675 * @param oscsel OSC clock select, OSCSEL.
1676 * @param frdiv FLL reference clock divider setting, FRDIV.
1677 * @param dmx32 DMX32 in FEE mode.
1678 * @param drs The DCO range selection.
1679 * @param fllStableDelay Delay function to ensure that the FLL is stable.
1680 *
1681 * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
1682 * @retval kStatus_Success Switched to the target mode successfully.
1683 */
1684status_t CLOCK_BootToFeeMode(
1685 mcg_oscsel_t oscsel, uint8_t frdiv, mcg_dmx32_t dmx32, mcg_drs_t drs, void (*fllStableDelay)(void));
1686
1687/*!
1688 * @brief Sets the MCG to BLPI mode during system boot up.
1689 *
1690 * This function sets the MCG to BLPI mode from the reset mode. It can also be used to
1691 * set up the MCG during system boot up.
1692 *
1693 * @param fcrdiv Fast IRC divider, FCRDIV.
1694 * @param ircs The internal reference clock to select, IRCS.
1695 * @param ircEnableMode The MCGIRCLK enable mode, OR'ed value of _mcg_irclk_enable_mode.
1696 *
1697 * @retval kStatus_MCG_SourceUsed Could not change MCGIRCLK setting.
1698 * @retval kStatus_Success Switched to the target mode successfully.
1699 */
1700status_t CLOCK_BootToBlpiMode(uint8_t fcrdiv, mcg_irc_mode_t ircs, uint8_t ircEnableMode);
1701
1702/*!
1703 * @brief Sets the MCG to BLPE mode during system boot up.
1704 *
1705 * This function sets the MCG to BLPE mode from the reset mode. It can also be used to
1706 * set up the MCG during system boot up.
1707 *
1708 * @param oscsel OSC clock select, MCG_C7[OSCSEL].
1709 *
1710 * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
1711 * @retval kStatus_Success Switched to the target mode successfully.
1712 */
1713status_t CLOCK_BootToBlpeMode(mcg_oscsel_t oscsel);
1714
1715/*!
1716 * @brief Sets the MCG to PEE mode during system boot up.
1717 *
1718 * This function sets the MCG to PEE mode from reset mode. It can also be used to
1719 * set up the MCG during system boot up.
1720 *
1721 * @param oscsel OSC clock select, MCG_C7[OSCSEL].
1722 * @param pllcs The PLL selection, PLLCS.
1723 * @param config Pointer to the PLL configuration.
1724 *
1725 * @retval kStatus_MCG_ModeUnreachable Could not switch to the target mode.
1726 * @retval kStatus_Success Switched to the target mode successfully.
1727 */
1728status_t CLOCK_BootToPeeMode(mcg_oscsel_t oscsel, mcg_pll_clk_select_t pllcs, mcg_pll_config_t const *config);
1729
1730/*!
1731 * @brief Sets the MCG to a target mode.
1732 *
1733 * This function sets MCG to a target mode defined by the configuration
1734 * structure. If switching to the target mode fails, this function
1735 * chooses the correct path.
1736 *
1737 * @param config Pointer to the target MCG mode configuration structure.
1738 * @return Return kStatus_Success if switched successfully; Otherwise, it returns an error code _mcg_status.
1739 *
1740 * @note If the external clock is used in the target mode, ensure that it is
1741 * enabled. For example, if the OSC0 is used, set up OSC0 correctly before calling this
1742 * function.
1743 */
1744status_t CLOCK_SetMcgConfig(mcg_config_t const *config);
1745
1746/*@}*/
1747
1748#if defined(__cplusplus)
1749}
1750#endif /* __cplusplus */
1751
1752/*! @} */
1753
1754#endif /* _FSL_CLOCK_H_ */