Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
fsl_mcg_hal.h File Reference
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>
#include "fsl_device_registers.h"

Enumerations

enum  _mcg_constant {
  kMcgConstant0 = (0u),
  kMcgConstant31250 = (31250u),
  kMcgConstant32768 = (32768u),
  kMcgConstant39063 = (39063u),
  kMcgConstant8000000 = (8000000u),
  kMcgConstant16000000 = (16000000u)
}
 MCG constant definitions.
 
enum  mcg_fll_src_t {
  kMcgFllSrcExternal,
  kMcgFllSrcInternal
}
 MCG internal reference clock source select. More...
 
enum  osc_range_t {
  kOscRangeLow,
  kOscRangeHigh,
  kOscRangeVeryHigh,
  kOscRangeVeryHigh1,
  kOscRangeLow,
  kOscRangeHigh,
  kOscRangeVeryHigh,
  kOscRangeVeryHigh1
}
 MCG OSC frequency range select. More...
 
enum  osc_gain_t {
  kOscGainLow,
  kOscGainHigh,
  kOscGainLow,
  kOscGainHigh
}
 MCG high gain oscillator select. More...
 
enum  osc_src_t {
  kOscSrcExt,
  kOscSrcOsc,
  kOscSrcExt,
  kOscSrcOsc
}
 MCG external reference clock select. More...
 
enum  mcg_irc_mode_t {
  kMcgIrcSlow,
  kMcgIrcFast
}
 MCG internal reference clock select. More...
 
enum  mcg_dmx32_select_t {
  kMcgDmx32Default,
  kMcgDmx32Fine
}
 MCG DCO Maximum Frequency with 32.768 kHz Reference. More...
 
enum  mcg_dco_range_select_t {
  kMcgDcoRangeSelLow,
  kMcgDcoRangeSelMid,
  kMcgDcoRangeSelMidHigh,
  kMcgDcoRangeSelHigh
}
 MCG DCO range select. More...
 
enum  mcg_pll_ref_mode_t {
  kMcgPllRefOsc0,
  kMcgPllRefOsc1
}
 MCG PLL external reference clock select. More...
 
enum  mcg_clkout_src_t {
  kMcgClkOutSrcOut,
  kMcgClkOutSrcInternal,
  kMcgClkOutSrcExternal
}
 MCGOUT clock source. More...
 
enum  mcg_clkout_stat_t {
  kMcgClkOutStatFll,
  kMcgClkOutStatInternal,
  kMcgClkOutStatExternal,
  kMcgClkOutStatPll
}
 MCG clock mode status. More...
 
enum  mcg_atm_select_t {
  kMcgAtmSel32k,
  kMcgAtmSel4m
}
 MCG Automatic Trim Machine Select. More...
 
enum  mcg_oscsel_select_t {
  kMcgOscselOsc,
  kMcgOscselRtc
}
 MCG OSC Clock Select. More...
 
enum  mcg_osc_monitor_mode_t {
  kMcgOscMonitorInt,
  kMcgOscMonitorReset
}
 MCG OSC monitor mode. More...
 
enum  mcg_pll_clk_select_t {
  kMcgPllClkSelPll0,
  kMcgPllClkSelPll1
}
 MCG PLLCS select. More...
 
enum  mcg_atm_error_t {
  kMcgAtmErrorNone,
  kMcgAtmErrorBusClockRange,
  kMcgAtmErrorDesireFreqRange,
  kMcgAtmErrorIrcUsed,
  kMcgAtmErrorTrimValueInvalid,
  kMcgAtmErrorHardwareFail
}
 MCG auto trim machine error code. More...
 
enum  mcg_status_t {
  kStatus_MCG_Success = 0U,
  kStatus_MCG_Fail = 1U
}
 MCG status. More...
 

Functions

MCG out clock access API
uint32_t CLOCK_HAL_TestOscFreq (MCG_Type *base, mcg_oscsel_select_t oscselVal)
 Tests the external clock frequency. More...
 
uint32_t CLOCK_HAL_TestFllExternalRefFreq (MCG_Type *base, uint32_t extFreq, uint8_t frdivVal, osc_range_t range0, mcg_oscsel_select_t oscsel)
 Tests the FLL external reference frequency based on the input parameters. More...
 
uint32_t CLOCK_HAL_GetFllRefClk (MCG_Type *base)
 Gets the current MCG FLL clock. More...
 
uint32_t CLOCK_HAL_TestFllFreq (MCG_Type *base, uint32_t fllRef, mcg_dmx32_select_t dmx32, mcg_dco_range_select_t drs)
 Calculates the FLL frequency based on the input parameters. More...
 
uint32_t CLOCK_HAL_GetFllClk (MCG_Type *base)
 Gets the current MCG FLL clock. More...
 
uint32_t CLOCK_HAL_GetInternalRefClk (MCG_Type *base)
 Gets the current MCG internal reference clock(MCGIRCLK). More...
 
