]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_KPSDK_CODE/hal/mcg/fsl_mcg_hal.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / hal / TARGET_Freescale / TARGET_KPSDK_MCUS / TARGET_KPSDK_CODE / hal / mcg / fsl_mcg_hal.h
1 /*
2  * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  *   of conditions and the following disclaimer.
10  *
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.
14  *
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.
18  *
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.
29  */
30
31 #if !defined(__FSL_MCG_HAL_H__)
32 #define __FSL_MCG_HAL_H__
33
34 #include <stdint.h>
35 #include <stdbool.h>
36 #include <assert.h>
37 #include "fsl_device_registers.h"
38 #include "fsl_mcg_features.h"
39
40 /*! @addtogroup mcg_hal*/
41 /*! @{*/
42
43 /*! @file fsl_mcg_hal.h */
44
45 /*******************************************************************************
46  * Definitions
47  ******************************************************************************/
48 /*! @brief MCG constant definitions*/
49 enum _mcg_constant
50 {
51    kMcgConstant0 =        (0u),
52    kMcgConstant1 =        (1u),
53    kMcgConstant2 =        (2u),
54    kMcgConstant3 =        (3u),
55    kMcgConstant4 =        (4u),
56    kMcgConstant5 =        (5u),
57    kMcgConstant32 =       (32u),
58
59    kMcgConstant640 =      (640u),
60    kMcgConstant1280 =    (1280u),
61    kMcgConstant1920 =    (1920u),
62    kMcgConstant2560 =    (2560u),
63    kMcgConstant732  =    (732u),
64    kMcgConstant1464 =    (1464u),
65    kMcgConstant2197 =    (2197u),
66    kMcgConstant2929 =    (2929u),
67
68    kMcgConstantHex20 =   (0x20u),
69    kMcgConstantHex40 =   (0x40u),
70    kMcgConstantHex60 =   (0x60u),
71    kMcgConstantHex80 =   (0x80u),
72    kMcgConstantHexA0 =   (0xA0u),
73    kMcgConstantHexC0 =   (0xC0u),
74    kMcgConstantHexE0 =   (0xE0u),
75
76    kMcgConstant2000  =   (2000u),
77    kMcgConstant3000  =   (3000u),
78    kMcgConstant4000  =   (4000u),
79
80    kMcgConstant10000 =   (10000u),
81    kMcgConstant30000 =   (30000u),
82    kMcgConstant31250 =   (31250u),
83    kMcgConstant39063 =   (39063u),
84    kMcgConstant40000 =   (40000u),
85
86    kMcgConstant1250000 = (1250000u),
87    kMcgConstant2500000 = (2500000u),
88    kMcgConstant3000000 = (3000000u),
89    kMcgConstant5000000 = (5000000u),
90    kMcgConstant8000000 = (8000000u),
91
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),
101
102    kMcgConstant100000000 = (100000000u),
103    kMcgConstant180000000 = (180000000u),
104    kMcgConstant360000000 = (360000000u)
105 };
106
107 /*! @brief MCG clock source select */
108 typedef enum _mcg_clock_select
109 {
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 */
113     kMcgClkSelReserved
114 } mcg_clock_select_t;
115
116 /*! @brief MCG internal reference clock source select */
117 typedef enum _mcg_internal_ref_clock_source
118 {
119     kMcgInternalRefClkSrcExternal,         /* External reference clock is selected */
120     kMcgInternalRefClkSrcSlow         /* The slow internal reference clock is selected */
121 } mcg_internal_ref_clock_source_t;
122
123 /*! @brief MCG frequency range select */
124 typedef enum _mcg_freq_range_select
125 {
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;
131
132 /*! @brief MCG high gain oscillator select */
133 typedef enum _mcg_high_gain_osc_select
134 {
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;
138
139 /*! @brief MCG high gain oscillator select */
140 typedef enum _mcg_external_ref_clock_select
141 {
142     kMcgExternalRefClkSelExternal,         /* External reference clock requested */
143     kMcgExternalRefClkSelOsc          /* Oscillator requested */
144 } mcg_external_ref_clock_select_t;
145
146 /*! @brief MCG low power select */
147 typedef enum _mcg_low_power_select
148 {
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;
152
153 /*! @brief MCG internal reference clock select */
154 typedef enum _mcg_internal_ref_clock_select
155 {
156     kMcgInternalRefClkSelSlow,        /* Slow internal reference clock selected */
157     kMcgInternalRefClkSelFast         /* Fast internal reference clock selected */
158 } mcg_internal_ref_clock_select_t;
159
160 /*! @brief MCG DCO Maximum Frequency with 32.768 kHz Reference */
161 typedef enum _mcg_dmx32_select
162 {
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;
166
167 /*! @brief MCG DCO range select */
168 typedef enum _mcg_digital_controlled_osc_range_select
169 {
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;
175
176 /*! @brief MCG PLL external reference clock select */
177 typedef enum _mcg_pll_external_ref_clk_select
178 {
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;
182
183 /*! @brief MCG PLL select */
184 typedef enum _mcg_pll_select
185 {
186     kMcgPllSelFll,              /* FLL is selected */
187     kMcgPllSelPllClkSel         /* PLLCS output clock is selected */
188 } mcg_pll_select_t;
189
190 /*! @brief MCG loss of lock status */
191 typedef enum _mcg_loss_of_lock_status
192 {
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;
196
197 /*! @brief MCG lock status */
198 typedef enum _mcg_lock_status
199 {
200     kMcgLockUnlocked,               /* PLL is currently unlocked */
201     kMcgLockLocked                  /* PLL is currently locked */
202 } mcg_lock_status_t;
203
204 /*! @brief MCG clock status */
205 typedef enum _mcg_pll_stat_status
206 {
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;
210
211 /*! @brief MCG iref status */
212 typedef enum _mcg_internal_ref_status
213 {
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;
217
218 /*! @brief MCG clock mode status */
219 typedef enum _mcg_clk_stat_status
220 {
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;
226
227 /*! @brief MCG ircst status */
228 typedef enum _mcg_internal_ref_clk_status
229 {
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;
233
234 /*! @brief MCG auto trim fail status */
235 typedef enum _mcg_auto_trim_machine_fail_status
236 {
237     kMcgAutoTrimMachineNormal,                 /* Automatic Trim Machine completed normally */
238     kMcgAutoTrimMachineFail                    /* Automatic Trim Machine failed */
239 } mcg_auto_trim_machine_fail_status_t;
240
241 /*! @brief MCG loss of clock status */
242 typedef enum _mcg_locs0_status
243 {
244     kMcgLocs0NotOccured,            /* Loss of OSC0 has not occurred */
245     kMcgLocs0Occured                /* Loss of OSC0 has occurred */
246 } mcg_locs0_status_t;
247
248 /*! @brief MCG Automatic Trim Machine Select */
249 typedef enum _mcg_auto_trim_machine_select
250 {
251     kMcgAutoTrimMachineSel32k,   /* 32 kHz Internal Reference Clock selected */
252     kMcgAutoTrimMachineSel4m     /* 4 MHz Internal Reference Clock selected */
253 } mcg_auto_trim_machine_select_t;
254
255 /*! @brief MCG OSC Clock Select */
256 typedef enum _mcg_oscsel_select
257 {
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 */
262 #endif
263 } mcg_oscsel_select_t;
264
265 /*! @brief MCG loss of clock status */
266 typedef enum _mcg_loss_of_clk1_status
267 {
268     kMcgLossOfClk1NotOccured,            /* Loss of RTC has not occurred */
269     kMcgLossOfClk1Occured                /* Loss of RTC has occurred */
270 } mcg_loss_of_clk1_status_t;
271
272 /*! @brief MCG PLLCS select */
273 typedef enum _mcg_pll_clk_select
274 {
275     kMcgPllClkSelPll0,            /* PLL0 output clock is selected */
276     kMcgPllClkSelPll1,            /* PLL1 output clock is selected */
277 } mcg_pll_clk_select_t;
278
279 /*! @brief MCG loss of clock status */
280 typedef enum _mcg_locs2_status
281 {
282     kMcgLocs2NotOccured,            /* Loss of OSC1 has not occurred */
283     kMcgLocs2Occured                /* Loss of OSC1 has occurred */
284 } mcg_locs2_status_t;
285
286 /*******************************************************************************
287  * API
288  ******************************************************************************/
289
290 #if defined(__cplusplus)
291 extern "C" {
292 #endif /* __cplusplus*/
293
294 /*! @name MCG out clock access API*/
295 /*@{*/
296
297 /*!
298  * @brief Gets the current MCG FLL clock.
299  *
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.
303  *
304  * @param baseAddr  Base address for current MCG instance.
305  * @return value Frequency value in Hertz of the mcgpllclk.
306  */
307 uint32_t CLOCK_HAL_GetFllRefClk(uint32_t baseAddr);  
308
309 /*!
310  * @brief Gets the current MCG FLL clock.
311  *
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.
315  *
316  * @param baseAddr  Base address for current MCG instance.
317  * @return value Frequency value in Hertz of the mcgpllclk.
318  */
319 uint32_t CLOCK_HAL_GetFllClk(uint32_t baseAddr);
320
321 /*!
322  * @brief Gets the current MCG PLL/PLL0 clock.
323  *
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.
327  *
328  * @param baseAddr  Base address for current MCG instance.
329  * @return value Frequency value in Hertz of the mcgpllclk or the mcgpll0clk.
330  */
331 uint32_t CLOCK_HAL_GetPll0Clk(uint32_t baseAddr);
332
333 #if FSL_FEATURE_MCG_HAS_PLL1
334 /*!
335  * @brief Gets the current MCG PLL1 clock.
336  *
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.
340  *
341  * @param baseAddr  Base address for current MCG instance.
342  * @return value Frequency value in Hertz of mcgpll1clk.
343  */
344 uint32_t CLOCK_HAL_GetPll1Clk(uint32_t baseAddr);
345 #endif
346
347 /*!
348  * @brief Gets the current MCG IR clock.
349  *
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.
353  *
354  * @param baseAddr  Base address for current MCG instance.
355  * @return value Frequency value in Hertz of the mcgirclk. 
356  */
357 uint32_t CLOCK_HAL_GetInternalRefClk(uint32_t baseAddr);
358
359 /*!
360  * @brief Gets the current MCG out clock.
361  *
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.
365  *
366  * @param baseAddr  Base address for current MCG instance.
367  * @return value Frequency value in Hertz of mcgoutclk.
368  */
369 uint32_t CLOCK_HAL_GetOutClk(uint32_t baseAddr);
370
371 /*@}*/
372
373 /*! @name MCG control register access API*/
374 /*@{*/
375
376 /*!
377  * @brief Sets the Clock Source Select 
378  *
379  * This function  selects the clock source for the MCGOUTCLK.
380  *
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.
386  *                  - 11: Reserved.
387  */
388 static inline void CLOCK_HAL_SetClkSrcMode(uint32_t baseAddr, mcg_clock_select_t select)
389 {
390     BW_MCG_C1_CLKS(baseAddr, select);
391 }
392
393 /*!
394  * @brief Gets the Clock Source Select.
395  *
396  * This function  gets the select of the clock source for the MCGOUTCLK.
397  *
398  * @param baseAddr  Base address for current MCG instance.
399  * @return select    Clock source selection
400  */
401 static inline mcg_clock_select_t CLOCK_HAL_GetClkSrcMode(uint32_t baseAddr)
402 {
403     return (mcg_clock_select_t)BR_MCG_C1_CLKS(baseAddr);
404 }
405
406 /*!
407  * @brief Sets the FLL External Reference Divider.
408  *
409  * This function  sets the FLL External Reference Divider.
410  *
411  * @param baseAddr  Base address for current MCG instance.
412  * @param setting   Divider setting
413  */
414 static inline void CLOCK_HAL_SetFllExternalRefDivider(uint32_t baseAddr,
415                                                                    uint8_t setting)
416 {
417     BW_MCG_C1_FRDIV(baseAddr, setting);
418 }
419
420 /*!
421  * @brief Gets the FLL External Reference Divider.
422  *
423  * This function  gets the FLL External Reference Divider.
424  *
425  * @param baseAddr  Base address for current MCG instance.
426  * @return setting  Divider setting
427  */
428 static inline uint8_t CLOCK_HAL_GetFllExternalRefDivider(uint32_t baseAddr)
429 {
430     return BR_MCG_C1_FRDIV(baseAddr);
431 }
432
433 /*!
434  * @brief Sets the Internal Reference Select. 
435  *
436  * This function  selects the reference clock source for the FLL.
437  *
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
442  */
443 static inline void CLOCK_HAL_SetInternalRefSelMode(uint32_t baseAddr,
444                                                    mcg_internal_ref_clock_source_t select)
445 {
446     BW_MCG_C1_IREFS(baseAddr, select);
447 }
448
449 /*!
450  * @brief Gets the Internal Reference Select  
451  *
452  * This function  gets the reference clock source for the FLL.
453  *
454  * @param baseAddr  Base address for current MCG instance.
455  * @return select  Clock source select
456  */
457 static inline mcg_internal_ref_clock_source_t CLOCK_HAL_GetInternalRefSelMode(uint32_t baseAddr)
458 {
459     return (mcg_internal_ref_clock_source_t)BR_MCG_C1_IREFS(baseAddr);
460 }
461
462 /*!
463  * @brief Sets the CLKS, FRDIV and IREFS at the same time.
464  *
465  * This function  sets the CLKS, FRDIV, and IREFS settings at the same time
466  * in order keep the integrity of the clock switching.
467  *
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
472  */
473 static inline void CLOCK_HAL_SetClksFrdivInternalRefSelect(uint32_t baseAddr,
474                                               mcg_clock_select_t clks,
475                                               uint8_t frdiv,
476                                               mcg_internal_ref_clock_source_t irefs)
477 {
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)));
481 }
482
483 /*!
484  * @brief Sets the Enable Internal Reference Clock setting.
485  *
486  * This function  enables/disables the internal reference clock to use as the MCGIRCLK.
487  *
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
492  */
493 static inline void CLOCK_HAL_SetInternalClkCmd(uint32_t baseAddr, bool enable)
494 {
495     BW_MCG_C1_IRCLKEN(baseAddr, enable ? 1 : 0);
496 }
497
498 /*!
499  * @brief Gets the enable Internal Reference Clock setting.
500  *
501  * This function  gets the reference clock enable setting.
502  *
503  * @param baseAddr  Base address for current MCG instance.
504  * @return enabled  True if the internal reference clock is enabled.
505  */
506 static inline bool CLOCK_HAL_GetInternalClkCmd(uint32_t baseAddr)
507 {
508     return BR_MCG_C1_IRCLKEN(baseAddr);
509 }
510
511 /*!
512  * @brief Sets the Internal Reference Clock Stop Enable setting.
513  *
514  * This function  controls whether or not the internal reference clock remains 
515  * enabled when the MCG enters Stop mode.
516  *
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
522  */
523 static inline void CLOCK_HAL_SetInternalRefStopCmd(uint32_t baseAddr, bool enable)
524 {
525     BW_MCG_C1_IREFSTEN(baseAddr, enable ? 1 : 0);
526 }
527
528 /*!
529  * @brief Gets the Enable Internal Reference Clock setting.
530  *
531  * This function  gets the Internal Reference Clock Stop Enable setting.
532  *
533  * @param baseAddr  Base address for current MCG instance.
534  * @return enabled  True if internal reference clock stop is enabled.
535  */
536 static inline bool CLOCK_HAL_GetInternalRefStopCmd(uint32_t baseAddr)
537 {
538     return BR_MCG_C1_IREFSTEN(baseAddr);
539 }
540
541 /*!
542  * @brief Sets the Loss of Clock Reset Enable setting.
543  *
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.
546  *
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
551  */
552 static inline void CLOCK_HAL_SetLossOfClkReset0Cmd(uint32_t baseAddr, bool enable)
553 {
554     BW_MCG_C2_LOCRE0(baseAddr, enable ? 1 : 0);
555 }
556
557 /*!
558  * @brief Gets the Loss of Clock Reset Enable setting.
559  *
560  * This function  gets the Loss of Clock Reset Enable setting.
561  *
562  * @param baseAddr  Base address for current MCG instance.
563  * @return enabled  True if Loss of Clock Reset is enabled.
564  */
565 static inline bool CLOCK_HAL_GetLossOfClkReset0Cmd(uint32_t baseAddr)
566 {
567     return BR_MCG_C2_LOCRE0(baseAddr);
568 }
569
570 #if FSL_FEATURE_MCG_HAS_FCFTRIM
571 /*!
572  * @brief Sets the Fast Internal Reference Clock Fine Trim setting.
573  *
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.
580  *
581  * @param baseAddr  Base address for current MCG instance.
582  * @params setting Fast Internal Reference Clock Fine Trim setting
583  */
584 static inline void CLOCK_HAL_SetFastInternalRefClkFineTrim(uint32_t baseAddr, uint8_t setting)
585 {
586     BW_MCG_C2_FCFTRIM(baseAddr, setting);
587 }
588
589 /*!
590  * @brief Gets the Fast Internal Reference Clock Fine Trim setting.
591  *
592  * This function  gets the Fast Internal Reference Clock Fine Trim setting.
593  *
594  * @param baseAddr  Base address for current MCG instance.
595  * @return setting  Fast Internal Reference Clock Fine Trim setting
596  */
597 static inline uint8_t CLOCK_HAL_GetFastInternalRefClkFineTrim(uint32_t baseAddr)
598 {
599     return BR_MCG_C2_FCFTRIM(baseAddr);
600 }
601 #endif /* FSL_FEATURE_MCG_HAS_FCFTRIM */
602
603 /*!
604  * @brief Sets the Frequency Range Select.
605  *
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.
609  *
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
615  */
616 static inline void CLOCK_HAL_SetRange0Mode(uint32_t baseAddr, mcg_freq_range_select_t select)
617 {
618     BW_MCG_C2_RANGE(baseAddr, select);
619 }
620
621 /*!
622  * @brief Gets the Frequency Range Select.
623  *
624  * This function  gets the Frequency Range Select.
625  *
626  * @param baseAddr  Base address for current MCG instance.
627  * @return select  Frequency Range Select
628  */
629 static inline mcg_freq_range_select_t CLOCK_HAL_GetRange0Mode(uint32_t baseAddr)
630 {
631     return (mcg_freq_range_select_t)BR_MCG_C2_RANGE(baseAddr);
632 }
633
634 /*!
635  * @brief Sets the High Gain Oscillator Select.
636  *
637  * This function  controls the crystal oscillator mode of operation. See the
638  * Oscillator (OSC) chapter for more details.
639  *
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
644  */
645 static inline void CLOCK_HAL_SetHighGainOsc0Mode(uint32_t baseAddr, mcg_high_gain_osc_select_t select)
646 {
647     BW_MCG_C2_HGO(baseAddr, select);
648 }
649
650 /*!
651  * @brief Gets the High Gain Oscillator Select.
652  *
653  * This function  gets the High Gain Oscillator Select.
654  *
655  * @param baseAddr  Base address for current MCG instance.
656  * @return select  High Gain Oscillator Select
657  */
658 static inline mcg_high_gain_osc_select_t CLOCK_HAL_GetHighGainOsc0Mode(uint32_t baseAddr)
659 {
660     return (mcg_high_gain_osc_select_t)BR_MCG_C2_HGO(baseAddr);
661 }
662
663 /*!
664  * @brief Sets the External Reference Select.
665  *
666  * This function  selects the source for the external reference clock. 
667  * See the Oscillator (OSC) chapter for more details.
668  *
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
673  */
674 static inline void CLOCK_HAL_SetExternalRefSel0Mode(uint32_t baseAddr, mcg_external_ref_clock_select_t select)
675 {
676     BW_MCG_C2_EREFS(baseAddr, select);
677 }
678
679 /*!
680  * @brief Gets the External Reference Select.
681  *
682  * This function  gets the External Reference Select.
683  *
684  * @param baseAddr  Base address for current MCG instance.
685  * @return select  External Reference Select
686  */
687 static inline mcg_external_ref_clock_select_t CLOCK_HAL_GetExternalRefSel0Mode(uint32_t baseAddr)
688 {
689     return (mcg_external_ref_clock_select_t)BR_MCG_C2_EREFS(baseAddr);
690 }
691
692 /*!
693  * @brief Sets the Low Power Select.
694  *
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..
699  *
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)
704  */
705 static inline void CLOCK_HAL_SetLowPowerMode(uint32_t baseAddr, mcg_low_power_select_t select)
706 {
707     BW_MCG_C2_LP(baseAddr, select);
708 }
709
710 /*!
711  * @brief Gets the Low Power Select.
712  *
713  * This function  gets the Low Power Select.
714  *
715  * @param baseAddr  Base address for current MCG instance.
716  * @return select  Low Power Select
717  */
718 static inline mcg_low_power_select_t CLOCK_HAL_GetLowPowerMode(uint32_t baseAddr)
719 {
720     return (mcg_low_power_select_t)BR_MCG_C2_LP(baseAddr);
721 }
722
723 /*!
724  * @brief Sets the Internal Reference Clock Select.
725  *
726  * This function  selects between the fast or slow internal reference clock source.
727  *
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.
732  */
733 static inline void CLOCK_HAL_SetInternalRefClkSelMode(uint32_t baseAddr,
734                                                       mcg_internal_ref_clock_select_t select)
735 {
736     BW_MCG_C2_IRCS(baseAddr, select);
737 }
738
739 /*!
740  * @brief Gets the Internal Reference Clock Select.
741  *
742  * This function  gets the Internal Reference Clock Select.
743  *
744  * @param baseAddr  Base address for current MCG instance.
745  * @return select  Internal Reference Clock Select
746  */
747 static inline mcg_internal_ref_clock_select_t CLOCK_HAL_GetInternalRefClkSelMode(uint32_t baseAddr)
748 {
749     return (mcg_internal_ref_clock_select_t)BR_MCG_C2_IRCS(baseAddr);
750 }
751
752 /*!
753  * @brief Sets the Slow Internal Reference Clock Trim Setting.
754  *
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 
764  * this register.
765  *
766  * @param baseAddr  Base address for current MCG instance.
767  * @params setting  Slow Internal Reference Clock Trim Setting
768  */
769 static inline void CLOCK_HAL_SetSlowInternalRefClkTrim(uint32_t baseAddr, uint8_t setting)
770 {
771     BW_MCG_C3_SCTRIM(baseAddr, setting);
772 }
773
774 /*!
775  * @brief Gets the Slow Internal Reference Clock Trim Setting.
776  *
777  * This function  gets the Slow Internal Reference Clock Trim Setting.
778  *
779  * @param baseAddr  Base address for current MCG instance.
780  * @return setting  Slow Internal Reference Clock Trim Setting
781  */
782 static inline uint8_t CLOCK_HAL_GetSlowInternalRefClkTrim(uint32_t baseAddr)
783 {
784     return BR_MCG_C3_SCTRIM(baseAddr);
785 }
786
787 /*!
788  * @brief Sets the DCO Maximum Frequency with 32.768 kHz Reference.
789  *
790  * This function  controls whether or not the DCO frequency range 
791  * is narrowed to its maximum frequency with a 32.768 kHz reference.
792  *
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.
797  */
798 static inline void CLOCK_HAL_SetDmx32(uint32_t baseAddr, mcg_dmx32_select_t setting)
799 {
800     BW_MCG_C4_DMX32(baseAddr, setting);
801 }
802
803 /*!
804  * @brief Gets the DCO Maximum Frequency with the 32.768 kHz Reference Setting.
805  *
806  * This function  gets the DCO Maximum Frequency with 32.768 kHz Reference Setting.
807  *
808  * @param baseAddr  Base address for current MCG instance.
809  * @return setting  DCO Maximum Frequency with 32.768 kHz Reference Setting
810  */
811 static inline mcg_dmx32_select_t CLOCK_HAL_GetDmx32(uint32_t baseAddr)
812 {
813     return (mcg_dmx32_select_t)BR_MCG_C4_DMX32(baseAddr);
814 }
815
816 /*!
817  * @brief Sets the DCO Range Select.
818  *
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
824  *  for more details.
825  *
826  * @param baseAddr  Base address for current MCG instance.
827  * @params setting  DCO Range Select Setting
828  *                  - 00: Low range (reset default).
829  *                  - 01: Mid range.
830  *                  - 10: Mid-high range.
831  *                  - 11: High range.
832  */
833 static inline void CLOCK_HAL_SetDigitalControlledOscRangeMode(uint32_t baseAddr, 
834                                                               mcg_digital_controlled_osc_range_select_t setting)
835 {
836     BW_MCG_C4_DRST_DRS(baseAddr, setting);
837 }
838
839 /*!
840  * @brief Gets the DCO Range Select Setting.
841  *
842  * This function  gets the DCO Range Select Setting.
843  *
844  * @param baseAddr  Base address for current MCG instance.
845  * @return setting  DCO Range Select Setting
846  */
847 static inline mcg_digital_controlled_osc_range_select_t CLOCK_HAL_GetDigitalControlledOscRangeMode(uint32_t baseAddr)
848 {
849     return (mcg_digital_controlled_osc_range_select_t)BR_MCG_C4_DRST_DRS(baseAddr);
850 }
851
852 /*!
853  * @brief Sets the Fast Internal Reference Clock Trim Setting.
854  *
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
862  * to this register.
863  *
864  * @param baseAddr  Base address for current MCG instance.
865  * @params setting  Fast Internal Reference Clock Trim Setting.
866  */
867 static inline void CLOCK_HAL_SetFastInternalRefClkTrim(uint32_t baseAddr, uint8_t setting)
868 {
869     BW_MCG_C4_FCTRIM(baseAddr, setting);
870 }
871
872 /*!
873  * @brief Gets the Fast Internal Reference Clock Trim Setting.
874  *
875  * This function  gets the Fast Internal Reference Clock Trim Setting.
876  *
877  * @param baseAddr  Base address for current MCG instance.
878  * @return setting  Fast Internal Reference Clock Trim Setting
879  */
880 static inline uint8_t CLOCK_HAL_GetFastInternalRefClkTrim(uint32_t baseAddr)
881 {
882     return BR_MCG_C4_FCTRIM(baseAddr);
883 }
884
885 /*!
886  * @brief Sets the Slow Internal Reference Clock Fine Trim Setting.
887  *
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.
894  *
895  * @param baseAddr  Base address for current MCG instance.
896  * @params setting  Slow Internal Reference Clock Fine Trim Setting
897  */
898 static inline void CLOCK_HAL_SetSlowInternalRefClkFineTrim(uint32_t baseAddr, uint8_t setting)
899 {
900     BW_MCG_C4_SCFTRIM(baseAddr, setting);
901 }
902
903 /*!
904  * @brief Gets the Slow Internal Reference Clock Fine Trim Setting.
905  *
906  * This function  gets the Slow Internal Reference Clock Fine Trim Setting.
907  *
908  * @param baseAddr  Base address for current MCG instance.
909  * @return setting  Slow Internal Reference Clock Fine Trim Setting
910  */
911 static inline uint8_t CLOCK_HAL_GetSlowInternalRefClkFineTrim(uint32_t baseAddr)
912 {
913     return BR_MCG_C4_SCFTRIM(baseAddr);
914 }
915
916 #if FSL_FEATURE_MCG_USE_PLLREFSEL
917 /*!
918  * @brief Sets the PLL0 External Reference Select Setting.
919  *
920  * This function  selects the PLL0 external reference clock source.
921  *
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
926  */
927 static inline void CLOCK_HAL_SetPllRefSel0Mode(uint32_t baseAddr,
928                                                mcg_pll_external_ref_clk_select_t setting)
929 {
930     BW_MCG_C5_PLLREFSEL0(baseAddr, setting);
931 }
932
933 /*!
934  * @brief Gets the PLL0 External Reference Select Setting.
935  *
936  * This function  gets the PLL0 External Reference Select Setting.
937  *
938  * @param baseAddr  Base address for current MCG instance.
939  * @return setting  PLL0 External Reference Select Setting
940  */
941 static inline mcg_pll_external_ref_clk_select_t CLOCK_HAL_GetPllRefSel0Mode(uint32_t baseAddr)
942 {
943     return (mcg_pll_external_ref_clk_select_t)BR_MCG_C5_PLLREFSEL0(baseAddr);
944 }
945 #endif /* FSL_FEATURE_MCG_USE_PLLREFSEL */
946
947 #if FSL_FEATURE_MCG_HAS_EXTERNAL_CLOCK_MONITOR
948
949 /*!
950  * @brief Sets the Clock Monitor Enable Setting.
951  *
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.
962  *
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.
967  */
968 static inline void CLOCK_HAL_SetClkMonitor0Cmd(uint32_t baseAddr, bool enable)
969 {
970 #if FSL_FEATURE_MCG_HAS_PLL  
971     BW_MCG_C6_CME0(baseAddr, enable ? 1 : 0);
972 #else
973     BW_MCG_C6_CME(baseAddr, enable ? 1 : 0);    
974 #endif
975 }
976
977 /*!
978  * @brief Gets the Clock Monitor Enable Setting.
979  *
980  * This function  gets the Clock Monitor Enable Setting.
981  *
982  * @param baseAddr  Base address for current MCG instance.
983  * @return enabled  True if Clock Monitor is enabled
984  */
985 static inline bool CLOCK_HAL_GetClkMonitor0Cmd(uint32_t baseAddr)
986 {
987 #if FSL_FEATURE_MCG_HAS_PLL   
988     return BR_MCG_C6_CME0(baseAddr);
989 #else
990     return BR_MCG_C6_CME(baseAddr);    
991 #endif    
992 }
993
994 #endif
995
996 #if FSL_FEATURE_MCG_HAS_PLL
997 /*!
998  * @brief Sets the PLL Clock Enable Setting.
999  *
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.
1007  *
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
1012  */
1013 static inline void CLOCK_HAL_SetPllClk0Cmd(uint32_t baseAddr, bool enable)
1014 {
1015     BW_MCG_C5_PLLCLKEN0(baseAddr, enable ? 1 : 0);
1016 }
1017
1018 /*!
1019  * @brief Gets the PLL Clock Enable Setting.
1020  *
1021  * This function  gets the PLL Clock Enable Setting.
1022  *
1023  * @param baseAddr  Base address for current MCG instance.
1024  * @return enabled True if PLL0 PLL Clock is enabled.
1025  */
1026 static inline bool CLOCK_HAL_GetPllClk0Cmd(uint32_t baseAddr)
1027 {
1028     return BR_MCG_C5_PLLCLKEN0(baseAddr);
1029 }
1030
1031 /*!
1032  * @brief Sets the PLL0 Stop Enable Setting.
1033  *
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.
1038  *
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
1042  *                       Normal Stop mode.
1043  *                  - false: MCGPLL0CLK and MCGPLL0CLK2X are disabled in any of the 
1044  *                       Stop modes.
1045  */
1046 static inline void CLOCK_HAL_SetPllStat0Cmd(uint32_t baseAddr, bool enable)
1047 {
1048     BW_MCG_C5_PLLSTEN0(baseAddr, enable ? 1 : 0);
1049 }
1050
1051 /*!
1052  * @brief Gets the PLL0 Stop Enable Setting.
1053  *
1054  * This function  gets the PLL0 Stop Enable Setting.
1055  *
1056  * @param baseAddr  Base address for current MCG instance.
1057  * @return enabled  True if the PLL0 Stop is enabled.
1058  */
1059 static inline bool CLOCK_HAL_GetPllStat0Cmd(uint32_t baseAddr)
1060 {
1061     return BR_MCG_C5_PLLSTEN0(baseAddr);
1062 }
1063
1064 /*!
1065  * @brief Sets the PLL0 External Reference Divider Setting.
1066  *
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.
1071  *
1072  * @param baseAddr  Base address for current MCG instance.
1073  * @params setting  PLL0 External Reference Divider Setting
1074  */
1075 static inline void CLOCK_HAL_SetPllExternalRefDivider0(uint32_t baseAddr, uint8_t setting)
1076 {
1077     BW_MCG_C5_PRDIV0(baseAddr, setting);
1078 }
1079
1080 /*!
1081  * @brief Gets the PLL0 External Reference Divider Setting.
1082  *
1083  * This function  gets the PLL0 External Reference Divider Setting.
1084  *
1085  * @param baseAddr  Base address for current MCG instance.
1086  * @return setting  PLL0 External Reference Divider Setting
1087  */
1088 static inline uint8_t CLOCK_HAL_GetPllExternalRefDivider0(uint32_t baseAddr)
1089 {
1090     return BR_MCG_C5_PRDIV0(baseAddr);
1091 }
1092
1093 /*!
1094  * @brief Sets the Loss of Lock Interrupt Enable Setting.
1095  *
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.
1098  *
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.
1103  */
1104 static inline void CLOCK_HAL_SetLossOfClkInt0Cmd(uint32_t baseAddr, bool enable)
1105 {
1106     BW_MCG_C6_LOLIE0(baseAddr, enable ? 1 : 0);
1107 }
1108
1109 /*!
1110  * @brief Gets the Loss of the Lock Interrupt Enable Setting.
1111  *
1112  * This function  gets the Loss of the Lock Interrupt Enable Setting.
1113  *
1114  * @param baseAddr  Base address for current MCG instance.
1115  * @return enabled  True if the Loss of Lock Interrupt is enabled.
1116  */
1117 static inline bool CLOCK_HAL_GetLossOfClkInt0Cmd(uint32_t baseAddr)
1118 {
1119     return BR_MCG_C6_LOLIE0(baseAddr);
1120 }
1121
1122 /*!
1123  * @brief Sets the PLL Select Setting.
1124  *
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.
1129  *
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).
1137  */
1138 static inline void CLOCK_HAL_SetPllSelMode(uint32_t baseAddr, mcg_pll_select_t setting)
1139 {
1140     BW_MCG_C6_PLLS(baseAddr, setting);
1141 }
1142
1143 /*!
1144  * @brief Gets the PLL Select Setting.
1145  *
1146  * This function  gets the PLL Select Setting.
1147  *
1148  * @param baseAddr  Base address for current MCG instance.
1149  * @return setting  PLL Select Setting
1150  */
1151 static inline mcg_pll_select_t CLOCK_HAL_GetPllSelMode(uint32_t baseAddr)
1152 {
1153     return (mcg_pll_select_t)BR_MCG_C6_PLLS(baseAddr);
1154 }
1155
1156 /*!
1157  * @brief Sets the VCO0 Divider Setting.
1158  *
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.
1163  *
1164  * @param baseAddr  Base address for current MCG instance.
1165  * @params setting  VCO0 Divider Setting
1166  */
1167 static inline void CLOCK_HAL_SetVoltCtrlOscDivider0(uint32_t baseAddr, uint8_t setting)
1168 {
1169     BW_MCG_C6_VDIV0(baseAddr, setting);
1170 }
1171
1172 /*!
1173  * @brief Gets the VCO0 Divider Setting.
1174  *
1175  * This function  gets the VCO0 Divider Setting.
1176  *
1177  * @param baseAddr  Base address for current MCG instance.
1178  * @return setting  VCO0 Divider Setting
1179  */
1180 static inline uint8_t CLOCK_HAL_GetVoltCtrlOscDivider0(uint32_t baseAddr)
1181 {
1182     return BR_MCG_C6_VDIV0(baseAddr);
1183 }
1184
1185 /*!
1186  * @brief Gets the Loss of the Lock Status.
1187  *
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.
1194  *
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
1199  */
1200 static inline mcg_loss_of_lock_status_t CLOCK_HAL_GetLossOfLock0Mode(uint32_t baseAddr)
1201 {
1202     return (mcg_loss_of_lock_status_t)BR_MCG_S_LOLS0(baseAddr);
1203 }
1204
1205 /*!
1206  * @brief Gets the Lock Status.
1207  *
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.
1221  *
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
1226  */
1227 static inline mcg_lock_status_t CLOCK_HAL_GetLock0Mode(uint32_t baseAddr)
1228 {
1229     return (mcg_lock_status_t)BR_MCG_S_LOCK0(baseAddr);
1230 }
1231
1232 /*!
1233  * @brief Gets the PLL Select Status.
1234  *
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.
1238  *
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.
1243  */
1244 static inline mcg_pll_stat_status_t CLOCK_HAL_GetPllStatMode(uint32_t baseAddr)
1245 {
1246     return (mcg_pll_stat_status_t)BR_MCG_S_PLLST(baseAddr);
1247 }
1248 #endif
1249
1250 /*!
1251  * @brief Gets the Internal Reference Status.
1252  *
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 
1256  * domains.
1257  *
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.
1262  */
1263 static inline mcg_internal_ref_status_t CLOCK_HAL_GetInternalRefStatMode(uint32_t baseAddr)
1264 {
1265     return (mcg_internal_ref_status_t)BR_MCG_S_IREFST(baseAddr);
1266 }
1267
1268 /*!
1269  * @brief Gets the Clock Mode Status.
1270  *
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.
1274  *
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.
1281  */
1282 static inline mcg_clk_stat_status_t CLOCK_HAL_GetClkStatMode(uint32_t baseAddr)
1283 {
1284     return (mcg_clk_stat_status_t)BR_MCG_S_CLKST(baseAddr);
1285 }
1286
1287 /*!
1288  * @brief Gets the OSC Initialization Status.
1289  *
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.
1294  *
1295  * @param baseAddr  Base address for current MCG instance.
1296  * @return status  OSC Initialization Status
1297  */
1298 static inline uint8_t CLOCK_HAL_GetOscInit0(uint32_t baseAddr)
1299 {
1300     return BR_MCG_S_OSCINIT0(baseAddr);
1301 }
1302
1303 /*!
1304  * @brief Gets the Internal Reference Clock Status.
1305  *
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.
1312  *
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).
1317  */
1318 static inline mcg_internal_ref_clk_status_t CLOCK_HAL_GetInternalRefClkStatMode(uint32_t baseAddr)
1319 {
1320     return (mcg_internal_ref_clk_status_t)BR_MCG_S_IRCST(baseAddr);
1321 }
1322
1323 /*!
1324  * @brief Gets the Automatic Trim machine Fail Flag.
1325  *
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.
1330  *
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.
1335  */
1336 static inline mcg_auto_trim_machine_fail_status_t CLOCK_HAL_GetAutoTrimMachineFailMode(uint32_t baseAddr)
1337 {
1338     return (mcg_auto_trim_machine_fail_status_t)BR_MCG_SC_ATMF(baseAddr);
1339 }
1340
1341 /*!
1342  * @brief Sets the Automatic Trim machine Fail Flag.
1343  *
1344  * This function  clears the ATMF flag.
1345  *
1346  * @param baseAddr  Base address for current MCG instance.
1347  */
1348 static inline void CLOCK_HAL_SetAutoTrimMachineFail(uint32_t baseAddr)
1349 {
1350     BW_MCG_SC_ATMF(baseAddr, 1);
1351 }
1352
1353 /*!
1354  * @brief Gets the OSC0 Loss of Clock Status.
1355  *
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.
1359  *
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.
1364  */
1365 static inline mcg_locs0_status_t CLOCK_HAL_GetLocs0Mode(uint32_t baseAddr)
1366 {
1367     return (mcg_locs0_status_t)BR_MCG_SC_LOCS0(baseAddr);
1368 }
1369
1370 /*!
1371  * @brief Sets the Automatic Trim Machine Enable Setting.
1372  *
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.
1379  *
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
1384  */
1385 static inline void CLOCK_HAL_SetAutoTrimMachineCmd(uint32_t baseAddr, bool enable)
1386 {
1387     BW_MCG_SC_ATME(baseAddr, enable ? 1 : 0);
1388 }
1389
1390 /*!
1391  * @brief Gets the Automatic Trim Machine Enable Setting.
1392  *
1393  * This function  gets the Automatic Trim Machine Enable Setting.
1394  *
1395  * @param baseAddr  Base address for current MCG instance.
1396  * @return enabled  True if Automatic Trim Machine is enabled
1397  */
1398 static inline bool CLOCK_HAL_GetAutoTrimMachineCmd(uint32_t baseAddr)
1399 {
1400     return BR_MCG_SC_ATME(baseAddr);
1401 }
1402
1403 /*!
1404  * @brief Sets the Automatic Trim Machine Select Setting.
1405  *
1406  * This function  selects the IRCS clock for Auto Trim Test.
1407  *
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
1412  */
1413 static inline void CLOCK_HAL_SetAutoTrimMachineSelMode(uint32_t baseAddr,
1414                                                        mcg_auto_trim_machine_select_t setting)
1415 {
1416     BW_MCG_SC_ATMS(baseAddr, setting);
1417 }
1418
1419 /*!
1420  * @brief Gets the Automatic Trim Machine Select Setting.
1421  *
1422  * This function  gets the Automatic Trim Machine Select Setting.
1423  *
1424  * @param baseAddr  Base address for current MCG instance.
1425  * @return setting  Automatic Trim Machine Select Setting
1426  */
1427 static inline mcg_auto_trim_machine_select_t CLOCK_HAL_GetAutoTrimMachineSelMode(uint32_t baseAddr)
1428 {
1429     return (mcg_auto_trim_machine_select_t)BR_MCG_SC_ATMS(baseAddr);
1430 }
1431
1432 /*!
1433  * @brief Sets the FLL Filter Preserve Enable Setting.
1434  *
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 
1440  * values  change.)
1441  *
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 
1447  *                       clock mode
1448  */
1449 static inline void CLOCK_HAL_SetFllFilterPreserveCmd(uint32_t baseAddr, bool enable)
1450 {
1451     BW_MCG_SC_FLTPRSRV(baseAddr, enable ? 1 : 0);
1452 }
1453
1454 /*!
1455  * @brief Gets the FLL Filter Preserve Enable Setting.
1456  *
1457  * This function  gets the FLL Filter Preserve Enable Setting.
1458  *
1459  * @param baseAddr  Base address for current MCG instance.
1460  * @return enabled  True if FLL Filter Preserve is enabled.
1461  */
1462 static inline bool CLOCK_HAL_GetFllFilterPreserveCmd(uint32_t baseAddr)
1463 {
1464     return BR_MCG_SC_FLTPRSRV(baseAddr);
1465 }
1466
1467 /*!
1468  * @brief Sets the Fast Clock Internal Reference Divider Setting.
1469  *
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).
1473  *
1474  * @param baseAddr  Base address for current MCG instance.
1475  * @params setting  Fast Clock Internal Reference Divider Setting
1476  */
1477 static inline void CLOCK_HAL_SetFastClkInternalRefDivider(uint32_t baseAddr, uint8_t setting)
1478 {
1479     BW_MCG_SC_FCRDIV(baseAddr, setting);
1480 }
1481
1482 /*!
1483  * @brief Gets the Fast Clock Internal Reference Divider Setting.
1484  *
1485  * This function  gets the Fast Clock Internal Reference Divider Setting.
1486  *
1487  * @param baseAddr  Base address for current MCG instance.
1488  * @return setting  Fast Clock Internal Reference Divider Setting
1489  */
1490 static inline uint8_t CLOCK_HAL_GetFastClkInternalRefDivider(uint32_t baseAddr)
1491 {
1492     return BR_MCG_SC_FCRDIV(baseAddr);
1493 }
1494
1495 /*!
1496  * @brief Sets the ATM Compare Value High Setting.
1497  *
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
1500  * SAR conversion.
1501  *
1502  * @param baseAddr  Base address for current MCG instance.
1503  * @params setting  ATM Compare Value High Setting
1504  */
1505 static inline void CLOCK_HAL_SetAutoTrimMachineCompValHigh(uint32_t baseAddr, uint8_t setting)
1506 {
1507     BW_MCG_ATCVH_ATCVH(baseAddr, setting);
1508 }
1509
1510 /*!
1511  * @brief Gets the ATM Compare Value High Setting.
1512  *
1513  * This function  gets the ATM Compare Value High Setting.
1514  *
1515  * @param baseAddr  Base address for current MCG instance.
1516  * @return setting  ATM Compare Value High Setting
1517  */
1518 static inline uint8_t CLOCK_HAL_GetAutoTrimMachineCompValHigh(uint32_t baseAddr)
1519 {
1520     return BR_MCG_ATCVH_ATCVH(baseAddr);
1521 }
1522
1523 /*!
1524  * @brief Sets the ATM Compare Value Low Setting.
1525  *
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
1528  * SAR conversion.
1529  *
1530  * @param baseAddr  Base address for current MCG instance.
1531  * @params setting  ATM Compare Value Low Setting
1532  */
1533 static inline void CLOCK_HAL_SetAutoTrimMachineCompValLow(uint32_t baseAddr, uint8_t setting)
1534 {
1535     BW_MCG_ATCVL_ATCVL(baseAddr, setting);
1536 }
1537
1538 /*!
1539  * @brief Gets the ATM Compare Value Low Setting.
1540  *
1541  * This function  gets the ATM Compare Value Low Setting.
1542  *
1543  * @param baseAddr  Base address for current MCG instance.
1544  * @return setting  ATM Compare Value Low Setting
1545  */
1546 static inline uint8_t CLOCK_HAL_GetAutoTrimMachineCompValLow(uint32_t baseAddr)
1547 {
1548     return BR_MCG_ATCVL_ATCVL(baseAddr);
1549 }
1550
1551 #if FSL_FEATURE_MCG_USE_OSCSEL
1552 /*!
1553  * @brief Sets the MCG OSC Clock Select Setting.
1554  *
1555  * This function  selects the MCG FLL external reference clock.
1556  *
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.
1561  */
1562 static inline void CLOCK_HAL_SetOscselMode(uint32_t baseAddr, mcg_oscsel_select_t setting)
1563 {
1564     BW_MCG_C7_OSCSEL(baseAddr, setting);
1565 }
1566
1567 /*!
1568  * @brief Gets the MCG OSC Clock Select Setting.
1569  *
1570  * This function  gets the MCG OSC Clock Select Setting.
1571  *
1572  * @param baseAddr  Base address for current MCG instance.
1573  * @return setting  MCG OSC Clock Select Setting
1574  */
1575 static inline mcg_oscsel_select_t CLOCK_HAL_GetOscselMode(uint32_t baseAddr)
1576 {
1577     return (mcg_oscsel_select_t)BR_MCG_C7_OSCSEL(baseAddr);
1578 }
1579 #endif /* FSL_FEATURE_MCG_USE_OSCSEL */
1580
1581 #if FSL_FEATURE_MCG_HAS_LOLRE
1582 /*!
1583  * @brief Sets the PLL Loss of Lock Reset Enable Setting.
1584  *
1585  * This function  determines whether an interrupt or a reset request is made
1586  * following a PLL loss of lock.
1587  *
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.
1594  */
1595 static inline void CLOCK_HAL_SetLossOfClkResetCmd(uint32_t baseAddr, bool enable)
1596 {
1597     BW_MCG_C8_LOLRE(baseAddr, enable ? 1 : 0);
1598 }
1599
1600 /*!
1601  * @brief Gets the PLL Loss of Lock Reset Enable Setting.
1602  *
1603  * This function  gets the PLL Loss of Lock Reset Enable Setting.
1604  *
1605  * @param baseAddr  Base address for current MCG instance.
1606  * @return enabled  True if the PLL Loss of Lock Reset is enabled.
1607  */
1608 static inline bool CLOCK_HAL_GetLossOfClkResetCmd(uint32_t baseAddr)
1609 {
1610     return BR_MCG_C8_LOLRE(baseAddr);
1611 }
1612 #endif /* FSL_FEATURE_MCG_HAS_LOLRE */
1613
1614
1615 #if FSL_FEATURE_MCG_HAS_RTC_32K
1616 /*!
1617  * @brief Sets the Loss of Clock Reset Enable Setting.
1618  *
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 
1621  * is set.
1622  *
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 
1627  *                       reference clock.
1628  */
1629 static inline void CLOCK_HAL_SetLossClkReset1Cmd(uint32_t baseAddr, bool enable)
1630 {
1631     BW_MCG_C8_LOCRE1(baseAddr, enable ? 1 : 0);
1632 }
1633
1634 /*!
1635  * @brief Gets the Loss of Clock Reset Enable Setting.
1636  *
1637  * This function  gets the Loss of Clock Reset Enable Setting.
1638  *
1639  * @param baseAddr  Base address for current MCG instance.
1640  * @return enabled  True if Loss of Clock Reset is enabled.
1641  */
1642 static inline bool CLOCK_HAL_GetLossClkReset1Cmd(uint32_t baseAddr)
1643 {
1644     return BR_MCG_C8_LOCRE1(baseAddr);
1645 }
1646
1647 /*!
1648  * @brief Sets the Clock Monitor Enable1 Setting.
1649  *
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.
1658  *
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.
1663  */
1664 static inline void CLOCK_HAL_SetClkMonitor1Cmd(uint32_t baseAddr, bool enable)
1665 {
1666     BW_MCG_C8_CME1(baseAddr, enable ? 1 : 0);
1667 }
1668
1669 /*!
1670  * @brief Gets the Clock Monitor Enable1 Setting.
1671  *
1672  * This function  gets the Clock Monitor Enable1 Setting.
1673  *
1674  * @param baseAddr  Base address for current MCG instance.
1675  * @return enabled True if Clock Monitor Enable1 is enabled
1676  */
1677 static inline bool CLOCK_HAL_GetClkMonitor1Cmd(uint32_t baseAddr)
1678 {
1679     return BR_MCG_C8_CME1(baseAddr);
1680 }
1681
1682 /*!
1683  * @brief Gets the RTC Loss of Clock Status.
1684  *
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.
1687  *
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
1692  */
1693 static inline mcg_loss_of_clk1_status_t CLOCK_HAL_GetLossOfClk1Mode(uint32_t baseAddr)
1694 {
1695     return (mcg_loss_of_clk1_status_t)BR_MCG_C8_LOCS1(baseAddr);
1696 }
1697 #endif /* FSL_FEATURE_MCG_HAS_RTC_32K */
1698
1699 #if FSL_FEATURE_MCG_USE_PLLREFSEL
1700 /*!
1701  * @brief Sets the OSC1 Loss of Clock Reset Enable Setting.
1702  *
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 
1705  * LOCS2 is set.
1706  *
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 
1710  *                       reference clock..
1711  *                  - false: Interrupt request is generated on a loss of OSC1 external 
1712  *                       reference clock.
1713  */
1714 static inline void CLOCK_HAL_SetLossClkReset2Cmd(uint32_t baseAddr, bool enable)
1715 {
1716     BW_MCG_C10_LOCRE2(baseAddr, enable ? 1 : 0);
1717 }
1718
1719 /*!
1720  * @brief Gets the OSC1 Loss of the Clock Reset Enable Setting.
1721  *
1722  * This function  gets the OSC1 Loss of Clock Reset Enable Setting.
1723  *
1724  * @param baseAddr  Base address for current MCG instance.
1725  * @return enabled  True if OSC1 Loss of Clock Reset is enabled.
1726  */
1727 static inline bool CLOCK_HAL_GetLossClkReset2Cmd(uint32_t baseAddr)
1728 {
1729     return BR_MCG_C10_LOCRE2(baseAddr);
1730 }
1731
1732 /*!
1733  * @brief Sets the Frequency Range1 Select Setting.
1734  *
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.
1738  *
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.
1744  */
1745 static inline void CLOCK_HAL_SetRange1Mode(uint32_t baseAddr, mcg_freq_range_select_t setting)
1746 {
1747     BW_MCG_C10_RANGE1(baseAddr, setting);
1748 }
1749
1750 /*!
1751  * @brief Gets the Frequency Range1 Select Setting.
1752  *
1753  * This function  gets the Frequency Range1 Select Setting.
1754  *
1755  * @param baseAddr  Base address for current MCG instance.
1756  * @return setting  Frequency Range1 Select Setting
1757  */
1758 static inline mcg_freq_range_select_t CLOCK_HAL_GetRange1Mode(uint32_t baseAddr)
1759 {
1760     return (mcg_freq_range_select_t)BR_MCG_C10_RANGE1(baseAddr);
1761 }
1762
1763 /*!
1764  * @brief Sets the High Gain Oscillator1 Select Setting.
1765  *
1766  * This function  controls the OSC1 crystal oscillator mode of operation.
1767  * See the Oscillator chapter for more details.
1768  *
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.
1773  */
1774 static inline void CLOCK_HAL_SetHighGainOsc1Mode(uint32_t baseAddr,
1775                                                  mcg_high_gain_osc_select_t setting)
1776 {
1777     BW_MCG_C10_HGO1(baseAddr, setting);
1778 }
1779
1780 /*!
1781  * @brief Gets the High Gain Oscillator1 Select Setting.
1782  *
1783  * This function  gets the High Gain Oscillator1 Select Setting.
1784  *
1785  * @param baseAddr  Base address for current MCG instance.
1786  * @return setting  High Gain Oscillator1 Select Setting
1787  */
1788 static inline mcg_high_gain_osc_select_t CLOCK_HAL_GetHighGainOsc1Mode(uint32_t baseAddr)
1789 {
1790     return (mcg_high_gain_osc_select_t)BR_MCG_C10_HGO1(baseAddr);
1791 }
1792
1793 /*!
1794  * @brief Sets the External Reference Select Setting.
1795  *
1796  * This function  selects the source for the OSC1 external reference clock. 
1797  * See the Oscillator chapter for more details.
1798  *
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.
1803  */
1804 static inline void CLOCK_HAL_SetExternalRefSel1Mode(uint32_t baseAddr,
1805                                                     mcg_external_ref_clock_select_t setting)
1806 {
1807     BW_MCG_C10_EREFS1(baseAddr, setting);
1808 }
1809
1810 /*!
1811  * @brief Gets the External Reference Select Setting.
1812  *
1813  * This function  gets the External Reference Select Setting.
1814  *
1815  * @param baseAddr  Base address for current MCG instance.
1816  * @return setting  External Reference Select Setting
1817  */
1818 static inline mcg_external_ref_clock_select_t CLOCK_HAL_GetExternalRefSel1Mode(uint32_t baseAddr)
1819 {
1820     return (mcg_external_ref_clock_select_t)BR_MCG_C10_EREFS1(baseAddr);
1821 }
1822
1823 /*!
1824  * @brief Sets the PLL1 External Reference Select Setting.
1825  *
1826  * This function  selects the PLL1 external reference clock source.
1827  *
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.
1832  */
1833 static inline void CLOCK_HAL_SetPllRefSel1Mode(uint32_t baseAddr,
1834                                                mcg_pll_external_ref_clk_select_t setting)
1835 {
1836     BW_MCG_C11_PLLREFSEL1(baseAddr, setting);
1837 }
1838
1839 /*!
1840  * @brief Gets the PLL1 External Reference Select Setting.
1841  *
1842  * This function  gets the PLL1 External Reference Select Setting.
1843  *
1844  * @param baseAddr  Base address for current MCG instance.
1845  * @return setting  PLL1 External Reference Select Setting
1846  */
1847 static inline mcg_pll_external_ref_clk_select_t CLOCK_HAL_GetPllRefSel1Mode(uint32_t baseAddr)
1848 {
1849     return (mcg_pll_external_ref_clk_select_t)BR_MCG_C11_PLLREFSEL1(baseAddr);
1850 }
1851
1852 /*!
1853  * @brief Sets the PLL1 Clock Enable Setting.
1854  *
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.
1863  *
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.
1869  */
1870 static inline void CLOCK_HAL_SetPllClk1Cmd(uint32_t baseAddr, bool enable)
1871 {
1872     BW_MCG_C11_PLLCLKEN1(baseAddr, enable ? 1 : 0);
1873 }
1874
1875 /*!
1876  * @brief Gets the PLL1 Clock Enable Setting.
1877  *
1878  * This function  gets the PLL1 Clock Enable Setting.
1879  *
1880  * @param baseAddr  Base address for current MCG instance.
1881  * @return enabled  True if the PLL1 Clock is enabled.
1882  */
1883 static inline bool CLOCK_HAL_GetPllClk1Cmd(uint32_t baseAddr)
1884 {
1885     return BR_MCG_C11_PLLCLKEN1(baseAddr);
1886 }
1887
1888 /*!
1889  * @brief Sets the PLL1 Stop Enable Setting.
1890  *
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.
1895  *
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.
1902  */
1903 static inline void CLOCK_HAL_SetPllStop1Cmd(uint32_t baseAddr, bool enable)
1904 {
1905     BW_MCG_C11_PLLSTEN1(baseAddr, enable ? 1 : 0);
1906 }
1907
1908 /*!
1909  * @brief Gets the PLL1 Stop Enable Setting.
1910  *
1911  * This function  gets the PLL1 Stop Enable Setting.
1912  *
1913  * @param baseAddr  Base address for current MCG instance.
1914  * @return enabled True if PLL1 Stop is enabled.
1915  */
1916 static inline bool CLOCK_HAL_GetPllStop1Cmd(uint32_t baseAddr)
1917 {
1918     return BR_MCG_C11_PLLSTEN1(baseAddr);
1919 }
1920
1921 /*!
1922  * @brief Sets the PLL Clock Select Setting.
1923  *
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).
1927  *
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.
1932  */
1933 static inline void CLOCK_HAL_SetPllClkSelMode(uint32_t baseAddr, mcg_pll_clk_select_t setting)
1934 {
1935     BW_MCG_C11_PLLCS(baseAddr, setting);
1936 }
1937
1938 /*!
1939  * @brief Gets the PLL Clock Select Setting.
1940  *
1941  * This function  gets the PLL Clock Select Setting.
1942  *
1943  * @param baseAddr  Base address for current MCG instance.
1944  * @return setting  PLL Clock Select Setting
1945  */
1946 static inline mcg_pll_clk_select_t CLOCK_HAL_GetPllClkSelMode(uint32_t baseAddr)
1947 {
1948     return (mcg_pll_clk_select_t)BR_MCG_C11_PLLCS(baseAddr);
1949 }
1950
1951 /*!
1952  * @brief Sets the PLL1 External Reference Divider Setting.
1953  *
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.
1958  *
1959  * @param baseAddr  Base address for current MCG instance.
1960  * @params setting  PLL1 External Reference Divider Setting
1961  */
1962 static inline void CLOCK_HAL_SetPllExternalRefDivider1(uint32_t baseAddr, uint8_t setting)
1963 {
1964     BW_MCG_C11_PRDIV1(baseAddr, setting);
1965 }
1966
1967 /*!
1968  * @brief Gets the PLL1 External Reference Divider Setting.
1969  *
1970  * This function  gets the PLL1 External Reference Divider Setting.
1971  *
1972  * @param baseAddr  Base address for current MCG instance.
1973  * @return setting  PLL1 External Reference Divider Setting
1974  */
1975 static inline uint8_t CLOCK_HAL_GetPllExternalRefDivider1(uint32_t baseAddr)
1976 {
1977     return BR_MCG_C11_PRDIV1(baseAddr);
1978 }
1979
1980 /*!
1981  * @brief Sets the PLL1 Loss of Lock Interrupt Enable Setting.
1982  *
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.
1985  *
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.
1990  */
1991 static inline void CLOCK_HAL_SetLossOfLock1Cmd(uint32_t baseAddr, bool enable)
1992 {
1993     BW_MCG_C12_LOLIE1(baseAddr, enable ? 1 : 0);
1994 }
1995
1996 /*!
1997  * @brief Gets the PLL1 Loss of Lock Interrupt Enable Setting.
1998  *
1999  * This function  gets the PLL1 Loss of Lock Interrupt Enable Setting.
2000  *
2001  * @param baseAddr  Base address for current MCG instance.
2002  * @return enabled true if PLL1 Loss of Lock Interrupt is enabled.
2003  */
2004 static inline bool CLOCK_HAL_GetLossOfLock1Cmd(uint32_t baseAddr)
2005 {
2006     return BR_MCG_C12_LOLIE1(baseAddr);
2007 }
2008
2009 /*!
2010  * @brief Sets the Clock Monitor Enable2 Setting
2011  *
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 
2019  * Stop mode.
2020  *
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.
2025  */
2026 static inline void CLOCK_HAL_SetClkMonitor2Cmd(uint32_t baseAddr, bool enable)
2027 {
2028     BW_MCG_C12_CME2(baseAddr, enable ? 1 : 0);
2029 }
2030
2031 /*!
2032  * @brief Gets the Clock Monitor Enable2 Setting.
2033  *
2034  * This function  gets the Clock Monitor Enable2 Setting.
2035  *
2036  * @param baseAddr  Base address for current MCG instance.
2037  * @return enabled True if Clock Monitor Enable2 is enabled.
2038  */
2039 static inline bool CLOCK_HAL_GetClkMonitor2Cmd(uint32_t baseAddr)
2040 {
2041     return BR_MCG_C12_CME2(baseAddr);
2042 }
2043
2044 /*!
2045  * @brief Sets the VCO1 Divider Setting.
2046  *
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.
2051  *
2052  * @param baseAddr  Base address for current MCG instance.
2053  * @params setting  VCO1 Divider Setting
2054  */
2055 static inline void CLOCK_HAL_SetVoltCtrlOscDivider1(uint32_t baseAddr, uint8_t setting)
2056 {
2057     BW_MCG_C12_VDIV1(baseAddr, setting);
2058 }
2059
2060 /*!
2061  * @brief Gets the VCO1 Divider Setting.
2062  *
2063  * This function  gets the VCO1 Divider Setting.
2064  *
2065  * @param baseAddr  Base address for current MCG instance.
2066  * @return setting  VCO1 Divider Setting
2067  */
2068 static inline uint8_t CLOCK_HAL_GetVoltCtrlOscDivider1(uint32_t baseAddr)
2069 {
2070     return BR_MCG_C12_VDIV1(baseAddr);
2071 }
2072
2073 /*!
2074  * @brief Gets the Loss of the Lock2 Status.
2075  *
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.
2082  *
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.
2087  */
2088 static inline mcg_loss_of_lock_status_t CLOCK_HAL_GetLossOfLock1Mode(uint32_t baseAddr)
2089 {
2090     return (mcg_loss_of_lock_status_t)BR_MCG_S2_LOLS1(baseAddr);
2091 }
2092
2093 /*!
2094  * @brief Gets the Lock1 Status.
2095  *
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.
2110  *
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.
2115  */
2116 static inline mcg_lock_status_t CLOCK_HAL_GetLock1Mode(uint32_t baseAddr)
2117 {
2118     return (mcg_lock_status_t)BR_MCG_S2_LOCK1(baseAddr);
2119 }
2120
2121 /*!
2122  * @brief Gets the PLL Clock Select Status.
2123  *
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.
2127  *
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.
2132  */
2133 static inline mcg_pll_clk_select_t CLOCK_HAL_GetPllClkSelStatMode(uint32_t baseAddr)
2134 {
2135     return (mcg_pll_clk_select_t)BR_MCG_S2_PLLCST(baseAddr);
2136 }
2137
2138 /*!
2139  * @brief Gets the OSC1 Initialization Status.
2140  *
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.
2144  *
2145  * @param baseAddr  Base address for current MCG instance.
2146  * @return status  OSC1 Initialization Status
2147  */
2148 static inline uint8_t CLOCK_HAL_GetOscInit1(uint32_t baseAddr)
2149 {
2150     return BR_MCG_S2_OSCINIT1(baseAddr);
2151 }
2152
2153 /*!
2154  * @brief Gets the OSC1 Loss of Clock Status.
2155  *
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.
2160  *
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.
2165  */
2166 static inline mcg_locs2_status_t CLOCK_HAL_GetLocs2Mode(uint32_t baseAddr)
2167 {
2168     return (mcg_locs2_status_t)BR_MCG_S2_LOCS2(baseAddr);
2169 }
2170 #endif /* FSL_FEATURE_MCG_USE_PLLREFSEL */
2171
2172 /*@}*/
2173
2174 #if defined(__cplusplus)
2175 }
2176 #endif /* __cplusplus*/
2177
2178 /*! @}*/
2179
2180 #endif /* __FSL_MCG_HAL_H__*/
2181 /*******************************************************************************
2182  * EOF
2183  ******************************************************************************/
2184