| Kinetis SDK API Reference Manual 1.0.0-beta Freescale Semiconductor, Inc.

- Introduction
- Related Pages
- API Usage

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Enumerations | Variables
Clock Manager (Clock)

The Kinetis SDK Clock Manager provides a set of API/services to configure the clock-related IPs, such as MCG, SIM, etc. More...

## Enumerations
enum | clock_names_t { kCoreClock, kSystemClock, kPlatformClock, kBusClock, kFlexBusClock, kFlashClock, kOsc32kClock, kOsc0ErClock, kOsc1ErClock, kIrc48mClock, kRtc32kClock, kRtc1hzClock, kLpoClock, kMcgFllClock, kMcgPll0Clock, kMcgPll1Clock, kMcgOutClock, kMcgIrClock, kSDHC0_CLKIN, kENET_1588_CLKIN, kEXTAL_Clock, kEXTAL1_Clock, kUSB_CLKIN, kReserved, kClockNameCount }
| Clock names.
enum | clock_gate_module_names_t { kClockModuleDMA, kClockModuleDMAMUX, kClockModulePORT, kClockModuleMPU, kClockModuleLLWU, kClockModuleEWM, kClockModuleOSC1, kClockModuleFTF, kClockModuleNFC, kClockModuleFLEXBUS, kClockModuleDDR, kClockModuleCRC, kClockModuleRNGA, kClockModuleREGFILE, kClockModuleDRYICESECREG, kClockModuleDRYICE, kClockModuleADC, kClockModuleCMP, kClockModuleDAC, kClockModuleVREF, kClockModuleSAI, kClockModuleTPM, kClockModulePDB, kClockModuleFTM, kClockModulePIT, kClockModuleLPTIMER, kClockModuleCMT, kClockModuleRTC, kClockModuleENET, kClockModuleUSBHS, kClockModuleUSBFS, kClockModuleUSBDCD, kClockModuleFLEXCAN, kClockModuleSPI, kClockModuleI2C, kClockModuleUART, kClockModuleESDHC, kClockModuleLPUART, kClockModuleTSI, kClockModuleLCDC, kClockModuleMax }
| Clock gate module names.
enum | clock_source_names_t { kClockNfcSrc, kClockEsdhcSrc, kClockSdhcSrc, kClockLcdcSrc, kClockTimeSrc, kClockRmiiSrc, kClockUsbfSrc, kClockUsbSrc, kClockUsbhSrc, kClockUart0Src, kClockTpmSrc, kClockOsc32kSel, kClockUsbfSel, kClockPllfllSel, kClockNfcSel, kClockLcdcSel, kClockTraceSel, kClockClkoutSel, kClockRtcClkoutSel, kClockSourceMax }
| Clock source and SEL names.
enum | clock_manager_error_code_t { kClockManagerSuccess, kClockManagerNoSuchClockName, kClockManagerNoSuchClockModule, kClockManagerNoSuchClockSource, kClockManagerNoSuchDivider, kClockManagerUnknown }
| Error code definition for the clock manager APIs. More...

## Variables
sim_clock_names_t | kClockNameSimMap [kClockNameCount]
| Clock manager clock names mapping into the SIM clock name.
sim_clock_source_names_t | kClockSourceNameSimMap [kClockSourceMax]
| Clock manager clock source names mapping into the SIM clock source name. More...
sim_clock_gate_module_names_t | kClockModuleNameSimMap [kClockModuleMax]
| Clock manager clock module names mapping into the SIM clock module name.
const sim_clock_source_value_t * | kSimClockSourceValueTable []

## Clock Gating
clock_manager_error_code_t | clock_manager_set_gate (clock_gate_module_names_t moduleName, uint8_t instance, bool enable)
| Enables or disables the clock for a specific clock module. More...
clock_manager_error_code_t | clock_manager_get_gate (clock_gate_module_names_t moduleName, uint8_t instance, bool *isEnabled)
| Gets the current clock gate status for a specific clock module. More...

## Clock Frequencies
clock_manager_error_code_t | clock_manager_get_frequency (clock_names_t clockName, uint32_t *frequency)
| Gets the clock frequency for a specific clock name. More...
clock_manager_error_code_t | clock_manager_get_frequency_by_source (clock_source_names_t clockSource, uint32_t *frequency)
| Gets the clock frequency for a specified clock source. More...

## System out clock access API
uint32_t | clock_hal_get_outclk (void)
| Gets the current out clock. More...
uint32_t | clock_hal_get_fllclk (void)
| Gets the current FLL clock. More...
uint32_t | clock_hal_get_pll0clk (void)
| Gets the current PLL0 clock. More...
uint32_t | clock_hal_get_pll1clk (void)
| Gets the current PLL1 clock. More...
uint32_t | clock_hal_get_irclk (void)
| Get the current IR (internal reference) clock. More...

### Clock Manager

# Overview

The Clock Manager is configures, accesses core, platform, system and bus clock setting. It provides a set of APIs to get and set functions of the clock gate control.It includes manager-level, SIM HAL-level, and MCG HAL-level access APIs.

# Clock names, Clock source names and Clock module names