uint32_t CLOCK_HAL_GetFixedFreqClk (MCG_Type *base)
 Gets the current MCG fixed frequency clock(MCGFFCLK). More...
 
uint32_t CLOCK_HAL_GetOutClk (MCG_Type *base)
 Gets the current MCG out clock. More...
 
MCG control register access API
static void CLOCK_HAL_SetClkOutSrc (MCG_Type *base, mcg_clkout_src_t select)
 Sets the Clock Source Select. More...
 
static void CLOCK_HAL_SetClksFrdivIrefs (MCG_Type *base, mcg_clkout_src_t clks, uint8_t frdiv, mcg_fll_src_t irefs)
 Sets the CLKS, FRDIV, IREFS at the same time. More...
 
static mcg_clkout_stat_t CLOCK_HAL_GetClkOutStat (MCG_Type *base)
 Gets the Clock Mode Status. More...
 
static void CLOCK_HAL_SetLowPowerModeCmd (MCG_Type *base, bool enable)
 Sets the Low Power Select. More...
 
void CLOCK_HAL_PrepareOsc (MCG_Type *base, mcg_oscsel_select_t setting)
 Prepare the OSC external clock. More...
 
MCG FLL API
static mcg_fll_src_t CLOCK_HAL_GetFllSrc (MCG_Type *base)
 Gets the FLL source status. More...
 
static void CLOCK_HAL_SetFllFilterPreserveCmd (MCG_Type *base, bool enable)
 Sets the FLL Filter Preserve Enable Setting. More...
 
mcg_status_t CLOCK_HAL_GetAvailableFrdiv (osc_range_t range0, mcg_oscsel_select_t oscsel, uint32_t inputFreq, uint8_t *frdiv)
 Calculates the proper FRDIV setting. More...
 
MCG internal reference clock APIs
static void CLOCK_HAL_SetInternalRefClkEnableCmd (MCG_Type *base, bool enable)
 Sets the internal reference clock enable or not. More...
 
static void CLOCK_HAL_SetInternalRefClkEnableInStopCmd (MCG_Type *base, bool enable)
 Sets the internal reference clock enable or nor in stop mode. More...
 
static void CLOCK_HAL_SetInternalRefClkMode (MCG_Type *base, mcg_irc_mode_t mode)
 Sets the Internal Reference Clock Select. More...
 
static mcg_irc_mode_t CLOCK_HAL_GetInternalRefClkMode (MCG_Type *base)
 Gets the Internal Reference Clock Status. More...
 
void CLOCK_HAL_UpdateFastClkInternalRefDiv (MCG_Type *base, uint8_t fcrdiv)
 Updates the Fast Clock Internal Reference Divider Setting. More...
 
void CLOCK_HAL_UpdateInternalRefClk (MCG_Type *base, mcg_irc_mode_t ircs, uint8_t fcrdiv, bool enableInStop)
 Updates the Internal Reference clock (MCGIRCLK) More...
 
MCG OSC APIs
void CLOCK_HAL_SetOsc0Mode (MCG_Type *base, osc_range_t range, osc_gain_t hgo, osc_src_t erefs)
 Sets the OSC0 work mode. More...
 
static bool CLOCK_HAL_IsOsc0Stable (MCG_Type *base)
 Gets the OSC initialization status. More...
 
void CLOCK_HAL_EnableOsc0Monitor (MCG_Type *base, mcg_osc_monitor_mode_t mode)
 Enables the OSC0 external clock monitor. More...
 
static void CLOCK_HAL_DisableOsc0Monitor (MCG_Type *base)
 Disables the OSC0 external clock monitor. More...
 
static bool CLOCK_HAL_IsOsc0MonitorEnabled (MCG_Type *base)
 Checks the OSC0 external clock monitor is enabled or not. More...
 
static bool CLOCK_HAL_IsOsc0LostLock (MCG_Type *base)
 Gets the OSC0 Loss of Clock Status. More...
 
static void CLOCK_HAL_ClearOsc0LostLock (MCG_Type *base)
 Clears the OSC0 Loss of Clock Status. More...
 
MCG Auto Trim Machine (ATM)
mcg_atm_error_t CLOCK_HAL_TrimInternalRefClk (MCG_Type *base, uint32_t extFreq, uint32_t desireFreq, uint32_t *actualFreq, mcg_atm_select_t atms)
 Auto trims the internal reference clock. More...
 
static bool CLOCK_HAL_IsAutoTrimMachineFailed (MCG_Type *base)
 Gets the Automatic Trim machine Fail Flag. More...
 
static void CLOCK_HAL_ClearAutoTrimMachineFailed (MCG_Type *base)
 Clears the Automatic Trim machine Fail Flag. More...
 

Variables

uint32_t g_xtal0ClkFreq
 
uint32_t g_xtalRtcClkFreq
 
uint32_t g_fastInternalRefClkFreq
 
uint32_t g_slowInternalRefClkFreq