Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

Overview

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"
// return frequency value for specified clock name
uint32_t frequency = 0;
// get the current system default reference clock frequency
frequency = CLOCK_HAL_GetOutClk();

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.

Files

file  fsl_mcglite_hal.h
 

Enumerations

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...
 

MCG_Lite output clock access API

uint32_t CLOCK_HAL_GetPeripheralClk (MCG_Type *base)
 Gets the current MCGPCLK frequency. More...
 
uint32_t CLOCK_HAL_GetLircClk (MCG_Type *base)
 Gets the current MCG_Lite low internal reference clock(2 MHz or 8 MHz) More...
 
uint32_t CLOCK_HAL_GetLircDiv1Clk (MCG_Type *base)
 Gets the current MCG_Lite LIRC_DIV1_CLK frequency. More...
 
uint32_t CLOCK_HAL_GetInternalRefClk (MCG_Type *base)
 Gets the current MCGIRCLK frequency. More...
 
uint32_t CLOCK_HAL_GetOutClk (MCG_Type *base)
 Gets the current MCGOUTCLK frequency. More...
 

MCG_Lite control register access API

static void CLOCK_HAL_SetLircSelMode (MCG_Type *base, mcglite_lirc_select_t select)
 Sets the Low Internal Reference Select. More...
 
static void CLOCK_HAL_SetLircRefDiv (MCG_Type *base, mcglite_lirc_div_t setting)
 Sets the low internal reference divider 1. More...
 
static void CLOCK_HAL_SetLircDiv2 (MCG_Type *base, mcglite_lirc_div_t setting)
 Sets the low internal reference divider 2. More...
 
static void CLOCK_HAL_SetLircCmd (MCG_Type *base, bool enable)
 Enables the Low Internal Reference Clock setting. More...
 
static void CLOCK_HAL_SetLircStopCmd (MCG_Type *base, bool enable)
 Sets the Low Internal Reference Clock disabled or not in STOP mode. More...
 
static void CLOCK_HAL_SetHircCmd (MCG_Type *base, bool enable)
 Enable or disable the High Internal Reference Clock setting. More...
 
static void CLOCK_HAL_SetExtRefSelMode0 (MCG_Type *base, osc_src_t select)
 Sets the External Reference Select. More...
 
static mcglite_mcgoutclk_source_t CLOCK_HAL_GetClkSrcStat (MCG_Type *base)
 Gets the Clock Mode Status. More...
 
static bool CLOCK_HAL_IsOscStable (MCG_Type *base)
 Gets the OSC Initialization Status. More...
 

MCG_Lite clock mode API

mcglite_mode_t CLOCK_HAL_GetMode (MCG_Type *base)
 Gets the current MCG_Lite clock mode. More...
 
mcglite_mode_error_t CLOCK_HAL_SetHircMode (MCG_Type *base)
 Sets the MCG_Lite to HIRC mode. More...
 
mcglite_mode_error_t CLOCK_HAL_SetLircMode (MCG_Type *base, mcglite_lirc_select_t lirc, mcglite_lirc_div_t div1)
 Sets the MCG_Lite to LIRC mode. More...
 
mcglite_mode_error_t CLOCK_HAL_SetExtMode (MCG_Type *base)
 Sets the MCG_Lite to EXT mode. More...
 

Enumeration Type Documentation

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

enum osc_src_t
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.

enum osc_gain_t
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 
  • No error
kMcgliteModeErrExt 
  • External clock source not available.

Function Documentation

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
baseMCG_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
baseMCG_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
baseMCG_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
baseMCG_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
baseMCG_Lite register base address.
Returns
Frequency value in Hertz of MCGOUTCLK.
static void CLOCK_HAL_SetLircSelMode ( MCG_Type *  base,
mcglite_lirc_select_t  select 
)
inlinestatic

This function sets the LIRC to work at 2 MHz or 8 MHz.

Parameters
baseMCG_Lite register base address.
select2MHz or 8MHz.
static void CLOCK_HAL_SetLircRefDiv ( MCG_Type *  base,
mcglite_lirc_div_t  setting 
)
inlinestatic

This function sets the low internal reference divider 1, the register FCRDIV.

Parameters
baseMCG_Lite register base address.
settingLIRC divider 1 setting value.
static void CLOCK_HAL_SetLircDiv2 ( MCG_Type *  base,
mcglite_lirc_div_t  setting 
)
inlinestatic

This function sets the low internal reference divider 2.

Parameters
baseMCG_Lite register base address.
settingLIRC 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
baseMCG_Lite register base address.
enableEnable 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
baseMCG_Lite register base address.
enableEnable 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
baseMCG_Lite register base address.
enableEnable 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
baseMCG_Lite register base address.
selectExternal Reference Select.
  • 0: External input clock requested
  • 1: Crystal requested
static mcglite_mcgoutclk_source_t CLOCK_HAL_GetClkSrcStat ( MCG_Type *  base)
inlinestatic

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
baseMCG_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
baseMCG_Lite register base address.
Returns
OSC initialization status
mcglite_mode_t CLOCK_HAL_GetMode ( MCG_Type *  base)

This is an internal function that checks the MCG registers and determines the current MCG_lite mode.

Parameters
baseMCG_Lite register base address.
Returns
Current MCG_Lite mode or error code.
mcglite_mode_error_t CLOCK_HAL_SetHircMode ( MCG_Type *  base)

This is an internal function that sets MCG_Lite to HRIC mode.

Parameters
baseMCG_Lite register base address.
Returns
Error code.
mcglite_mode_error_t CLOCK_HAL_SetLircMode ( MCG_Type *  base,
mcglite_lirc_select_t  lirc,
mcglite_lirc_div_t  div1 
)

This is an internal function that sets MCG_Lite to LIRC mode.

Parameters
baseMCG_Lite register base address.
lircSet to LIRC2M or LIRC8M.
div1The FCRDIV setting.
Returns
Error code.
mcglite_mode_error_t CLOCK_HAL_SetExtMode ( MCG_Type *  base)

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
baseMCG_Lite register base address.
Returns
Error code.