There are three sets of clock related names: clock names, clock source names, and clock module names. Each CPU only supports a subset of clock related names. If there is a new clock or a clock module that does exist in the current name set, it has to be added in the definition.Clock names get a system clock frequency. The clock module names control and access the clock module gate status for a specific module.Example to get a system clock frequency:
#include "clock/fsl_clock_manager.h"
uint32_t uFrequency = 0;
// get the system clock frequency based on current mode configuration
if (kClockManagerSuccess == clock_manager_get_frequency(kSystemClock, &frequency))
// check the frequency value for system clock in frequency
Example to get a clock frequency based on the clock source:
#include "fsl_clock_manager.h"
uint32_t uFrequency = 0;
// get the USBSRC clock frequency based on current mode configuration
if (kClockManagerSuccess == clock_manager_get_frequency_by_source(kClockUsbSrc, &frequency))
// check the frequency value for USBSRC clock in frequency
Example to enable a clock module:
#include "fsl_clock_manager.h"
clock_manager_error_code_t retCode = 0;
// enable the DMA clock
retCode = clock_manager_set_gate(kClockModuleDMA, 0, true);
// check the error to confirm if the enabling is done successfully

## Enumeration Type Documentation

enum clock_manager_error_code_t

Enumerator
kClockManagerSuccess | success
kClockManagerNoSuchClockName | cannot find the clock name
kClockManagerNoSuchClockModule | cannot find the clock module name
kClockManagerNoSuchClockSource | cannot find the clock source name
kClockManagerNoSuchDivider | cannot find the divider name
kClockManagerUnknown | unknown error

## Function Documentation

clock_manager_error_code_t clock_manager_set_gate | ( | clock_gate_module_names_t | moduleName,
|  | uint8_t | instance,
|  | bool | enable
| ) |  |

This function enables/disables the clock for a specified clock module and instance. See the clock_gate_module_names_t for supported clock module names for a specific function and see the Reference Manual for supported clock module name for a specific chip family. Most module drivers call this function to gate(disable)/ungate(enable) the clock for a module. However, the application can also call this function as needed. Disabling the clock causes the module to stop working. See the Reference Manual to properly enable and disable the clock for a device module.

Parameters

  moduleName | Gate control module name defined in clock_gate_module_names_t
  instance | Instance of the module
  enable | Enable or disable the clock for the module true: Enable false: Disable

Returns
  status Error code defined in clock_manager_error_code_t

clock_manager_error_code_t clock_manager_get_gate | ( | clock_gate_module_names_t | moduleName,
|  | uint8_t | instance,
|  | bool * | isEnabled
| ) |  |

This function returns the current clock gate status for a specific clock module. See clock_gate_module_names_t for supported clock module name.

Parameters

  moduleName | Gate control module name defined in clock_gate_module_names_t
  instance | Instance of the module
  isEnabled | Status of the module clock true: Enabled false: Disabled

Returns
  status Error code defined in clock_manager_error_code_t

clock_manager_error_code_t clock_manager_get_frequency | ( | clock_names_t | clockName,
|  | uint32_t * | frequency
| ) |  |

This function checks the current clock configurations and then calculates the clock frequency for a specific clock name defined in clock_names_t. The MCG must be properly configured before using this function. See the Reference Manual for supported clock names for different chip families. The returned value is in Hertz. If it cannot find the clock name or the name is not supported for a specific chip family, it returns an error.

Parameters

  clockName | Clock names defined in clock_names_t
  frequency | Returned clock frequency value in Hertz

Returns
  status Error code defined in clock_manager_error_code_t

clock_manager_error_code_t clock_manager_get_frequency_by_source | ( | clock_source_names_t | clockSource,
|  | uint32_t * | frequency
| ) |  |

This function gets the specified clock source setting and converts it into a clock name. It calls the internal function to get the value for that clock name. The returned value is in Hertz. If it cannot find the clock source or the source is not supported for the specific chip family, it returns an error.

Parameters

  clockSource | Clock source names defined in clock_source_names_t
  frequency | Returned clock frequency value in Hertz

Returns
  status Error code defined in clock_manager_error_code_t

uint32_t clock_hal_get_outclk | ( | void |  | ) |

Parameters

  none |

Returns
  frequency Out clock frequency for the clock system

uint32_t clock_hal_get_fllclk | ( | void |  | ) |

Parameters

  none |

Returns
  frequency FLL clock frequency for the clock system

uint32_t clock_hal_get_pll0clk | ( | void |  | ) |

Parameters

  none |

Returns
  frequency PLL0 clock frequency for the clock system

uint32_t clock_hal_get_pll1clk | ( | void |  | ) |

Parameters

  none |

Returns
  frequency PLL1 clock frequency for the clock system

uint32_t clock_hal_get_irclk | ( | void |  | ) |

Parameters

  none |

Returns
  frequency IR clock frequency for the clock system

## Variable Documentation

sim_clock_source_names_t kClockSourceNameSimMap[kClockSourceMax]

Initial value:
= {
kSimClockNfcSrc,
kSimClockEsdhcSrc,
kSimClockSdhcSrc,
kSimClockLcdcSrc,
kSimClockTimeSrc,
kSimClockRmiiSrc,
kSimClockUsbfSrc,
kSimClockUsbSrc,
kSimClockUsbhSrc,
kSimClockUart0Src,
kSimClockTpmSrc,
kSimClockOsc32kSel,
kSimClockUsbfSel,
kSimClockPllfllSel,
kSimClockNfcSel,
kSimClockLcdcSel,
kSimClockTraceSel,
kSimClockClkoutSel,
kSimClockRtcClkoutSel
}