2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * o Redistributions of source code must retain the above copyright notice, this list
9 * of conditions and the following disclaimer.
11 * o Redistributions in binary form must reproduce the above copyright notice, this
12 * list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #if !defined(__FSL_MCG_HAL_H__)
32 #define __FSL_MCG_HAL_H__
37 #include "fsl_device_registers.h"
38 #include "fsl_mcg_features.h"
40 /*! @addtogroup mcg_hal*/
43 /*! @file fsl_mcg_hal.h */
45 /*******************************************************************************
47 ******************************************************************************/
48 /*! @brief MCG constant definitions*/
57 kMcgConstant32 = (32u),
59 kMcgConstant640 = (640u),
60 kMcgConstant1280 = (1280u),
61 kMcgConstant1920 = (1920u),
62 kMcgConstant2560 = (2560u),
63 kMcgConstant732 = (732u),
64 kMcgConstant1464 = (1464u),
65 kMcgConstant2197 = (2197u),
66 kMcgConstant2929 = (2929u),
68 kMcgConstantHex20 = (0x20u),
69 kMcgConstantHex40 = (0x40u),
70 kMcgConstantHex60 = (0x60u),
71 kMcgConstantHex80 = (0x80u),
72 kMcgConstantHexA0 = (0xA0u),
73 kMcgConstantHexC0 = (0xC0u),
74 kMcgConstantHexE0 = (0xE0u),
76 kMcgConstant2000 = (2000u),
77 kMcgConstant3000 = (3000u),
78 kMcgConstant4000 = (4000u),
80 kMcgConstant10000 = (10000u),
81 kMcgConstant30000 = (30000u),
82 kMcgConstant31250 = (31250u),
83 kMcgConstant39063 = (39063u),
84 kMcgConstant40000 = (40000u),
86 kMcgConstant1250000 = (1250000u),
87 kMcgConstant2500000 = (2500000u),
88 kMcgConstant3000000 = (3000000u),
89 kMcgConstant5000000 = (5000000u),
90 kMcgConstant8000000 = (8000000u),
92 kMcgConstant10000000 = (10000000u),
93 kMcgConstant20000000 = (20000000u),
94 kMcgConstant25000000 = (25000000u),
95 kMcgConstant32000000 = (32000000u),
96 kMcgConstant40000000 = (40000000u),
97 kMcgConstant50000000 = (50000000u),
98 kMcgConstant60000000 = (60000000u),
99 kMcgConstant75000000 = (75000000u),
100 kMcgConstant80000000 = (80000000u),
102 kMcgConstant100000000 = (100000000u),
103 kMcgConstant180000000 = (180000000u),
104 kMcgConstant360000000 = (360000000u)
107 /*! @brief MCG clock source select */
108 typedef enum _mcg_clock_select
110 kMcgClkSelOut, /* Output of FLL or PLLCS is selected(depends on PLLS bit) */
111 kMcgClkSelInternal, /* Internal reference clock is selected */
112 kMcgClkSelExternal, /* External reference clock is selected */
114 } mcg_clock_select_t;
116 /*! @brief MCG internal reference clock source select */
117 typedef enum _mcg_internal_ref_clock_source
119 kMcgInternalRefClkSrcExternal, /* External reference clock is selected */
120 kMcgInternalRefClkSrcSlow /* The slow internal reference clock is selected */
121 } mcg_internal_ref_clock_source_t;
123 /*! @brief MCG frequency range select */
124 typedef enum _mcg_freq_range_select
126 kMcgFreqRangeSelLow, /* Low frequency range selected for the crystal OSC */
127 kMcgFreqRangeSelHigh, /* High frequency range selected for the crystal OSC */
128 kMcgFreqRangeSelVeryHigh, /* Very High frequency range selected for the crystal OSC */
129 kMcgFreqRangeSelVeryHigh1 /* Very High frequency range selected for the crystal OSC */
130 } mcg_freq_range_select_t;
132 /*! @brief MCG high gain oscillator select */
133 typedef enum _mcg_high_gain_osc_select
135 kMcgHighGainOscSelLow, /* Configure crystal oscillator for low-power operation */
136 kMcgHighGainOscSelHigh /* Configure crystal oscillator for high-gain operation */
137 } mcg_high_gain_osc_select_t;
139 /*! @brief MCG high gain oscillator select */
140 typedef enum _mcg_external_ref_clock_select
142 kMcgExternalRefClkSelExternal, /* External reference clock requested */
143 kMcgExternalRefClkSelOsc /* Oscillator requested */
144 } mcg_external_ref_clock_select_t;
146 /*! @brief MCG low power select */
147 typedef enum _mcg_low_power_select
149 kMcgLowPowerSelNormal, /* FLL (or PLL) is not disabled in bypass modes */
150 kMcgLowPowerSelLowPower /* FLL (or PLL) is disabled in bypass modes (lower power) */
151 } mcg_low_power_select_t;
153 /*! @brief MCG internal reference clock select */
154 typedef enum _mcg_internal_ref_clock_select
156 kMcgInternalRefClkSelSlow, /* Slow internal reference clock selected */
157 kMcgInternalRefClkSelFast /* Fast internal reference clock selected */
158 } mcg_internal_ref_clock_select_t;
160 /*! @brief MCG DCO Maximum Frequency with 32.768 kHz Reference */
161 typedef enum _mcg_dmx32_select
163 kMcgDmx32Default, /* DCO has a default range of 25% */
164 kMcgDmx32Fine /* DCO is fine-tuned for maximum frequency with 32.768 kHz reference */
165 } mcg_dmx32_select_t;
167 /*! @brief MCG DCO range select */
168 typedef enum _mcg_digital_controlled_osc_range_select
170 kMcgDigitalControlledOscRangeSelLow, /* Low frequency range */
171 kMcgDigitalControlledOscRangeSelMid, /* Mid frequency range*/
172 kMcgDigitalControlledOscRangeSelMidHigh, /* Mid-High frequency range */
173 kMcgDigitalControlledOscRangeSelHigh /* High frequency range */
174 } mcg_digital_controlled_osc_range_select_t;
176 /*! @brief MCG PLL external reference clock select */
177 typedef enum _mcg_pll_external_ref_clk_select
179 kMcgPllExternalRefClkSelOsc0, /* Selects OSC0 clock source as its external reference clock */
180 kMcgPllExternalRefClkSelOsc1 /* Selects OSC1 clock source as its external reference clock */
181 } mcg_pll_external_ref_clk_select_t;
183 /*! @brief MCG PLL select */
184 typedef enum _mcg_pll_select
186 kMcgPllSelFll, /* FLL is selected */
187 kMcgPllSelPllClkSel /* PLLCS output clock is selected */
190 /*! @brief MCG loss of lock status */
191 typedef enum _mcg_loss_of_lock_status
193 kMcgLossOfLockNotLost, /* PLL has not lost lock since LOLS 0 was last cleared */
194 kMcgLossOfLockLost /* PLL has lost lock since LOLS 0 was last cleared */
195 } mcg_loss_of_lock_status_t;
197 /*! @brief MCG lock status */
198 typedef enum _mcg_lock_status
200 kMcgLockUnlocked, /* PLL is currently unlocked */
201 kMcgLockLocked /* PLL is currently locked */
204 /*! @brief MCG clock status */
205 typedef enum _mcg_pll_stat_status
207 kMcgPllStatFll, /* Source of PLLS clock is FLL clock */
208 kMcgPllStatPllClkSel /* Source of PLLS clock is PLLCS output clock */
209 } mcg_pll_stat_status_t;
211 /*! @brief MCG iref status */
212 typedef enum _mcg_internal_ref_status
214 kMcgInternalRefStatExternal, /* FLL reference clock is the external reference clock */
215 kMcgInternalRefStatInternal /* FLL reference clock is the internal reference clock */
216 } mcg_internal_ref_status_t;
218 /*! @brief MCG clock mode status */
219 typedef enum _mcg_clk_stat_status
221 kMcgClkStatFll, /* Output of the FLL is selected (reset default) */
222 kMcgClkStatInternalRef, /* Internal reference clock is selected */
223 kMcgClkStatExternalRef, /* External reference clock is selected */
224 kMcgClkStatPll /* Output of the PLL is selected */
225 } mcg_clk_stat_status_t;
227 /*! @brief MCG ircst status */
228 typedef enum _mcg_internal_ref_clk_status
230 kMcgInternalRefClkStatSlow, /* internal reference clock is the slow clock (32 kHz IRC) */
231 kMcgInternalRefClkStatFast /* internal reference clock is the fast clock (2 MHz IRC) */
232 } mcg_internal_ref_clk_status_t;
234 /*! @brief MCG auto trim fail status */
235 typedef enum _mcg_auto_trim_machine_fail_status
237 kMcgAutoTrimMachineNormal, /* Automatic Trim Machine completed normally */
238 kMcgAutoTrimMachineFail /* Automatic Trim Machine failed */
239 } mcg_auto_trim_machine_fail_status_t;
241 /*! @brief MCG loss of clock status */
242 typedef enum _mcg_locs0_status
244 kMcgLocs0NotOccured, /* Loss of OSC0 has not occurred */
245 kMcgLocs0Occured /* Loss of OSC0 has occurred */
246 } mcg_locs0_status_t;
248 /*! @brief MCG Automatic Trim Machine Select */
249 typedef enum _mcg_auto_trim_machine_select
251 kMcgAutoTrimMachineSel32k, /* 32 kHz Internal Reference Clock selected */
252 kMcgAutoTrimMachineSel4m /* 4 MHz Internal Reference Clock selected */
253 } mcg_auto_trim_machine_select_t;
255 /*! @brief MCG OSC Clock Select */
256 typedef enum _mcg_oscsel_select
258 kMcgOscselOsc, /* Selects System Oscillator (OSCCLK) */
259 kMcgOscselRtc, /* Selects 32 kHz RTC Oscillator */
260 #if FSL_FEATURE_MCG_HAS_IRC_48M
261 kMcgOscselIrc /* Selects 48 MHz IRC Oscillator */
263 } mcg_oscsel_select_t;
265 /*! @brief MCG loss of clock status */
266 typedef enum _mcg_loss_of_clk1_status
268 kMcgLossOfClk1NotOccured, /* Loss of RTC has not occurred */
269 kMcgLossOfClk1Occured /* Loss of RTC has occurred */
270 } mcg_loss_of_clk1_status_t;
272 /*! @brief MCG PLLCS select */
273 typedef enum _mcg_pll_clk_select
275 kMcgPllClkSelPll0, /* PLL0 output clock is selected */
276 kMcgPllClkSelPll1, /* PLL1 output clock is selected */
277 } mcg_pll_clk_select_t;
279 /*! @brief MCG loss of clock status */
280 typedef enum _mcg_locs2_status
282 kMcgLocs2NotOccured, /* Loss of OSC1 has not occurred */
283 kMcgLocs2Occured /* Loss of OSC1 has occurred */
284 } mcg_locs2_status_t;
286 /*******************************************************************************
288 ******************************************************************************/
290 #if defined(__cplusplus)
292 #endif /* __cplusplus*/
294 /*! @name MCG out clock access API*/
298 * @brief Gets the current MCG FLL clock.
300 * This function returns the mcgfllclk value in frequency(Hertz) based on the
301 * current MCG configurations and settings. FLL should be properly configured
302 * in order to get the valid value.
304 * @param baseAddr Base address for current MCG instance.
305 * @return value Frequency value in Hertz of the mcgpllclk.
307 uint32_t CLOCK_HAL_GetFllRefClk(uint32_t baseAddr);
310 * @brief Gets the current MCG FLL clock.
312 * This function returns the mcgfllclk value in frequency(Hertz) based on the
313 * current MCG configurations and settings. FLL should be properly configured
314 * in order to get the valid value.
316 * @param baseAddr Base address for current MCG instance.
317 * @return value Frequency value in Hertz of the mcgpllclk.
319 uint32_t CLOCK_HAL_GetFllClk(uint32_t baseAddr);
322 * @brief Gets the current MCG PLL/PLL0 clock.
324 * This function returns the mcgpllclk/mcgpll0 value in frequency(Hertz) based
325 * on the current MCG configurations and settings. PLL/PLL0 should be properly
326 * configured in order to get the valid value.
328 * @param baseAddr Base address for current MCG instance.
329 * @return value Frequency value in Hertz of the mcgpllclk or the mcgpll0clk.
331 uint32_t CLOCK_HAL_GetPll0Clk(uint32_t baseAddr);
333 #if FSL_FEATURE_MCG_HAS_PLL1
335 * @brief Gets the current MCG PLL1 clock.
337 * This function returns the mcgpll1clk value in frequency (Hertz) based
338 * on the current MCG configurations and settings. PLL1 should be properly configured
339 * in order to get the valid value.
341 * @param baseAddr Base address for current MCG instance.
342 * @return value Frequency value in Hertz of mcgpll1clk.
344 uint32_t CLOCK_HAL_GetPll1Clk(uint32_t baseAddr);
348 * @brief Gets the current MCG IR clock.
350 * This function returns the mcgirclk value in frequency (Hertz) based
351 * on the current MCG configurations and settings. It does not check if the
352 * mcgirclk is enabled or not, just calculate and return the value.
354 * @param baseAddr Base address for current MCG instance.
355 * @return value Frequency value in Hertz of the mcgirclk.
357 uint32_t CLOCK_HAL_GetInternalRefClk(uint32_t baseAddr);
360 * @brief Gets the current MCG out clock.
362 * This function returns the mcgoutclk value in frequency (Hertz) based on the
363 * current MCG configurations and settings. The configuration should be
364 * properly done in order to get the valid value.
366 * @param baseAddr Base address for current MCG instance.
367 * @return value Frequency value in Hertz of mcgoutclk.
369 uint32_t CLOCK_HAL_GetOutClk(uint32_t baseAddr);
373 /*! @name MCG control register access API*/
377 * @brief Sets the Clock Source Select
379 * This function selects the clock source for the MCGOUTCLK.
381 * @param baseAddr Base address for current MCG instance.
382 * @param select Clock source selection
383 * - 00: Output of FLL or PLLCS is selected(depends on PLLS control bit)
384 * - 01: Internal reference clock is selected.
385 * - 10: External reference clock is selected.
388 static inline void CLOCK_HAL_SetClkSrcMode(uint32_t baseAddr, mcg_clock_select_t select)
390 BW_MCG_C1_CLKS(baseAddr, select);
394 * @brief Gets the Clock Source Select.
396 * This function gets the select of the clock source for the MCGOUTCLK.
398 * @param baseAddr Base address for current MCG instance.
399 * @return select Clock source selection
401 static inline mcg_clock_select_t CLOCK_HAL_GetClkSrcMode(uint32_t baseAddr)
403 return (mcg_clock_select_t)BR_MCG_C1_CLKS(baseAddr);
407 * @brief Sets the FLL External Reference Divider.
409 * This function sets the FLL External Reference Divider.
411 * @param baseAddr Base address for current MCG instance.
412 * @param setting Divider setting
414 static inline void CLOCK_HAL_SetFllExternalRefDivider(uint32_t baseAddr,
417 BW_MCG_C1_FRDIV(baseAddr, setting);
421 * @brief Gets the FLL External Reference Divider.
423 * This function gets the FLL External Reference Divider.
425 * @param baseAddr Base address for current MCG instance.
426 * @return setting Divider setting
428 static inline uint8_t CLOCK_HAL_GetFllExternalRefDivider(uint32_t baseAddr)
430 return BR_MCG_C1_FRDIV(baseAddr);
434 * @brief Sets the Internal Reference Select.
436 * This function selects the reference clock source for the FLL.
438 * @param baseAddr Base address for current MCG instance.
439 * @param select Clock source select
440 * - 0: External reference clock is selected
441 * - 1: The slow internal reference clock is selected
443 static inline void CLOCK_HAL_SetInternalRefSelMode(uint32_t baseAddr,
444 mcg_internal_ref_clock_source_t select)
446 BW_MCG_C1_IREFS(baseAddr, select);
450 * @brief Gets the Internal Reference Select
452 * This function gets the reference clock source for the FLL.
454 * @param baseAddr Base address for current MCG instance.
455 * @return select Clock source select
457 static inline mcg_internal_ref_clock_source_t CLOCK_HAL_GetInternalRefSelMode(uint32_t baseAddr)
459 return (mcg_internal_ref_clock_source_t)BR_MCG_C1_IREFS(baseAddr);
463 * @brief Sets the CLKS, FRDIV and IREFS at the same time.
465 * This function sets the CLKS, FRDIV, and IREFS settings at the same time
466 * in order keep the integrity of the clock switching.
468 * @param baseAddr Base address for current MCG instance.
469 * @param clks Clock source select
470 * @param frdiv FLL external reference divider select
471 * @param irefs Internal reference select
473 static inline void CLOCK_HAL_SetClksFrdivInternalRefSelect(uint32_t baseAddr,
474 mcg_clock_select_t clks,
476 mcg_internal_ref_clock_source_t irefs)
478 /* Set the required CLKS , FRDIV and IREFS values */
479 HW_MCG_C1_WR(baseAddr, (HW_MCG_C1_RD(baseAddr) & ~(BM_MCG_C1_CLKS | BM_MCG_C1_FRDIV | BM_MCG_C1_IREFS))
480 | (BF_MCG_C1_CLKS(clks) | BF_MCG_C1_FRDIV(frdiv) | BF_MCG_C1_IREFS(irefs)));
484 * @brief Sets the Enable Internal Reference Clock setting.
486 * This function enables/disables the internal reference clock to use as the MCGIRCLK.
488 * @param baseAddr Base address for current MCG instance.
489 * @params enable Enable or disable internal reference clock.
490 * - true: MCGIRCLK active
491 * - false: MCGIRCLK inactive
493 static inline void CLOCK_HAL_SetInternalClkCmd(uint32_t baseAddr, bool enable)
495 BW_MCG_C1_IRCLKEN(baseAddr, enable ? 1 : 0);
499 * @brief Gets the enable Internal Reference Clock setting.
501 * This function gets the reference clock enable setting.
503 * @param baseAddr Base address for current MCG instance.
504 * @return enabled True if the internal reference clock is enabled.
506 static inline bool CLOCK_HAL_GetInternalClkCmd(uint32_t baseAddr)
508 return BR_MCG_C1_IRCLKEN(baseAddr);
512 * @brief Sets the Internal Reference Clock Stop Enable setting.
514 * This function controls whether or not the internal reference clock remains
515 * enabled when the MCG enters Stop mode.
517 * @param baseAddr Base address for current MCG instance.
518 * @params enable Enable or disable the internal reference clock stop setting.
519 * - true: Internal reference clock is enabled in Stop mode if IRCLKEN is set
520 * or if MCG is in FEI, FBI, or BLPI modes before entering Stop mode.
521 * - false: Internal reference clock is disabled in Stop mode
523 static inline void CLOCK_HAL_SetInternalRefStopCmd(uint32_t baseAddr, bool enable)
525 BW_MCG_C1_IREFSTEN(baseAddr, enable ? 1 : 0);
529 * @brief Gets the Enable Internal Reference Clock setting.
531 * This function gets the Internal Reference Clock Stop Enable setting.
533 * @param baseAddr Base address for current MCG instance.
534 * @return enabled True if internal reference clock stop is enabled.
536 static inline bool CLOCK_HAL_GetInternalRefStopCmd(uint32_t baseAddr)
538 return BR_MCG_C1_IREFSTEN(baseAddr);
542 * @brief Sets the Loss of Clock Reset Enable setting.
544 * This function determines whether an interrupt or a reset request is made following a loss
545 * of the OSC0 external reference clock. The LOCRE0 only has an affect when CME0 is set.
547 * @param baseAddr Base address for current MCG instance.
548 * @params enable Loss of Clock Reset Enable setting
549 * - true: Generate a reset request on a loss of OSC0 external reference clock
550 * - false: Interrupt request is generated on a loss of OSC0 external reference clock
552 static inline void CLOCK_HAL_SetLossOfClkReset0Cmd(uint32_t baseAddr, bool enable)
554 BW_MCG_C2_LOCRE0(baseAddr, enable ? 1 : 0);
558 * @brief Gets the Loss of Clock Reset Enable setting.
560 * This function gets the Loss of Clock Reset Enable setting.
562 * @param baseAddr Base address for current MCG instance.
563 * @return enabled True if Loss of Clock Reset is enabled.
565 static inline bool CLOCK_HAL_GetLossOfClkReset0Cmd(uint32_t baseAddr)
567 return BR_MCG_C2_LOCRE0(baseAddr);
570 #if FSL_FEATURE_MCG_HAS_FCFTRIM
572 * @brief Sets the Fast Internal Reference Clock Fine Trim setting.
574 * This function sets the Fast Internal Reference Clock Fine Trim setting. FCFTRIM
575 * controls the smallest adjustment of the fast internal reference clock frequency.
576 * Setting the FCFTRIM increases the period and clearing FCFTRIM decreases the period
577 * by the smallest amount possible. If an FCFTRIM value is stored and non-volatile
578 * memory is to be used, it is the user's responsibility to copy that value from the
579 * non-volatile memory location to this bit.
581 * @param baseAddr Base address for current MCG instance.
582 * @params setting Fast Internal Reference Clock Fine Trim setting
584 static inline void CLOCK_HAL_SetFastInternalRefClkFineTrim(uint32_t baseAddr, uint8_t setting)
586 BW_MCG_C2_FCFTRIM(baseAddr, setting);
590 * @brief Gets the Fast Internal Reference Clock Fine Trim setting.
592 * This function gets the Fast Internal Reference Clock Fine Trim setting.
594 * @param baseAddr Base address for current MCG instance.
595 * @return setting Fast Internal Reference Clock Fine Trim setting
597 static inline uint8_t CLOCK_HAL_GetFastInternalRefClkFineTrim(uint32_t baseAddr)
599 return BR_MCG_C2_FCFTRIM(baseAddr);
601 #endif /* FSL_FEATURE_MCG_HAS_FCFTRIM */
604 * @brief Sets the Frequency Range Select.
606 * This function selects the frequency range for the crystal oscillator or an external
607 * clock source. See the Oscillator (OSC) chapter for more details and the device
608 * data sheet for the frequency ranges used.
610 * @param baseAddr Base address for current MCG instance.
611 * @params select Frequency Range Select
612 * - 00: Low frequency range selected for the crystal oscillator
613 * - 01: High frequency range selected for the crystal oscillator
614 * - 1X: Very high frequency range selected for the crystal oscillator
616 static inline void CLOCK_HAL_SetRange0Mode(uint32_t baseAddr, mcg_freq_range_select_t select)
618 BW_MCG_C2_RANGE(baseAddr, select);
622 * @brief Gets the Frequency Range Select.
624 * This function gets the Frequency Range Select.
626 * @param baseAddr Base address for current MCG instance.
627 * @return select Frequency Range Select
629 static inline mcg_freq_range_select_t CLOCK_HAL_GetRange0Mode(uint32_t baseAddr)
631 return (mcg_freq_range_select_t)BR_MCG_C2_RANGE(baseAddr);
635 * @brief Sets the High Gain Oscillator Select.
637 * This function controls the crystal oscillator mode of operation. See the
638 * Oscillator (OSC) chapter for more details.
640 * @param baseAddr Base address for current MCG instance.
641 * @params select High Gain Oscillator Select.
642 * - 0: Configure crystal oscillator for low-power operation
643 * - 1: Configure crystal oscillator for high-gain operation
645 static inline void CLOCK_HAL_SetHighGainOsc0Mode(uint32_t baseAddr, mcg_high_gain_osc_select_t select)
647 BW_MCG_C2_HGO(baseAddr, select);
651 * @brief Gets the High Gain Oscillator Select.
653 * This function gets the High Gain Oscillator Select.
655 * @param baseAddr Base address for current MCG instance.
656 * @return select High Gain Oscillator Select
658 static inline mcg_high_gain_osc_select_t CLOCK_HAL_GetHighGainOsc0Mode(uint32_t baseAddr)
660 return (mcg_high_gain_osc_select_t)BR_MCG_C2_HGO(baseAddr);
664 * @brief Sets the External Reference Select.
666 * This function selects the source for the external reference clock.
667 * See the Oscillator (OSC) chapter for more details.
669 * @param baseAddr Base address for current MCG instance.
670 * @params select External Reference Select
671 * - 0: External reference clock requested
672 * - 1: Oscillator requested
674 static inline void CLOCK_HAL_SetExternalRefSel0Mode(uint32_t baseAddr, mcg_external_ref_clock_select_t select)
676 BW_MCG_C2_EREFS(baseAddr, select);
680 * @brief Gets the External Reference Select.
682 * This function gets the External Reference Select.
684 * @param baseAddr Base address for current MCG instance.
685 * @return select External Reference Select
687 static inline mcg_external_ref_clock_select_t CLOCK_HAL_GetExternalRefSel0Mode(uint32_t baseAddr)
689 return (mcg_external_ref_clock_select_t)BR_MCG_C2_EREFS(baseAddr);
693 * @brief Sets the Low Power Select.
695 * This function controls whether the FLL (or PLL) is disabled in the BLPI and the
696 * BLPE modes. In the FBE or the PBE modes, setting this bit to 1 transitions the MCG
697 * into the BLPE mode; in the FBI mode, setting this bit to 1 transitions the MCG into
698 * the BLPI mode. In any other MCG mode, the LP bit has no affect..
700 * @param baseAddr Base address for current MCG instance.
701 * @params select Low Power Select
702 * - 0: FLL (or PLL) is not disabled in bypass modes
703 * - 1: FLL (or PLL) is disabled in bypass modes (lower power)
705 static inline void CLOCK_HAL_SetLowPowerMode(uint32_t baseAddr, mcg_low_power_select_t select)
707 BW_MCG_C2_LP(baseAddr, select);
711 * @brief Gets the Low Power Select.
713 * This function gets the Low Power Select.
715 * @param baseAddr Base address for current MCG instance.
716 * @return select Low Power Select
718 static inline mcg_low_power_select_t CLOCK_HAL_GetLowPowerMode(uint32_t baseAddr)
720 return (mcg_low_power_select_t)BR_MCG_C2_LP(baseAddr);
724 * @brief Sets the Internal Reference Clock Select.
726 * This function selects between the fast or slow internal reference clock source.
728 * @param baseAddr Base address for current MCG instance.
729 * @params select Low Power Select
730 * - 0: Slow internal reference clock selected.
731 * - 1: Fast internal reference clock selected.
733 static inline void CLOCK_HAL_SetInternalRefClkSelMode(uint32_t baseAddr,
734 mcg_internal_ref_clock_select_t select)
736 BW_MCG_C2_IRCS(baseAddr, select);
740 * @brief Gets the Internal Reference Clock Select.
742 * This function gets the Internal Reference Clock Select.
744 * @param baseAddr Base address for current MCG instance.
745 * @return select Internal Reference Clock Select
747 static inline mcg_internal_ref_clock_select_t CLOCK_HAL_GetInternalRefClkSelMode(uint32_t baseAddr)
749 return (mcg_internal_ref_clock_select_t)BR_MCG_C2_IRCS(baseAddr);
753 * @brief Sets the Slow Internal Reference Clock Trim Setting.
755 * This function controls the slow internal reference clock frequency by
756 * controlling the slow internal reference clock period. The SCTRIM bits are
757 * binary weighted (that is, bit 1 adjusts twice as much as bit 0).
758 * Increasing the binary value increases the period, and decreasing the value
759 * decreases the period.
760 * An additional fine trim bit is available in the C4 register as the SCFTRIM bit.
761 * Upon reset, this value is loaded with a factory trim value.
762 * If an SCTRIM value stored in non-volatile memory is to be used, it is the user's
763 * responsibility to copy that value from the non-volatile memory location to
766 * @param baseAddr Base address for current MCG instance.
767 * @params setting Slow Internal Reference Clock Trim Setting
769 static inline void CLOCK_HAL_SetSlowInternalRefClkTrim(uint32_t baseAddr, uint8_t setting)
771 BW_MCG_C3_SCTRIM(baseAddr, setting);
775 * @brief Gets the Slow Internal Reference Clock Trim Setting.
777 * This function gets the Slow Internal Reference Clock Trim Setting.
779 * @param baseAddr Base address for current MCG instance.
780 * @return setting Slow Internal Reference Clock Trim Setting
782 static inline uint8_t CLOCK_HAL_GetSlowInternalRefClkTrim(uint32_t baseAddr)
784 return BR_MCG_C3_SCTRIM(baseAddr);
788 * @brief Sets the DCO Maximum Frequency with 32.768 kHz Reference.
790 * This function controls whether or not the DCO frequency range
791 * is narrowed to its maximum frequency with a 32.768 kHz reference.
793 * @param baseAddr Base address for current MCG instance.
794 * @params setting DCO Maximum Frequency with 32.768 kHz Reference Setting
795 * - 0: DCO has a default range of 25%.
796 * - 1: DCO is fine-tuned for maximum frequency with 32.768 kHz reference.
798 static inline void CLOCK_HAL_SetDmx32(uint32_t baseAddr, mcg_dmx32_select_t setting)
800 BW_MCG_C4_DMX32(baseAddr, setting);
804 * @brief Gets the DCO Maximum Frequency with the 32.768 kHz Reference Setting.
806 * This function gets the DCO Maximum Frequency with 32.768 kHz Reference Setting.
808 * @param baseAddr Base address for current MCG instance.
809 * @return setting DCO Maximum Frequency with 32.768 kHz Reference Setting
811 static inline mcg_dmx32_select_t CLOCK_HAL_GetDmx32(uint32_t baseAddr)
813 return (mcg_dmx32_select_t)BR_MCG_C4_DMX32(baseAddr);
817 * @brief Sets the DCO Range Select.
819 * This function selects the frequency range for the FLL output, DCOOUT.
820 * When the LP bit is set, the writes to the DRS bits are ignored. The DRST read
821 * field indicates the current frequency range for the DCOOUT. The DRST field does
822 * not update immediately after a write to the DRS field due to internal
823 * synchronization between the clock domains. See the DCO Frequency Range table
826 * @param baseAddr Base address for current MCG instance.
827 * @params setting DCO Range Select Setting
828 * - 00: Low range (reset default).
830 * - 10: Mid-high range.
833 static inline void CLOCK_HAL_SetDigitalControlledOscRangeMode(uint32_t baseAddr,
834 mcg_digital_controlled_osc_range_select_t setting)
836 BW_MCG_C4_DRST_DRS(baseAddr, setting);
840 * @brief Gets the DCO Range Select Setting.
842 * This function gets the DCO Range Select Setting.
844 * @param baseAddr Base address for current MCG instance.
845 * @return setting DCO Range Select Setting
847 static inline mcg_digital_controlled_osc_range_select_t CLOCK_HAL_GetDigitalControlledOscRangeMode(uint32_t baseAddr)
849 return (mcg_digital_controlled_osc_range_select_t)BR_MCG_C4_DRST_DRS(baseAddr);
853 * @brief Sets the Fast Internal Reference Clock Trim Setting.
855 * This function controls the fast internal reference clock frequency
856 * by controlling the fast internal reference clock period. The FCTRIM
857 * bits are binary weighted (that is, bit 1 adjusts twice as much as bit 0).
858 * Increasing the binary value increases the period, and decreasing the
859 * value decreases the period.
860 * If an FCTRIM[3:0] value stored in non-volatile memory is to be used, it is
861 * the user's responsibility to copy that value from the non-volatile memory location
864 * @param baseAddr Base address for current MCG instance.
865 * @params setting Fast Internal Reference Clock Trim Setting.
867 static inline void CLOCK_HAL_SetFastInternalRefClkTrim(uint32_t baseAddr, uint8_t setting)
869 BW_MCG_C4_FCTRIM(baseAddr, setting);
873 * @brief Gets the Fast Internal Reference Clock Trim Setting.
875 * This function gets the Fast Internal Reference Clock Trim Setting.
877 * @param baseAddr Base address for current MCG instance.
878 * @return setting Fast Internal Reference Clock Trim Setting
880 static inline uint8_t CLOCK_HAL_GetFastInternalRefClkTrim(uint32_t baseAddr)
882 return BR_MCG_C4_FCTRIM(baseAddr);
886 * @brief Sets the Slow Internal Reference Clock Fine Trim Setting.
888 * This function controls the smallest adjustment of the slow internal
889 * reference clock frequency. Setting the SCFTRIM increases the period and
890 * clearing the SCFTRIM decreases the period by the smallest amount possible.
891 * If an SCFTRIM value, stored in non-volatile memory, is to be used, it is
892 * the user's responsibility to copy that value from the non-volatile memory
893 * location to this bit.
895 * @param baseAddr Base address for current MCG instance.
896 * @params setting Slow Internal Reference Clock Fine Trim Setting
898 static inline void CLOCK_HAL_SetSlowInternalRefClkFineTrim(uint32_t baseAddr, uint8_t setting)
900 BW_MCG_C4_SCFTRIM(baseAddr, setting);
904 * @brief Gets the Slow Internal Reference Clock Fine Trim Setting.
906 * This function gets the Slow Internal Reference Clock Fine Trim Setting.
908 * @param baseAddr Base address for current MCG instance.
909 * @return setting Slow Internal Reference Clock Fine Trim Setting
911 static inline uint8_t CLOCK_HAL_GetSlowInternalRefClkFineTrim(uint32_t baseAddr)
913 return BR_MCG_C4_SCFTRIM(baseAddr);
916 #if FSL_FEATURE_MCG_USE_PLLREFSEL
918 * @brief Sets the PLL0 External Reference Select Setting.
920 * This function selects the PLL0 external reference clock source.
922 * @param baseAddr Base address for current MCG instance.
923 * @params setting PLL0 External Reference Select Setting
924 * - 0: Selects OSC0 clock source as its external reference clock
925 * - 1: Selects OSC1 clock source as its external reference clock
927 static inline void CLOCK_HAL_SetPllRefSel0Mode(uint32_t baseAddr,
928 mcg_pll_external_ref_clk_select_t setting)
930 BW_MCG_C5_PLLREFSEL0(baseAddr, setting);
934 * @brief Gets the PLL0 External Reference Select Setting.
936 * This function gets the PLL0 External Reference Select Setting.
938 * @param baseAddr Base address for current MCG instance.
939 * @return setting PLL0 External Reference Select Setting
941 static inline mcg_pll_external_ref_clk_select_t CLOCK_HAL_GetPllRefSel0Mode(uint32_t baseAddr)
943 return (mcg_pll_external_ref_clk_select_t)BR_MCG_C5_PLLREFSEL0(baseAddr);
945 #endif /* FSL_FEATURE_MCG_USE_PLLREFSEL */
947 #if FSL_FEATURE_MCG_HAS_EXTERNAL_CLOCK_MONITOR
950 * @brief Sets the Clock Monitor Enable Setting.
952 * This function enables/disables the loss of clock monitoring circuit for
953 * the OSC0 external reference mux select. The LOCRE0 bit determines whether an
954 * interrupt or a reset request is generated following a loss of the OSC0 indication.
955 * The CME0 bit should only be set to a logic 1 when the MCG is in an operational
956 * mode that uses the external clock (FEE, FBE, PEE, PBE, or BLPE). Whenever the
957 * CME0 bit is set to a logic 1, the value of the RANGE0 bits in the C2 register
958 * should not be changed. CME0 bit should be set to a logic 0 before the MCG
959 * enters any Stop mode. Otherwise, a reset request may occur while in Stop mode.
960 * CME0 should also be set to a logic 0 before entering VLPR or VLPW power modes
961 * if the MCG is in BLPE mode.
963 * @param baseAddr Base address for current MCG instance.
964 * @params enable Clock Monitor Enable Setting
965 * - true: External clock monitor is enabled for OSC0.
966 * - false: External clock monitor is disabled for OSC0.
968 static inline void CLOCK_HAL_SetClkMonitor0Cmd(uint32_t baseAddr, bool enable)
970 #if FSL_FEATURE_MCG_HAS_PLL
971 BW_MCG_C6_CME0(baseAddr, enable ? 1 : 0);
973 BW_MCG_C6_CME(baseAddr, enable ? 1 : 0);
978 * @brief Gets the Clock Monitor Enable Setting.
980 * This function gets the Clock Monitor Enable Setting.
982 * @param baseAddr Base address for current MCG instance.
983 * @return enabled True if Clock Monitor is enabled
985 static inline bool CLOCK_HAL_GetClkMonitor0Cmd(uint32_t baseAddr)
987 #if FSL_FEATURE_MCG_HAS_PLL
988 return BR_MCG_C6_CME0(baseAddr);
990 return BR_MCG_C6_CME(baseAddr);
996 #if FSL_FEATURE_MCG_HAS_PLL
998 * @brief Sets the PLL Clock Enable Setting.
1000 * This function enables/disables the PLL0 independent of the PLLS and enables the PLL0
1001 * clock to use as the MCGPLL0CLK and the MCGPLL0CLK2X. (PRDIV0 needs to be programmed to
1002 * the correct divider to generate a PLL1 reference clock in a valid reference range
1003 * prior to setting the PLLCLKEN0 bit). Setting PLLCLKEN0 enables the external
1004 * oscillator selected by REFSEL if not already enabled. Whenever the PLL0 is being
1005 * enabled with the PLLCLKEN0 bit, and the external oscillator is being used
1006 * as the reference clock, the OSCINIT 0 bit should be checked to make sure it is set.
1008 * @param baseAddr Base address for current MCG instance.
1009 * @params enable PLL Clock Enable Setting
1010 * - true: MCGPLL0CLK and MCGPLL0CLK2X are active
1011 * - false: MCGPLL0CLK and MCGPLL0CLK2X are inactive
1013 static inline void CLOCK_HAL_SetPllClk0Cmd(uint32_t baseAddr, bool enable)
1015 BW_MCG_C5_PLLCLKEN0(baseAddr, enable ? 1 : 0);
1019 * @brief Gets the PLL Clock Enable Setting.
1021 * This function gets the PLL Clock Enable Setting.
1023 * @param baseAddr Base address for current MCG instance.
1024 * @return enabled True if PLL0 PLL Clock is enabled.
1026 static inline bool CLOCK_HAL_GetPllClk0Cmd(uint32_t baseAddr)
1028 return BR_MCG_C5_PLLCLKEN0(baseAddr);
1032 * @brief Sets the PLL0 Stop Enable Setting.
1034 * This function enables/disables the PLL0 Clock during a Normal Stop (In Low
1035 * Power Stop mode, the PLL0 clock gets disabled even if PLLSTEN0=1). In all other
1036 * power modes, the PLLSTEN0 bit has no affect and does not enable the PLL0 Clock
1037 * to run if it is written to 1.
1039 * @param baseAddr Base address for current MCG instance.
1040 * @params enable PLL0 Stop Enable Setting
1041 * - true: MCGPLL0CLK and MCGPLL0CLK2X are enabled if system is in
1043 * - false: MCGPLL0CLK and MCGPLL0CLK2X are disabled in any of the
1046 static inline void CLOCK_HAL_SetPllStat0Cmd(uint32_t baseAddr, bool enable)
1048 BW_MCG_C5_PLLSTEN0(baseAddr, enable ? 1 : 0);
1052 * @brief Gets the PLL0 Stop Enable Setting.
1054 * This function gets the PLL0 Stop Enable Setting.
1056 * @param baseAddr Base address for current MCG instance.
1057 * @return enabled True if the PLL0 Stop is enabled.
1059 static inline bool CLOCK_HAL_GetPllStat0Cmd(uint32_t baseAddr)
1061 return BR_MCG_C5_PLLSTEN0(baseAddr);
1065 * @brief Sets the PLL0 External Reference Divider Setting.
1067 * This function selects the amount to divide down the external reference
1068 * clock for the PLL0. The resulting frequency must be in a valid reference
1069 * range. After the PLL0 is enabled, (by setting either PLLCLKEN0 or PLLS), the
1070 * PRDIV0 value must not be changed when LOCK0 is zero.
1072 * @param baseAddr Base address for current MCG instance.
1073 * @params setting PLL0 External Reference Divider Setting
1075 static inline void CLOCK_HAL_SetPllExternalRefDivider0(uint32_t baseAddr, uint8_t setting)
1077 BW_MCG_C5_PRDIV0(baseAddr, setting);
1081 * @brief Gets the PLL0 External Reference Divider Setting.
1083 * This function gets the PLL0 External Reference Divider Setting.
1085 * @param baseAddr Base address for current MCG instance.
1086 * @return setting PLL0 External Reference Divider Setting
1088 static inline uint8_t CLOCK_HAL_GetPllExternalRefDivider0(uint32_t baseAddr)
1090 return BR_MCG_C5_PRDIV0(baseAddr);
1094 * @brief Sets the Loss of Lock Interrupt Enable Setting.
1096 * This function determine whether an interrupt request is made following a loss
1097 * of lock indication. This bit only has an effect when LOLS 0 is set.
1099 * @param baseAddr Base address for current MCG instance.
1100 * @params enable Loss of Lock Interrupt Enable Setting
1101 * - true: Generate an interrupt request on loss of lock.
1102 * - false: No interrupt request is generated on loss of lock.
1104 static inline void CLOCK_HAL_SetLossOfClkInt0Cmd(uint32_t baseAddr, bool enable)
1106 BW_MCG_C6_LOLIE0(baseAddr, enable ? 1 : 0);
1110 * @brief Gets the Loss of the Lock Interrupt Enable Setting.
1112 * This function gets the Loss of the Lock Interrupt Enable Setting.
1114 * @param baseAddr Base address for current MCG instance.
1115 * @return enabled True if the Loss of Lock Interrupt is enabled.
1117 static inline bool CLOCK_HAL_GetLossOfClkInt0Cmd(uint32_t baseAddr)
1119 return BR_MCG_C6_LOLIE0(baseAddr);
1123 * @brief Sets the PLL Select Setting.
1125 * This function controls whether the PLLCS or FLL output is selected as the
1126 * MCG source when CLKS[1:0]=00. If the PLLS bit is cleared and PLLCLKEN0 and
1127 * PLLCLKEN1 is not set, the PLLCS output clock is disabled in all modes. If the
1128 * PLLS is set, the FLL is disabled in all modes.
1130 * @param baseAddr Base address for current MCG instance.
1131 * @params setting PLL Select Setting
1132 * - 0: FLL is selected.
1133 * - 1: PLLCS output clock is selected (PRDIV0 bits of PLL in
1134 * control need to be programmed to the correct divider to
1135 * generate a PLL reference clock in the range of 1 - 32 MHz
1136 * prior to setting the PLLS bit).
1138 static inline void CLOCK_HAL_SetPllSelMode(uint32_t baseAddr, mcg_pll_select_t setting)
1140 BW_MCG_C6_PLLS(baseAddr, setting);
1144 * @brief Gets the PLL Select Setting.
1146 * This function gets the PLL Select Setting.
1148 * @param baseAddr Base address for current MCG instance.
1149 * @return setting PLL Select Setting
1151 static inline mcg_pll_select_t CLOCK_HAL_GetPllSelMode(uint32_t baseAddr)
1153 return (mcg_pll_select_t)BR_MCG_C6_PLLS(baseAddr);
1157 * @brief Sets the VCO0 Divider Setting.
1159 * This function selects the amount to divide the VCO output of the PLL0.
1160 * The VDIV0 bits establish the multiplication factor (M) applied to the
1161 * reference clock frequency. After the PLL0 is enabled (by setting either
1162 * PLLCLKEN0 or PLLS), the VDIV0 value must not be changed when LOCK0 is zero.
1164 * @param baseAddr Base address for current MCG instance.
1165 * @params setting VCO0 Divider Setting
1167 static inline void CLOCK_HAL_SetVoltCtrlOscDivider0(uint32_t baseAddr, uint8_t setting)
1169 BW_MCG_C6_VDIV0(baseAddr, setting);
1173 * @brief Gets the VCO0 Divider Setting.
1175 * This function gets the VCO0 Divider Setting.
1177 * @param baseAddr Base address for current MCG instance.
1178 * @return setting VCO0 Divider Setting
1180 static inline uint8_t CLOCK_HAL_GetVoltCtrlOscDivider0(uint32_t baseAddr)
1182 return BR_MCG_C6_VDIV0(baseAddr);
1186 * @brief Gets the Loss of the Lock Status.
1188 * This function gets the Loss of Lock Status. This bit is a sticky bit indicating
1189 * the lock status for the PLL. LOLS 0 is set if after acquiring lock, the PLL
1190 * output frequency has fallen outside the lock exit frequency tolerance, D unl .
1191 * LOLIE 0 determines whether an interrupt request is made when LOLS 0 is set.
1192 * This bit is cleared by reset or by writing a logic 1 to it when set. Writing a
1193 * logic 0 to this bit has no effect.
1195 * @param baseAddr Base address for current MCG instance.
1196 * @return status Loss of Lock Status
1197 * - 0: PLL has not lost lock since LOLS 0 was last cleared
1198 * - 1: PLL has lost lock since LOLS 0 was last cleared
1200 static inline mcg_loss_of_lock_status_t CLOCK_HAL_GetLossOfLock0Mode(uint32_t baseAddr)
1202 return (mcg_loss_of_lock_status_t)BR_MCG_S_LOLS0(baseAddr);
1206 * @brief Gets the Lock Status.
1208 * This function gets the Lock Status. This bit indicates whether the PLL0 has
1209 * acquired the lock. Lock detection is disabled when not operating in either the PBE or the
1210 * PEE mode unless PLLCLKEN0=1 and the MCG is not configured in the BLPI or the BLPE mode.
1211 * While the PLL0 clock is locking to the desired frequency, MCGPLL0CLK and
1212 * MCGPLL0CLK2X are gated off until the LOCK0 bit gets asserted. If the lock
1213 * status bit is set, changing the value of the PRDIV0[2:0] bits in the C5 register
1214 * or the VDIV0[4:0] bits in the C6 register causes the lock status bit to clear
1215 * and stay cleared until the PLL0 has reacquired the lock. The loss of the PLL0 reference
1216 * clock also causes the LOCK0 bit to clear until the PLL0 has an entry into the LLS,
1217 * VLPS, or a regular Stop with PLLSTEN0=0 also causes the lock status bit to clear
1218 * and stay cleared until the stop mode is exited and the PLL0 has reacquired the lock.
1219 * Any time the PLL0 is enabled and the LOCK0 bit is cleared, the MCGPLL0CLK and
1220 * MCGPLL0CLK2X are gated off until the LOCK0 bit is reasserted.
1222 * @param baseAddr Base address for current MCG instance.
1223 * @return status Lock Status
1224 * - 0: PLL is currently unlocked
1225 * - 1: PLL is currently locked
1227 static inline mcg_lock_status_t CLOCK_HAL_GetLock0Mode(uint32_t baseAddr)
1229 return (mcg_lock_status_t)BR_MCG_S_LOCK0(baseAddr);
1233 * @brief Gets the PLL Select Status.
1235 * This function gets the PLL Select Status. This bit indicates the clock source
1236 * selected by PLLS . The PLLST bit does not update immediately after a write to
1237 * the PLLS bit due to the internal synchronization between the clock domains.
1239 * @param baseAddr Base address for current MCG instance.
1240 * @return status PLL Select Status
1241 * - 0: Source of PLLS clock is FLL clock.
1242 * - 1: Source of PLLS clock is PLLCS output clock.
1244 static inline mcg_pll_stat_status_t CLOCK_HAL_GetPllStatMode(uint32_t baseAddr)
1246 return (mcg_pll_stat_status_t)BR_MCG_S_PLLST(baseAddr);
1251 * @brief Gets the Internal Reference Status.
1253 * This function gets the Internal Reference Status. This bit indicates the current
1254 * source for the FLL reference clock. The IREFST bit does not update immediately
1255 * after a write to the IREFS bit due to internal synchronization between the clock
1258 * @param baseAddr Base address for current MCG instance.
1259 * @return status Internal Reference Status
1260 * - 0: Source of FLL reference clock is the external reference clock.
1261 * - 1: Source of FLL reference clock is the internal reference clock.
1263 static inline mcg_internal_ref_status_t CLOCK_HAL_GetInternalRefStatMode(uint32_t baseAddr)
1265 return (mcg_internal_ref_status_t)BR_MCG_S_IREFST(baseAddr);
1269 * @brief Gets the Clock Mode Status.
1271 * This function gets the Clock Mode Status. These bits indicate the current clock mode.
1272 * The CLKST bits do not update immediately after a write to the CLKS bits due to
1273 * internal synchronization between clock domains.
1275 * @param baseAddr Base address for current MCG instance.
1276 * @return status Clock Mode Status
1277 * - 00: Output of the FLL is selected (reset default).
1278 * - 01: Internal reference clock is selected.
1279 * - 10: External reference clock is selected.
1280 * - 11: Output of the PLL is selected.
1282 static inline mcg_clk_stat_status_t CLOCK_HAL_GetClkStatMode(uint32_t baseAddr)
1284 return (mcg_clk_stat_status_t)BR_MCG_S_CLKST(baseAddr);
1288 * @brief Gets the OSC Initialization Status.
1290 * This function gets the OSC Initialization Status. This bit, which resets to 0, is set
1291 * to 1 after the initialization cycles of the crystal oscillator clock have completed.
1292 * After being set, the bit is cleared to 0 if the OSC is subsequently disabled. See the
1293 * OSC module's detailed description for more information.
1295 * @param baseAddr Base address for current MCG instance.
1296 * @return status OSC Initialization Status
1298 static inline uint8_t CLOCK_HAL_GetOscInit0(uint32_t baseAddr)
1300 return BR_MCG_S_OSCINIT0(baseAddr);
1304 * @brief Gets the Internal Reference Clock Status.
1306 * This function gets the Internal Reference Clock Status. The IRCST bit indicates the
1307 * current source for the internal reference clock select clock (IRCSCLK). The IRCST bit
1308 * does not update immediately after a write to the IRCS bit due to the internal
1309 * synchronization between clock domains. The IRCST bit is only updated if the
1310 * internal reference clock is enabled, either by the MCG being in a mode that uses the
1311 * IRC or by setting the C1[IRCLKEN] bit.
1313 * @param baseAddr Base address for current MCG instance.
1314 * @return status Internal Reference Clock Status
1315 * - 0: Source of internal reference clock is the slow clock (32 kHz IRC).
1316 * - 1: Source of internal reference clock is the fast clock (2 MHz IRC).
1318 static inline mcg_internal_ref_clk_status_t CLOCK_HAL_GetInternalRefClkStatMode(uint32_t baseAddr)
1320 return (mcg_internal_ref_clk_status_t)BR_MCG_S_IRCST(baseAddr);
1324 * @brief Gets the Automatic Trim machine Fail Flag.
1326 * This function gets the Automatic Trim machine Fail Flag. This Fail flag for the
1327 * Automatic Trim Machine (ATM). This bit asserts when the Automatic Trim Machine is
1328 * enabled (ATME=1) and a write to the C1, C3, C4, and SC registers is detected or the MCG
1329 * enters into any Stop mode. A write to ATMF clears the flag.
1331 * @param baseAddr Base address for current MCG instance.
1332 * @return flag Automatic Trim machine Fail Flag
1333 * - 0: Automatic Trim Machine completed normally.
1334 * - 1: Automatic Trim Machine failed.
1336 static inline mcg_auto_trim_machine_fail_status_t CLOCK_HAL_GetAutoTrimMachineFailMode(uint32_t baseAddr)
1338 return (mcg_auto_trim_machine_fail_status_t)BR_MCG_SC_ATMF(baseAddr);
1342 * @brief Sets the Automatic Trim machine Fail Flag.
1344 * This function clears the ATMF flag.
1346 * @param baseAddr Base address for current MCG instance.
1348 static inline void CLOCK_HAL_SetAutoTrimMachineFail(uint32_t baseAddr)
1350 BW_MCG_SC_ATMF(baseAddr, 1);
1354 * @brief Gets the OSC0 Loss of Clock Status.
1356 * This function gets the OSC0 Loss of Clock Status. The LOCS0 indicates when a loss of
1357 * OSC0 reference clock has occurred. The LOCS0 bit only has an effect when CME0 is set.
1358 * This bit is cleared by writing a logic 1 to it when set.
1360 * @param baseAddr Base address for current MCG instance.
1361 * @return status OSC0 Loss of Clock Status
1362 * - 0: Loss of OSC0 has not occurred.
1363 * - 1: Loss of OSC0 has occurred.
1365 static inline mcg_locs0_status_t CLOCK_HAL_GetLocs0Mode(uint32_t baseAddr)
1367 return (mcg_locs0_status_t)BR_MCG_SC_LOCS0(baseAddr);
1371 * @brief Sets the Automatic Trim Machine Enable Setting.
1373 * This function enables/disables the Auto Trim Machine to start automatically
1374 * trimming the selected Internal Reference Clock.
1375 * ATME de-asserts after the Auto Trim Machine has completed trimming all trim bits
1376 * of the IRCS clock selected by the ATMS bit.
1377 * Writing to C1, C3, C4, and SC registers or entering Stop mode aborts the auto
1378 * trim operation and clears this bit.
1380 * @param baseAddr Base address for current MCG instance.
1381 * @params enable Automatic Trim Machine Enable Setting
1382 * - true: Auto Trim Machine enabled
1383 * - false: Auto Trim Machine disabled
1385 static inline void CLOCK_HAL_SetAutoTrimMachineCmd(uint32_t baseAddr, bool enable)
1387 BW_MCG_SC_ATME(baseAddr, enable ? 1 : 0);
1391 * @brief Gets the Automatic Trim Machine Enable Setting.
1393 * This function gets the Automatic Trim Machine Enable Setting.
1395 * @param baseAddr Base address for current MCG instance.
1396 * @return enabled True if Automatic Trim Machine is enabled
1398 static inline bool CLOCK_HAL_GetAutoTrimMachineCmd(uint32_t baseAddr)
1400 return BR_MCG_SC_ATME(baseAddr);
1404 * @brief Sets the Automatic Trim Machine Select Setting.
1406 * This function selects the IRCS clock for Auto Trim Test.
1408 * @param baseAddr Base address for current MCG instance.
1409 * @params setting Automatic Trim Machine Select Setting
1410 * - 0: 32 kHz Internal Reference Clock selected
1411 * - 1: 4 MHz Internal Reference Clock selected
1413 static inline void CLOCK_HAL_SetAutoTrimMachineSelMode(uint32_t baseAddr,
1414 mcg_auto_trim_machine_select_t setting)
1416 BW_MCG_SC_ATMS(baseAddr, setting);
1420 * @brief Gets the Automatic Trim Machine Select Setting.
1422 * This function gets the Automatic Trim Machine Select Setting.
1424 * @param baseAddr Base address for current MCG instance.
1425 * @return setting Automatic Trim Machine Select Setting
1427 static inline mcg_auto_trim_machine_select_t CLOCK_HAL_GetAutoTrimMachineSelMode(uint32_t baseAddr)
1429 return (mcg_auto_trim_machine_select_t)BR_MCG_SC_ATMS(baseAddr);
1433 * @brief Sets the FLL Filter Preserve Enable Setting.
1435 * This function sets the FLL Filter Preserve Enable. This bit prevents the
1436 * FLL filter values from resetting allowing the FLL output frequency to remain the
1437 * same during the clock mode changes where the FLL/DCO output is still valid.
1438 * (Note: This requires that the FLL reference frequency remain the same as
1439 * the value prior to the new clock mode switch. Otherwise, the FLL filter and the frequency
1442 * @param baseAddr Base address for current MCG instance.
1443 * @params enable FLL Filter Preserve Enable Setting
1444 * - true: FLL filter and FLL frequency retain their previous values
1445 * during new clock mode change
1446 * - false: FLL filter and FLL frequency will reset on changes to correct
1449 static inline void CLOCK_HAL_SetFllFilterPreserveCmd(uint32_t baseAddr, bool enable)
1451 BW_MCG_SC_FLTPRSRV(baseAddr, enable ? 1 : 0);
1455 * @brief Gets the FLL Filter Preserve Enable Setting.
1457 * This function gets the FLL Filter Preserve Enable Setting.
1459 * @param baseAddr Base address for current MCG instance.
1460 * @return enabled True if FLL Filter Preserve is enabled.
1462 static inline bool CLOCK_HAL_GetFllFilterPreserveCmd(uint32_t baseAddr)
1464 return BR_MCG_SC_FLTPRSRV(baseAddr);
1468 * @brief Sets the Fast Clock Internal Reference Divider Setting.
1470 * This function selects the amount to divide down the fast internal reference
1471 * clock. The resulting frequency is in the range 31.25 kHz to 4 MHz.
1472 * (Note: Changing the divider when the Fast IRC is enabled is not supported).
1474 * @param baseAddr Base address for current MCG instance.
1475 * @params setting Fast Clock Internal Reference Divider Setting
1477 static inline void CLOCK_HAL_SetFastClkInternalRefDivider(uint32_t baseAddr, uint8_t setting)
1479 BW_MCG_SC_FCRDIV(baseAddr, setting);
1483 * @brief Gets the Fast Clock Internal Reference Divider Setting.
1485 * This function gets the Fast Clock Internal Reference Divider Setting.
1487 * @param baseAddr Base address for current MCG instance.
1488 * @return setting Fast Clock Internal Reference Divider Setting
1490 static inline uint8_t CLOCK_HAL_GetFastClkInternalRefDivider(uint32_t baseAddr)
1492 return BR_MCG_SC_FCRDIV(baseAddr);
1496 * @brief Sets the ATM Compare Value High Setting.
1498 * This function sets the ATM compare value high setting. The values are used by the
1499 * Auto Trim Machine to compare and adjust the Internal Reference trim values during the ATM
1502 * @param baseAddr Base address for current MCG instance.
1503 * @params setting ATM Compare Value High Setting
1505 static inline void CLOCK_HAL_SetAutoTrimMachineCompValHigh(uint32_t baseAddr, uint8_t setting)
1507 BW_MCG_ATCVH_ATCVH(baseAddr, setting);
1511 * @brief Gets the ATM Compare Value High Setting.
1513 * This function gets the ATM Compare Value High Setting.
1515 * @param baseAddr Base address for current MCG instance.
1516 * @return setting ATM Compare Value High Setting
1518 static inline uint8_t CLOCK_HAL_GetAutoTrimMachineCompValHigh(uint32_t baseAddr)
1520 return BR_MCG_ATCVH_ATCVH(baseAddr);
1524 * @brief Sets the ATM Compare Value Low Setting.
1526 * This function sets the ATM compare value low setting. The values are used by the
1527 * Auto Trim Machine to compare and adjust Internal Reference trim values during the ATM
1530 * @param baseAddr Base address for current MCG instance.
1531 * @params setting ATM Compare Value Low Setting
1533 static inline void CLOCK_HAL_SetAutoTrimMachineCompValLow(uint32_t baseAddr, uint8_t setting)
1535 BW_MCG_ATCVL_ATCVL(baseAddr, setting);
1539 * @brief Gets the ATM Compare Value Low Setting.
1541 * This function gets the ATM Compare Value Low Setting.
1543 * @param baseAddr Base address for current MCG instance.
1544 * @return setting ATM Compare Value Low Setting
1546 static inline uint8_t CLOCK_HAL_GetAutoTrimMachineCompValLow(uint32_t baseAddr)
1548 return BR_MCG_ATCVL_ATCVL(baseAddr);
1551 #if FSL_FEATURE_MCG_USE_OSCSEL
1553 * @brief Sets the MCG OSC Clock Select Setting.
1555 * This function selects the MCG FLL external reference clock.
1557 * @param baseAddr Base address for current MCG instance.
1558 * @params setting MCG OSC Clock Select Setting
1559 * - 0: Selects System Oscillator (OSCCLK).
1560 * - 1: Selects 32 kHz RTC Oscillator.
1562 static inline void CLOCK_HAL_SetOscselMode(uint32_t baseAddr, mcg_oscsel_select_t setting)
1564 BW_MCG_C7_OSCSEL(baseAddr, setting);
1568 * @brief Gets the MCG OSC Clock Select Setting.
1570 * This function gets the MCG OSC Clock Select Setting.
1572 * @param baseAddr Base address for current MCG instance.
1573 * @return setting MCG OSC Clock Select Setting
1575 static inline mcg_oscsel_select_t CLOCK_HAL_GetOscselMode(uint32_t baseAddr)
1577 return (mcg_oscsel_select_t)BR_MCG_C7_OSCSEL(baseAddr);
1579 #endif /* FSL_FEATURE_MCG_USE_OSCSEL */
1581 #if FSL_FEATURE_MCG_HAS_LOLRE
1583 * @brief Sets the PLL Loss of Lock Reset Enable Setting.
1585 * This function determines whether an interrupt or a reset request is made
1586 * following a PLL loss of lock.
1588 * @param baseAddr Base address for current MCG instance.
1589 * @params enable PLL Loss of Lock Reset Enable Setting
1590 * - true: Generate a reset request on a PLL loss of lock indication.
1591 * - false: Interrupt request is generated on a PLL loss of lock
1592 * indication. The PLL loss of lock interrupt enable bit
1593 * must also be set to generate the interrupt request.
1595 static inline void CLOCK_HAL_SetLossOfClkResetCmd(uint32_t baseAddr, bool enable)
1597 BW_MCG_C8_LOLRE(baseAddr, enable ? 1 : 0);
1601 * @brief Gets the PLL Loss of Lock Reset Enable Setting.
1603 * This function gets the PLL Loss of Lock Reset Enable Setting.
1605 * @param baseAddr Base address for current MCG instance.
1606 * @return enabled True if the PLL Loss of Lock Reset is enabled.
1608 static inline bool CLOCK_HAL_GetLossOfClkResetCmd(uint32_t baseAddr)
1610 return BR_MCG_C8_LOLRE(baseAddr);
1612 #endif /* FSL_FEATURE_MCG_HAS_LOLRE */
1615 #if FSL_FEATURE_MCG_HAS_RTC_32K
1617 * @brief Sets the Loss of Clock Reset Enable Setting.
1619 * This function determines whether an interrupt or a reset request is made following
1620 * a loss of the RTC external reference clock. The LOCRE1 only has an affect when CME1
1623 * @param baseAddr Base address for current MCG instance.
1624 * @params enable Loss of Clock Reset Enable Setting
1625 * - true: Generate a reset request on a loss of RTC external reference clock.
1626 * - false: Interrupt request is generated on a loss of RTC external
1629 static inline void CLOCK_HAL_SetLossClkReset1Cmd(uint32_t baseAddr, bool enable)
1631 BW_MCG_C8_LOCRE1(baseAddr, enable ? 1 : 0);
1635 * @brief Gets the Loss of Clock Reset Enable Setting.
1637 * This function gets the Loss of Clock Reset Enable Setting.
1639 * @param baseAddr Base address for current MCG instance.
1640 * @return enabled True if Loss of Clock Reset is enabled.
1642 static inline bool CLOCK_HAL_GetLossClkReset1Cmd(uint32_t baseAddr)
1644 return BR_MCG_C8_LOCRE1(baseAddr);
1648 * @brief Sets the Clock Monitor Enable1 Setting.
1650 * This function enables/disables the loss of the clock monitoring circuit for the
1651 * output of the RTC external reference clock. The LOCRE1 bit determines whether an
1652 * interrupt or a reset request is generated following a loss of the RTC clock indication.
1653 * The CME1 bit should only be set to a logic 1 when the MCG is in an operational mode
1654 * that uses the external clock (FEE, FBE, PEE, PBE, or BLPE). CME1 bit must be set to
1655 * a logic 0 before the MCG enters any Stop mode. Otherwise, a reset request may occur
1656 * while in Stop mode. CME1 should also be set to a logic 0 before entering VLPR or
1657 * VLPW power modes if the MCG is in BLPE mode.
1659 * @param baseAddr Base address for current MCG instance.
1660 * @params enable Clock Monitor Enable1 Setting
1661 * - true: External clock monitor is enabled for RTC clock.
1662 * - false: External clock monitor is disabled for RTC clock.
1664 static inline void CLOCK_HAL_SetClkMonitor1Cmd(uint32_t baseAddr, bool enable)
1666 BW_MCG_C8_CME1(baseAddr, enable ? 1 : 0);
1670 * @brief Gets the Clock Monitor Enable1 Setting.
1672 * This function gets the Clock Monitor Enable1 Setting.
1674 * @param baseAddr Base address for current MCG instance.
1675 * @return enabled True if Clock Monitor Enable1 is enabled
1677 static inline bool CLOCK_HAL_GetClkMonitor1Cmd(uint32_t baseAddr)
1679 return BR_MCG_C8_CME1(baseAddr);
1683 * @brief Gets the RTC Loss of Clock Status.
1685 * This function gets the RTC Loss of Clock Status. This bit indicates when a loss
1686 * of clock has occurred. This bit is cleared by writing a logic 1 to it when set.
1688 * @param baseAddr Base address for current MCG instance.
1689 * @return status RTC Loss of Clock Status
1690 * - 0: Loss of RTC has not occurred
1691 * - 1: Loss of RTC has occurred
1693 static inline mcg_loss_of_clk1_status_t CLOCK_HAL_GetLossOfClk1Mode(uint32_t baseAddr)
1695 return (mcg_loss_of_clk1_status_t)BR_MCG_C8_LOCS1(baseAddr);
1697 #endif /* FSL_FEATURE_MCG_HAS_RTC_32K */
1699 #if FSL_FEATURE_MCG_USE_PLLREFSEL
1701 * @brief Sets the OSC1 Loss of Clock Reset Enable Setting.
1703 * This function determines whether an interrupt or reset request is made following
1704 * a loss of OSC1 external reference clock. The LOCRE2 only has an affect when
1707 * @param baseAddr Base address for current MCG instance.
1708 * @params enable OSC1 Loss of Clock Reset Enable Setting
1709 * - true: Reset request is generated on a loss of OSC1 external
1711 * - false: Interrupt request is generated on a loss of OSC1 external
1714 static inline void CLOCK_HAL_SetLossClkReset2Cmd(uint32_t baseAddr, bool enable)
1716 BW_MCG_C10_LOCRE2(baseAddr, enable ? 1 : 0);
1720 * @brief Gets the OSC1 Loss of the Clock Reset Enable Setting.
1722 * This function gets the OSC1 Loss of Clock Reset Enable Setting.
1724 * @param baseAddr Base address for current MCG instance.
1725 * @return enabled True if OSC1 Loss of Clock Reset is enabled.
1727 static inline bool CLOCK_HAL_GetLossClkReset2Cmd(uint32_t baseAddr)
1729 return BR_MCG_C10_LOCRE2(baseAddr);
1733 * @brief Sets the Frequency Range1 Select Setting.
1735 * This function selects the frequency range for the OSC1 crystal oscillator
1736 * or an external clock source. See the Oscillator chapter for more details and
1737 * the device data sheet for the frequency ranges used.
1739 * @param baseAddr Base address for current MCG instance.
1740 * @params setting Frequency Range1 Select Setting
1741 * - 00: Low frequency range selected for the crystal oscillator.
1742 * - 01: High frequency range selected for the crystal oscillator.
1743 * - 1X: Very high frequency range selected for the crystal oscillator.
1745 static inline void CLOCK_HAL_SetRange1Mode(uint32_t baseAddr, mcg_freq_range_select_t setting)
1747 BW_MCG_C10_RANGE1(baseAddr, setting);
1751 * @brief Gets the Frequency Range1 Select Setting.
1753 * This function gets the Frequency Range1 Select Setting.
1755 * @param baseAddr Base address for current MCG instance.
1756 * @return setting Frequency Range1 Select Setting
1758 static inline mcg_freq_range_select_t CLOCK_HAL_GetRange1Mode(uint32_t baseAddr)
1760 return (mcg_freq_range_select_t)BR_MCG_C10_RANGE1(baseAddr);
1764 * @brief Sets the High Gain Oscillator1 Select Setting.
1766 * This function controls the OSC1 crystal oscillator mode of operation.
1767 * See the Oscillator chapter for more details.
1769 * @param baseAddr Base address for current MCG instance.
1770 * @params setting High Gain Oscillator1 Select Setting
1771 * - 0: Configure crystal oscillator for low-power operation.
1772 * - 1: Configure crystal oscillator for high-gain operation.
1774 static inline void CLOCK_HAL_SetHighGainOsc1Mode(uint32_t baseAddr,
1775 mcg_high_gain_osc_select_t setting)
1777 BW_MCG_C10_HGO1(baseAddr, setting);
1781 * @brief Gets the High Gain Oscillator1 Select Setting.
1783 * This function gets the High Gain Oscillator1 Select Setting.
1785 * @param baseAddr Base address for current MCG instance.
1786 * @return setting High Gain Oscillator1 Select Setting
1788 static inline mcg_high_gain_osc_select_t CLOCK_HAL_GetHighGainOsc1Mode(uint32_t baseAddr)
1790 return (mcg_high_gain_osc_select_t)BR_MCG_C10_HGO1(baseAddr);
1794 * @brief Sets the External Reference Select Setting.
1796 * This function selects the source for the OSC1 external reference clock.
1797 * See the Oscillator chapter for more details.
1799 * @param baseAddr Base address for current MCG instance.
1800 * @params setting External Reference Select Setting
1801 * - 0: External reference clock requested.
1802 * - 1: Oscillator requested.
1804 static inline void CLOCK_HAL_SetExternalRefSel1Mode(uint32_t baseAddr,
1805 mcg_external_ref_clock_select_t setting)
1807 BW_MCG_C10_EREFS1(baseAddr, setting);
1811 * @brief Gets the External Reference Select Setting.
1813 * This function gets the External Reference Select Setting.
1815 * @param baseAddr Base address for current MCG instance.
1816 * @return setting External Reference Select Setting
1818 static inline mcg_external_ref_clock_select_t CLOCK_HAL_GetExternalRefSel1Mode(uint32_t baseAddr)
1820 return (mcg_external_ref_clock_select_t)BR_MCG_C10_EREFS1(baseAddr);
1824 * @brief Sets the PLL1 External Reference Select Setting.
1826 * This function selects the PLL1 external reference clock source.
1828 * @param baseAddr Base address for current MCG instance.
1829 * @params setting PLL1 External Reference Select Setting
1830 * - 0: Selects OSC0 clock source as its external reference clock.
1831 * - 1: Selects OSC1 clock source as its external reference clock.
1833 static inline void CLOCK_HAL_SetPllRefSel1Mode(uint32_t baseAddr,
1834 mcg_pll_external_ref_clk_select_t setting)
1836 BW_MCG_C11_PLLREFSEL1(baseAddr, setting);
1840 * @brief Gets the PLL1 External Reference Select Setting.
1842 * This function gets the PLL1 External Reference Select Setting.
1844 * @param baseAddr Base address for current MCG instance.
1845 * @return setting PLL1 External Reference Select Setting
1847 static inline mcg_pll_external_ref_clk_select_t CLOCK_HAL_GetPllRefSel1Mode(uint32_t baseAddr)
1849 return (mcg_pll_external_ref_clk_select_t)BR_MCG_C11_PLLREFSEL1(baseAddr);
1853 * @brief Sets the PLL1 Clock Enable Setting.
1855 * This function enables/disables the PLL1 independent of PLLS and enables the
1856 * PLL clocks for use as MCGPLL1CLK, MCGPLL1CLK2X, and MCGDDRCLK2X. (PRDIV1 needs
1857 * to be programmed to the correct divider to generate a PLL1 reference clock in a
1858 * valid reference range prior to setting the PLLCLKEN1 bit.) Setting PLLCLKEN1
1859 * enables the PLL1 selected external oscillator if not already enabled.
1860 * Whenever the PLL1 is enabled with the PLLCLKEN1 bit, and the
1861 * external oscillator is used as the reference clock, the OSCINIT1 bit should
1862 * be checked to make sure it is set.
1864 * @param baseAddr Base address for current MCG instance.
1865 * @params enable PLL1 Clock Enable Setting
1866 * - true: MCGPLL1CLK, MCGPLL1CLK2X, and MCGDDRCLK2X are active unless
1867 * MCG is in a bypass mode with LP=1 (BLPI or BLPE).
1868 * - false: MCGPLL1CLK, MCGPLL1CLK2X, and MCGDDRCLK2X are inactive.
1870 static inline void CLOCK_HAL_SetPllClk1Cmd(uint32_t baseAddr, bool enable)
1872 BW_MCG_C11_PLLCLKEN1(baseAddr, enable ? 1 : 0);
1876 * @brief Gets the PLL1 Clock Enable Setting.
1878 * This function gets the PLL1 Clock Enable Setting.
1880 * @param baseAddr Base address for current MCG instance.
1881 * @return enabled True if the PLL1 Clock is enabled.
1883 static inline bool CLOCK_HAL_GetPllClk1Cmd(uint32_t baseAddr)
1885 return BR_MCG_C11_PLLCLKEN1(baseAddr);
1889 * @brief Sets the PLL1 Stop Enable Setting.
1891 * This function enables/disables the PLL1 Clock during the Normal Stop (In Low
1892 * Power Stop modes, the PLL1 clock gets disabled even if PLLSTEN1=1. In all other
1893 * power modes, PLLSTEN1 bit has no affect and does not enable the PLL1 Clock to
1894 * run if it is written to 1.
1896 * @param baseAddr Base address for current MCG instance.
1897 * @params enable PLL1 Stop Enable Setting
1898 * - true: PLL1 and its clocks (MCGPLL1CLK, MCGPLL1CLK2X, and
1899 * MCGDDRCLK2X) are enabled if system is in Normal Stop mode.
1900 * - false: PLL1 clocks (MCGPLL1CLK, MCGPLL1CLK2X, and MCGDDRCLK2X)
1901 * are disabled in any of the Stop modes.
1903 static inline void CLOCK_HAL_SetPllStop1Cmd(uint32_t baseAddr, bool enable)
1905 BW_MCG_C11_PLLSTEN1(baseAddr, enable ? 1 : 0);
1909 * @brief Gets the PLL1 Stop Enable Setting.
1911 * This function gets the PLL1 Stop Enable Setting.
1913 * @param baseAddr Base address for current MCG instance.
1914 * @return enabled True if PLL1 Stop is enabled.
1916 static inline bool CLOCK_HAL_GetPllStop1Cmd(uint32_t baseAddr)
1918 return BR_MCG_C11_PLLSTEN1(baseAddr);
1922 * @brief Sets the PLL Clock Select Setting.
1924 * This function controls whether the PLL0 or PLL1 output is selected as the
1925 * MCG source when CLKS are programmed in PLL Engaged External (PEE) mode
1926 * (CLKS[1:0]=00 and IREFS=0 and PLLS=1).
1928 * @param baseAddr Base address for current MCG instance.
1929 * @params setting PLL Clock Select Setting
1930 * - 0: PLL0 output clock is selected.
1931 * - 1: PLL1 output clock is selected.
1933 static inline void CLOCK_HAL_SetPllClkSelMode(uint32_t baseAddr, mcg_pll_clk_select_t setting)
1935 BW_MCG_C11_PLLCS(baseAddr, setting);
1939 * @brief Gets the PLL Clock Select Setting.
1941 * This function gets the PLL Clock Select Setting.
1943 * @param baseAddr Base address for current MCG instance.
1944 * @return setting PLL Clock Select Setting
1946 static inline mcg_pll_clk_select_t CLOCK_HAL_GetPllClkSelMode(uint32_t baseAddr)
1948 return (mcg_pll_clk_select_t)BR_MCG_C11_PLLCS(baseAddr);
1952 * @brief Sets the PLL1 External Reference Divider Setting.
1954 * This function selects the amount to divide down the external reference
1955 * clock selected by REFSEL2 for PLL1. The resulting frequency must be in a valid
1956 * reference range. After the PLL1 is enabled (by setting either PLLCLKEN1 or PLLS),
1957 * the PRDIV1 value must not be changed when LOCK1 is zero.
1959 * @param baseAddr Base address for current MCG instance.
1960 * @params setting PLL1 External Reference Divider Setting
1962 static inline void CLOCK_HAL_SetPllExternalRefDivider1(uint32_t baseAddr, uint8_t setting)
1964 BW_MCG_C11_PRDIV1(baseAddr, setting);
1968 * @brief Gets the PLL1 External Reference Divider Setting.
1970 * This function gets the PLL1 External Reference Divider Setting.
1972 * @param baseAddr Base address for current MCG instance.
1973 * @return setting PLL1 External Reference Divider Setting
1975 static inline uint8_t CLOCK_HAL_GetPllExternalRefDivider1(uint32_t baseAddr)
1977 return BR_MCG_C11_PRDIV1(baseAddr);
1981 * @brief Sets the PLL1 Loss of Lock Interrupt Enable Setting.
1983 * This function determines whether an interrupt request is made following a
1984 * loss of lock indication for PLL1. This bit only has an affect when LOLS1 is set.
1986 * @param baseAddr Base address for current MCG instance.
1987 * @params enable PLL1 Loss of Lock Interrupt Enable Setting
1988 * - true: Generate an interrupt request on loss of lock on PLL1.
1989 * - false: No interrupt request is generated on loss of lock on PLL1.
1991 static inline void CLOCK_HAL_SetLossOfLock1Cmd(uint32_t baseAddr, bool enable)
1993 BW_MCG_C12_LOLIE1(baseAddr, enable ? 1 : 0);
1997 * @brief Gets the PLL1 Loss of Lock Interrupt Enable Setting.
1999 * This function gets the PLL1 Loss of Lock Interrupt Enable Setting.
2001 * @param baseAddr Base address for current MCG instance.
2002 * @return enabled true if PLL1 Loss of Lock Interrupt is enabled.
2004 static inline bool CLOCK_HAL_GetLossOfLock1Cmd(uint32_t baseAddr)
2006 return BR_MCG_C12_LOLIE1(baseAddr);
2010 * @brief Sets the Clock Monitor Enable2 Setting
2012 * This function enables/disables the loss of the clock monitor for the OSC1 external
2013 * reference clock. LOCRE2 determines whether a reset or interrupt request is generated
2014 * following a loss of OSC1 external reference clock. The CME2 bit should only be set
2015 * to a logic 1 when the MCG is in an operational mode that uses the external clock
2016 * (PEE or PBE) . Whenever the CME2 bit is set to a logic 1, the value of the RANGE1
2017 * bits in the C10 register should not be changed. CME2 bit should be set to a logic 0
2018 * before the MCG enters any Stop mode. Otherwise, a reset request may occur while in
2021 * @param baseAddr Base address for current MCG instance.
2022 * @params enable Clock Monitor Enable2 Setting
2023 * - true: Generate a reset request on loss of external clock on OSC1.
2024 * - false: External clock monitor for OSC1 is disabled.
2026 static inline void CLOCK_HAL_SetClkMonitor2Cmd(uint32_t baseAddr, bool enable)
2028 BW_MCG_C12_CME2(baseAddr, enable ? 1 : 0);
2032 * @brief Gets the Clock Monitor Enable2 Setting.
2034 * This function gets the Clock Monitor Enable2 Setting.
2036 * @param baseAddr Base address for current MCG instance.
2037 * @return enabled True if Clock Monitor Enable2 is enabled.
2039 static inline bool CLOCK_HAL_GetClkMonitor2Cmd(uint32_t baseAddr)
2041 return BR_MCG_C12_CME2(baseAddr);
2045 * @brief Sets the VCO1 Divider Setting.
2047 * This function selects the amount to divide the VCO output of the PLL1.
2048 * The VDIV1 bits establishes the multiplication factor (M) applied to the reference
2049 * clock frequency. After the PLL1 is enabled (by setting either PLLCLKEN1 or
2050 * PLLS), the VDIV1 value must not be changed when LOCK1 is zero.
2052 * @param baseAddr Base address for current MCG instance.
2053 * @params setting VCO1 Divider Setting
2055 static inline void CLOCK_HAL_SetVoltCtrlOscDivider1(uint32_t baseAddr, uint8_t setting)
2057 BW_MCG_C12_VDIV1(baseAddr, setting);
2061 * @brief Gets the VCO1 Divider Setting.
2063 * This function gets the VCO1 Divider Setting.
2065 * @param baseAddr Base address for current MCG instance.
2066 * @return setting VCO1 Divider Setting
2068 static inline uint8_t CLOCK_HAL_GetVoltCtrlOscDivider1(uint32_t baseAddr)
2070 return BR_MCG_C12_VDIV1(baseAddr);
2074 * @brief Gets the Loss of the Lock2 Status.
2076 * This function gets the Loss of the Lock2 Status. This bit is a sticky bit indicating
2077 * the lock status for the PLL1. LOLS1 is set if after acquiring lock, the PLL1
2078 * output frequency has fallen outside the lock exit frequency tolerance, D unl.
2079 * LOLIE1 determines whether an interrupt request is made when LOLS1 is set. This
2080 * bit is cleared by reset or by writing a logic 1 to it when set. Writing a logic 0
2081 * to this bit has no effect.
2083 * @param baseAddr Base address for current MCG instance.
2084 * @return status Loss of Lock2 Status
2085 * - 0: PLL1 has not lost lock since LOLS1 was last cleared.
2086 * - 1: PLL1 has lost lock since LOLS1 was last cleared.
2088 static inline mcg_loss_of_lock_status_t CLOCK_HAL_GetLossOfLock1Mode(uint32_t baseAddr)
2090 return (mcg_loss_of_lock_status_t)BR_MCG_S2_LOLS1(baseAddr);
2094 * @brief Gets the Lock1 Status.
2096 * This function gets the Lock1 Status. This bit indicates whether PLL1 has
2097 * acquired the lock. PLL1 Lock detection is disabled when not operating in either
2098 * PBE or PEE mode unless the PLLCLKEN1=1 and the the MCG is not configured in the BLPI or the
2099 * BLPE mode. While the PLL1 clock is locking to the desired frequency, MCGPLL1CLK,
2100 * MCGPLL1CLK2X, and MCGDDRCLK2X are gated off until the LOCK1 bit gets
2101 * asserted. If the lock status bit is set, changing the value of the PRDIV1[2:0]
2102 * bits in the C8 register or the VDIV2[4:0] bits in the C9 register causes the
2103 * lock status bit to clear and stay cleared until the PLL1 has reacquired lock.
2104 * Loss of PLL1 reference clock will also causes the LOCK1 bit to clear until the PLL1
2105 * has reacquired lock. Entry into the LLS, VLPS, or a regular Stop with the PLLSTEN1=0 also
2106 * causes the lock status bit to clear and stay cleared until the Stop mode is exited
2107 * and the PLL1 has reacquired the lock. Any time the PLL1 is enabled and the LOCK1 bit
2108 * is cleared, the MCGPLL1CLK, MCGPLL1CLK2X, and MCGDDRCLK2X are gated off
2109 * until the LOCK1 bit is asserted again.
2111 * @param baseAddr Base address for current MCG instance.
2112 * @return status Lock1 Status
2113 * - 0: PLL1 is currently unlocked.
2114 * - 1: PLL1 is currently locked.
2116 static inline mcg_lock_status_t CLOCK_HAL_GetLock1Mode(uint32_t baseAddr)
2118 return (mcg_lock_status_t)BR_MCG_S2_LOCK1(baseAddr);
2122 * @brief Gets the PLL Clock Select Status.
2124 * This function gets the PLL Clock Select Status. The PLLCST indicates the PLL
2125 * clock selected by PLLCS. The PLLCST bit is not updated immediately after a
2126 * write to the PLLCS bit due internal synchronization between clock domains.
2128 * @param baseAddr Base address for current MCG instance.
2129 * @return status PLL Clock Select Status
2130 * - 0: Source of PLLCS is PLL0 clock.
2131 * - 1: Source of PLLCS is PLL1 clock.
2133 static inline mcg_pll_clk_select_t CLOCK_HAL_GetPllClkSelStatMode(uint32_t baseAddr)
2135 return (mcg_pll_clk_select_t)BR_MCG_S2_PLLCST(baseAddr);
2139 * @brief Gets the OSC1 Initialization Status.
2141 * This function gets the OSC1 Initialization Status. This bit is set after the
2142 * initialization cycles of the 2nd crystal oscillator clock have completed. See
2143 * the Oscillator block guide for more details.
2145 * @param baseAddr Base address for current MCG instance.
2146 * @return status OSC1 Initialization Status
2148 static inline uint8_t CLOCK_HAL_GetOscInit1(uint32_t baseAddr)
2150 return BR_MCG_S2_OSCINIT1(baseAddr);
2154 * @brief Gets the OSC1 Loss of Clock Status.
2156 * This function gets the OSC1 Loss of Clock Status. This bit indicates when a loss
2157 * of the OSC1 external reference clock has occurred. LOCRE2 determines if a reset or
2158 * interrupt is generated when LOCS2 is set. This bit is cleared by writing a
2159 * logic 1 to it when set.
2161 * @param baseAddr Base address for current MCG instance.
2162 * @return status OSC1 Loss of Clock Status
2163 * - 0: No loss of OSC1 external reference clock has occurred.
2164 * - 1: Loss of OSC1 external reference clock has occurred.
2166 static inline mcg_locs2_status_t CLOCK_HAL_GetLocs2Mode(uint32_t baseAddr)
2168 return (mcg_locs2_status_t)BR_MCG_S2_LOCS2(baseAddr);
2170 #endif /* FSL_FEATURE_MCG_USE_PLLREFSEL */
2174 #if defined(__cplusplus)
2176 #endif /* __cplusplus*/
2180 #endif /* __FSL_MCG_HAL_H__*/
2181 /*******************************************************************************
2183 ******************************************************************************/