The section describes the programming interface of the MCGLite HAL driver. The multi-purpose clock generator Lite (MCG_Lite) module provides several clock source choices for the MCU. The MCG_Lite HAL provides a set of APIs to access these registers.
Get current clock output
The MCG_Lite HAL provides a set of APIs, which are dedicated to getting the different clock frequency, such as MCGOUTCLK, MCGPCLK, MCGIRCLK and LIRC_CLK. Ensure that the mode setting registers have been configured properly. Otherwise, the API functions are provided with an invalid value.
This example shows how to get a default system reference clock:
#include "fsl_mcglite_hal.h"
uint32_t frequency = 0;
Clock mode switching
MCG_Lite HAL provides API functions to switch between different clock modes. Before switching, ensure that the operation is valid. For example, a direct switch between the LIRC8M and the LIRC2M is not allowed. Therefore, before switching to the LIRC8M, ensure that the current mode is not LIRC2M.
|
enum | _mcglite_constant |
| MCG_Lite constant definitions. More...
|
|
enum | mcglite_mcgoutclk_source_t {
kMcgliteClkSrcHirc,
kMcgliteClkSrcLirc,
kMcgliteClkSrcExt
} |
| MCG_Lite clock source selection. More...
|
|
enum | mcglite_lirc_select_t {
kMcgliteLircSel2M,
kMcgliteLircSel8M
} |
| MCG_Lite LIRC select. More...
|
|
enum | mcglite_lirc_div_t {
kMcgliteLircDivBy1 = 0U,
kMcgliteLircDivBy2,
kMcgliteLircDivBy4,
kMcgliteLircDivBy8,
kMcgliteLircDivBy16,
kMcgliteLircDivBy32,
kMcgliteLircDivBy64,
kMcgliteLircDivBy128
} |
| MCG_Lite divider factor selection for clock source. More...
|
|
enum | osc_src_t {
kOscSrcExt,
kOscSrcOsc,
kOscSrcExt,
kOscSrcOsc
} |
| MCG_Lite external clock Select. More...
|
|
enum | osc_range_t {
kOscRangeLow,
kOscRangeHigh,
kOscRangeVeryHigh,
kOscRangeVeryHigh1,
kOscRangeLow,
kOscRangeHigh,
kOscRangeVeryHigh,
kOscRangeVeryHigh1
} |
| MCG frequency range select. More...
|
|
enum | osc_gain_t {
kOscGainLow,
kOscGainHigh,
kOscGainLow,
kOscGainHigh
} |
| MCG high gain oscillator select. More...
|
|
enum | mcglite_mode_t {
kMcgliteModeHirc48M,
kMcgliteModeLirc8M,
kMcgliteModeLirc2M,
kMcgliteModeExt,
kMcgliteModeLirc,
kMcgliteModeStop,
kMcgliteModeError
} |
| MCG_Lite clock mode definitions. More...
|
|
enum | mcglite_mode_error_t {
kMcgliteModeErrNone = 0x00,
kMcgliteModeErrExt = 0x01
} |
| MCG_Lite mode transition API error code definitions. More...
|
|
Enumerator |
---|
kMcgliteClkSrcHirc |
MCGOUTCLK source is HIRC.
|
kMcgliteClkSrcLirc |
MCGOUTCLK source is LIRC.
|
kMcgliteClkSrcExt |
MCGOUTCLK source is external clock source.
|
Enumerator |
---|
kMcgliteLircSel2M |
slow internal reference(LIRC) 2 MHz clock selected
|
kMcgliteLircSel8M |
slow internal reference(LIRC) 8 MHz clock selected
|
Enumerator |
---|
kMcgliteLircDivBy1 |
divider is 1
|
kMcgliteLircDivBy2 |
divider is 2
|
kMcgliteLircDivBy4 |
divider is 4
|
kMcgliteLircDivBy8 |
divider is 8
|
kMcgliteLircDivBy16 |
divider is 16
|
kMcgliteLircDivBy32 |
divider is 32
|
kMcgliteLircDivBy64 |
divider is 64
|
kMcgliteLircDivBy128 |
divider is 128
|
Enumerator |
---|
kOscSrcExt |
External reference clock requested.
|
kOscSrcOsc |
Oscillator requested.
|
kOscSrcExt |
Selects external input clock.
|
kOscSrcOsc |
Selects Oscillator.
|
Enumerator |
---|
kOscRangeLow |
Low frequency range selected for the crystal OSC.
|
kOscRangeHigh |
High frequency range selected for the crystal OSC.
|
kOscRangeVeryHigh |
Very High frequency range selected for the crystal OSC.
|
kOscRangeVeryHigh1 |
Very High frequency range selected for the crystal OSC.
|
kOscRangeLow |
Low frequency range selected for the crystal OSC.
|
kOscRangeHigh |
High frequency range selected for the crystal OSC.
|
kOscRangeVeryHigh |
Very High frequency range selected for the crystal OSC.
|
kOscRangeVeryHigh1 |
Very High frequency range selected for the crystal OSC.
|
Enumerator |
---|
kOscGainLow |
Configure crystal oscillator for low-power operation.
|
kOscGainHigh |
Configure crystal oscillator for high-gain operation.
|
kOscGainLow |
Configure crystal oscillator for low-power operation.
|
kOscGainHigh |
Configure crystal oscillator for high-gain operation.
|
Enumerator |
---|
kMcgliteModeHirc48M |
clock mode is HIRC 48M
|
kMcgliteModeLirc8M |
clock mode is LIRC 8M
|
kMcgliteModeLirc2M |
clock mode is LIRC 2M
|
kMcgliteModeExt |
clock mode is EXT
|
kMcgliteModeLirc |
clock mode is LIRC 2M or 8M
|
kMcgliteModeStop |
clock mode is STOP
|
kMcgliteModeError |
Unknown mode.
|
Enumerator |
---|
kMcgliteModeErrNone |
|
kMcgliteModeErrExt |
- External clock source not available.
|
uint32_t CLOCK_HAL_GetPeripheralClk |
( |
MCG_Type * |
base | ) |
|
This function returns the MCGPCLK frequency (Hertz) based on the current MCG_Lite configurations and settings. The configuration should be properly done in order to get the valid value.
- Parameters
-
base | MCG_Lite register base address. |
- Returns
- Frequency value in Hertz of MCGPCLK.
uint32_t CLOCK_HAL_GetLircClk |
( |
MCG_Type * |
base | ) |
|
This function returns the MCG_Lite LIRC frequency (Hertz) based on the current MCG_Lite configurations and settings. Ensure that the LIRC has been properly configured to get the valid value.
- Parameters
-
base | MCG_Lite register base address. |
- Returns
- Frequency value in Hertz of the MCG_Lite LIRC.
uint32_t CLOCK_HAL_GetLircDiv1Clk |
( |
MCG_Type * |
base | ) |
|
This function returns the MCG_Lite LIRC_DIV1_CLK frequency (Hertz) based on the current MCG_Lite configurations and settings. Ensure that the LIRC has been properly configured to get the valid value.
- Parameters
-
base | MCG_Lite register base address. |
- Returns
- Frequency value in Hertz of the MCG_Lite LIRC_DIV1_CLK.
uint32_t CLOCK_HAL_GetInternalRefClk |
( |
MCG_Type * |
base | ) |
|
This function returns the MCGIRCLK frequency (Hertz) based on the current MCG_Lite configurations and settings. Ensure that the LIRC has been properly configured to get the valid value.
- Parameters
-
base | MCG_Lite register base address. |
- Returns
- Frequency value in Hertz of MCGIRCLK.
uint32_t CLOCK_HAL_GetOutClk |
( |
MCG_Type * |
base | ) |
|
This function returns the MCGOUTCLK frequency (Hertz) based on the current MCG_Lite configurations and settings. The configuration should be properly done to get the valid value.
- Parameters
-
base | MCG_Lite register base address. |
- Returns
- Frequency value in Hertz of MCGOUTCLK.
This function sets the LIRC to work at 2 MHz or 8 MHz.
- Parameters
-
base | MCG_Lite register base address. |
select | 2MHz or 8MHz. |
This function sets the low internal reference divider 1, the register FCRDIV.
- Parameters
-
base | MCG_Lite register base address. |
setting | LIRC divider 1 setting value. |
This function sets the low internal reference divider 2.
- Parameters
-
base | MCG_Lite register base address. |
setting | LIRC divider 2 setting value. |
static void CLOCK_HAL_SetLircCmd |
( |
MCG_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
This function enables/disables the low internal reference clock.
- Parameters
-
base | MCG_Lite register base address. |
enable | Enable or disable internal reference clock.
- true: MCG_Lite Low IRCLK active
- false: MCG_Lite Low IRCLK inactive
|
static void CLOCK_HAL_SetLircStopCmd |
( |
MCG_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
This function controls whether or not the low internal reference clock remains enabled when the MCG_Lite enters STOP mode.
- Parameters
-
base | MCG_Lite register base address. |
enable | Enable or disable low internal reference clock stop setting.
- true: Internal reference clock is enabled in stop mode if IRCLKEN is set before entering STOP mode.
- false: Low internal reference clock is disabled in STOP mode
|
static void CLOCK_HAL_SetHircCmd |
( |
MCG_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
This function enables/disables the internal reference clock for use as MCGPCLK.
- Parameters
-
base | MCG_Lite register base address. |
enable | Enable or disable HIRC.
- true: MCG_Lite HIRC active
- false: MCG_Lite HIRC inactive
|
static void CLOCK_HAL_SetExtRefSelMode0 |
( |
MCG_Type * |
base, |
|
|
osc_src_t |
select |
|
) |
| |
|
inlinestatic |
This function selects the source for the external reference clock. Refer to the Oscillator (OSC) for more details.
- Parameters
-
base | MCG_Lite register base address. |
select | External Reference Select.
- 0: External input clock requested
- 1: Crystal requested
|
This function gets the Clock Mode Status. These bits indicate the current clock mode. The CLKST bits do not update immediately after a write to the CLKS bits because of the internal synchronization between clock domains.
- Parameters
-
base | MCG_Lite register base address. |
- Returns
- status Clock Mode Status
- 00: HIRC clock is select.
- 01: LIRC(low Internal reference clock) is selected.
- 10: External reference clock is selected.
- 11: Reserved.
static bool CLOCK_HAL_IsOscStable |
( |
MCG_Type * |
base | ) |
|
|
inlinestatic |
This function gets the OSC Initialization Status OSCINIT0. This bit, which resets to 0, is set to 1 after the initialization cycles of the crystal oscillator clock have completed. After being set, the bit is cleared to 0 if the OSC is subsequently disabled. See the OSC module's detailed description for more information.
- Parameters
-
base | MCG_Lite register base address. |
- Returns
- OSC initialization status
This is an internal function that checks the MCG registers and determines the current MCG_lite mode.
- Parameters
-
base | MCG_Lite register base address. |
- Returns
- Current MCG_Lite mode or error code.
This is an internal function that sets MCG_Lite to HRIC mode.
- Parameters
-
base | MCG_Lite register base address. |
- Returns
- Error code.
This is an internal function that sets MCG_Lite to LIRC mode.
- Parameters
-
base | MCG_Lite register base address. |
lirc | Set to LIRC2M or LIRC8M. |
div1 | The FCRDIV setting. |
- Returns
- Error code.
This is an internal function that sets MCG_Lite to EXT mode. Before calling this function, ensure that either the OSC or external clock source is ready.
- Parameters
-
base | MCG_Lite register base address. |
- Returns
- Error code.