aboutsummaryrefslogtreecommitdiff
path: root/KSDK_1.2.0/platform/system
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amatus.name>2015-09-27 12:55:47 -0500
committerDavid Barksdale <amatus@amatus.name>2015-09-27 12:59:41 -0500
commitf0668e8033f3858c520d98bd787f951c3f9fb0fd (patch)
treeb7c8b19d579fcd13e30a6ca8f6e44235d83d823e /KSDK_1.2.0/platform/system
parent5a84136c6b03f7e4efd051d3afa557f9bbde2fa9 (diff)
Adding subset of Kinetis SDK
This is just the free-software-licensed stuff and the KL27Z4 stuff.
Diffstat (limited to 'KSDK_1.2.0/platform/system')
-rwxr-xr-xKSDK_1.2.0/platform/system/inc/fsl_clock_manager.h906
-rwxr-xr-xKSDK_1.2.0/platform/system/inc/fsl_hwtimer.h462
-rwxr-xr-xKSDK_1.2.0/platform/system/inc/fsl_hwtimer_pit.h43
-rwxr-xr-xKSDK_1.2.0/platform/system/inc/fsl_hwtimer_systick.h46
-rwxr-xr-xKSDK_1.2.0/platform/system/inc/fsl_interrupt_manager.h147
-rwxr-xr-xKSDK_1.2.0/platform/system/inc/fsl_power_manager.h645
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK02F12810/fsl_clock_MK02F12810.c807
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK02F12810/fsl_clock_MK02F12810.h1116
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK10D10/fsl_clock_MK10D10.c1075
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK10D10/fsl_clock_MK10D10.h2048
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK11DA5/fsl_clock_MK11DA5.c861
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK11DA5/fsl_clock_MK11DA5.h1436
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK20D10/fsl_clock_MK20D10.c1075
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK20D10/fsl_clock_MK20D10.h2048
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK21DA5/fsl_clock_MK21DA5.c891
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK21DA5/fsl_clock_MK21DA5.h1462
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK21FA12/fsl_clock_MK21FA12.c965
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK21FA12/fsl_clock_MK21FA12.h1712
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK22F12810/fsl_clock_MK22F12810.c883
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK22F12810/fsl_clock_MK22F12810.h1450
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK22F25612/fsl_clock_MK22F25612.c889
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK22F25612/fsl_clock_MK22F25612.h1486
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK22F51212/fsl_clock_MK22F51212.c954
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK22F51212/fsl_clock_MK22F51212.h1545
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK24F12/fsl_clock_MK24F12.c970
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK24F12/fsl_clock_MK24F12.h1703
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK24F25612/fsl_clock_MK24F25612.c900
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK24F25612/fsl_clock_MK24F25612.h1467
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK26F18/fsl_clock_MK26F18.c1219
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK26F18/fsl_clock_MK26F18.h2093
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK30D10/fsl_clock_MK30D10.c1075
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK30D10/fsl_clock_MK30D10.h2048
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK40D10/fsl_clock_MK40D10.c1075
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK40D10/fsl_clock_MK40D10.h2048
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK50D10/fsl_clock_MK50D10.c1075
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK50D10/fsl_clock_MK50D10.h2048
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK51D10/fsl_clock_MK51D10.c1075
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK51D10/fsl_clock_MK51D10.h2048
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK52D10/fsl_clock_MK52D10.c1075
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK52D10/fsl_clock_MK52D10.h2048
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK53D10/fsl_clock_MK53D10.c1075
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK53D10/fsl_clock_MK53D10.h2048
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK60D10/fsl_clock_MK60D10.c1075
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK60D10/fsl_clock_MK60D10.h2048
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK63F12/fsl_clock_MK63F12.c1026
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK63F12/fsl_clock_MK63F12.h1834
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK64F12/fsl_clock_MK64F12.c1026
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK64F12/fsl_clock_MK64F12.h1834
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK65F18/fsl_clock_MK65F18.c1275
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK65F18/fsl_clock_MK65F18.h2222
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK66F18/fsl_clock_MK66F18.c1275
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MK66F18/fsl_clock_MK66F18.h2222
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL02Z4/fsl_clock_MKL02Z4.c723
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL02Z4/fsl_clock_MKL02Z4.h675
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL03Z4/fsl_clock_MKL03Z4.c704
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL03Z4/fsl_clock_MKL03Z4.h812
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL14Z4/fsl_clock_MKL14Z4.c986
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL14Z4/fsl_clock_MKL14Z4.h1115
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL15Z4/fsl_clock_MKL15Z4.c986
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL15Z4/fsl_clock_MKL15Z4.h1115
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL16Z4/fsl_clock_MKL16Z4.c1012
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL16Z4/fsl_clock_MKL16Z4.h1237
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL17Z4/fsl_clock_MKL17Z4.c840
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL17Z4/fsl_clock_MKL17Z4.h1323
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL17Z644/fsl_clock_MKL17Z644.c804
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL17Z644/fsl_clock_MKL17Z644.h1193
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL24Z4/fsl_clock_MKL24Z4.c986
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL24Z4/fsl_clock_MKL24Z4.h1115
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL25Z4/fsl_clock_MKL25Z4.c986
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL25Z4/fsl_clock_MKL25Z4.h1115
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL26Z4/fsl_clock_MKL26Z4.c1012
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL26Z4/fsl_clock_MKL26Z4.h1237
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL27Z4/fsl_clock_MKL27Z4.c840
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL27Z4/fsl_clock_MKL27Z4.h1323
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL27Z644/fsl_clock_MKL27Z644.c804
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL27Z644/fsl_clock_MKL27Z644.h1193
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL33Z4/fsl_clock_MKL33Z4.c840
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL33Z4/fsl_clock_MKL33Z4.h1323
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL34Z4/fsl_clock_MKL34Z4.c1012
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL34Z4/fsl_clock_MKL34Z4.h1237
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL36Z4/fsl_clock_MKL36Z4.c1012
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL36Z4/fsl_clock_MKL36Z4.h1237
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL43Z4/fsl_clock_MKL43Z4.c840
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL43Z4/fsl_clock_MKL43Z4.h1323
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL46Z4/fsl_clock_MKL46Z4.c1012
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKL46Z4/fsl_clock_MKL46Z4.h1237
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV10Z7/fsl_clock_MKV10Z7.c806
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV10Z7/fsl_clock_MKV10Z7.h926
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV30F12810/fsl_clock_MKV30F12810.c809
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV30F12810/fsl_clock_MKV30F12810.h1119
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV31F12810/fsl_clock_MKV31F12810.c848
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV31F12810/fsl_clock_MKV31F12810.h1198
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV31F25612/fsl_clock_MKV31F25612.c854
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV31F25612/fsl_clock_MKV31F25612.h1232
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV31F51212/fsl_clock_MKV31F51212.c871
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV31F51212/fsl_clock_MKV31F51212.h1299
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV40F15/fsl_clock_MKV40F15.c765
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV40F15/fsl_clock_MKV40F15.h1267
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV43F15/fsl_clock_MKV43F15.c765
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV43F15/fsl_clock_MKV43F15.h1267
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV44F15/fsl_clock_MKV44F15.c765
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV44F15/fsl_clock_MKV44F15.h1267
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV45F15/fsl_clock_MKV45F15.c765
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV45F15/fsl_clock_MKV45F15.h1267
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV46F15/fsl_clock_MKV46F15.c765
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKV46F15/fsl_clock_MKV46F15.h1267
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKW01Z4/fsl_clock_MKW01Z4.c1012
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKW01Z4/fsl_clock_MKW01Z4.h1236
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKW21D5/fsl_clock_MKW21D5.c861
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKW21D5/fsl_clock_MKW21D5.h1436
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKW22D5/fsl_clock_MKW22D5.c891
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKW22D5/fsl_clock_MKW22D5.h1460
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKW24D5/fsl_clock_MKW24D5.c891
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/MKW24D5/fsl_clock_MKW24D5.h1460
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/fsl_clock_manager.c742
-rwxr-xr-xKSDK_1.2.0/platform/system/src/clock/fsl_clock_manager_common.c62
-rwxr-xr-xKSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer.c417
-rwxr-xr-xKSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer_pit.c434
-rwxr-xr-xKSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer_pit_irq.c116
-rwxr-xr-xKSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer_systick.c399
-rwxr-xr-xKSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer_systick_irq.c58
-rwxr-xr-xKSDK_1.2.0/platform/system/src/interrupt/fsl_interrupt_manager.c128
-rwxr-xr-xKSDK_1.2.0/platform/system/src/power/fsl_power_manager.c953
-rwxr-xr-xKSDK_1.2.0/platform/system/src/power/fsl_power_manager_common.h209
124 files changed, 135975 insertions, 0 deletions
diff --git a/KSDK_1.2.0/platform/system/inc/fsl_clock_manager.h b/KSDK_1.2.0/platform/system/inc/fsl_clock_manager.h
new file mode 100755
index 0000000..8732163
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/inc/fsl_clock_manager.h
@@ -0,0 +1,906 @@
+/*
+ * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_MANAGER_H__)
+#define __FSL_CLOCK_MANAGER_H__
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_sim_hal.h"
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/* Macro to determine which clock module is used. */
+#if (defined(SCG_INSTANCE_COUNT))
+#define CLOCK_USE_SCG /* SCG is used. */
+#elif (defined(FSL_FEATURE_MCGLITE_MCGLITE))
+#define CLOCK_USE_MCG_LITE /* MCG_LITE is used. */
+#else
+#define CLOCK_USE_MCG /* MCG is used. */
+#endif
+
+/*! @brief The register base of SIM module. */
+extern SIM_Type * const g_simBase[];
+
+#if (defined(CLOCK_USE_MCG) || defined(CLOCK_USE_MCG_LITE))
+/*! @brief The register base of MCG/MCG_LITE module. */
+extern MCG_Type * const g_mcgBase[];
+#endif
+
+#if (defined(CLOCK_USE_SCG))
+/*! @brief The register base of SCG module. */
+extern const uint32_t g_scgBase[];
+#endif
+
+#if (!defined(CLOCK_USE_SCG))
+/*! @brief The register base of OSC module. */
+extern OSC_Type * const g_oscBase[];
+#endif
+
+#if (defined(PCC_INSTANCE_COUNT))
+/*! @brief The register base of PCC module. */
+extern PCC_Type * const g_pccBase[];
+#endif
+
+/*! @brief Frequency of LPO. */
+#define CPU_LPO_CLK_HZ 1000U
+
+/*! @brief Systick clock source selection. */
+typedef enum _clock_systick_src
+{
+ kClockSystickSrcExtRef = 0U, /*!< Use external reference clock. */
+ kClockSystickSrcCore = 1U, /*!< Use processer clock (Core clock). */
+} clock_systick_src_t;
+
+/*! @brief Clock name used to get clock frequency. */
+typedef enum _clock_names {
+
+ /* default clocks*/
+ kCoreClock, /*!< Core clock */
+ kSystemClock, /*!< System clock */
+ kPlatformClock, /*!< Platform clock */
+ kBusClock, /*!< Bus clock */
+ kFlexBusClock, /*!< FlexBus clock */
+ kFlashClock, /*!< Flash clock */
+ kFastPeripheralClock, /*!< Flash peripheral clock */
+ kSystickClock, /*!< Clock for systick. */
+
+ /* other internal clocks used by peripherals*/
+ /* osc clock*/
+ kOsc32kClock, /*!< ERCLK32K */
+ kOsc0ErClock, /*!< OSC0ERCLK */
+ kOsc1ErClock, /*!< OSC1ERCLK */
+ kOsc0ErClockUndiv, /*!< OSC0ERCLK_UNDIV */
+
+ kIrc48mClock, /*!< IRC 48M */
+
+ /* rtc clock*/
+ kRtcoutClock, /*!< RTC_CLKOUT */
+
+ /* mcg clocks*/
+ kMcgFfClock, /*!< MCG fixed frequency clock (MCGFFCLK) */
+ kMcgFllClock, /*!< MCGFLLCLK */
+ kMcgPll0Clock, /*!< MCGPLL0CLK */
+ kMcgPll1Clock, /*!< MCGPLL1CLK */
+ kMcgExtPllClock, /*!< EXT_PLLCLK */
+ kMcgOutClock, /*!< MCGOUTCLK */
+ kMcgIrClock, /*!< MCGIRCLK */
+
+ /* LPO clock */
+ kLpoClock, /*!< LPO clock */
+
+ kClockNameCount
+
+} clock_names_t;
+
+/*!
+ * @brief Error code definition for the clock manager APIs
+ */
+typedef enum _clock_manager_error_code {
+ kClockManagerSuccess, /*!< Success */
+ kClockManagerError, /*!< Some error occurs. */
+ kClockManagerNoSuchClockName, /*!< Invalid name */
+ kClockManagerInvalidParam, /*!< Invalid parameter */
+ kClockManagerErrorOutOfRange, /*!< Configuration index out of range. */
+ kClockManagerErrorNotificationBefore, /*!< Error occurs during send "BEFORE" notification. */
+ kClockManagerErrorNotificationAfter, /*!< Error occurs during send "AFTER" notification. */
+ kClockManagerErrorUnknown, /*!< Unknown error. */
+} clock_manager_error_code_t;
+
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Gets the clock frequency for a specific clock name.
+ *
+ * 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.
+ *
+ * @param clockName Clock names defined in clock_names_t
+ * @param frequency Returned clock frequency value in Hertz
+ * @return status Error code defined in clock_manager_error_code_t
+ */
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency);
+
+/*!
+ * @brief Get core clock frequency.
+ *
+ * This function gets the core clock frequency.
+ *
+ * @return Current core clock frequency.
+ */
+uint32_t CLOCK_SYS_GetCoreClockFreq(void);
+
+/*!
+ * @brief Get system clock frequency.
+ *
+ * This function gets the system clock frequency.
+ *
+ * @return Current system clock frequency.
+ */
+uint32_t CLOCK_SYS_GetSystemClockFreq(void);
+
+/*!
+ * @brief Get bus clock frequency.
+ *
+ * This function gets the bus clock frequency.
+ *
+ * @return Current bus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetBusClockFreq(void);
+
+/*!
+ * @brief Get flash clock frequency.
+ *
+ * This function gets the flash clock frequency.
+ *
+ * @return Current flash clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlashClockFreq(void);
+
+/*!
+ * @brief Get LPO clock frequency.
+ *
+ * This function gets the LPO clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetLpoClockFreq(void)
+{
+ return CPU_LPO_CLK_HZ;
+}
+
+/*!
+ * @brief Set Systick clock source SYST_CSR[CLKSOURCE].
+ *
+ * This function selects the clock source for systick, systick clock source
+ * could be external reference clock or processor clock. Please check
+ * reference manual for details.
+ *
+ * @param src Clock source for systick.
+ */
+static inline void CLOCK_SYS_SetSystickSrc(clock_systick_src_t src)
+{
+ SysTick->CTRL = ((SysTick->CTRL & ~SysTick_CTRL_CLKSOURCE_Msk)
+ | ((uint32_t)src) << SysTick_CTRL_CLKSOURCE_Pos);
+}
+
+/*!
+ * @brief Get Systick clock frequency.
+ *
+ * This function gets the clock frequency for systick. Systick clock source
+ * could be external reference clock or processor clock. Please check
+ * reference manual for details.
+ *
+ * @return Clock frequency for systick.
+ */
+#if FSL_FEATURE_SYSTICK_HAS_EXT_REF
+uint32_t CLOCK_SYS_GetSystickFreq(void);
+#else
+static inline uint32_t CLOCK_SYS_GetSystickFreq(void)
+{
+ return CLOCK_SYS_GetCoreClockFreq();
+}
+#endif // FSL_FEATURE_SYSTICK_HAS_EXT_REF
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*
+ * Include the cpu specific clock API header files.
+ */
+#if (defined(K02F12810_SERIES))
+ /* Clock System Level API header file */
+ #include "../src/clock/MK02F12810/fsl_clock_MK02F12810.h"
+
+#elif (defined(K20D5_SERIES))
+
+#elif (defined(K22F12810_SERIES))
+
+ /* Clock System Level API header file */
+ #include "../src/clock/MK22F12810/fsl_clock_MK22F12810.h"
+
+#elif (defined(K22F25612_SERIES))
+
+ /* Clock System Level API header file */
+ #include "../src/clock/MK22F25612/fsl_clock_MK22F25612.h"
+
+
+
+#elif (defined(K22F51212_SERIES))
+
+ /* Clock System Level API header file */
+ #include "../src/clock/MK22F51212/fsl_clock_MK22F51212.h"
+
+
+#elif (defined(K24F12_SERIES))
+
+ /* Clock System Level API header file */
+ #include "../src/clock/MK24F12/fsl_clock_MK24F12.h"
+
+
+#elif (defined(K24F25612_SERIES))
+
+ #include "../src/clock/MK24F25612/fsl_clock_MK24F25612.h"
+
+#elif (defined(K26F18_SERIES))
+
+ /* Clock System Level API header file */
+ #include "../src/clock/MK26F18/fsl_clock_MK26F18.h"
+
+#elif (defined(K10D10_SERIES))
+#include "../src/clock/MK10D10/fsl_clock_MK10D10.h"
+
+#elif (defined(K20D10_SERIES))
+#include "../src/clock/MK20D10/fsl_clock_MK20D10.h"
+
+#elif (defined(K30D10_SERIES))
+#include "../src/clock/MK30D10/fsl_clock_MK30D10.h"
+
+#elif (defined(K40D10_SERIES))
+#include "../src/clock/MK40D10/fsl_clock_MK40D10.h"
+
+#elif (defined(K50D10_SERIES))
+#include "../src/clock/MK50D10/fsl_clock_MK50D10.h"
+
+#elif (defined(K51D10_SERIES))
+#include "../src/clock/MK51D10/fsl_clock_MK51D10.h"
+
+#elif (defined(K52D10_SERIES))
+#include "../src/clock/MK52D10/fsl_clock_MK52D10.h"
+
+#elif (defined(K53D10_SERIES))
+#include "../src/clock/MK53D10/fsl_clock_MK53D10.h"
+
+#elif (defined(K60D10_SERIES))
+
+ /* Clock System Level API header file */
+ #include "../src/clock/MK60D10/fsl_clock_MK60D10.h"
+
+#elif (defined(K63F12_SERIES))
+
+ /* Clock System Level API header file */
+ #include "../src/clock/MK63F12/fsl_clock_MK63F12.h"
+
+#elif (defined(K64F12_SERIES))
+
+ /* Clock System Level API header file */
+ #include "../src/clock/MK64F12/fsl_clock_MK64F12.h"
+
+#elif (defined(K65F18_SERIES))
+
+ /* Clock System Level API header file */
+ #include "../src/clock/MK65F18/fsl_clock_MK65F18.h"
+
+#elif (defined(K66F18_SERIES))
+
+ /* Clock System Level API header file */
+ #include "../src/clock/MK66F18/fsl_clock_MK66F18.h"
+
+#elif (defined(K70F12_SERIES))
+
+
+#elif (defined(K70F15_SERIES))
+
+
+#elif (defined(KL02Z4_SERIES))
+/* Clock System Level API header file */
+#include "../src/clock/MKL02Z4/fsl_clock_MKL02Z4.h"
+#elif (defined(KL03Z4_SERIES))
+
+ /* Clock System Level API header file */
+ #include "../src/clock/MKL03Z4/fsl_clock_MKL03Z4.h"
+
+#elif (defined(KL28T7_SERIES))
+#include "../src/clock/MKL28T7/fsl_clock_MKL28T7.h"
+
+#elif (defined(KL05Z4_SERIES))
+
+#elif (defined(KL13Z4_SERIES))
+
+#elif (defined(KL14Z4_SERIES))
+#include "../src/clock/MKL14Z4/fsl_clock_MKL14Z4.h"
+
+#elif (defined(KL15Z4_SERIES))
+#include "../src/clock/MKL15Z4/fsl_clock_MKL15Z4.h"
+
+#elif (defined(KL16Z4_SERIES))
+/* Clock System Level API header file */
+#include "../src/clock/MKL16Z4/fsl_clock_MKL16Z4.h"
+
+#elif (defined(KL23Z4_SERIES))
+
+#elif (defined(KL24Z4_SERIES))
+#include "../src/clock/MKL24Z4/fsl_clock_MKL24Z4.h"
+
+#elif (defined(KL25Z4_SERIES))
+/* Clock System Level API header file */
+#include "../src/clock/MKL25Z4/fsl_clock_MKL25Z4.h"
+
+#elif (defined (KL17Z644_SERIES))
+#include "../src/clock/MKL17Z644/fsl_clock_MKL17Z644.h"
+
+#elif (defined (KL27Z644_SERIES))
+#include "../src/clock/MKL27Z644/fsl_clock_MKL27Z644.h"
+
+#elif (defined(KL26Z4_SERIES))
+ /* Clock System Level API header file */
+ #include "../src/clock/MKL26Z4/fsl_clock_MKL26Z4.h"
+
+#elif (defined(KL17Z4_SERIES))
+#include "../src/clock/MKL17Z4/fsl_clock_MKL17Z4.h"
+
+#elif (defined(KL27Z4_SERIES))
+#include "../src/clock/MKL27Z4/fsl_clock_MKL27Z4.h"
+
+#elif (defined(KL33Z4_SERIES))
+#include "../src/clock/MKL33Z4/fsl_clock_MKL33Z4.h"
+
+#elif (defined(KL34Z4_SERIES))
+#include "../src/clock/MKL34Z4/fsl_clock_MKL34Z4.h"
+
+#elif (defined(KL43Z4_SERIES))
+#include "../src/clock/MKL43Z4/fsl_clock_MKL43Z4.h"
+
+#elif (defined(KL16Z4_SERIES))
+#include "../src/clock/MKL16Z4/fsl_clock_MKL16Z4.h"
+
+#elif (defined(KL26Z4_SERIES))
+#include "../src/clock/MKL26Z4/fsl_clock_MKL26Z4.h"
+
+#elif (defined(KL36Z4_SERIES))
+#include "../src/clock/MKL36Z4/fsl_clock_MKL36Z4.h"
+
+#elif (defined(KL46Z4_SERIES))
+
+ /* Clock System Level API header file */
+ #include "../src/clock/MKL46Z4/fsl_clock_MKL46Z4.h"
+
+#elif (defined(KV30F12810_SERIES))
+ /* Clock System Level API header file */
+ #include "../src/clock/MKV30F12810/fsl_clock_MKV30F12810.h"
+
+#elif (defined(KV31F12810_SERIES))
+
+ /* Clock System Level API header file */
+ #include "../src/clock/MKV31F12810/fsl_clock_MKV31F12810.h"
+
+#elif (defined(KV31F25612_SERIES))
+
+ /* Clock System Level API header file */
+ #include "../src/clock/MKV31F25612/fsl_clock_MKV31F25612.h"
+
+
+#elif (defined(KV31F51212_SERIES))
+
+ /* Clock System Level API header file */
+ #include "../src/clock/MKV31F51212/fsl_clock_MKV31F51212.h"
+
+#elif (defined(KV40F15_SERIES))
+
+ #include "../src/clock/MKV40F15/fsl_clock_MKV40F15.h"
+
+#elif (defined(KV43F15_SERIES))
+
+ #include "../src/clock/MKV43F15/fsl_clock_MKV43F15.h"
+
+#elif (defined(KV44F15_SERIES))
+
+ #include "../src/clock/MKV44F15/fsl_clock_MKV44F15.h"
+
+#elif (defined(KV45F15_SERIES))
+
+ #include "../src/clock/MKV45F15/fsl_clock_MKV45F15.h"
+
+#elif (defined(KV46F15_SERIES))
+
+ #include "../src/clock/MKV46F15/fsl_clock_MKV46F15.h"
+
+#elif (defined(KV10Z7_SERIES))
+
+ #include "../src/clock/MKV10Z7/fsl_clock_MKV10Z7.h"
+
+#elif (defined(KW01Z4_SERIES))
+
+ /* Clock System Level API header file */
+ #include "../src/clock/MKW01Z4/fsl_clock_MKW01Z4.h"
+
+#elif (defined(K11DA5_SERIES))
+
+ #include "../src/clock/MK11DA5/fsl_clock_MK11DA5.h"
+
+#elif (defined(K21DA5_SERIES))
+
+ #include "../src/clock/MK21DA5/fsl_clock_MK21DA5.h"
+
+
+#elif (defined(KW21D5_SERIES))
+ #include "../src/clock/MKW21D5/fsl_clock_MKW21D5.h"
+#elif (defined(K21FA12_SERIES))
+ #include "../src/clock/MK21FA12/fsl_clock_MK21FA12.h"
+
+#elif (defined(KW22D5_SERIES))
+
+ #include "../src/clock/MKW22D5/fsl_clock_MKW22D5.h"
+
+#elif (defined(KW24D5_SERIES))
+
+ #include "../src/clock/MKW24D5/fsl_clock_MKW24D5.h"
+
+#else
+ #error "No valid CPU defined!"
+#endif
+
+#if (defined(CLOCK_USE_SCG)) // If SCG is used.
+
+#else
+
+/*! @brief OSC configuration for OSCERCLK. */
+typedef struct OscerConfig
+{
+ bool enable; /*!< OSCERCLK enable or not. */
+ bool enableInStop; /*!< OSCERCLK enable or not in stop mode. */
+#if FSL_FEATURE_OSC_HAS_EXT_REF_CLOCK_DIVIDER
+ uint8_t erclkDiv; /*!< Divider for OSCERCLK. */
+#endif
+} oscer_config_t;
+
+/*!
+ * @brief OSC Initialization Configuration Structure
+ *
+ * Defines the configuration data structure to initialize the OSC.
+ * When porting to a new board, please set the following members
+ * according to board setting:
+ * 1. freq: The external frequency.
+ * 2. hgo/range/erefs: These members should be set base on the board setting.
+ */
+typedef struct OscUserConfig
+{
+ uint32_t freq; /*!< External clock frequency. */
+
+ /*------------------- Configuration for oscillator. ----------------------*/
+ bool enableCapacitor2p; /*!< Enable 2pF capacitor load. */
+ bool enableCapacitor4p; /*!< Enable 4pF capacitor load. */
+ bool enableCapacitor8p; /*!< Enable 8pF capacitor load. */
+ bool enableCapacitor16p; /*!< Enable 16pF capacitor load. */
+#if !(defined(FSL_FEATURE_MCGLITE_HAS_HGO0) && (!FSL_FEATURE_MCGLITE_HAS_HGO0))
+ osc_gain_t hgo; /*!< High gain oscillator select. */
+#endif
+#if !(defined(FSL_FEATURE_MCGLITE_HAS_RANGE0) && (!FSL_FEATURE_MCGLITE_HAS_RANGE0))
+ osc_range_t range; /*!< Oscillator range setting. */
+#endif
+#if defined(CLOCK_USE_MCG)
+ osc_src_t erefs; /*!< External reference select. */
+#else
+ osc_src_t erefs; /*!< External reference select. */
+#endif
+
+ /*------------------- Configuration for OSCERCLK. ------------------------*/
+ oscer_config_t oscerConfig; /*!< Configuration for OSCERCLK. */
+} osc_user_config_t;
+#endif
+
+/*!
+ * @brief RTC OSC Initialization Configuration Structure
+ *
+ * Defines the configuration data structure to initialize the RTC OSC.
+ * When porting to a new board, please set the following members
+ * according to board setting:
+ * 1. freq: The external frequency for RTC.
+ * 2. enableOSC: RTC could use its dedicate OSC, or override the OSC0 setting
+ * and use OSC0, or use external input clock directly. This is different by
+ * SOC and board setting, please set this correctly.
+ */
+typedef struct RtcOscUserConfig
+{
+ uint32_t freq; /*!< External clock frequency. */
+ bool enableCapacitor2p; /*!< Enable 2pF capacitor load. */
+ bool enableCapacitor4p; /*!< Enable 4pF capacitor load. */
+ bool enableCapacitor8p; /*!< Enable 8pF capacitor load. */
+ bool enableCapacitor16p; /*!< Enable 16pF capacitor load. */
+ bool enableOsc; /*!< Enable OSC or use external clock directly.*/
+ bool enableClockOutput; /*!< Output clock to other peripherals or not. */
+} rtc_osc_user_config_t;
+
+#if (defined(CLOCK_USE_SCG)) // If SCG is used.
+
+#elif (defined(CLOCK_USE_MCG_LITE))
+/*! @brief MCG_LITE configure structure for mode change. */
+typedef struct McgliteConfig
+{
+ mcglite_mode_t mcglite_mode; /*!< MCG_LITE mode. */
+
+ bool irclkEnable; /*!< MCGIRCLK enable. */
+ bool irclkEnableInStop; /*!< MCGIRCLK enable in stop mode.*/
+ mcglite_lirc_select_t ircs; /*!< MCG_C2[IRCS]. */
+ mcglite_lirc_div_t fcrdiv; /*!< MCG_SC[FCRDIV]. */
+ mcglite_lirc_div_t lircDiv2; /*!< MCG_MC[LIRC_DIV2]. */
+ bool hircEnableInNotHircMode; /*!< HIRC enable when not in HIRC mode. */
+} mcglite_config_t;
+#else
+/*! @brief MCG configure structure for mode change.
+ *
+ * When porting to a new board, please set the following members
+ * according to board setting:
+ * 1. frdiv: If FLL uses the external reference clock, please set this
+ * value to make sure external reference clock divided by frdiv is
+ * in the range 31.25kHz to 39.0625kHz.
+ * 2. prdiv0/vdiv0/prdiv1/vdiv1: Please set these values for PLL, the
+ * PLL reference clock frequency after prdiv should be in the range
+ * of FSL_FEATURE_MCG_PLL_REF_MIN to FSL_FEATURE_MCG_PLL_REF_MAX.
+ */
+typedef struct McgConfig
+{
+ mcg_modes_t mcg_mode; /*!< MCG mode. */
+
+ /* ------------------ MCGIRCCLK settings ---------------------- */
+ bool irclkEnable; /*!< MCGIRCLK enable. */
+ bool irclkEnableInStop; /*!< MCGIRCLK enable in stop mode. */
+ mcg_irc_mode_t ircs; /*!< MCG_C2[IRCS]. */
+ uint8_t fcrdiv; /*!< MCG_SC[FCRDIV]. */
+
+ /* -------------------- MCG FLL settings ---------------------- */
+ uint8_t frdiv; /*!< MCG_C1[FRDIV]. */
+ mcg_dco_range_select_t drs; /*!< MCG_C4[DRST_DRS]. */
+ mcg_dmx32_select_t dmx32; /*!< MCG_C4[DMX32]. */
+#if FSL_FEATURE_MCG_USE_OSCSEL
+ mcg_oscsel_select_t oscsel; /*!< MCG_C7[OSCSEL]. */
+#endif
+
+ /* -------------------- MCG PLL settings ---------------------- */
+#if FSL_FEATURE_MCG_HAS_PLL
+ bool pll0EnableInFllMode; /*!< PLL0 enable in FLL mode. */
+ bool pll0EnableInStop; /*!< PLL0 enable in stop mode. */
+ uint8_t prdiv0; /*!< PRDIV0. */
+ uint8_t vdiv0; /*!< VDIV0. */
+#if FSL_FEATURE_MCG_HAS_PLL1
+ bool pll1EnableInFllMode; /*!< PLL1 enable in FLL mode. */
+ bool pll2EnableInStop; /*!< PLL1 enable in stop mode. */
+ uint8_t prdiv1; /*!< PRDIV1. */
+ uint8_t vdiv1; /*!< VDIV1. */
+#endif
+#if (FSL_FEATURE_MCG_HAS_PLL1 || FSL_FEATURE_MCG_HAS_EXTERNAL_PLL)
+ mcg_pll_clk_select_t pllcs; /*!< MCG_C11[PLLCS]. */
+#endif
+#endif
+} mcg_config_t;
+#endif
+
+/*! @brief Clock configuration structure. */
+typedef struct ClockUserConfig
+{
+#if (defined(CLOCK_USE_SCG)) // If use SCG, then OSC is also controled by SCG.
+
+#else // Not use SCG.
+#if (defined(CLOCK_USE_MCG_LITE)) // USE MCG_LITE.
+ mcglite_config_t mcgliteConfig; /*!< MCGLite configuration. */
+#else
+ mcg_config_t mcgConfig; /*!< MCG configuration. */
+#endif
+ oscer_config_t oscerConfig; /*!< OSCERCLK configuration. */
+#endif
+
+ sim_config_t simConfig; /*!< SIM configuration. */
+} clock_manager_user_config_t;
+
+/*! @brief The clock notification type. */
+typedef enum _clock_manager_notify
+{
+ kClockManagerNotifyRecover = 0x00U, /*!< Notify IP to recover to previous work state. */
+ kClockManagerNotifyBefore = 0x01U, /*!< Notify IP that system will change clock setting. */
+ kClockManagerNotifyAfter = 0x02U, /*!< Notify IP that have changed to new clock setting. */
+} clock_manager_notify_t;
+
+/*! @brief The callback type, indicates what kinds of notification this callback handles. */
+typedef enum _clock_manager_callback_type
+{
+ kClockManagerCallbackBefore = 0x01U, /*!< Callback handles BEFORE notification. */
+ kClockManagerCallbackAfter = 0x02U, /*!< Callback handles AFTER notification. */
+ kClockManagerCallbackBeforeAfter = 0x03U /*!< Callback handles BEFORE and AFTER notification */
+} clock_manager_callback_type_t;
+
+/*! @brief Clock transition policy. */
+typedef enum ClockManagerPolicy
+{
+ kClockManagerPolicyAgreement, /*!< Clock transfers gracefully. */
+ kClockManagerPolicyForcible /*!< Clock transfers forcefully. */
+} clock_manager_policy_t;
+
+/*! @brief Clock notification structure passed to clock callback function. */
+typedef struct ClockNotifyStruct
+{
+ uint8_t targetClockConfigIndex; /*!< Target clock configuration index. */
+ clock_manager_policy_t policy; /*!< Clock transition policy. */
+ clock_manager_notify_t notifyType; /*!< Clock notification type. */
+} clock_notify_struct_t;
+
+/*! @brief Type of clock callback functions. */
+typedef clock_manager_error_code_t (*clock_manager_callback_t)(clock_notify_struct_t *notify,
+ void* callbackData);
+
+/*! @brief Structure for callback function and its parameter. */
+typedef struct ClockManagerCallbackUserConfig
+{
+ clock_manager_callback_t callback; /*!< Entry of callback function. */
+ clock_manager_callback_type_t callbackType; /*!< Callback type. */
+ void* callbackData; /*!< Parameter of callback function. */
+} clock_manager_callback_user_config_t;
+
+/*! @brief Clock manager state structure. */
+typedef struct ClockManagerState
+{
+ clock_manager_user_config_t const **configTable;/*!< Pointer to clock configure table.*/
+ uint8_t clockConfigNum; /*!< Number of clock configurations. */
+ uint8_t curConfigIndex; /*!< Index of current configuration. */
+ clock_manager_callback_user_config_t **callbackConfig; /*!< Pointer to callback table. */
+ uint8_t callbackNum; /*!< Number of clock callbacks. */
+ uint8_t errorCallbackIndex; /*!< Index of callback returns error. */
+} clock_manager_state_t;
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @name Dynamic clock setting
+ * @{
+ */
+
+/*!
+ * @brief Install pre-defined clock configurations.
+ *
+ * This function installs the pre-defined clock configuration table to
+ * clock manager.
+ *
+ * @param clockConfigsPtr Pointer to the clock configuration table.
+ * @param configsNumber Number of clock configurations in table.
+ * @param callbacksPtr Pointer to the callback configuration table.
+ * @param callbacksNumber Number of callback configurations in table.
+ *
+ * @return Error code.
+ */
+clock_manager_error_code_t CLOCK_SYS_Init(clock_manager_user_config_t const **clockConfigsPtr,
+ uint8_t configsNumber,
+ clock_manager_callback_user_config_t **callbacksPtr,
+ uint8_t callbacksNumber);
+
+/*!
+ * @brief Set system clock configuration according to pre-defined structure.
+ *
+ * This function sets system to target clock configuration, before transition,
+ * clock manager will send notifications to all drivers registered to the
+ * callback table. When graceful policy is used, if some drivers are not ready
+ * to change, clock transition will not occur, all drivers still work in
+ * previous configuration and error is returned. When forceful policy is used,
+ * all drivers should stop work and system changes to new clock configuration.
+ *
+ * @param targetConfigIndex Index of the clock configuration.
+ * @param policy Transaction policy, graceful or forceful.
+ *
+ * @return Error code.
+ *
+ * @note If external clock is used in the target mode, please make sure it is
+ * enabled, for example, if the external oscillator is used, please setup
+ * EREFS/HGO correctly and make sure OSCINIT is set.
+ */
+clock_manager_error_code_t CLOCK_SYS_UpdateConfiguration(uint8_t targetConfigIndex,
+ clock_manager_policy_t policy);
+
+/*!
+ * @brief Set system clock configuration.
+ *
+ * This funtion sets the system to target configuration, it only sets the
+ * clock modules registers for clock mode change, but not send notifications
+ * to drivers. This function is different by different SoCs.
+ *
+ * @param config Target configuration.
+ *
+ * @return Error code.
+ *
+ * @note If external clock is used in the target mode, please make sure it is
+ * enabled, for example, if the external oscillator is used, please setup
+ * EREFS/HGO correctly and make sure OSCINIT is set.
+ */
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const * config);
+
+/*!
+ * @brief Get current system clock configuration.
+ *
+ * @return Current clock configuration index.
+ */
+uint8_t CLOCK_SYS_GetCurrentConfiguration(void);
+
+/*!
+ * @brief Get the callback which returns error in last clock switch.
+ *
+ * When graceful policy is used, if some IP is not ready to change clock
+ * setting, the callback will return error and system stay in current
+ * configuration. Applications can use this function to check which
+ * IP callback returns error.
+ *
+ * @return Pointer to the callback which returns error.
+ */
+clock_manager_callback_user_config_t* CLOCK_SYS_GetErrorCallback(void);
+
+#if (defined(CLOCK_USE_SCG))
+
+#elif (defined(CLOCK_USE_MCG_LITE))
+/*!
+ * @brief Sets the MCG_Lite to some specific mode.
+ *
+ * This function sets the MCG_lite to some mode according to configuration
+ * parameter.
+ *
+ * @param targetConfig Pointer to the configure structure.
+ *
+ * @return Error code.
+ */
+mcglite_mode_error_t CLOCK_SYS_SetMcgliteMode(mcglite_config_t const *targetConfig);
+#else
+/*!
+ * @brief Set MCG to some target mode.
+ *
+ * This function sets MCG to some target mode defined by the configure
+ * structure, if cannot switch to target mode directly, this function will
+ * choose the proper path.
+ * @param targetConfig Pointer to the target MCG mode configuration structure.
+ * @param fllStableDelay Delay function to make sure FLL is stable.
+ * @return Error code.
+ *
+ * @note If external clock is used in the target mode, please make sure it is
+ * enabled, for example, if the external oscillator is used, please setup
+ * EREFS/HGO correctly and make sure OSCINIT is set.
+ */
+mcg_mode_error_t CLOCK_SYS_SetMcgMode(mcg_config_t const *targetConfig,
+ void (* fllStableDelay)(void));
+#endif
+
+/* @} */
+
+/*!
+ * @name OSC configuration
+ * @{
+ */
+
+/*!
+ * @brief Initialize OSC.
+ *
+ * This function initializes OSC according to board configuration.
+ *
+ * @param instance Instance of the OSC.
+ * @param config Pointer to the OSC configuration structure.
+ * @return kClockManagerSuccess on success.
+ */
+clock_manager_error_code_t CLOCK_SYS_OscInit(uint32_t instance,
+ osc_user_config_t *config);
+
+/*!
+ * @brief Deinitialize OSC.
+ *
+ * This function deinitializes OSC.
+ * @param instance Instance of the OSC.
+ */
+void CLOCK_SYS_OscDeinit(uint32_t instance);
+
+/*!
+ * @brief Configure the OSCERCLK.
+ *
+ * This function configures the OSCERCLK, including whether OSCERCLK is enable
+ * or not in normal mode and stop mode.
+ *
+ * @param instance Instance of the OSC.
+ * @param config Pointer to the OSCERCLK configuration structure.
+ */
+void CLOCK_SYS_SetOscerConfigration(uint32_t instance, oscer_config_t const *config);
+
+/* @} */
+
+#if defined(RTC_INSTANCE_COUNT)
+/*!
+ * @name RTC OSC configuration
+ * @{
+ */
+
+/*!
+ * @brief Initialize the RTC OSC.
+ *
+ * This function initializes the RTC OSC according to board configuration.
+ *
+ * @param instance Instance of the RTC OSC.
+ * @param config Pointer to the configuration structure.
+ * @return kClockManagerSuccess on success.
+ */
+clock_manager_error_code_t CLOCK_SYS_RtcOscInit(uint32_t instance,
+ rtc_osc_user_config_t *config);
+
+/*!
+ * @brief Deinitialize RTC OSC.
+ *
+ * This function deinitializes RTC OSC.
+ * @param instance Instance of the RTC OSC.
+ */
+void CLOCK_SYS_RtcOscDeinit(uint32_t instance);
+
+/* @} */
+#endif
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_MANAGER_H__*/
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/inc/fsl_hwtimer.h b/KSDK_1.2.0/platform/system/inc/fsl_hwtimer.h
new file mode 100755
index 0000000..3bd2afa
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/inc/fsl_hwtimer.h
@@ -0,0 +1,462 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __FSL_HWTIMER_H__
+#define __FSL_HWTIMER_H__
+
+#include <stdint.h>
+#include "fsl_clock_manager.h"
+
+/*!
+ * @addtogroup hwtimer_driver
+ * @{
+ */
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/*!
+ * @brief Hwtimer error codes definition.
+ */
+typedef enum _hwtimer_error_code
+{
+ kHwtimerSuccess, /*!< success */
+ kHwtimerInvalidInput, /*!< invalid input parameter */
+ kHwtimerInvalidPointer, /*!< invalid pointer */
+ kHwtimerClockManagerError, /*!< clock manager return error */
+ kHwtimerRegisterHandlerError, /*!< Interrupt handler registration returns error */
+ kHwtimerUnknown, /*!< unknown error*/
+} _hwtimer_error_code_t;
+
+/*!
+ * @brief Hwtimer low level context data length definition.
+ */
+#define HWTIMER_LL_CONTEXT_LEN 5U
+
+/*!
+ * @brief Define for low level context data length
+ */
+typedef void (* hwtimer_callback_t)(void *p);
+
+/*!
+ * @brief Hwtimer structure.
+ *
+ * This structure defines a hwtimer.
+ * The context structure is passed to all API functions (besides other parameters).
+ *
+ * @warning Application should not access members of this structure directly.
+ *
+ * @see HWTIMER_SYS_init
+ * @see HWTIMER_SYS_deinit
+ * @see HWTIMER_SYS_start
+ * @see HWTIMER_SYS_stop
+ * @see HWTIMER_SYS_set_period
+ * @see HWTIMER_SYS_get_period
+ * @see HWTIMER_SYS_get_modulo
+ * @see HWTIMER_SYS_get_time
+ * @see HWTIMER_SYS_get_ticks
+ * @see HWTIMER_SYS_callback_reg
+ * @see HWTIMER_SYS_callback_block
+ * @see HWTIMER_SYS_callback_unblock
+ * @see HWTIMER_SYS_callback_cancel
+ */
+typedef struct Hwtimer
+{
+ /*! @brief Pointer to device interface structure */
+ const struct Hwtimer_devif * devif;
+ /*! @brief Timer's source clock frequency */
+ uint32_t clockFreq;
+ /*! @brief Actual total divider */
+ uint32_t divider;
+ /*! @brief Determine how many sub ticks are in one tick */
+ uint32_t modulo;
+ /*! @brief Number of elapsed ticks */
+ volatile uint64_t ticks;
+ /*! @brief Function pointer to be called when the timer expires. */
+ hwtimer_callback_t callbackFunc;
+ /*! @brief Arbitrary pointer passed as parameter to the callback function. */
+ void *callbackData;
+ /*! @brief Indicate pending callback.
+ * If the timer overflows when callbacks are blocked the callback becomes pending. */
+ volatile int callbackPending;
+ /*! @brief Indicate blocked callback. */
+ int callbackBlocked;
+ /*! @brief Private storage locations for arbitrary data keeping the context of the lower layer driver. */
+ uint32_t llContext[HWTIMER_LL_CONTEXT_LEN];
+} hwtimer_t, * hwtimer_ptr_t;
+
+/*!
+ * @brief Hwtimer_time structure.
+ *
+ * Hwtimer time structure represents a time stamp consisting of timer elapsed periods (TICKS) and current value of the timer counter (subTicks).
+ *
+ * @see HWTIMER_SYS_GetTime
+ */
+typedef struct Hwtimer_time
+{
+ /*! @brief Ticks of timer */
+ uint64_t ticks;
+ /*! @brief Sub ticks of timer */
+ uint32_t subTicks;
+} hwtimer_time_t, * hwtimer_time_ptr_t;
+
+/*!
+ * @brief Type defines init function for devif structure.
+ */
+typedef _hwtimer_error_code_t (* hwtimer_devif_init_t)(hwtimer_t *hwtimer, uint32_t id, void *data);
+
+/*!
+ * @brief Type defines deinit function for devif structure.
+ */
+typedef _hwtimer_error_code_t (* hwtimer_devif_deinit_t)(hwtimer_t *hwtimer);
+
+/*!
+ * @brief Type defines set_div function for devif structure.
+ */
+typedef _hwtimer_error_code_t (* hwtimer_devif_set_div_t)(hwtimer_t *hwtimer, uint32_t period);
+
+/*!
+ * @brief Type defines start function for devif structure.
+ */
+typedef _hwtimer_error_code_t (* hwtimer_devif_start_t)(hwtimer_t *hwtimer);
+
+/*!
+ * @brief Type defines stop function for devif structure.
+ */
+typedef _hwtimer_error_code_t (* hwtimer_devif_stop_t)(hwtimer_t *hwtimer);
+
+/*!
+ * @brief Type defines reset function for devif structure.
+ */
+typedef _hwtimer_error_code_t (* hwtimer_devif_reset_t)(hwtimer_t *hwtimer);
+
+/*!
+ * @brief Type defines get_time function for devif structure.
+ */
+typedef _hwtimer_error_code_t (* hwtimer_devif_get_time_t)(hwtimer_t *hwtimer, hwtimer_time_t *time);
+
+/*!
+ * @brief hwtimer_devif structure.
+ *
+ * Each low layer driver exports instance of this structure initialized with pointers to API functions the driver implements.
+ * The functions themselves should be declared as static (not exported directly).
+ *
+ * @see HWTIMER_SYS_Init
+ * @see HWTIMER_SYS_Deinit
+ */
+typedef struct Hwtimer_devif
+{
+ /*! @brief Function pointer to lower layer initialization */
+ hwtimer_devif_init_t init;
+ /*! @brief Function pointer to lower layer de-initialization */
+ hwtimer_devif_deinit_t deinit;
+ /*! @brief Function pointer to lower layer set divider functionality */
+ hwtimer_devif_set_div_t setDiv;
+ /*! @brief Function pointer to lower layer start functionality */
+ hwtimer_devif_start_t start;
+ /*! @brief Function pointer to lower layer stop functionality */
+ hwtimer_devif_stop_t stop;
+ /*! @brief Function pointer to lower layer get time functionality */
+ hwtimer_devif_get_time_t getTime;
+} hwtimer_devif_t, * hwtimer_devif_ptr_t;
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/*!
+ * @brief Initializes caller allocated structure according to given parameters.
+ *
+ * The device interface pointer determines low layer driver to be used.
+ * Device interface structure is exported by each low layer driver and is opaque to the applications.
+ * Please refer to chapter concerning low layer driver below for details.
+ * Meaning of the numerical identifier varies depending on low layer driver used.
+ * Typically, it identifies particular timer channel to initialize.
+ * The initialization function has to be called prior using any other API function.
+ *
+ * @param hwtimer [out] Returns initialized hwtimer structure handle.
+ * @param kDevif [in] Structure determines low layer driver to be used.
+ * @param id [in] Numerical identifier of the timer.
+ * @param data [in] Specific data for low level of interrupt.
+ *
+ * @return success or an error code returned from low level init function.
+ * @retval kHwtimerSuccess Success
+ * @retval kHwtimerInvalidInput When input parameter hwtimer is a NULL pointer
+ * @retval kHwtimerInvalidPointer When device structure points to NULL.
+ *
+ * @warning The initialization function has to be called prior using any other API function.
+ *
+ * @see HWTIMER_SYS_deinit
+ * @see HWTIMER_SYS_start
+ * @see HWTIMER_SYS_stop
+ */
+_hwtimer_error_code_t HWTIMER_SYS_Init(hwtimer_t *hwtimer, const hwtimer_devif_t * kDevif, uint32_t id, void *data);
+
+/*!
+ * @brief De-initialization of the hwtimer.
+ *
+ * Calls lower layer stop function to stop timer, then calls low layer de-initialization function
+ * and afterwards invalidates hwtimer structure by clearing it.
+ *
+ * @param hwtimer [in] Pointer to hwtimer structure.
+ *
+ * @return success or an error code returned from low level DEINIT function.
+ * @retval kHwtimerSuccess Success
+ * @retval kHwtimerInvalidInput When input parameter hwtimer is a NULL pointer
+ * @retval kHwtimerInvalidPointer When device structure points to NULL.
+ *
+ * @see HWTIMER_SYS_Init
+ * @see HWTIMER_SYS_Start
+ * @see HWTIMER_SYS_Stop
+ */
+_hwtimer_error_code_t HWTIMER_SYS_Deinit(hwtimer_t *hwtimer);
+
+/*!
+ * @brief Set period of hwtimer.
+ *
+ * The function provides a way to set up the timer to desired period specified in microseconds.
+ * Calls the low layer driver to set up the timer divider according to the specified period.
+ *
+ * @param hwtimer [in] Pointer to hwtimer structure.
+ * @param period [in] Required period of timer in micro seconds.
+ *
+ * @return success or an error code returned from low level SETDIV function.
+ * @retval kHwtimerSuccess Success
+ * @retval kHwtimerInvalidInput When input parameter hwtimer or his device structure are NULL pointers.
+ * @retval kHwtimerInvalidPointer When low level SETDIV function point to NULL.
+ * @retval kHwtimerClockManagerError When Clock manager returns error.
+ *
+ * @see HWTIMER_SYS_GetPeriod
+ * @see HWTIMER_SYS_GetModulo
+ * @see HWTIMER_SYS_GetTime
+ * @see HWTIMER_SYS_GetTicks
+ */
+_hwtimer_error_code_t HWTIMER_SYS_SetPeriod(hwtimer_t *hwtimer, uint32_t period);
+
+/*!
+ * @brief Get period of hwtimer.
+ *
+ * The function returns current period of the timer in microseconds calculated from the base frequency and actual divider settings of the timer.
+ *
+ * @param hwtimer [in] Pointer to hwtimer structure.
+ *
+ * @return already set period of hwtimer.
+ * @retval 0 Input parameter hwtimer is NULL pointer or clock manager returns error.
+ *
+ * @see HWTIMER_SYS_SetPeriod
+ * @see HWTIMER_SYS_GetModulo
+ * @see HWTIMER_SYS_GetTime
+ * @see HWTIMER_SYS_GetTicks
+ */
+uint32_t HWTIMER_SYS_GetPeriod(hwtimer_t *hwtimer);
+
+/*!
+ * @brief Enables the timer and leaves it running.
+ *
+ * The timer starts counting a new period generating interrupts every time the timer rolls over.
+ *
+ * @param hwtimer [in] Pointer to hwtimer structure.
+ *
+ * @return success or an error code returned from low level START function.
+ * @retval kHwtimerSuccess Success
+ * @retval kHwtimerInvalidInput When input parameter hwtimer is a NULL pointer
+ * @retval kHwtimerInvalidPointer When device structure points to NULL.
+ *
+ * @see HWTIMER_SYS_Init
+ * @see HWTIMER_SYS_Deinit
+ * @see HWTIMER_SYS_Stop
+ */
+_hwtimer_error_code_t HWTIMER_SYS_Start(hwtimer_t *hwtimer);
+
+/*!
+ * @brief The timer stops counting after this function is called.
+ *
+ * Pending interrupts and callbacks are cancelled.
+ *
+ * @param hwtimer [in] Pointer to hwtimer structure.
+ *
+ * @return success or an error code returned from low level STOP function.
+ * @retval kHwtimerSuccess Success
+ * @retval kHwtimerInvalidInput When input parameter hwtimer is a NULL pointer
+ * @retval kHwtimerInvalidPointer When device structure points to NULL.
+ *
+ * @see HWTIMER_SYS_Init
+ * @see HWTIMER_SYS_Deinit
+ * @see HWTIMER_SYS_Start
+ */
+_hwtimer_error_code_t HWTIMER_SYS_Stop(hwtimer_t *hwtimer);
+
+/*!
+ * @brief The function returns period of the timer in sub-ticks.
+ *
+ * It is typically called after HWTIMER_SYS_SetPeriod() to obtain actual resolution of the timer in the current configuration.
+ *
+ * @param hwtimer [in] Pointer to hwtimer structure.
+ *
+ * @return resolution of hwtimer.
+ * @retval 0 Input parameter hwtimer is NULL pointer.
+ *
+ * @see HWTIMER_SYS_SetPeriod
+ * @see HWTIMER_SYS_GetPeriod
+ * @see HWTIMER_SYS_GetTime
+ * @see HWTIMER_SYS_GetTicks
+ */
+uint32_t HWTIMER_SYS_GetModulo(hwtimer_t *hwtimer);
+
+/*!
+ * @brief The function reads the current value of the hwtimer.
+ *
+ * Elapsed periods(ticks) and current value of the timer counter (sub-ticks) are filled into the Hwtimer_time structure.
+ * The sub-ticks number always counts up and is reset to zero when the timer overflows regardless of the counting direction of the underlying device.
+ *
+ * @param hwtimer [in] Pointer to hwtimer structure.
+ * @param time [out] Pointer to time structure. This value is filled with current value of the timer.
+ *
+ * @return success or an error code returned from low level GET_TIME function.
+ * @retval kHwtimerSuccess Success
+ * @retval kHwtimerInvalidInput When input parameter hwtimer or input parameter time are NULL pointers.
+ * @retval kHwtimerInvalidPointer When device structure points to NULL.
+ *
+ * @see HWTIMER_SYS_SetPeriod
+ * @see HWTIMER_SYS_GetPeriod
+ * @see HWTIMER_SYS_GetModulo
+ * @see HWTIMER_SYS_GetTicks
+ */
+_hwtimer_error_code_t HWTIMER_SYS_GetTime(hwtimer_t *hwtimer, hwtimer_time_t *time);
+
+/*!
+ * @brief The function reads the current value of the hwtimer
+ *
+ * The returned value corresponds with lower 32 bits of elapsed periods (ticks).
+ * The value is guaranteed to be obtained atomically without necessity to mask timer interrupt.
+ * Lower layer driver is not involved at all, thus call to this function is considerably faster than HWTIMER_SYS_GetTime.
+ *
+ * @param hwtimer [in] Pointer to hwtimer structure.
+ *
+ * @return low 32 bits of 64 bit tick value.
+ * @retval 0 When input parameter hwtimer is NULL pointer.
+ *
+ * @see HWTIMER_SYS_SetPeriod
+ * @see HWTIMER_SYS_GetPeriod
+ * @see HWTIMER_SYS_GetModulo
+ * @see HWTIMER_SYS_GetTime
+ */
+uint32_t HWTIMER_SYS_GetTicks(hwtimer_t *hwtimer);
+
+/*!
+ * @brief Registers function to be called when the timer expires.
+ *
+ * The callback_data is arbitrary pointer passed as parameter to the callback function.
+ *
+ * @param hwtimer [in] Pointer to hwtimer structure.
+ * @param callbackFunc [in] Function pointer to be called when the timer expires.
+ * @param callbackData [in] Data pointer for the function callback_func.
+ *
+ * @return success or an error code
+ * @retval kHwtimerInvalidInput When input parameter hwtimer is NULL pointer.
+ * @retval kHwtimerSuccess When registration callback succeed.
+ *
+ * @warning This function must not be called from a callback routine.
+ *
+ * @see HWTIMER_SYS_BlockCallback
+ * @see HWTIMER_SYS_UnblockCallback
+ * @see HWTIMER_SYS_CancelCallback
+ */
+_hwtimer_error_code_t HWTIMER_SYS_RegisterCallback(hwtimer_t *hwtimer, hwtimer_callback_t callbackFunc, void *callbackData);
+
+/*!
+ * @brief The function is used to block callbacks in circumstances when execution of the callback function is undesired.
+ *
+ * If the timer overflows when callbacks are blocked the callback becomes pending.
+ *
+ * @param hwtimer [in] Pointer to hwtimer structure.
+ *
+ * @return success or an error code
+ * @retval kHwtimerInvalidInput When input parameter hwtimer is NULL pointer.
+ * @retval kHwtimerSuccess When callback block succeed.
+ *
+ * @warning This function must not be called from a callback routine.
+ *
+ * @see HWTIMER_SYS_RegCallback
+ * @see HWTIMER_SYS_UnblockCallback
+ * @see HWTIMER_SYS_CancelCallback
+ */
+_hwtimer_error_code_t HWTIMER_SYS_BlockCallback(hwtimer_t *hwtimer);
+
+/*!
+ * @brief The function is used to unblock previously blocked callbacks.
+ *
+ * If there is a callback pending, it gets immediately executed.
+ * This function must not be called from a callback routine (it does not make sense to do so anyway as callback function never gets executed while callbacks are blocked).
+ *
+ * @param hwtimer [in] Pointer to hwtimer structure.
+ *
+ * @return success or an error code
+ * @retval kHwtimerInvalidInput When input parameter hwtimer is NULL pointer.
+ * @retval kHwtimerSuccess When callback unblock succeed.
+ *
+ * @warning This function must not be called from a callback routine.
+ *
+ * @see HWTIMER_SYS_RegCallback
+ * @see HWTIMER_SYS_BlockCallback
+ * @see HWTIMER_SYS_CancelCallback
+ */
+_hwtimer_error_code_t HWTIMER_SYS_UnblockCallback(hwtimer_t *hwtimer);
+
+/*!
+ * @brief The function cancels pending callback, if any.
+ *
+ * @param hwtimer [in] Pointer to hwtimer structure.
+ *
+ * @return success or an error code
+ * @retval kHwtimerInvalidInput When input parameter hwtimer is NULL pointer.
+ * @retval kHwtimerSuccess When callback cancel succeed.
+ *
+ * @warning This function must not be called from a callback routine (it does not make sense to do so anyway as callback function never gets executed while callbacks are blocked).
+ *
+ * @see HWTIMER_SYS_RegCallback
+ * @see HWTIMER_SYS_BlockCallback
+ * @see HWTIMER_SYS_UnblockCallback
+ */
+_hwtimer_error_code_t HWTIMER_SYS_CancelCallback(hwtimer_t *hwtimer);
+
+#if defined(__cplusplus)
+}
+#endif
+
+/*! @}*/
+
+#endif /* __FSL_HWTIMER_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/inc/fsl_hwtimer_pit.h b/KSDK_1.2.0/platform/system/inc/fsl_hwtimer_pit.h
new file mode 100755
index 0000000..1db82c4
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/inc/fsl_hwtimer_pit.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef __FSL_HWTIMER_PIT_H__
+#define __FSL_HWTIMER_PIT_H__
+
+#include "fsl_hwtimer.h"
+
+/*! @brief Instance of HWTIMER_DEVIF_STRUCT structure initialized
+ * with pointers to API functions the pit driver implements
+ */
+extern const hwtimer_devif_t kPitDevif;
+
+#endif /* __FSL_HWTIMER_PIT_H__ */
+/*******************************************************************************
+* EOF
+*******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/inc/fsl_hwtimer_systick.h b/KSDK_1.2.0/platform/system/inc/fsl_hwtimer_systick.h
new file mode 100755
index 0000000..a8b4b02
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/inc/fsl_hwtimer_systick.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __FSL_HWTIMER_SYSTICK_H__
+#define __FSL_HWTIMER_SYSTICK_H__
+
+#include "fsl_hwtimer.h"
+
+/*! @brief Instance of hwtimer_devif_t structure initialized
+ * with pointers to API functions the systick driver implements
+ */
+extern const hwtimer_devif_t kSystickDevif;
+
+
+#endif /* __FSL_HWTIMER_SYSTICK_H__ */
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/inc/fsl_interrupt_manager.h b/KSDK_1.2.0/platform/system/inc/fsl_interrupt_manager.h
new file mode 100755
index 0000000..fcce0e5
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/inc/fsl_interrupt_manager.h
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#if !defined(__FSL_INTERRUPT_MANAGER_H__)
+#define __FSL_INTERRUPT_MANAGER_H__
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+
+/*! @addtogroup interrupt_manager*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief interrupt status return codes.*/
+typedef enum _interrupt_status_t {
+ kStatus_INT_Success = 0x0U,
+ kStatus_INT_NoVectorInRAM = 0x1U,
+} interrupt_status_t;
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*! @name interrupt_manager APIs*/
+/*@{*/
+
+/*!
+ * @brief Installs an interrupt handler routine for a given IRQ number.
+ *
+ * This function lets the application register/replace the interrupt
+ * handler for a specified IRQ number. The IRQ number is different than the vector
+ * number. IRQ 0 starts from the vector 16 address. See a chip-specific reference
+ * manual for details and the startup_MKxxxx.s file for each chip
+ * family to find out the default interrupt handler for each device. This
+ * function converts the IRQ number to the vector number by adding 16 to
+ * it.
+ *
+ * @param irqNumber IRQ number
+ * @param handler Interrupt handler routine address pointer
+ * @return Whether the installation succeed or not
+ */
+void * INT_SYS_InstallHandler(IRQn_Type irqNumber, void (*handler)(void));
+
+/*!
+ * @brief Enables an interrupt for a given IRQ number.
+ *
+ * This function enables the individual interrupt for a specified IRQ
+ * number. It calls the system NVIC API to access the interrupt control
+ * register. The input IRQ number does not include the core interrupt, only
+ * the peripheral interrupt, from 0 to a maximum supported IRQ.
+ *
+ * @param irqNumber IRQ number
+ */
+static inline void INT_SYS_EnableIRQ(IRQn_Type irqNumber)
+{
+ /* check IRQ number */
+ assert(0 <= irqNumber);
+ assert(irqNumber <= FSL_FEATURE_INTERRUPT_IRQ_MAX);
+
+ /* call core API to enable the IRQ*/
+ NVIC_EnableIRQ(irqNumber);
+}
+
+/*!
+ * @brief Disables an interrupt for a given IRQ number.
+ *
+ * This function enables the individual interrupt for a specified IRQ
+ * number. It calls the system NVIC API to access the interrupt control
+ * register.
+ *
+ * @param irqNumber IRQ number
+ */
+static inline void INT_SYS_DisableIRQ(IRQn_Type irqNumber)
+{
+ /* check IRQ number */
+ assert(0 <= irqNumber);
+ assert(irqNumber <= FSL_FEATURE_INTERRUPT_IRQ_MAX);
+
+ /* call core API to disable the IRQ*/
+ NVIC_DisableIRQ(irqNumber);
+}
+
+/*!
+ * @brief Enables system interrupt.
+ *
+ * This function enables the global interrupt by calling the core API.
+ *
+ */
+void INT_SYS_EnableIRQGlobal(void);
+
+/*!
+ * @brief Disable system interrupt.
+ *
+ * This function disables the global interrupt by calling the core API.
+ *
+ */
+void INT_SYS_DisableIRQGlobal(void);
+
+/*@}*/
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_INTERRUPT_MANAGER_H__*/
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/inc/fsl_power_manager.h b/KSDK_1.2.0/platform/system/inc/fsl_power_manager.h
new file mode 100755
index 0000000..546a3d6
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/inc/fsl_power_manager.h
@@ -0,0 +1,645 @@
+/*
+ * Copyright (c) 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __FSL_POWER_MANAGER_H__
+#define __FSL_POWER_MANAGER_H__
+
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "fsl_smc_hal.h"
+
+/*!
+ * @addtogroup power_manager
+ * @{
+ */
+
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/*!
+ * @brief Power modes enumeration.
+ *
+ * Defines power mode. Used in the power mode configuration structure
+ * (power_manager_user_config_t). From ARM core perspective, Power modes
+ * can be generally divided to run modes (High speed run, Run and
+ * Very low power run), sleep (Wait and Very low power wait) and deep sleep modes
+ * (all Stop modes).
+ * List of power modes supported by specific chip along with requirements for entering
+ * and exiting of these modes can be found in chip documentation.
+ * List of all supported power modes:\n
+ * \li kPowerManagerHsrun - High speed run mode. Chip-specific.
+ * \li kPowerManagerRun - Run mode. All Kinetis chips.
+ * \li kPowerManagerVlpr - Very low power run mode. All Kinetis chips.
+ * \li kPowerManagerWait - Wait mode. All Kinetis chips.
+ * \li kPowerManagerVlpw - Very low power wait mode. All Kinetis chips.
+ * \li kPowerManagerStop - Stop mode. All Kinetis chips.
+ * \li kPowerManagerVlps - Very low power stop mode. All Kinetis chips.
+ * \li kPowerManagerPstop1 - Partial stop 1 mode. Chip-specific.
+ * \li kPowerManagerPstop2 - Partial stop 2 mode. Chip-specific.
+ * \li kPowerManagerLls - Low leakage stop mode. All Kinetis chips.
+ * \li kPowerManagerLls2 - Low leakage stop 2 mode. Chip-specific.
+ * \li kPowerManagerLls3 - Low leakage stop 3 mode. Chip-specific.
+ * \li kPowerManagerVlls0 - Very low leakage stop 0 mode. Chip-specific.
+ * \li kPowerManagerVlls1 - Very low leakage stop 1 mode. All Kinetis chips.
+ * \li kPowerManagerVlls2 - Very low leakage stop 2 mode. All Kinetis chips.
+ * \li kPowerManagerVlls3 - Very low leakage stop 3 mode. All Kinetis chips.
+ */
+typedef enum _power_manager_modes {
+#if FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE
+ kPowerManagerHsrun, /*!< High speed run mode. All Kinetis chips. @internal gui name="High speed run mode" */
+#endif
+ kPowerManagerRun, /*!< Run mode. All Kinetis chips. @internal gui name="Run mode" */
+ kPowerManagerVlpr, /*!< Very low power run mode. All Kinetis chips. @internal gui name="Very low power run mode" */
+ kPowerManagerWait, /*!< Wait mode. All Kinetis chips. @internal gui name="Wait mode" */
+ kPowerManagerVlpw, /*!< Very low power wait mode. All Kinetis chips. @internal gui name="Very low power wait mode" */
+ kPowerManagerStop, /*!< Stop mode. All Kinetis chips. @internal gui name="Stop mode" */
+ kPowerManagerVlps, /*!< Very low power stop mode. All Kinetis chips. @internal gui name="Very low power stop mode" */
+#if FSL_FEATURE_SMC_HAS_PSTOPO
+ kPowerManagerPstop1, /*!< Partial stop 1 mode. Chip-specific. @internal gui name="Partial stop 1 mode" */
+ kPowerManagerPstop2, /*!< Partial stop 2 mode. Chip-specific. @internal gui name="Partial stop 2 mode" */
+#endif
+#if FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE
+ kPowerManagerLls, /*!< Low leakage stop mode. All Kinetis chips. @internal gui name="Low leakage stop mode" */
+#endif
+#if FSL_FEATURE_SMC_HAS_LLS_SUBMODE
+ kPowerManagerLls2, /*!< Low leakage stop 2 mode. Chip-specific. @internal gui name="Low leakage stop 2 mode" */
+ kPowerManagerLls3, /*!< Low leakage stop 3 mode. Chip-specific. @internal gui name="Low leakage stop 3 mode" */
+#endif
+#if FSL_FEATURE_SMC_HAS_STOP_SUBMODE0
+ kPowerManagerVlls0, /*!< Very low leakage stop 0 mode. All Kinetis chips. @internal gui name="Very low leakage stop 0 mode" */
+#endif
+ kPowerManagerVlls1, /*!< Very low leakage stop 1 mode. All Kinetis chips. @internal gui name="Very low leakage stop 1 mode" */
+#if FSL_FEATURE_SMC_HAS_STOP_SUBMODE2
+ kPowerManagerVlls2, /*!< Very low leakage stop 2 mode. All Kinetis chips. @internal gui name="Very low leakage stop 2 mode" */
+#endif
+ kPowerManagerVlls3, /*!< Very low leakage stop 3 mode. All Kinetis chips. @internal gui name="Very low leakage stop 3 mode" */
+ kPowerManagerMax
+} power_manager_modes_t;
+
+/*!
+ * @brief Power manager success code and error codes.
+ *
+ * Used as return value of Power manager functions.
+ */
+typedef enum _power_manager_error_code {
+ kPowerManagerSuccess, /*!< Success */
+ kPowerManagerError, /*!< Some error occurs. */
+ kPowerManagerErrorOutOfRange, /*!< Configuration index out of range. */
+ kPowerManagerErrorSwitch, /*!< Error occurs during mode switch. */
+ kPowerManagerErrorNotificationBefore, /*!< Error occurs during send "BEFORE" notification. */
+ kPowerManagerErrorNotificationAfter, /*!< Error occurs during send "AFTER" notification. */
+ kPowerManagerErrorClock /*!< Error occurs due to wrong clock setup for power modes */
+} power_manager_error_code_t;
+
+/*!
+ * @brief Power manager policies.
+ *
+ * Define whether the power mode change is forced or not. Used to specify whether
+ * the mode switch initiated by the POWER_SYS_SetMode() depends on the callback
+ * notification results. For kPowerManagerPolicyForcible the power mode is changed
+ * regardless of the results, while kPowerManagerPolicyAgreement policy is used
+ * the POWER_SYS_SetMode() is exited when any of the callbacks returns error code.
+ * See also POWER_SYS_SetMode() description.
+ */
+typedef enum _power_manager_policy {
+ kPowerManagerPolicyAgreement, /*!< POWER_SYS_SetMode() method is exited when any of the callbacks returns error code. @internal gui name="Agreement policy" */
+ kPowerManagerPolicyForcible /*!< Power mode is changed regardless of the results. @internal gui name="Forcible policy" */
+} power_manager_policy_t;
+
+/*! @brief The PM notification type. Used to notify registered callbacks */
+typedef enum _power_manager_notify
+{
+ kPowerManagerNotifyRecover = 0x00U, /*!< Notify IP to recover to previous work state. */
+ kPowerManagerNotifyBefore = 0x01U, /*!< Notify IP that system will change power setting. */
+ kPowerManagerNotifyAfter = 0x02U, /*!< Notify IP that have changed to new power setting. */
+} power_manager_notify_t;
+
+/*!
+ * @brief The callback type, indicates what kinds of notification this callback handles.
+ *
+ * Used in the callback configuration structures (power_manager_callback_user_config_t)
+ * to specify when the registered callback will be called during power mode change initiated by
+ * POWER_SYS_SetMode().
+ * Callback can be invoked in following situations:
+ * - before the power mode change (Callback return value can affect POWER_SYS_SetMode()
+ * execution. Refer to the POWER_SYS_SetMode() and power_manager_policy_t documentation).
+ * - after entering one of the run modes or after exiting from one of the (deep) sleep power
+ * modes back to the run mode.
+ * - after unsuccessful attempt to switch power mode
+ */
+typedef enum _power_manager_callback_type {
+ kPowerManagerCallbackBefore = 0x01U, /*!< Before callback. @internal gui name="Before" */
+ kPowerManagerCallbackAfter = 0x02U, /*!< After callback. @internal gui name="After" */
+ kPowerManagerCallbackBeforeAfter = 0x03U, /*!< Before-After callback. @internal gui name="Before-After" */
+} power_manager_callback_type_t;
+
+/*!
+ * @brief Callback-specific data.
+ *
+ * Reference to data of this type is passed during callback registration. The reference is
+ * part of the power_manager_callback_user_config_t structure and is passed to the callback during
+ * power mode change notifications.
+ */
+typedef void power_manager_callback_data_t;
+
+/*!
+ * @brief Power mode user configuration structure.
+ *
+ * This structure defines Kinetis power mode with additional power options and specifies
+ * transition to and out of this mode. Application may define multiple power modes and
+ * switch between them. List of defined power modes is passed to the Power manager during
+ * initialization as an array of references to structures of this type (see POWER_SYS_Init()).
+ * Power modes can be switched by calling POWER_SYS_SetMode() which accepts index to the list
+ * of power modes passed during manager initialization. Currently used power mode can be
+ * retrieved by calling POWER_SYS_GetLastMode(), which returns index of the current power mode, or
+ * by POWER_SYS_GetLastModeConfig(), which returns reference to the structure of current mode.
+ * List of power mode configuration structure members depends on power options available
+ * for specific chip. Complete list contains:
+ * mode - Kinetis power mode. List of available modes is chip-specific. See power_manager_modes_t
+ * list of modes. This item is common for all Kinetis chips.
+ * sleepOnExitOption - Controls whether the sleep-on-exit option value is used (when set to true)
+ * or ignored (when set to false). See sleepOnExitValue. This item is common for all Kinetis chips.
+ * sleepOnExitValue - When set to true, ARM core returns to sleep (Kinetis wait modes) or deep sleep
+ * state (Kinetis stop modes) after interrupt service finishes. When set to false, core stays
+ * woken-up. This item is common for all Kinetis chips.
+ * lowPowerWakeUpOnInterruptOption - Controls whether the wake-up-on-interrupt option value is used
+ * (when set to true) or ignored (when set to false). See lowPowerWakeUpOnInterruptValue. This
+ * item is chip-specific.
+ * lowPowerWakeUpOnInterruptValue - When set to true, system exits to Run mode when any interrupt occurs while in
+ * Very low power run, Very low power wait or Very low power stop mode. This item is chip-specific.
+ * powerOnResetDetectionOption - Controls whether the power on reset detection option value is used
+ * (when set to true) or ignored (when set to false). See powerOnResetDetectionValue. This item is
+ * chip-specific.
+ * powerOnResetDetectionValue - When set to true, power on reset detection circuit is enabled in
+ * Very low leakage stop 0 mode. When set to false, circuit is disabled. This item is chip-specific.
+ * RAM2PartitionOption - Controls whether the RAM2 partition power option value is used (when set to
+ * true) or ignored (when set to false). See RAM2PartitionValue. This item is chip-specific.
+ * RAM2PartitionValue - When set to true, RAM2 partition content is retained through Very low
+ * leakage stop 2 mode. When set to false, RAM2 partition power is disabled and memory content lost.
+ * This item is chip-specific.
+ * lowPowerOscillatorOption - Controls whether the Low power oscillator power option value is used
+ * (when set to true) or ignored (when set to false). See lowPowerOscillatorValue. This item is
+ * chip-specific.
+ * lowPowerOscillatorValue - When set to true, the 1 kHz Low power oscillator is enabled in any
+ * Low leakage or Very low leakage stop mode. When set to false, oscillator is disabled in these modes.
+ * This item is chip-specific.
+ * @internal gui name="Power manager configuration" id="power_managerCfg"
+ */
+typedef struct _power_manager_mode_user_config {
+ power_manager_modes_t mode; /*!< Power mode. @internal gui name="Power mode" id="mode" */
+ bool sleepOnExitValue; /*!< Sleep or deep sleep after interrupt service finished. @internal gui name="Sleep or deep sleep after interrupt service finished" id="sleepOnExitValue" */
+#if FSL_FEATURE_SMC_HAS_LPWUI
+ smc_lpwui_option_t lowPowerWakeUpOnInterruptValue; /*!< Wake-up on interrupt from Very low power run, Very low power wait or Very low power stop mode. @internal gui name="Wake-up on interrupt from Very low power run, Very low power wait or Very low power stop mode" id="lowPowerWakeUpOnInterruptValue" */
+#endif
+#if FSL_FEATURE_SMC_HAS_PORPO
+ smc_por_option_t powerOnResetDetectionValue; /*!< Power on reset detection circuit is enabled in Very low leakage stop 0 mode. @internal gui name="Power on reset detection circuit is enabled in Very low leakage stop 0 mode" id="powerOnResetDetectionValue" */
+#endif
+#if FSL_FEATURE_SMC_HAS_RAM2_POWER_OPTION
+ smc_ram2_option_t RAM2PartitionValue; /*!< RAM2 partition content is retained through Very low leakage stop 2 mode. @internal gui name="RAM2 partition content is retained through Very low leakage stop 2 mode" id="RAM2PartitionValue" */
+#endif
+#if FSL_FEATURE_SMC_HAS_PSTOPO
+ smc_pstop_option_t partialStopOptionValue; /*!< Defines Normal stop mode, or Partial Stop with both system and bus clocks disabled, or Partial Stop with system clock disabled and bus clock enabled. @internal gui name="Defines Normal stop mode, or Partial Stop with both system and bus clocks disabled, or Partial Stop with system clock disabled and bus clock enabled" id="partialStopOptionValue" */
+#endif
+#if FSL_FEATURE_SMC_HAS_LPOPO
+ smc_lpo_option_t lowPowerOscillatorValue; /*!< The 1 kHz Low power oscillator is enabled in any Low leakage or Very low leakage stop mode. @internal gui name="The 1 kHz Low power oscillator is enabled in any Low leakage or Very low leakage stop mode" id="lowPowerOscillatorValue" */
+#endif
+} power_manager_user_config_t;
+
+/*! @brief Power notification structure passed to registered callback function. */
+typedef struct _power_notify_struct
+{
+ uint8_t targetPowerConfigIndex; /*!< Target power configuration index. */
+ power_manager_user_config_t const *targetPowerConfigPtr; /*!< Pointer to target power configuration */
+ power_manager_policy_t policy; /*!< Clock transition policy. */
+ power_manager_notify_t notifyType; /*!< Clock notification type. */
+} power_manager_notify_struct_t;
+
+/*!
+ * @brief Callback prototype.
+ *
+ * Declaration of callback. It is common for registered callbacks.
+ * Reference to function of this type is part of power_manager_callback_user_config_t callback
+ * configuration structure.
+ * Depending on callback type, function of this prototype is called during power mode change
+ * (see POWER_SYS_SetMode()) before the mode change, after it or in both cases to notify about
+ * the change progress (see power_manager_callback_type_t). When called, type of the notification
+ * is passed as parameter along with reference to entered power mode configuration structure
+ * (see power_manager_notify_struct_t) and any data passed during the callback registration (see
+ * power_manager_callback_data_t).
+ * When notified before the mode change, depending on the power mode change policy (see
+ * power_manager_policy_t) the callback may deny the mode change by returning any error code different
+ * from kPowerManagerSuccess (see POWER_SYS_SetMode()).
+ * @param notify Notification structure.
+ * @param dataPtr Callback data. Refers to the data passed during callback registration. Intended to
+ * pass any driver or application data such as internal state information.
+ * @return An error code or kPowerManagerSuccess.
+ */
+typedef power_manager_error_code_t (* power_manager_callback_t)(
+ power_manager_notify_struct_t * notify,
+ power_manager_callback_data_t * dataPtr
+);
+
+/*!
+ * @brief callback configuration structure
+ *
+ * This structure holds configuration of callbacks passed
+ * to the Power manager during its initialization.
+ * Callbacks of this type are expected to be statically
+ * allocated.
+ * This structure contains following application-defined data:
+ * callback - pointer to the callback function
+ * callbackType - specifies when the callback is called
+ * callbackData - pointer to the data passed to the callback
+ */
+typedef struct _power_manager_callback_user_config {
+ power_manager_callback_t callback;
+ power_manager_callback_type_t callbackType;
+ power_manager_callback_data_t * callbackData;
+} power_manager_callback_user_config_t;
+
+/*!
+ * @brief Power manager internal state structure.
+ *
+ * Power manager internal structure. Contains data necessary for Power manager proper
+ * function. Stores references to registered power mode configurations,
+ * callbacks, information about their numbers and other internal data.
+ * This structure is statically allocated and initialized after POWER_SYS_Init() call.
+ */
+typedef struct _power_manager_state {
+ power_manager_user_config_t const ** configs; /*!< Pointer to power configure table.*/
+ uint8_t configsNumber; /*!< Number of power configurations */
+ power_manager_callback_user_config_t ** staticCallbacks; /*!< Pointer to callback table. */
+ uint8_t staticCallbacksNumber; /*!< Max. number of callback configurations */
+ uint8_t errorCallbackIndex; /*!< Index of callback returns error. */
+ uint8_t currentConfig; /*!< Index of current configuration. */
+} power_manager_state_t;
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/*!
+ * @brief Power manager initialization for operation.
+ *
+ * This function initializes the Power manager and its run-time state structure.
+ * Reference to an array of Power mode configuration structures has to be passed
+ * as a parameter along with a parameter specifying its size. At least one power mode
+ * configuration is required. Optionally, reference to the array of predefined
+ * callbacks can be passed with its size parameter.
+ * For details about callbacks, refer to the power_manager_callback_user_config_t.
+ * As Power manager stores only references to array of these structures, they have
+ * to exist while Power manager is used.
+ * It is expected that prior to the POWER_SYS_Init() call the write-once protection
+ * register was configured appropriately allowing for entry to all required low power
+ * modes.
+ * The following is an example of how to set up two power modes and three
+ * callbacks, and initialize the Power manager with structures containing their settings.
+ * The example shows two possible ways the configuration structures can be stored
+ * (ROM or RAM), although it is expected that they will be placed in the read-only
+ * memory to save the RAM space. (Note: In the example it is assumed that the programmed chip
+ * doesn't support any optional power options described in the power_manager_user_config_t)
+ * :
+ * @code
+ const power_manager_user_config_t waitConfig = {
+ kPowerManagerVlpw,
+ true,
+ true,
+ };
+
+ const power_manager_callback_user_config_t callbackCfg0 = {
+ callback0,
+ kPowerManagerCallbackBefore,
+ &callback_data0
+ };
+
+ const power_manager_callback_user_config_t callbackCfg1 = {
+ callback1,
+ kPowerManagerCallbackAfter,
+ &callback_data1
+ };
+
+ const power_manager_callback_user_config_t callbackCfg2 = {
+ callback2,
+ kPowerManagerCallbackBeforeAfter,
+ &callback_data2
+ };
+
+ const power_manager_callback_user_config_t * const callbacks[] = {&callbackCfg0, &callbackCfg1, &callbackCfg2};
+
+ void main(void)
+ {
+ power_manager_user_config_t idleConfig;
+ power_manager_user_config_t *powerConfigs[] = {&idleConfig, &waitConfig};
+
+ idleConfig.mode = kPowerManagerVlps;
+ idleConfig.sleepOnExitOption = true;
+ idleConfig.sleepOnExitValue = false;
+
+ POWER_SYS_Init(&powerConfigs, 2U, &callbacks, 3U);
+
+ POWER_SYS_SetMode(0U, kPowerManagerPolicyAgreement);
+
+ }
+ * @endcode
+ *
+ * @param powerConfigsPtr A pointer to an array with references to all power
+ * configurations which will be handled by Power manager.
+ * @param configsNumber Number of power configurations. Size of powerConfigsPtr
+ * array.
+ * @param callbacksPtr A pointer to an array with references to callback configurations.
+ * If there are no callbacks to register during Power manager initialization, use NULL value.
+ * @param callbacksNumber Number of registered callbacks. Size of callbacksPtr
+ * array.
+ * @return An error code or kPowerManagerSuccess.
+ */
+power_manager_error_code_t POWER_SYS_Init(power_manager_user_config_t const ** powerConfigsPtr,
+ uint8_t configsNumber,
+ power_manager_callback_user_config_t ** callbacksPtr,
+ uint8_t callbacksNumber);
+
+/*!
+ * @brief This function deinitializes the Power manager.
+ *
+ * @return An error code or kPowerManagerSuccess.
+ */
+power_manager_error_code_t POWER_SYS_Deinit(void);
+
+/*!
+ * @brief This function configures the power mode.
+ *
+ * This function switches to one of the defined power modes. Requested mode number is passed
+ * as an input parameter. This function notifies all registered callback functions before
+ * the mode change (using kPowerManagerCallbackBefore set as callback type parameter),
+ * sets specific power options defined in the power mode configuration and enters the specified
+ * mode. In case of run modes (for example, Run, Very low power run, or High speed run), this function
+ * also invokes all registered callbacks after the mode change (using kPowerManagerCallbackAfter).
+ * In case of sleep or deep sleep modes, if the requested mode is not exited through
+ * a reset, these notifications are sent after the core wakes up.
+ * Callbacks are invoked in the following order: All registered callbacks are notified
+ * ordered by index in the callbacks array (see callbacksPtr parameter of POWER_SYS_Init()).
+ * The same order is used for before and after switch notifications.
+ * The notifications before the power mode switch can be used to obtain confirmation about
+ * the change from registered callbacks. If any registered callback denies the power
+ * mode change, further execution of this function depends on mode change policy: the mode
+ * change is either forced (kPowerManagerPolicyForcible) or exited (kPowerManagerPolicyAgreement).
+ * When mode change is forced, the result of the before switch notifications are ignored. If
+ * agreement is required, if any callback returns an error code then further notifications
+ * before switch notifications are cancelled and all already notified callbacks are re-invoked
+ * with kPowerManagerCallbackAfter set as callback type parameter. The index of the callback
+ * which returned error code during pre-switch notifications is stored (any error codes during
+ * callbacks re-invocation are ignored) and POWER_SYS_GetErrorCallback() can be used to get it.
+ * Regardless of the policies, if any callback returned an error code, an error code denoting in which phase
+ * the error occurred is returned when POWER_SYS_SetMode() exits.
+ * It is possible to enter any mode supported by the processor. Refer to the chip reference manual
+ * for list of available power modes. If it is necessary to switch into intermediate power mode prior to
+ * entering requested mode (for example, when switching from Run into Very low power wait through Very low
+ * power run mode), then the intermediate mode is entered without invoking the callback mechanism.
+ *
+ * @param powerModeIndex Requested power mode represented as an index into
+ * array of user-defined power mode configurations passed to the POWER_SYS_Init().
+ * @param policy Transaction policy
+ * @return An error code or kPowerManagerSuccess.
+ */
+power_manager_error_code_t POWER_SYS_SetMode(uint8_t powerModeIndex, power_manager_policy_t policy);
+
+/*!
+ * @brief This function returns power mode set as the last one.
+ *
+ * This function returns index of power mode which was set using POWER_SYS_SetMode() as the last one.
+ * If the power mode was entered even though some of the registered callback denied the mode change,
+ * or if any of the callbacks invoked after the entering/restoring run mode failed, then the return
+ * code of this function has kPowerManagerError value.
+ *
+ * @param powerModeIndexPtr Power mode which has been set represented as an index into array of power mode
+ * configurations passed to the POWER_SYS_Init().
+ * @return An error code or kPowerManagerSuccess.
+ */
+power_manager_error_code_t POWER_SYS_GetLastMode(uint8_t *powerModeIndexPtr);
+
+/*!
+ * @brief This function returns user configuration structure of power mode set as the last one.
+ *
+ * This function returns reference to configuration structure which was set using POWER_SYS_SetMode()
+ * as the last one. If the current power mode was entered even though some of the registered callback denied
+ * the mode change, or if any of the callbacks invoked after the entering/restoring run mode failed, then
+ * the return code of this function has kPowerManagerError value.
+ *
+ * @param powerModePtr Pointer to power mode configuration structure of power mode set as last one.
+ * @return An error code or kPowerManagerSuccess.
+ */
+power_manager_error_code_t POWER_SYS_GetLastModeConfig(power_manager_user_config_t const ** powerModePtr);
+
+/*!
+ * @brief This function returns currently running power mode.
+ *
+ * This function reads hardware settings and returns currently running power mode. Generally,
+ * this function can return only kPowerManagerRun, kPowerManagerVlpr or kPowerManagerHsrun value.
+ *
+ * @return Currently used run power mode.
+ */
+power_manager_modes_t POWER_SYS_GetCurrentMode(void);
+
+/*!
+ * @brief This function returns the last failed notification callback.
+ *
+ * This function returns index of the last callback that failed during the power mode switch while
+ * the last POWER_SYS_SetMode() was called. If the last POWER_SYS_SetMode() call ended successfully
+ * value equal to callbacks number is returned. Returned value represents index in the array of
+ * static call-backs.
+ *
+ * @return Callback index of last failed callback or value equal to callbacks count.
+ */
+uint8_t POWER_SYS_GetErrorCallbackIndex(void);
+
+/*!
+ * @brief This function returns the last failed notification callback configuration structure.
+ *
+ * This function returns pointer to configuration structure of the last callback that failed during
+ * the power mode switch while the last POWER_SYS_SetMode() was called.
+ * If the last POWER_SYS_SetMode() call ended successfully value NULL is returned.
+ *
+ * @return Pointer to the callback configuration which returns error.
+ */
+power_manager_callback_user_config_t* POWER_SYS_GetErrorCallback(void);
+
+/*!
+ * @brief This function returns whether very low power mode is running.
+ *
+ * This function is used to detect whether very low power mode is running.
+ *
+ * @return Returns true if processor runs in very low power mode, otherwise false.
+ */
+bool POWER_SYS_GetVeryLowPowerModeStatus(void);
+
+/*!
+ * @brief This function returns whether reset was caused by low leakage wake up.
+ *
+ * This function is used to check that processor exited low leakage power mode
+ * through reset.
+ *
+ * @return Returns true if processor was reset by low leakage wake up,
+ * otherwise false.
+ */
+bool POWER_SYS_GetLowLeakageWakeupResetStatus(void);
+
+/*!
+ * @brief Gets the acknowledge isolation flag.
+ *
+ * This function is used to check certain peripherals and the I/O pads are in a latched state
+ * as a result of having been in a VLLS mode.
+ *
+ * After recovery from VLLS, the LLWU continues to detect wake-up events until the user has
+ * acknowledged the wake-up via POWER_SYS_ClearAckIsolation()
+ *
+ * @return Returns true if ACK isolation is set.
+ */
+bool POWER_SYS_GetAckIsolation(void);
+
+/*!
+ * @brief Clears the acknowledge isolation flag.
+ *
+ * This function clears the ACK Isolation flag. Clearing releases the I/O pads and certain
+ * peripherals to their normal run mode state.
+ *
+ * After recovery from VLLS, the LLWU continues to detect wake-up events until the user has
+ * acknowledged the wake-up via POWER_SYS_ClearAckIsolation()
+ *
+ */
+void POWER_SYS_ClearAckIsolation(void);
+
+#include "../src/power/fsl_power_manager_common.h"
+
+#if FSL_FEATURE_SOC_LLWU_COUNT
+/*!
+ * The LLWU module becomes functional on entry into a low-leakage power mode. After
+ * recovery from LLS, the LLWU is immediately disabled. After recovery from VLLS, the
+ * LLWU continues to detect wake-up events until the user has acknowledged the wake-up
+ * via POWER_SYS_ClearAckIsolation().
+ *
+ * LLS modes:
+ * The wake-up events due to external wake-up inputs and internal module wake-up inputs
+ * result in an interrupt flow when exiting LLS. A reset event due to RESET pin assertion
+ * results in a reset flow when exiting LLS.
+ *
+ * VLLS modes:
+ * All wakeup and reset events result in VLLS exit via a reset flow.
+ *
+ * The LLWU is not active in all non-low leakage modes where detection and control logic
+ * are in a static state. The LLWU registers are accessible in non-low leakage modes and are
+ * available for configuring and reading status when bus transactions are possible.
+ */
+
+#if FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE
+/*!
+ * @brief This function allows to set wake up module in low leakage wake up unit (LLWU).
+ * Each of the available wake-up sources can be individually enabled or disabled.
+ *
+ * The LLWU is not active in all non-low leakage modes where detection and control logic
+ * are in a static state. The LLWU registers are accessible in non-low leakage modes and are
+ * available for configuring and reading status when bus transactions are possible.
+ *
+ * After recovery from VLLS, the LLWU continues to detect wake-up events until the user has
+ * acknowledged the wake-up via POWER_SYS_ClearAckIsolation()
+ *
+ * @param module Wake up module name which will be set.
+ * @param enable Specifies if wake up from module will be enabled (true) or disabled (false).
+ */
+void POWER_SYS_SetWakeupModule(power_wakeup_module_t module,bool enable);
+
+/*!
+ * @brief This function allows to get wake up module flag in LLWU.
+ *
+ * For internal peripherals that are capable of running in a low-leakage power mode, such as
+ * a real time clock module or CMP module, the flag from the associated peripheral is
+ * accessible and returned by this function.
+ *
+ * The flag will need to be cleared in the peripheral instead of clearing in LLWU.
+ *
+ * @param module Wake up module name.
+ * @return Returns true if module flag is set.
+ */
+bool POWER_SYS_GetWakeupModuleFlag(power_wakeup_module_t module);
+
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN
+/*!
+ * @brief This function allows to set wake up pin in low leakage wake up unit (LLWU) and allows to configure
+ * pin electrical parameters if gpio pin configuration is passed as parameter.
+ * Each of the available wake-up sources can be individually enabled or disabled.
+ *
+ * The LLWU is not active in all non-low leakage modes where detection and control logic
+ * are in a static state. The LLWU registers are accessible in non-low leakage modes and are
+ * available for configuring and reading status when bus transactions are possible.
+ *
+ * After recovery from VLLS, the LLWU continues to detect wake-up events until the user has
+ * acknowledged the wake-up via POWER_SYS_ClearAckIsolation()
+ *
+ * @param pin Wake up pin name which will be set.
+ * @param pinMode pin configuration mode defined in llwu_external_pin_modes_t.
+ * @param config optional parameter. If passed gpio pin configuration gpio pin will be configured.
+ */
+void POWER_SYS_SetWakeupPin(power_wakeup_pin_t pin, llwu_external_pin_modes_t pinMode, const gpio_input_pin_t * config);
+
+/*!
+ * @brief This function allows to get wake up pin flag in low leakage wake up unit (LLWU).
+ *
+ * @param pin Wake up pin name.
+ * @return Returns pin wake up flag.
+ */
+bool POWER_SYS_GetWakeupPinFlag(power_wakeup_pin_t pin);
+
+/*!
+ * @brief This function allows to clear wake up pin flag in low leakage wake up unit (LLWU).
+ *
+ * @param pin Wake up pin name
+ */
+void POWER_SYS_ClearWakeupPinFlag(power_wakeup_pin_t pin);
+
+#endif
+#endif
+
+#if defined(__cplusplus)
+}
+#endif
+
+/*! @}*/
+
+#endif /* __FSL_POWER_MANAGER_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK02F12810/fsl_clock_MK02F12810.c b/KSDK_1.2.0/platform/system/src/clock/MK02F12810/fsl_clock_MK02F12810.c
new file mode 100755
index 0000000..860a021
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK02F12810/fsl_clock_MK02F12810.c
@@ -0,0 +1,807 @@
+/*
+ * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+
+ CLOCK_HAL_SetOutDiv(SIM, 1U, 1U, 0U, 7U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kOsc0ErClockUndiv:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelIrc48M:
+ freq = CPU_INTERNAL_IRC_48M;
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq
+ * Description : Gets OSC0ERCLKUDIV.
+ * This function gets the OSC0 external reference undivided frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq()
+ >> OSC_HAL_GetExternalRefClkDiv(g_oscBase[0]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG);
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClkUndiv: /* OSC0ERCLKUDIV clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK02F12810/fsl_clock_MK02F12810.h b/KSDK_1.2.0/platform/system/src/clock/MK02F12810/fsl_clock_MK02F12810.h
new file mode 100755
index 0000000..e4947fb
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK02F12810/fsl_clock_MK02F12810.h
@@ -0,0 +1,1116 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K02F12810_H__)
+#define __FSL_CLOCK_K02F12810_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k02f12810*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+/*! @brief FTM external clock frequency. */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k02f12810_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @} */
+/*! @addtogroup clock_manager */
+/*! @{ */
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets the OSC0ERCLK_UNDIV frequency.
+ *
+ * This function gets the undivided OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void);
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate 2 clock frequency.
+ *
+ * This function gets the ADC alternate 2 clock frequency (ALTCLK2).
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAlt2Freq(uint32_t instance)
+{
+ return CPU_INTERNAL_IRC_48M;
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K02F12810_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK10D10/fsl_clock_MK10D10.c b/KSDK_1.2.0/platform/system/src/clock/MK10D10/fsl_clock_MK10D10.c
new file mode 100755
index 0000000..74bc257
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK10D10/fsl_clock_MK10D10.c
@@ -0,0 +1,1075 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+#if FSL_FEATURE_SOC_ENET_COUNT
+uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT]; /* ENET_1588_CLKIN */
+#endif
+uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT]; /* SDHC_CLKIN */
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+#endif
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 1U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlexBusClock:
+ *frequency = CLOCK_SYS_GetFlexbusFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexbusFreq
+ * Description : Gets the clock frequency for FLEXBUS module
+ * This function gets the clock frequency for FLEXBUS module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexbusFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv3(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG) / 2U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq() / 2U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetRmiiFreq
+ * Description : Gets the clock frequency for ENET module RMII clock.
+ * This function gets the clock frequency for ENET module RMII clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance)
+{
+ /* get the sim clock source setting*/
+ if (CLOCK_HAL_GetRmiiSrc(SIM, instance) == kClockRmiiSrcExtalClk)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq(); /* OSCERCLK */
+ }
+ else
+ {
+ return g_enet1588ClkInFreq[0]; /* ENET_1588_CLKIN */
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetTimeStampFreq
+ * Description : Gets the clock frequency for ENET module TIME clock.
+ * This function gets the clock frequency for ENET module TIME clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_time_src_t src;
+
+ src = CLOCK_HAL_GetTimeSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTimeSrcCoreSysClk: /* Core/System clock. */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockTimeSrcPllFllSel: /* FLL/PLL/IRC48M. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTimeSrcOsc0erClk: /* OSCERCLK. */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTimeSrcExt: /* ENET 1588 clock in. */
+ freq = g_enet1588ClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+#endif
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSdhcFreq
+ * Description : Gets the clock frequency for SDHC module
+ * This function gets the clock frequency for SDHC module
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_sdhc_src_t src;
+
+ src = CLOCK_HAL_GetSdhcSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockSdhcSrcCoreSysClk: /* Core/system clock */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockSdhcSrcPllFllSel: /* Clock selected by SOPT2[PLLFLLSEL]. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockSdhcSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSdhcSrcExt: /* External bypass clock (SDHC0_CLKIN) */
+ freq = g_sdhcClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+ kSimClockGateDac1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/* FlexCAN instance table. */
+static const sim_clock_gate_name_t flexcanGateTable[] =
+{
+ kSimClockGateFlexcan0,
+ kSimClockGateFlexcan1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFlexcanClock
+ * Description : Enable the clock for Flexcan module
+ * This function enables the clock for Flexcan module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, flexcanGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFlexcanClock
+ * Description : Disable the clock for Flexcan module
+ * This function disables the clock for Flexcan module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, flexcanGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanGateCmd
+ * Description : Get the the clock gate state for Flexcan module
+ * This function will get the clock gate state for Flexcan module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, flexcanGateTable[instance]);
+}
+#endif
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+ kSimClockGateSpi2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3,
+ kSimClockGateUart4,
+ kSimClockGateUart5
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK10D10/fsl_clock_MK10D10.h b/KSDK_1.2.0/platform/system/src/clock/MK10D10/fsl_clock_MK10D10.h
new file mode 100755
index 0000000..c531cc9
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK10D10/fsl_clock_MK10D10.h
@@ -0,0 +1,2048 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K10D10_H__)
+#define __FSL_CLOCK_K10D10_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k10d10*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief ENET external clock source count. */
+#define ENET_EXT_CLK_COUNT 1
+/*! @brief SDHC external clock source count. */
+#define SDHC_EXT_CLK_COUNT 1
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*! @brief ENET external clock frequency(ENET_1588_CLKIN) */
+extern uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT];
+#endif
+/*! @brief SDHC external clock frequency(SDHC_CLKIN). */
+extern uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT];
+#if FSL_FEATURE_SOC_USB_COUNT
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+#endif
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k10d10_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @} */
+/*! @addtogroup clock_manager*/
+/*! @{*/
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function sets divide value OUTDIV3.
+ *
+ * @param outdiv3 Outdivider3 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv3(uint8_t outdiv3)
+{
+ CLOCK_HAL_SetOutDiv3(SIM, outdiv3);
+}
+
+/*!
+ * @brief Gets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function gets divide value OUTDIV3.
+ *
+ * @return Outdivider3 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv3(void)
+{
+ return CLOCK_HAL_GetOutDiv3(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Gets ethernet RMII clock source.
+ *
+ * This function gets the ethernet RMII clock source.
+ *
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_rmii_src_t CLOCK_SYS_GetEnetRmiiSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetRmiiSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets ethernet RMII clock source.
+ *
+ * This function sets the ethernet RMII clock source.
+ *
+ * @param instance module device instance.
+ * @param rmiiSrc RMII clock source.
+ */
+static inline void CLOCK_SYS_SetEnetRmiiSrc(uint32_t instance, clock_rmii_src_t rmiiSrc)
+{
+ CLOCK_HAL_SetRmiiSrc(SIM, instance, rmiiSrc);
+}
+
+/*!
+ * @brief Gets ethernet RMII clock frequency.
+ *
+ * This function gets the ethernet RMII clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance);
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc);
+#endif
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Set the ethernet timestamp clock source selection.
+ *
+ * This function sets the ethernet timestamp clock source selection.
+ *
+ * @param instance module device instance.
+ * @param timeSrc Ethernet timestamp clock source.
+ */
+static inline void CLOCK_SYS_SetEnetTimeStampSrc(uint32_t instance, clock_time_src_t timeSrc)
+{
+ CLOCK_HAL_SetTimeSrc(SIM, instance, timeSrc);
+}
+
+/*!
+ * @brief Get the ethernet timestamp clock source selection.
+ *
+ * This function gets the ethernet timestamp clock source selection.
+ *
+ * @param instance IP instance.
+ *
+ * @return Current source.
+ */
+static inline clock_time_src_t CLOCK_SYS_GetEnetTimeStampSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTimeSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets ethernet timestamp clock frequency.
+ *
+ * This function gets the ethernet timestamp clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance);
+#endif
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+#endif
+
+/*!
+ * @brief Gets the clock frequency for SDHC.
+ *
+ * This function gets the clock frequency for SDHC.
+ * @param instance module device instance
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance);
+
+/*!
+ * @brief Set the SDHC clock source selection.
+ *
+ * This function sets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetSdhcSrc( uint32_t instance,
+ clock_sdhc_src_t setting)
+{
+ CLOCK_HAL_SetSdhcSrc(SIM, instance, setting);
+}
+
+/*!
+ * @brief Get the SDHC clock source selection.
+ *
+ * This function gets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_sdhc_src_t CLOCK_SYS_GetSdhcSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetSdhcSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+#if FSL_FEATURE_SOC_OPAMP_COUNT
+/*!
+ * @brief Enable the clock for OPAMP module.
+ *
+ * This function enables the clock for OPAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableOpampClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateOpamp);
+}
+
+/*!
+ * @brief Disable the clock for OPAMP module.
+ *
+ * This function disables the clock for OPAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableOpampClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateOpamp);
+}
+
+/*!
+ * @brief Get the the clock gate state for OPAMP module.
+ *
+ * This function will get the clock gate state for OPAMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetOpampGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateOpamp);
+}
+#endif
+
+#if FSL_FEATURE_SOC_TRIAMP_COUNT
+/*!
+ * @brief Enable the clock for TRIAMP module.
+ *
+ * This function enables the clock for TRIAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTriampClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTriamp);
+}
+
+/*!
+ * @brief Disable the clock for TRIAMP module.
+ *
+ * This function disables the clock for TRIAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTriampClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTriamp);
+}
+
+/*!
+ * @brief Get the the clock gate state for TRIAMP module.
+ *
+ * This function will get the clock gate state for TRIAMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTriampGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTriamp);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for MPU module.
+ *
+ * This function enables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableMpuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Disable the clock for MPU module.
+ *
+ * This function disables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableMpuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for MPU module.
+ *
+ * This function will get the clock gate state for MPU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetMpuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXBUS module.
+ *
+ * This function enables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXBUS module.
+ *
+ * This function disables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXBUS module.
+ *
+ * This function will get the clock gate state for FLEXBUS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexbusGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+#if FSL_FEATURE_SOC_RNG_COUNT
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+ * @brief Enable the clock for SLCD module.
+ *
+ * This function enables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Disable the clock for SLCD module.
+ *
+ * This function disables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SLCD module.
+ *
+ * This function will get the clock gate state for SLCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSlcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD default clock.
+ *
+ * This function gets the frequency for SLCD default clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdDefaultFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate clock.
+ *
+ * This function gets the frequency for SLCD alternate clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAltFreq(uint32_t instance)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Enable the clock for ENET module.
+ *
+ * This function enables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEnetClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Disable the clock for ENET module.
+ *
+ * This function disables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEnetClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Get the the clock gate state for ENET module.
+ *
+ * This function will get the clock gate state for ENET module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEnetGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEnet0);
+}
+#endif
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance);
+#endif
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SDHC module.
+ *
+ * This function enables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Disable the clock for SDHC module.
+ *
+ * This function disables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SDHC module.
+ *
+ * This function will get the clock gate state for SDHC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSdhcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Enable the clock for LLWU module.
+ *
+ * This function enables the clock for LLWU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLlwuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLlwu0);
+}
+
+/*!
+ * @brief Disable the clock for LLWU module.
+ *
+ * This function disables the clock for LLWU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLlwuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLlwu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LLWU module.
+ *
+ * This function will get the clock gate state for LLWU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLlwuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLlwu0);
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Set the ENET external clock frequency(ENET_1588_CLKIN).
+ *
+ * This function sets the ENET external clock frequency (ENET_1588_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetEnetExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < ENET_EXT_CLK_COUNT);
+
+ g_enet1588ClkInFreq[srcInstance] = freq;
+}
+#endif
+
+/*!
+ * @brief Set the SDHC external clock frequency(SDHC_CLKIN).
+ *
+ * This function sets the SDHC external clock frequency (SDHC_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetSdhcExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < SDHC_EXT_CLK_COUNT);
+
+ g_sdhcClkInFreq[srcInstance] = freq;
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+#endif
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K10D10_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK11DA5/fsl_clock_MK11DA5.c b/KSDK_1.2.0/platform/system/src/clock/MK11DA5/fsl_clock_MK11DA5.c
new file mode 100755
index 0000000..4e8f36b
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK11DA5/fsl_clock_MK11DA5.c
@@ -0,0 +1,861 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_osc_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 1U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG) / 2U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq() / 2U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case 3:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case 4:
+ case 5:
+
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK11DA5/fsl_clock_MK11DA5.h b/KSDK_1.2.0/platform/system/src/clock/MK11DA5/fsl_clock_MK11DA5.h
new file mode 100755
index 0000000..56bb274
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK11DA5/fsl_clock_MK11DA5.h
@@ -0,0 +1,1436 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K11DA5_H__)
+#define __FSL_CLOCK_K11DA5_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k11da5*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k11da5_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @brief Default clock configuration number. */
+#define CLOCK_CONFIG_NUM 2
+
+/*! @brief Clock configuration index for VLPR mode. */
+#define CLOCK_CONFIG_INDEX_FOR_VLPR 0
+
+/*! @brief Clock configuration index for RUN mode. */
+#define CLOCK_CONFIG_INDEX_FOR_RUN 1
+
+/*! @} */
+/*! @addtogroup clock_manager*/
+/*! @{*/
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K11DA5_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK20D10/fsl_clock_MK20D10.c b/KSDK_1.2.0/platform/system/src/clock/MK20D10/fsl_clock_MK20D10.c
new file mode 100755
index 0000000..74bc257
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK20D10/fsl_clock_MK20D10.c
@@ -0,0 +1,1075 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+#if FSL_FEATURE_SOC_ENET_COUNT
+uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT]; /* ENET_1588_CLKIN */
+#endif
+uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT]; /* SDHC_CLKIN */
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+#endif
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 1U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlexBusClock:
+ *frequency = CLOCK_SYS_GetFlexbusFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexbusFreq
+ * Description : Gets the clock frequency for FLEXBUS module
+ * This function gets the clock frequency for FLEXBUS module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexbusFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv3(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG) / 2U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq() / 2U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetRmiiFreq
+ * Description : Gets the clock frequency for ENET module RMII clock.
+ * This function gets the clock frequency for ENET module RMII clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance)
+{
+ /* get the sim clock source setting*/
+ if (CLOCK_HAL_GetRmiiSrc(SIM, instance) == kClockRmiiSrcExtalClk)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq(); /* OSCERCLK */
+ }
+ else
+ {
+ return g_enet1588ClkInFreq[0]; /* ENET_1588_CLKIN */
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetTimeStampFreq
+ * Description : Gets the clock frequency for ENET module TIME clock.
+ * This function gets the clock frequency for ENET module TIME clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_time_src_t src;
+
+ src = CLOCK_HAL_GetTimeSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTimeSrcCoreSysClk: /* Core/System clock. */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockTimeSrcPllFllSel: /* FLL/PLL/IRC48M. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTimeSrcOsc0erClk: /* OSCERCLK. */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTimeSrcExt: /* ENET 1588 clock in. */
+ freq = g_enet1588ClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+#endif
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSdhcFreq
+ * Description : Gets the clock frequency for SDHC module
+ * This function gets the clock frequency for SDHC module
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_sdhc_src_t src;
+
+ src = CLOCK_HAL_GetSdhcSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockSdhcSrcCoreSysClk: /* Core/system clock */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockSdhcSrcPllFllSel: /* Clock selected by SOPT2[PLLFLLSEL]. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockSdhcSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSdhcSrcExt: /* External bypass clock (SDHC0_CLKIN) */
+ freq = g_sdhcClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+ kSimClockGateDac1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/* FlexCAN instance table. */
+static const sim_clock_gate_name_t flexcanGateTable[] =
+{
+ kSimClockGateFlexcan0,
+ kSimClockGateFlexcan1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFlexcanClock
+ * Description : Enable the clock for Flexcan module
+ * This function enables the clock for Flexcan module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, flexcanGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFlexcanClock
+ * Description : Disable the clock for Flexcan module
+ * This function disables the clock for Flexcan module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, flexcanGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanGateCmd
+ * Description : Get the the clock gate state for Flexcan module
+ * This function will get the clock gate state for Flexcan module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, flexcanGateTable[instance]);
+}
+#endif
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+ kSimClockGateSpi2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3,
+ kSimClockGateUart4,
+ kSimClockGateUart5
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK20D10/fsl_clock_MK20D10.h b/KSDK_1.2.0/platform/system/src/clock/MK20D10/fsl_clock_MK20D10.h
new file mode 100755
index 0000000..0b41237
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK20D10/fsl_clock_MK20D10.h
@@ -0,0 +1,2048 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K20D10_H__)
+#define __FSL_CLOCK_K20D10_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k20d10*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief ENET external clock source count. */
+#define ENET_EXT_CLK_COUNT 1
+/*! @brief SDHC external clock source count. */
+#define SDHC_EXT_CLK_COUNT 1
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*! @brief ENET external clock frequency(ENET_1588_CLKIN) */
+extern uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT];
+#endif
+/*! @brief SDHC external clock frequency(SDHC_CLKIN). */
+extern uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT];
+#if FSL_FEATURE_SOC_USB_COUNT
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+#endif
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k20d10_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @} */
+/*! @addtogroup clock_manager*/
+/*! @{*/
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function sets divide value OUTDIV3.
+ *
+ * @param outdiv3 Outdivider3 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv3(uint8_t outdiv3)
+{
+ CLOCK_HAL_SetOutDiv3(SIM, outdiv3);
+}
+
+/*!
+ * @brief Gets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function gets divide value OUTDIV3.
+ *
+ * @return Outdivider3 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv3(void)
+{
+ return CLOCK_HAL_GetOutDiv3(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Gets ethernet RMII clock source.
+ *
+ * This function gets the ethernet RMII clock source.
+ *
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_rmii_src_t CLOCK_SYS_GetEnetRmiiSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetRmiiSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets ethernet RMII clock source.
+ *
+ * This function sets the ethernet RMII clock source.
+ *
+ * @param instance module device instance.
+ * @param rmiiSrc RMII clock source.
+ */
+static inline void CLOCK_SYS_SetEnetRmiiSrc(uint32_t instance, clock_rmii_src_t rmiiSrc)
+{
+ CLOCK_HAL_SetRmiiSrc(SIM, instance, rmiiSrc);
+}
+
+/*!
+ * @brief Gets ethernet RMII clock frequency.
+ *
+ * This function gets the ethernet RMII clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance);
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc);
+#endif
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Set the ethernet timestamp clock source selection.
+ *
+ * This function sets the ethernet timestamp clock source selection.
+ *
+ * @param instance module device instance.
+ * @param timeSrc Ethernet timestamp clock source.
+ */
+static inline void CLOCK_SYS_SetEnetTimeStampSrc(uint32_t instance, clock_time_src_t timeSrc)
+{
+ CLOCK_HAL_SetTimeSrc(SIM, instance, timeSrc);
+}
+
+/*!
+ * @brief Get the ethernet timestamp clock source selection.
+ *
+ * This function gets the ethernet timestamp clock source selection.
+ *
+ * @param instance IP instance.
+ *
+ * @return Current source.
+ */
+static inline clock_time_src_t CLOCK_SYS_GetEnetTimeStampSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTimeSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets ethernet timestamp clock frequency.
+ *
+ * This function gets the ethernet timestamp clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance);
+#endif
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+#endif
+
+/*!
+ * @brief Gets the clock frequency for SDHC.
+ *
+ * This function gets the clock frequency for SDHC.
+ * @param instance module device instance
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance);
+
+/*!
+ * @brief Set the SDHC clock source selection.
+ *
+ * This function sets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetSdhcSrc( uint32_t instance,
+ clock_sdhc_src_t setting)
+{
+ CLOCK_HAL_SetSdhcSrc(SIM, instance, setting);
+}
+
+/*!
+ * @brief Get the SDHC clock source selection.
+ *
+ * This function gets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_sdhc_src_t CLOCK_SYS_GetSdhcSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetSdhcSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+#if FSL_FEATURE_SOC_OPAMP_COUNT
+/*!
+ * @brief Enable the clock for OPAMP module.
+ *
+ * This function enables the clock for OPAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableOpampClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateOpamp);
+}
+
+/*!
+ * @brief Disable the clock for OPAMP module.
+ *
+ * This function disables the clock for OPAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableOpampClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateOpamp);
+}
+
+/*!
+ * @brief Get the the clock gate state for OPAMP module.
+ *
+ * This function will get the clock gate state for OPAMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetOpampGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateOpamp);
+}
+#endif
+
+#if FSL_FEATURE_SOC_TRIAMP_COUNT
+/*!
+ * @brief Enable the clock for TRIAMP module.
+ *
+ * This function enables the clock for TRIAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTriampClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTriamp);
+}
+
+/*!
+ * @brief Disable the clock for TRIAMP module.
+ *
+ * This function disables the clock for TRIAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTriampClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTriamp);
+}
+
+/*!
+ * @brief Get the the clock gate state for TRIAMP module.
+ *
+ * This function will get the clock gate state for TRIAMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTriampGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTriamp);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for MPU module.
+ *
+ * This function enables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableMpuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Disable the clock for MPU module.
+ *
+ * This function disables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableMpuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for MPU module.
+ *
+ * This function will get the clock gate state for MPU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetMpuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXBUS module.
+ *
+ * This function enables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXBUS module.
+ *
+ * This function disables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXBUS module.
+ *
+ * This function will get the clock gate state for FLEXBUS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexbusGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+#if FSL_FEATURE_SOC_RNG_COUNT
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+ * @brief Enable the clock for SLCD module.
+ *
+ * This function enables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Disable the clock for SLCD module.
+ *
+ * This function disables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SLCD module.
+ *
+ * This function will get the clock gate state for SLCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSlcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD default clock.
+ *
+ * This function gets the frequency for SLCD default clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdDefaultFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate clock.
+ *
+ * This function gets the frequency for SLCD alternate clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAltFreq(uint32_t instance)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Enable the clock for ENET module.
+ *
+ * This function enables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEnetClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Disable the clock for ENET module.
+ *
+ * This function disables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEnetClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Get the the clock gate state for ENET module.
+ *
+ * This function will get the clock gate state for ENET module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEnetGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEnet0);
+}
+#endif
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance);
+#endif
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SDHC module.
+ *
+ * This function enables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Disable the clock for SDHC module.
+ *
+ * This function disables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SDHC module.
+ *
+ * This function will get the clock gate state for SDHC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSdhcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Enable the clock for LLWU module.
+ *
+ * This function enables the clock for LLWU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLlwuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLlwu0);
+}
+
+/*!
+ * @brief Disable the clock for LLWU module.
+ *
+ * This function disables the clock for LLWU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLlwuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLlwu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LLWU module.
+ *
+ * This function will get the clock gate state for LLWU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLlwuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLlwu0);
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Set the ENET external clock frequency(ENET_1588_CLKIN).
+ *
+ * This function sets the ENET external clock frequency (ENET_1588_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetEnetExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < ENET_EXT_CLK_COUNT);
+
+ g_enet1588ClkInFreq[srcInstance] = freq;
+}
+#endif
+
+/*!
+ * @brief Set the SDHC external clock frequency(SDHC_CLKIN).
+ *
+ * This function sets the SDHC external clock frequency (SDHC_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetSdhcExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < SDHC_EXT_CLK_COUNT);
+
+ g_sdhcClkInFreq[srcInstance] = freq;
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+#endif
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K20D10_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK21DA5/fsl_clock_MK21DA5.c b/KSDK_1.2.0/platform/system/src/clock/MK21DA5/fsl_clock_MK21DA5.c
new file mode 100755
index 0000000..8ab1d63
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK21DA5/fsl_clock_MK21DA5.c
@@ -0,0 +1,891 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_osc_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 1U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG) / 2U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq() / 2U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case 3:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case 4:
+ case 5:
+
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK21DA5/fsl_clock_MK21DA5.h b/KSDK_1.2.0/platform/system/src/clock/MK21DA5/fsl_clock_MK21DA5.h
new file mode 100755
index 0000000..87ff3d1
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK21DA5/fsl_clock_MK21DA5.h
@@ -0,0 +1,1462 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K21DA5_H__)
+#define __FSL_CLOCK_K21DA5_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k21da5*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief SDHC external clock source count. */
+#define SDHC_EXT_CLK_COUNT 1
+ /*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k21da5_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @brief Default clock configuration number. */
+#define CLOCK_CONFIG_NUM 2
+
+/*! @brief Clock configuration index for VLPR mode. */
+#define CLOCK_CONFIG_INDEX_FOR_VLPR 0
+
+/*! @brief Clock configuration index for RUN mode. */
+#define CLOCK_CONFIG_INDEX_FOR_RUN 1
+
+/*! @} */
+/*! @addtogroup clock_manager*/
+/*! @{*/
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K21DA5_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK21FA12/fsl_clock_MK21FA12.c b/KSDK_1.2.0/platform/system/src/clock/MK21FA12/fsl_clock_MK21FA12.c
new file mode 100755
index 0000000..173f98b
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK21FA12/fsl_clock_MK21FA12.c
@@ -0,0 +1,965 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT]; /* SDHC_CLKIN */
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 2U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlexBusClock:
+ *frequency = CLOCK_SYS_GetFlexbusFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexbusFreq
+ * Description : Gets the clock frequency for FLEXBUS module
+ * This function gets the clock frequency for FLEXBUS moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexbusFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv3(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG) / 2U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq() / 2U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx prescaler/glitch filter clock frequency.
+ * This function gets the LPTMRx prescaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSdhcFreq
+ * Description : Gets the clock frequency for SDHC module
+ * This function gets the clock frequency for SDHC moudle
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_sdhc_src_t src;
+
+ src = CLOCK_HAL_GetSdhcSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockSdhcSrcCoreSysClk: /* Core/system clock */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockSdhcSrcPllFllSel: /* Clock selected by SOPT2[PLLFLLSEL]. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockSdhcSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSdhcSrcExt: /* External bypass clock (SDHC0_CLKIN) */
+ freq = g_sdhcClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+ kSimClockGateDac1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+ kSimClockGateFtm3
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+ kSimClockGateSpi2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+ kSimClockGateI2c2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3,
+ kSimClockGateUart4,
+ kSimClockGateUart5
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK21FA12/fsl_clock_MK21FA12.h b/KSDK_1.2.0/platform/system/src/clock/MK21FA12/fsl_clock_MK21FA12.h
new file mode 100755
index 0000000..9f6aa38
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK21FA12/fsl_clock_MK21FA12.h
@@ -0,0 +1,1712 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_MK21FA12_H__)
+#define __FSL_CLOCK_MK21FA12_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k21fa12 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/*! @brief SDHC external clock source count. */
+#define SDHC_EXT_CLK_COUNT 1
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+/*! @brief SDHC external clock frequency(SDHC_CLKIN). */
+extern uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT];
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k21fa12_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function sets divide value OUTDIV3.
+ *
+ * @param outdiv3 Outdivider3 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv3(uint8_t outdiv3)
+{
+ CLOCK_HAL_SetOutDiv3(SIM, outdiv3);
+}
+
+/*!
+ * @brief Gets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function gets divide value OUTDIV3.
+ *
+ * @return Outdivider3 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv3(void)
+{
+ return CLOCK_HAL_GetOutDiv3(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS moduel instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc);
+
+/*!
+ * @brief Gets the clock frequency for SDHC.
+ *
+ * This function gets the clock frequency for SDHC.
+ * @param instance module device instance
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance);
+
+/*!
+ * @brief Set the SDHC clock source selection.
+ *
+ * This function sets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetSdhcSrc( uint32_t instance,
+ clock_sdhc_src_t setting)
+{
+ CLOCK_HAL_SetSdhcSrc(SIM, instance, setting);
+}
+
+/*!
+ * @brief Get the SDHC clock source selection.
+ *
+ * This function gets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_sdhc_src_t CLOCK_SYS_GetSdhcSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetSdhcSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for MPU module.
+ *
+ * This function enables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableMpuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Disable the clock for MPU module.
+ *
+ * This function disables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableMpuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for MPU module.
+ *
+ * This function will get the clock gate state for MPU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetMpuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXBUS module.
+ *
+ * This function enables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXBUS module.
+ *
+ * This function disables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXBUS module.
+ *
+ * This function will get the clock gate state for FLEXBUS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexbusGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexcan0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexcan0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexcan0);
+}
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SDHC module.
+ *
+ * This function enables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Disable the clock for SDHC module.
+ *
+ * This function disables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SDHC module.
+ *
+ * This function will get the clock gate state for SDHC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSdhcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Deinitialize OSC0.
+ *
+ * This function deinitializes OSC0.
+ */
+void CLOCK_SYS_Osc0Deinit(void);
+
+/*!
+ * @brief Set the SDHC external clock frequency(SDHC_CLKIN).
+ *
+ * This function sets the SDHC external clock frequency (SDHC_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetSdhcExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < SDHC_EXT_CLK_COUNT);
+
+ g_sdhcClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_MK21FA12_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK22F12810/fsl_clock_MK22F12810.c b/KSDK_1.2.0/platform/system/src/clock/MK22F12810/fsl_clock_MK22F12810.c
new file mode 100755
index 0000000..3e9986b
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK22F12810/fsl_clock_MK22F12810.c
@@ -0,0 +1,883 @@
+/*
+ * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+
+ CLOCK_HAL_SetOutDiv(SIM, 1U, 1U, 0U, 7U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kOsc0ErClockUndiv:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kIrc48mClock:
+ *frequency = CPU_INTERNAL_IRC_48M;
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelIrc48M:
+ freq = CPU_INTERNAL_IRC_48M;
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq
+ * Description : Gets OSC0ERCLKUDIV.
+ * This function gets the OSC0 external reference undevided frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq()
+ >> OSC_HAL_GetExternalRefClkDiv(g_oscBase[0]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG);
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClkUndiv: /* OSC0ERCLKUDIV clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpuartFreq
+ * Description : Gets the clock frequency for LPUART module.
+ * This function gets the clock frequency for LPUART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance)
+{
+ clock_lpuart_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetLpuartSrc(SIM, instance);
+ switch (src)
+ {
+ case kClockLpuartSrcPllFllSel:
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockLpuartSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpuartSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllFllSel:
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK22F12810/fsl_clock_MK22F12810.h b/KSDK_1.2.0/platform/system/src/clock/MK22F12810/fsl_clock_MK22F12810.h
new file mode 100755
index 0000000..08efded
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK22F12810/fsl_clock_MK22F12810.h
@@ -0,0 +1,1450 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K22F12810_H__)
+#define __FSL_CLOCK_K22F12810_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k22f12810*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+/*! @brief USB external clock frequency. */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+/*! @brief FTM external clock frequency. */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k22f12810_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @} */
+/*! @addtogroup clock_manager*/
+/*! @{*/
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets the OSC0ERCLK_UNDIV frequency.
+ *
+ * This function gets the undivided OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Gets the clock source for LPUART module
+ *
+ * This function gets the clock source for LPUART module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_lpuart_src_t CLOCK_SYS_GetLpuartSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpuartSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for LPUART module
+ *
+ * This function sets the clock source for LPUART module.
+ * @param instance module device instance
+ * @param lpuartSrc Clock source.
+ */
+static inline void CLOCK_SYS_SetLpuartSrc(uint32_t instance, clock_lpuart_src_t lpuartSrc)
+{
+ CLOCK_HAL_SetLpuartSrc(SIM, instance, lpuartSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for LPUART module
+ *
+ * This function gets the clock frequency for LPUART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate 2 clock frequency.
+ *
+ * This function gets the ADC alternate 2 clock frequency (ALTCLK2).
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAlt2Freq(uint32_t instance)
+{
+ return CPU_INTERNAL_IRC_48M;
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDac0);
+}
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDac0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDac0);
+}
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPUART module.
+ *
+ * This function enables the clock for LPUART module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLpuartClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Disable the clock for LPUART module.
+ *
+ * This function disables the clock for LPUART module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLpuartClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPUART module.
+ *
+ * This function will get the clock gate state for LPUART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K22F12810_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK22F25612/fsl_clock_MK22F25612.c b/KSDK_1.2.0/platform/system/src/clock/MK22F25612/fsl_clock_MK22F25612.c
new file mode 100755
index 0000000..9722697
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK22F25612/fsl_clock_MK22F25612.c
@@ -0,0 +1,889 @@
+/*
+ * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+
+ CLOCK_HAL_SetOutDiv(SIM, 1U, 3U, 0U, 7U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kOsc0ErClockUndiv:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kIrc48mClock:
+ *frequency = CPU_INTERNAL_IRC_48M;
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockPllFllSelIrc48M:
+ freq = CPU_INTERNAL_IRC_48M;
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq
+ * Description : Gets OSC0ERCLKUDIV.
+ * This function gets the OSC0 external reference undivided frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq()
+ >> OSC_HAL_GetExternalRefClkDiv(g_oscBase[0]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG);
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClkUndiv: /* OSC0ERCLKUDIV clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpuartFreq
+ * Description : Gets the clock frequency for LPUART module.
+ * This function gets the clock frequency for LPUART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance)
+{
+ clock_lpuart_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetLpuartSrc(SIM, instance);
+ switch (src)
+ {
+ case kClockLpuartSrcPllFllSel:
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockLpuartSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpuartSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllFllSel:
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK22F25612/fsl_clock_MK22F25612.h b/KSDK_1.2.0/platform/system/src/clock/MK22F25612/fsl_clock_MK22F25612.h
new file mode 100755
index 0000000..8e5632b
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK22F25612/fsl_clock_MK22F25612.h
@@ -0,0 +1,1486 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K22F25612_H__)
+#define __FSL_CLOCK_K22F25612_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k22f25612*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+/*! @brief USB external clock frequency. */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+/*! @brief FTM external clock frequency. */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k22f25612_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @} */
+/*! @addtogroup clock_manager*/
+/*! @{*/
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets the OSC0ERCLK_UNDIV frequency.
+ *
+ * This function gets the undivided OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS moduel instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Gets the clock source for LPUART module
+ *
+ * This function gets the clock source for LPUART module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_lpuart_src_t CLOCK_SYS_GetLpuartSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpuartSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for LPUART module
+ *
+ * This function sets the clock source for LPUART module.
+ * @param instance module device instance
+ * @param lpuartSrc Clock source.
+ */
+static inline void CLOCK_SYS_SetLpuartSrc(uint32_t instance, clock_lpuart_src_t lpuartSrc)
+{
+ CLOCK_HAL_SetLpuartSrc(SIM, instance, lpuartSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for LPUART module
+ *
+ * This function gets the clock frequency for LPUART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate 2 clock frequency.
+ *
+ * This function gets the ADC alternate 2 clock frequency (ALTCLK2).
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAlt2Freq(uint32_t instance)
+{
+ return CPU_INTERNAL_IRC_48M;
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDac0);
+}
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDac0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDac0);
+}
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPUART module.
+ *
+ * This function enables the clock for LPUART module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLpuartClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Disable the clock for LPUART module.
+ *
+ * This function disables the clock for LPUART module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLpuartClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPUART module.
+ *
+ * This function will get the clock gate state for LPUART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K22F25612_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK22F51212/fsl_clock_MK22F51212.c b/KSDK_1.2.0/platform/system/src/clock/MK22F51212/fsl_clock_MK22F51212.c
new file mode 100755
index 0000000..4d51926
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK22F51212/fsl_clock_MK22F51212.c
@@ -0,0 +1,954 @@
+/*
+ * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+
+ CLOCK_HAL_SetOutDiv(SIM, 1U, 3U, 3U, 7U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlexBusClock:
+ *frequency = CLOCK_SYS_GetFlexbusFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kOsc0ErClockUndiv:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kIrc48mClock:
+ *frequency = CPU_INTERNAL_IRC_48M;
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexbusFreq
+ * Description : Gets the clock frequency for FLEXBUS module
+ * This function gets the clock frequency for FLEXBUS module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexbusFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv3(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockPllFllSelIrc48M:
+ freq = CPU_INTERNAL_IRC_48M;
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq
+ * Description : Gets OSC0ERCLKUDIV.
+ * This function gets the OSC0 external reference undivided frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq()
+ >> OSC_HAL_GetExternalRefClkDiv(g_oscBase[0]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG);
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClkUndiv: /* OSC0ERCLKUDIV clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpuartFreq
+ * Description : Gets the clock frequency for LPUART module.
+ * This function gets the clock frequency for LPUART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance)
+{
+ clock_lpuart_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetLpuartSrc(SIM, instance);
+ switch (src)
+ {
+ case kClockLpuartSrcPllFllSel:
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockLpuartSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpuartSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllFllSel:
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+ kSimClockGateDac1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+ kSimClockGateFtm3
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK22F51212/fsl_clock_MK22F51212.h b/KSDK_1.2.0/platform/system/src/clock/MK22F51212/fsl_clock_MK22F51212.h
new file mode 100755
index 0000000..99cd708
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK22F51212/fsl_clock_MK22F51212.h
@@ -0,0 +1,1545 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K22F51212_H__)
+#define __FSL_CLOCK_K22F51212_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k22f51212 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+/*! @brief USB external clock frequency. */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+/*! @brief FTM external clock frequency. */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k22f51212_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function sets divide value OUTDIV3.
+ *
+ * @param outdiv3 Outdivider3 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv3(uint8_t outdiv3)
+{
+ CLOCK_HAL_SetOutDiv3(SIM, outdiv3);
+}
+
+/*!
+ * @brief Gets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function gets divide value OUTDIV3.
+ *
+ * @return Outdivider3 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv3(void)
+{
+ return CLOCK_HAL_GetOutDiv3(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets the OSC0ERCLK_UNDIV frequency.
+ *
+ * This function gets the undivided OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Gets the clock source for LPUART module
+ *
+ * This function gets the clock source for LPUART module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_lpuart_src_t CLOCK_SYS_GetLpuartSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpuartSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for LPUART module
+ *
+ * This function sets the clock source for LPUART module.
+ * @param instance module device instance
+ * @param lpuartSrc Clock source.
+ */
+static inline void CLOCK_SYS_SetLpuartSrc(uint32_t instance, clock_lpuart_src_t lpuartSrc)
+{
+ CLOCK_HAL_SetLpuartSrc(SIM, instance, lpuartSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for LPUART module
+ *
+ * This function gets the clock frequency for LPUART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate 2 clock frequency.
+ *
+ * This function gets the ADC alternate 2 clock frequency (ALTCLK2).
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAlt2Freq(uint32_t instance)
+{
+ return CPU_INTERNAL_IRC_48M;
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXBUS module.
+ *
+ * This function enables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXBUS module.
+ *
+ * This function disables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXBUS module.
+ *
+ * This function will get the clock gate state for FLEXBUS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexbusGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPUART module.
+ *
+ * This function enables the clock for LPUART module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLpuartClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Disable the clock for LPUART module.
+ *
+ * This function disables the clock for LPUART module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLpuartClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPUART module.
+ *
+ * This function will get the clock gate state for LPUART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K22F51212_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK24F12/fsl_clock_MK24F12.c b/KSDK_1.2.0/platform/system/src/clock/MK24F12/fsl_clock_MK24F12.c
new file mode 100755
index 0000000..af3fe42
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK24F12/fsl_clock_MK24F12.c
@@ -0,0 +1,970 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT]; /* SDHC_CLKIN */
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 2U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlexBusClock:
+ *frequency = CLOCK_SYS_GetFlexbusFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kIrc48mClock:
+ *frequency = CPU_INTERNAL_IRC_48M;
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexbusFreq
+ * Description : Gets the clock frequency for FLEXBUS module
+ * This function gets the clock frequency for FLEXBUS module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexbusFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv3(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockPllFllSelIrc48M:
+ freq = CPU_INTERNAL_IRC_48M;
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG) / 2U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq() / 2U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSdhcFreq
+ * Description : Gets the clock frequency for SDHC module
+ * This function gets the clock frequency for SDHC module
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_sdhc_src_t src;
+
+ src = CLOCK_HAL_GetSdhcSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockSdhcSrcCoreSysClk: /* Core/system clock */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockSdhcSrcPllFllSel: /* Clock selected by SOPT2[PLLFLLSEL]. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockSdhcSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSdhcSrcExt: /* External bypass clock (SDHC0_CLKIN) */
+ freq = g_sdhcClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+ kSimClockGateDac1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+ kSimClockGateFtm3
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+ kSimClockGateSpi2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+ kSimClockGateI2c2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3,
+ kSimClockGateUart4,
+ kSimClockGateUart5
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK24F12/fsl_clock_MK24F12.h b/KSDK_1.2.0/platform/system/src/clock/MK24F12/fsl_clock_MK24F12.h
new file mode 100755
index 0000000..1f24dbf
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK24F12/fsl_clock_MK24F12.h
@@ -0,0 +1,1703 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K24F12_H__)
+#define __FSL_CLOCK_K24F12_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k24f12*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief SDHC external clock source count. */
+#define SDHC_EXT_CLK_COUNT 1
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+/*! @brief SDHC external clock frequency(SDHC_CLKIN). */
+extern uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT];
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k24f12_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+/*! @addtogroup clock_manager*/
+/*! @{*/
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function sets divide value OUTDIV3.
+ *
+ * @param outdiv3 Outdivider3 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv3(uint8_t outdiv3)
+{
+ CLOCK_HAL_SetOutDiv3(SIM, outdiv3);
+}
+
+/*!
+ * @brief Gets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function gets divide value OUTDIV3.
+ *
+ * @return Outdivider3 setting
+ */
+
+static inline uint8_t CLOCK_SYS_GetOutDiv3(void)
+{
+ return CLOCK_HAL_GetOutDiv3(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc);
+
+/*!
+ * @brief Gets the clock frequency for SDHC.
+ *
+ * This function gets the clock frequency for SDHC.
+ * @param instance module device instance
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance);
+
+/*!
+ * @brief Set the SDHC clock source selection.
+ *
+ * This function sets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetSdhcSrc( uint32_t instance,
+ clock_sdhc_src_t setting)
+{
+ CLOCK_HAL_SetSdhcSrc(SIM, instance, setting);
+}
+
+/*!
+ * @brief Get the SDHC clock source selection.
+ *
+ * This function gets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_sdhc_src_t CLOCK_SYS_GetSdhcSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetSdhcSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for MPU module.
+ *
+ * This function enables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableMpuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Disable the clock for MPU module.
+ *
+ * This function disables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableMpuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for MPU module.
+ *
+ * This function will get the clock gate state for MPU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetMpuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXBUS module.
+ *
+ * This function enables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXBUS module.
+ *
+ * This function disables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXBUS module.
+ *
+ * This function will get the clock gate state for FLEXBUS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexbusGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexcan0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexcan0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexcan0);
+}
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SDHC module.
+ *
+ * This function enables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Disable the clock for SDHC module.
+ *
+ * This function disables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SDHC module.
+ *
+ * This function will get the clock gate state for SDHC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSdhcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Set the SDHC external clock frequency(SDHC_CLKIN).
+ *
+ * This function sets the SDHC external clock frequency(SDHC_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+ static inline void CLOCK_SYS_SetSdhcExternalFreq(uint32_t srcInstance, uint32_t freq)
+ {
+ assert(srcInstance < SDHC_EXT_CLK_COUNT);
+
+ g_sdhcClkInFreq[srcInstance] = freq;
+ }
+
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency(USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+ static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+ {
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+ }
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency(FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+ static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+ {
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+ }
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K24F12_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK24F25612/fsl_clock_MK24F25612.c b/KSDK_1.2.0/platform/system/src/clock/MK24F25612/fsl_clock_MK24F25612.c
new file mode 100755
index 0000000..dd52f9d
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK24F25612/fsl_clock_MK24F25612.c
@@ -0,0 +1,900 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ /* system/core clock < 120M, bus clock < 60M; */
+ /* flash clock < 25M; */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 2U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kIrc48mClock:
+ *frequency = CPU_INTERNAL_IRC_48M;
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockPllFllSelIrc48M:
+ freq = CPU_INTERNAL_IRC_48M;
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG);
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+ kSimClockGateFtm3
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+ kSimClockGateSpi2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+ kSimClockGateI2c2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3,
+ kSimClockGateUart4,
+ kSimClockGateUart5
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK24F25612/fsl_clock_MK24F25612.h b/KSDK_1.2.0/platform/system/src/clock/MK24F25612/fsl_clock_MK24F25612.h
new file mode 100755
index 0000000..96fb12d
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK24F25612/fsl_clock_MK24F25612.h
@@ -0,0 +1,1467 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K24F25612_H__)
+#define __FSL_CLOCK_K24F25612_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k24f25612*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k24f25612_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @} */
+/*! @addtogroup clock_manager*/
+/*! @{*/
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency(USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+ static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+ {
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+ }
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency(FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+ static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+ {
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+ }
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K24F25612_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK26F18/fsl_clock_MK26F18.c b/KSDK_1.2.0/platform/system/src/clock/MK26F18/fsl_clock_MK26F18.c
new file mode 100755
index 0000000..766bcfe
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK26F18/fsl_clock_MK26F18.c
@@ -0,0 +1,1219 @@
+/*
+ * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT]; /* SDHC_CLKIN */
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+ CLOCK_HAL_SetPllFllDiv(SIM, simConfig->pllflldiv, simConfig->pllfllfrac);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 3U, 7U, 7U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlexBusClock:
+ *frequency = CLOCK_SYS_GetFlexbusFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kOsc0ErClockUndiv:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgExtPllClock:
+ *frequency = CLOCK_HAL_GetExtPllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kIrc48mClock:
+ *frequency = CPU_INTERNAL_IRC_48M;
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexbusFreq
+ * Description : Gets the clock frequency for FLEXBUS module
+ * This function gets the clock frequency for FLEXBUS module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexbusFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv3(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockPllFllSelUsb1pfd:
+ freq = CLOCK_HAL_GetExtPllClk(MCG);
+ break;
+ case kClockPllFllSelIrc48M:
+ freq = CPU_INTERNAL_IRC_48M;
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllDivClockFreq
+ * Description : Gets the PLL/FLL clock divided by the fractional divider.
+ * This function gets the frequency of the PLL/FLL clock divided
+ * by the fractional divider configured by SIM_CLKDIV3[PLLFLLFRAC, PLLFLLDIV].
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllDivClockFreq(void)
+{
+ uint32_t freq;
+ uint8_t pllflldiv, pllfllfrac;
+
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetPllFllDiv(SIM, &pllflldiv, &pllfllfrac);
+ return freq * (pllfllfrac + 1) / (pllflldiv + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq
+ * Description : Gets OSC0ERCLKUDIV.
+ * This function gets the OSC0 external reference undivided frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq()
+ >> OSC_HAL_GetExternalRefClkDiv(g_oscBase[0]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+ uint32_t freq;
+ uint8_t tracediv, tracefrac;
+
+ if (kClockTraceSrcMcgoutClkDiv == src)
+ {
+ freq = CLOCK_HAL_GetOutClk(MCG);
+ CLOCK_HAL_GetTraceDiv(SIM, &tracediv, &tracefrac);
+ return freq * (tracefrac + 1) / (tracediv + 1);
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ }
+ return freq / 2U;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClkUndiv: /* OSC0ERCLKUDIV clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmfFreq
+ * Description : Gets the clock frequency for TPM module.
+ * This function gets the clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_tpm_src_t src;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTpmSrcPllFllSelDiv: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllDivClockFreq();
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmExternalFreq
+ * Description : Gets the external clock frequency for TPM module.
+ * This function gets the external clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t src = CLOCK_SYS_GetTpmExternalSrc(instance);
+
+ if (kSimTpmClkSel0 == src)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpuartFreq
+ * Description : Gets the clock frequency for LPUART module.
+ * This function gets the clock frequency for LPUART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance)
+{
+ clock_lpuart_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetLpuartSrc(SIM, instance);
+ switch (src)
+ {
+ case kClockLpuartSrcPllFllSel:
+ freq = CLOCK_SYS_GetPllFllDivClockFreq();
+ break;
+ case kClockLpuartSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpuartSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbhsSlowClockFreq
+ * Description : Gets the slow clock frequency for USB HS/USB PHY module.
+ * This function gets the clock frequency for USB HS/USB PHY module,
+ * used to detect wakeup and resume events.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbhsSlowClockFreq(uint32_t instance) {
+
+ if (CLOCK_HAL_GetUsbhsSlowClockSrc(SIM, instance) == kClockUsbhsSlowClkSrcMcgIrClk)
+ {
+ return CLOCK_SYS_GetInternalRefClockFreq(); /* MCGIRCLK */
+ }
+ else
+ {
+ return CLOCK_SYS_GetRtcFreq(0U); /* RTC 32.768kHz clock */
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSdhcFreq
+ * Description : Gets the clock frequency for SDHC module
+ * This function gets the clock frequency for SDHC moudle
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_sdhc_src_t src;
+
+ src = CLOCK_HAL_GetSdhcSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockSdhcSrcCoreSysClk: /* Core/system clock */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockSdhcSrcPllFllSel: /* Clock selected by SOPT2[PLLFLLSEL]. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockSdhcSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSdhcSrcExt: /* External bypass clock (SDHC0_CLKIN) */
+ freq = g_sdhcClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllFllSel:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+ kSimClockGateDac1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+ kSimClockGateFtm3
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t canGateTable[] =
+{
+ kSimClockGateFlexcan0,
+ kSimClockGateFlexcan1
+};
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFlexcanClock
+ * Description : Enable the clock for FLEXCAN module
+ * This function enables the clock for FLEXCAN module.
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(canGateTable)/sizeof(canGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, canGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFlexcanClock
+ * Description : Disable the clock for FLEXCAN module
+ * This function disables the clock for FLEXCAN module.
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(canGateTable)/sizeof(canGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, canGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanGateCmd
+ * Description : Get the the clock gate state for FLEXCAN module
+ * This function will get the clock gate state for FLEXCAN module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(canGateTable)/sizeof(canGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, canGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+ kSimClockGateSpi2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+ kSimClockGateI2c2,
+ kSimClockGateI2c3,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3,
+ kSimClockGateUart4
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/* TPM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm1,
+ kSimClockGateTpm2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableTpmClock
+ * Description : Enable the clock for TPM module
+ * This function enables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableTpmClock
+ * Description : Disable the clock for TPM module
+ * This function disables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmGateCmd
+ * Description : Get the the clock gate state for TPM module
+ * This function will get the clock gate state for TPM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK26F18/fsl_clock_MK26F18.h b/KSDK_1.2.0/platform/system/src/clock/MK26F18/fsl_clock_MK26F18.h
new file mode 100755
index 0000000..635ebae
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK26F18/fsl_clock_MK26F18.h
@@ -0,0 +1,2093 @@
+/*
+ * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K26F18_H__)
+#define __FSL_CLOCK_K26F18_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k64f12 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/*! @brief SDHC external clock source count. */
+#define SDHC_EXT_CLK_COUNT 1
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+
+
+/*! @brief SDHC external clock frequency(SDHC_CLKIN). */
+extern uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT];
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ uint8_t pllflldiv, pllfllfrac; /*!< PLL/FLL fractional divider setting */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k26f18_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function sets divide value OUTDIV3.
+ *
+ * @param outdiv3 Outdivider3 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv3(uint8_t outdiv3)
+{
+ CLOCK_HAL_SetOutDiv3(SIM, outdiv3);
+}
+
+/*!
+ * @brief Gets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function gets divide value OUTDIV3.
+ *
+ * @return Outdivider3 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv3(void)
+{
+ return CLOCK_HAL_GetOutDiv3(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Gets the PLL/FLL clock divided by the fractional divider.
+ *
+ * This function gets the frequency of the PLL/FLL clock divided
+ * by the fractional divider configured by SIM_CLKDIV3[PLLFLLFRAC, PLLFLLDIV].
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllDivClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets the OSC0ERCLK_UNDIV frequency.
+ *
+ * This function gets the undivided OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock source for LPUART module
+ *
+ * This function gets the clock source for LPUART module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_lpuart_src_t CLOCK_SYS_GetLpuartSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpuartSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for LPUART module
+ *
+ * This function sets the clock source for LPUART module.
+ * @param instance module device instance
+ * @param lpuartSrc Clock source.
+ */
+static inline void CLOCK_SYS_SetLpuartSrc(uint32_t instance, clock_lpuart_src_t lpuartSrc)
+{
+ CLOCK_HAL_SetLpuartSrc(SIM, instance, lpuartSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for LPUART module
+ *
+ * This function gets the clock frequency for LPUART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS moduel instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Gets the slow clock source for USB HS/USB PHY module
+ *
+ * This function gets the slow clock source for USB HS/USB PHY module,
+ * used to detect wakeup and resume events.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbhs_slowclk_src_t CLOCK_SYS_GetUsbhsSlowClockSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbhsSlowClockSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB HS/USB PHY module
+ *
+ * This function sets the clock source for USB HS/USB PHY module,
+ * used to detect wakeup and resume events.
+ * @param instance module device instance.
+ * @param usbhsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbhsSlowClockSrc(uint32_t instance, clock_usbhs_slowclk_src_t usbhsSrc)
+{
+ CLOCK_HAL_SetUsbhsSlowClockSrc(SIM, instance, usbhsSrc);
+}
+
+/*!
+ * @brief Gets the slow clock frequency for USB HS/USB PHY module
+ *
+ * This function gets the clock frequency for USB HS/USB PHY module,
+ * used to detect wakeup and resume events.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbhsSlowClockFreq(uint32_t instance);
+
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc);
+
+/*!
+ * @brief Gets the clock frequency for SDHC.
+ *
+ * This function gets the clock frequency for SDHC.
+ * @param instance module device instance
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance);
+
+/*!
+ * @brief Set the SDHC clock source selection.
+ *
+ * This function sets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetSdhcSrc( uint32_t instance,
+ clock_sdhc_src_t setting)
+{
+ CLOCK_HAL_SetSdhcSrc(SIM, instance, setting);
+}
+
+/*!
+ * @brief Get the SDHC clock source selection.
+ *
+ * This function gets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_sdhc_src_t CLOCK_SYS_GetSdhcSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetSdhcSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for MPU module.
+ *
+ * This function enables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableMpuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Disable the clock for MPU module.
+ *
+ * This function disables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableMpuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for MPU module.
+ *
+ * This function will get the clock gate state for MPU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetMpuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXBUS module.
+ *
+ * This function enables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXBUS module.
+ *
+ * This function disables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXBUS module.
+ *
+ * This function will get the clock gate state for FLEXBUS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexbusGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Enable the clock for SDRAMC module.
+ *
+ * This function enables the clock for SDRAMC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSdramcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSdramc0);
+}
+
+/*!
+ * @brief Disable the clock for SDRAMC module.
+ *
+ * This function disables the clock for SDRAMC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSdramcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSdramc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SDRAMC module.
+ *
+ * This function will get the clock gate state for SDRAMC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSdramcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSdramc0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Enable the clock for USBHS module.
+ *
+ * This function enables the clock for USBHS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbhsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbhs0);
+}
+
+/*!
+ * @brief Disable the clock for USBHS module.
+ *
+ * This function disables the clock for USBHS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbhsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbhs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBHS module.
+ *
+ * This function will get the clock gate state for USBHS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbhsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbhs0);
+}
+
+/*!
+ * @brief Enable the clock for USBPHY module.
+ *
+ * This function enables the clock for USBPHY module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbphyClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbhsphy0);
+}
+
+/*!
+ * @brief Disable the clock for USBPHY module.
+ *
+ * This function disables the clock for USBPHY module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbphyClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbhsphy0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBPHY module.
+ *
+ * This function will get the clock gate state for USBPHY module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbphyGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbhsphy0);
+}
+
+/*!
+ * @brief Enable the clock for USBHSDCD module.
+ *
+ * This function enables the clock for USBHSDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbhsdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbhsdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBHSDCD module.
+ *
+ * This function disables the clock for USBHSDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbhsdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbhsdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBHSDCD module.
+ *
+ * This function will get the clock gate state for USBHSDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbhsdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbhsdcd0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPUART module.
+ *
+ * This function enables the clock for LPUART module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLpuartClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Disable the clock for LPUART module.
+ *
+ * This function disables the clock for LPUART module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLpuartClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPUART module.
+ *
+ * This function will get the clock gate state for LPUART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Enable the clock for SDHC module.
+ *
+ * This function enables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Disable the clock for SDHC module.
+ *
+ * This function disables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SDHC module.
+ *
+ * This function will get the clock gate state for SDHC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSdhcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Set the SDHC external clock frequency(SDHC_CLKIN).
+ *
+ * This function sets the SDHC external clock frequency (SDHC_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetSdhcExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < SDHC_EXT_CLK_COUNT);
+
+ g_sdhcClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K26F18_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK30D10/fsl_clock_MK30D10.c b/KSDK_1.2.0/platform/system/src/clock/MK30D10/fsl_clock_MK30D10.c
new file mode 100755
index 0000000..74bc257
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK30D10/fsl_clock_MK30D10.c
@@ -0,0 +1,1075 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+#if FSL_FEATURE_SOC_ENET_COUNT
+uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT]; /* ENET_1588_CLKIN */
+#endif
+uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT]; /* SDHC_CLKIN */
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+#endif
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 1U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlexBusClock:
+ *frequency = CLOCK_SYS_GetFlexbusFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexbusFreq
+ * Description : Gets the clock frequency for FLEXBUS module
+ * This function gets the clock frequency for FLEXBUS module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexbusFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv3(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG) / 2U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq() / 2U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetRmiiFreq
+ * Description : Gets the clock frequency for ENET module RMII clock.
+ * This function gets the clock frequency for ENET module RMII clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance)
+{
+ /* get the sim clock source setting*/
+ if (CLOCK_HAL_GetRmiiSrc(SIM, instance) == kClockRmiiSrcExtalClk)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq(); /* OSCERCLK */
+ }
+ else
+ {
+ return g_enet1588ClkInFreq[0]; /* ENET_1588_CLKIN */
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetTimeStampFreq
+ * Description : Gets the clock frequency for ENET module TIME clock.
+ * This function gets the clock frequency for ENET module TIME clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_time_src_t src;
+
+ src = CLOCK_HAL_GetTimeSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTimeSrcCoreSysClk: /* Core/System clock. */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockTimeSrcPllFllSel: /* FLL/PLL/IRC48M. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTimeSrcOsc0erClk: /* OSCERCLK. */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTimeSrcExt: /* ENET 1588 clock in. */
+ freq = g_enet1588ClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+#endif
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSdhcFreq
+ * Description : Gets the clock frequency for SDHC module
+ * This function gets the clock frequency for SDHC module
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_sdhc_src_t src;
+
+ src = CLOCK_HAL_GetSdhcSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockSdhcSrcCoreSysClk: /* Core/system clock */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockSdhcSrcPllFllSel: /* Clock selected by SOPT2[PLLFLLSEL]. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockSdhcSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSdhcSrcExt: /* External bypass clock (SDHC0_CLKIN) */
+ freq = g_sdhcClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+ kSimClockGateDac1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/* FlexCAN instance table. */
+static const sim_clock_gate_name_t flexcanGateTable[] =
+{
+ kSimClockGateFlexcan0,
+ kSimClockGateFlexcan1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFlexcanClock
+ * Description : Enable the clock for Flexcan module
+ * This function enables the clock for Flexcan module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, flexcanGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFlexcanClock
+ * Description : Disable the clock for Flexcan module
+ * This function disables the clock for Flexcan module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, flexcanGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanGateCmd
+ * Description : Get the the clock gate state for Flexcan module
+ * This function will get the clock gate state for Flexcan module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, flexcanGateTable[instance]);
+}
+#endif
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+ kSimClockGateSpi2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3,
+ kSimClockGateUart4,
+ kSimClockGateUart5
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK30D10/fsl_clock_MK30D10.h b/KSDK_1.2.0/platform/system/src/clock/MK30D10/fsl_clock_MK30D10.h
new file mode 100755
index 0000000..b70593d
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK30D10/fsl_clock_MK30D10.h
@@ -0,0 +1,2048 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K30D10_H__)
+#define __FSL_CLOCK_K30D10_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k30d10*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief ENET external clock source count. */
+#define ENET_EXT_CLK_COUNT 1
+/*! @brief SDHC external clock source count. */
+#define SDHC_EXT_CLK_COUNT 1
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*! @brief ENET external clock frequency(ENET_1588_CLKIN) */
+extern uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT];
+#endif
+/*! @brief SDHC external clock frequency(SDHC_CLKIN). */
+extern uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT];
+#if FSL_FEATURE_SOC_USB_COUNT
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+#endif
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k30d10_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @} */
+/*! @addtogroup clock_manager*/
+/*! @{*/
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function sets divide value OUTDIV3.
+ *
+ * @param outdiv3 Outdivider3 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv3(uint8_t outdiv3)
+{
+ CLOCK_HAL_SetOutDiv3(SIM, outdiv3);
+}
+
+/*!
+ * @brief Gets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function gets divide value OUTDIV3.
+ *
+ * @return Outdivider3 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv3(void)
+{
+ return CLOCK_HAL_GetOutDiv3(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Gets ethernet RMII clock source.
+ *
+ * This function gets the ethernet RMII clock source.
+ *
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_rmii_src_t CLOCK_SYS_GetEnetRmiiSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetRmiiSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets ethernet RMII clock source.
+ *
+ * This function sets the ethernet RMII clock source.
+ *
+ * @param instance module device instance.
+ * @param rmiiSrc RMII clock source.
+ */
+static inline void CLOCK_SYS_SetEnetRmiiSrc(uint32_t instance, clock_rmii_src_t rmiiSrc)
+{
+ CLOCK_HAL_SetRmiiSrc(SIM, instance, rmiiSrc);
+}
+
+/*!
+ * @brief Gets ethernet RMII clock frequency.
+ *
+ * This function gets the ethernet RMII clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance);
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc);
+#endif
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Set the ethernet timestamp clock source selection.
+ *
+ * This function sets the ethernet timestamp clock source selection.
+ *
+ * @param instance module device instance.
+ * @param timeSrc Ethernet timestamp clock source.
+ */
+static inline void CLOCK_SYS_SetEnetTimeStampSrc(uint32_t instance, clock_time_src_t timeSrc)
+{
+ CLOCK_HAL_SetTimeSrc(SIM, instance, timeSrc);
+}
+
+/*!
+ * @brief Get the ethernet timestamp clock source selection.
+ *
+ * This function gets the ethernet timestamp clock source selection.
+ *
+ * @param instance IP instance.
+ *
+ * @return Current source.
+ */
+static inline clock_time_src_t CLOCK_SYS_GetEnetTimeStampSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTimeSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets ethernet timestamp clock frequency.
+ *
+ * This function gets the ethernet timestamp clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance);
+#endif
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+#endif
+
+/*!
+ * @brief Gets the clock frequency for SDHC.
+ *
+ * This function gets the clock frequency for SDHC.
+ * @param instance module device instance
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance);
+
+/*!
+ * @brief Set the SDHC clock source selection.
+ *
+ * This function sets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetSdhcSrc( uint32_t instance,
+ clock_sdhc_src_t setting)
+{
+ CLOCK_HAL_SetSdhcSrc(SIM, instance, setting);
+}
+
+/*!
+ * @brief Get the SDHC clock source selection.
+ *
+ * This function gets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_sdhc_src_t CLOCK_SYS_GetSdhcSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetSdhcSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+#if FSL_FEATURE_SOC_OPAMP_COUNT
+/*!
+ * @brief Enable the clock for OPAMP module.
+ *
+ * This function enables the clock for OPAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableOpampClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateOpamp);
+}
+
+/*!
+ * @brief Disable the clock for OPAMP module.
+ *
+ * This function disables the clock for OPAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableOpampClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateOpamp);
+}
+
+/*!
+ * @brief Get the the clock gate state for OPAMP module.
+ *
+ * This function will get the clock gate state for OPAMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetOpampGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateOpamp);
+}
+#endif
+
+#if FSL_FEATURE_SOC_TRIAMP_COUNT
+/*!
+ * @brief Enable the clock for TRIAMP module.
+ *
+ * This function enables the clock for TRIAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTriampClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTriamp);
+}
+
+/*!
+ * @brief Disable the clock for TRIAMP module.
+ *
+ * This function disables the clock for TRIAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTriampClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTriamp);
+}
+
+/*!
+ * @brief Get the the clock gate state for TRIAMP module.
+ *
+ * This function will get the clock gate state for TRIAMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTriampGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTriamp);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for MPU module.
+ *
+ * This function enables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableMpuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Disable the clock for MPU module.
+ *
+ * This function disables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableMpuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for MPU module.
+ *
+ * This function will get the clock gate state for MPU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetMpuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXBUS module.
+ *
+ * This function enables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXBUS module.
+ *
+ * This function disables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXBUS module.
+ *
+ * This function will get the clock gate state for FLEXBUS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexbusGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+#if FSL_FEATURE_SOC_RNG_COUNT
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+ * @brief Enable the clock for SLCD module.
+ *
+ * This function enables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Disable the clock for SLCD module.
+ *
+ * This function disables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SLCD module.
+ *
+ * This function will get the clock gate state for SLCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSlcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD default clock.
+ *
+ * This function gets the frequency for SLCD default clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdDefaultFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate clock.
+ *
+ * This function gets the frequency for SLCD alternate clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAltFreq(uint32_t instance)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Enable the clock for ENET module.
+ *
+ * This function enables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEnetClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Disable the clock for ENET module.
+ *
+ * This function disables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEnetClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Get the the clock gate state for ENET module.
+ *
+ * This function will get the clock gate state for ENET module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEnetGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEnet0);
+}
+#endif
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance);
+#endif
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SDHC module.
+ *
+ * This function enables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Disable the clock for SDHC module.
+ *
+ * This function disables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SDHC module.
+ *
+ * This function will get the clock gate state for SDHC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSdhcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Enable the clock for LLWU module.
+ *
+ * This function enables the clock for LLWU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLlwuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLlwu0);
+}
+
+/*!
+ * @brief Disable the clock for LLWU module.
+ *
+ * This function disables the clock for LLWU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLlwuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLlwu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LLWU module.
+ *
+ * This function will get the clock gate state for LLWU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLlwuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLlwu0);
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Set the ENET external clock frequency(ENET_1588_CLKIN).
+ *
+ * This function sets the ENET external clock frequency (ENET_1588_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetEnetExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < ENET_EXT_CLK_COUNT);
+
+ g_enet1588ClkInFreq[srcInstance] = freq;
+}
+#endif
+
+/*!
+ * @brief Set the SDHC external clock frequency(SDHC_CLKIN).
+ *
+ * This function sets the SDHC external clock frequency (SDHC_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetSdhcExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < SDHC_EXT_CLK_COUNT);
+
+ g_sdhcClkInFreq[srcInstance] = freq;
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+#endif
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K30D10_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK40D10/fsl_clock_MK40D10.c b/KSDK_1.2.0/platform/system/src/clock/MK40D10/fsl_clock_MK40D10.c
new file mode 100755
index 0000000..74bc257
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK40D10/fsl_clock_MK40D10.c
@@ -0,0 +1,1075 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+#if FSL_FEATURE_SOC_ENET_COUNT
+uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT]; /* ENET_1588_CLKIN */
+#endif
+uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT]; /* SDHC_CLKIN */
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+#endif
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 1U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlexBusClock:
+ *frequency = CLOCK_SYS_GetFlexbusFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexbusFreq
+ * Description : Gets the clock frequency for FLEXBUS module
+ * This function gets the clock frequency for FLEXBUS module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexbusFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv3(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG) / 2U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq() / 2U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetRmiiFreq
+ * Description : Gets the clock frequency for ENET module RMII clock.
+ * This function gets the clock frequency for ENET module RMII clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance)
+{
+ /* get the sim clock source setting*/
+ if (CLOCK_HAL_GetRmiiSrc(SIM, instance) == kClockRmiiSrcExtalClk)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq(); /* OSCERCLK */
+ }
+ else
+ {
+ return g_enet1588ClkInFreq[0]; /* ENET_1588_CLKIN */
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetTimeStampFreq
+ * Description : Gets the clock frequency for ENET module TIME clock.
+ * This function gets the clock frequency for ENET module TIME clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_time_src_t src;
+
+ src = CLOCK_HAL_GetTimeSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTimeSrcCoreSysClk: /* Core/System clock. */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockTimeSrcPllFllSel: /* FLL/PLL/IRC48M. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTimeSrcOsc0erClk: /* OSCERCLK. */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTimeSrcExt: /* ENET 1588 clock in. */
+ freq = g_enet1588ClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+#endif
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSdhcFreq
+ * Description : Gets the clock frequency for SDHC module
+ * This function gets the clock frequency for SDHC module
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_sdhc_src_t src;
+
+ src = CLOCK_HAL_GetSdhcSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockSdhcSrcCoreSysClk: /* Core/system clock */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockSdhcSrcPllFllSel: /* Clock selected by SOPT2[PLLFLLSEL]. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockSdhcSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSdhcSrcExt: /* External bypass clock (SDHC0_CLKIN) */
+ freq = g_sdhcClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+ kSimClockGateDac1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/* FlexCAN instance table. */
+static const sim_clock_gate_name_t flexcanGateTable[] =
+{
+ kSimClockGateFlexcan0,
+ kSimClockGateFlexcan1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFlexcanClock
+ * Description : Enable the clock for Flexcan module
+ * This function enables the clock for Flexcan module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, flexcanGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFlexcanClock
+ * Description : Disable the clock for Flexcan module
+ * This function disables the clock for Flexcan module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, flexcanGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanGateCmd
+ * Description : Get the the clock gate state for Flexcan module
+ * This function will get the clock gate state for Flexcan module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, flexcanGateTable[instance]);
+}
+#endif
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+ kSimClockGateSpi2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3,
+ kSimClockGateUart4,
+ kSimClockGateUart5
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK40D10/fsl_clock_MK40D10.h b/KSDK_1.2.0/platform/system/src/clock/MK40D10/fsl_clock_MK40D10.h
new file mode 100755
index 0000000..6445b7c
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK40D10/fsl_clock_MK40D10.h
@@ -0,0 +1,2048 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K40D10_H__)
+#define __FSL_CLOCK_K40D10_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k40d10*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief ENET external clock source count. */
+#define ENET_EXT_CLK_COUNT 1
+/*! @brief SDHC external clock source count. */
+#define SDHC_EXT_CLK_COUNT 1
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*! @brief ENET external clock frequency(ENET_1588_CLKIN) */
+extern uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT];
+#endif
+/*! @brief SDHC external clock frequency(SDHC_CLKIN). */
+extern uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT];
+#if FSL_FEATURE_SOC_USB_COUNT
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+#endif
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k40d10_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @} */
+/*! @addtogroup clock_manager*/
+/*! @{*/
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function sets divide value OUTDIV3.
+ *
+ * @param outdiv3 Outdivider3 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv3(uint8_t outdiv3)
+{
+ CLOCK_HAL_SetOutDiv3(SIM, outdiv3);
+}
+
+/*!
+ * @brief Gets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function gets divide value OUTDIV3.
+ *
+ * @return Outdivider3 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv3(void)
+{
+ return CLOCK_HAL_GetOutDiv3(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Gets ethernet RMII clock source.
+ *
+ * This function gets the ethernet RMII clock source.
+ *
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_rmii_src_t CLOCK_SYS_GetEnetRmiiSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetRmiiSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets ethernet RMII clock source.
+ *
+ * This function sets the ethernet RMII clock source.
+ *
+ * @param instance module device instance.
+ * @param rmiiSrc RMII clock source.
+ */
+static inline void CLOCK_SYS_SetEnetRmiiSrc(uint32_t instance, clock_rmii_src_t rmiiSrc)
+{
+ CLOCK_HAL_SetRmiiSrc(SIM, instance, rmiiSrc);
+}
+
+/*!
+ * @brief Gets ethernet RMII clock frequency.
+ *
+ * This function gets the ethernet RMII clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance);
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc);
+#endif
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Set the ethernet timestamp clock source selection.
+ *
+ * This function sets the ethernet timestamp clock source selection.
+ *
+ * @param instance module device instance.
+ * @param timeSrc Ethernet timestamp clock source.
+ */
+static inline void CLOCK_SYS_SetEnetTimeStampSrc(uint32_t instance, clock_time_src_t timeSrc)
+{
+ CLOCK_HAL_SetTimeSrc(SIM, instance, timeSrc);
+}
+
+/*!
+ * @brief Get the ethernet timestamp clock source selection.
+ *
+ * This function gets the ethernet timestamp clock source selection.
+ *
+ * @param instance IP instance.
+ *
+ * @return Current source.
+ */
+static inline clock_time_src_t CLOCK_SYS_GetEnetTimeStampSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTimeSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets ethernet timestamp clock frequency.
+ *
+ * This function gets the ethernet timestamp clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance);
+#endif
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+#endif
+
+/*!
+ * @brief Gets the clock frequency for SDHC.
+ *
+ * This function gets the clock frequency for SDHC.
+ * @param instance module device instance
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance);
+
+/*!
+ * @brief Set the SDHC clock source selection.
+ *
+ * This function sets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetSdhcSrc( uint32_t instance,
+ clock_sdhc_src_t setting)
+{
+ CLOCK_HAL_SetSdhcSrc(SIM, instance, setting);
+}
+
+/*!
+ * @brief Get the SDHC clock source selection.
+ *
+ * This function gets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_sdhc_src_t CLOCK_SYS_GetSdhcSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetSdhcSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+#if FSL_FEATURE_SOC_OPAMP_COUNT
+/*!
+ * @brief Enable the clock for OPAMP module.
+ *
+ * This function enables the clock for OPAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableOpampClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateOpamp);
+}
+
+/*!
+ * @brief Disable the clock for OPAMP module.
+ *
+ * This function disables the clock for OPAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableOpampClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateOpamp);
+}
+
+/*!
+ * @brief Get the the clock gate state for OPAMP module.
+ *
+ * This function will get the clock gate state for OPAMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetOpampGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateOpamp);
+}
+#endif
+
+#if FSL_FEATURE_SOC_TRIAMP_COUNT
+/*!
+ * @brief Enable the clock for TRIAMP module.
+ *
+ * This function enables the clock for TRIAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTriampClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTriamp);
+}
+
+/*!
+ * @brief Disable the clock for TRIAMP module.
+ *
+ * This function disables the clock for TRIAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTriampClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTriamp);
+}
+
+/*!
+ * @brief Get the the clock gate state for TRIAMP module.
+ *
+ * This function will get the clock gate state for TRIAMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTriampGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTriamp);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for MPU module.
+ *
+ * This function enables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableMpuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Disable the clock for MPU module.
+ *
+ * This function disables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableMpuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for MPU module.
+ *
+ * This function will get the clock gate state for MPU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetMpuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXBUS module.
+ *
+ * This function enables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXBUS module.
+ *
+ * This function disables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXBUS module.
+ *
+ * This function will get the clock gate state for FLEXBUS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexbusGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+#if FSL_FEATURE_SOC_RNG_COUNT
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+ * @brief Enable the clock for SLCD module.
+ *
+ * This function enables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Disable the clock for SLCD module.
+ *
+ * This function disables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SLCD module.
+ *
+ * This function will get the clock gate state for SLCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSlcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD default clock.
+ *
+ * This function gets the frequency for SLCD default clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdDefaultFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate clock.
+ *
+ * This function gets the frequency for SLCD alternate clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAltFreq(uint32_t instance)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Enable the clock for ENET module.
+ *
+ * This function enables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEnetClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Disable the clock for ENET module.
+ *
+ * This function disables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEnetClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Get the the clock gate state for ENET module.
+ *
+ * This function will get the clock gate state for ENET module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEnetGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEnet0);
+}
+#endif
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance);
+#endif
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SDHC module.
+ *
+ * This function enables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Disable the clock for SDHC module.
+ *
+ * This function disables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SDHC module.
+ *
+ * This function will get the clock gate state for SDHC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSdhcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Enable the clock for LLWU module.
+ *
+ * This function enables the clock for LLWU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLlwuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLlwu0);
+}
+
+/*!
+ * @brief Disable the clock for LLWU module.
+ *
+ * This function disables the clock for LLWU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLlwuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLlwu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LLWU module.
+ *
+ * This function will get the clock gate state for LLWU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLlwuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLlwu0);
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Set the ENET external clock frequency(ENET_1588_CLKIN).
+ *
+ * This function sets the ENET external clock frequency (ENET_1588_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetEnetExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < ENET_EXT_CLK_COUNT);
+
+ g_enet1588ClkInFreq[srcInstance] = freq;
+}
+#endif
+
+/*!
+ * @brief Set the SDHC external clock frequency(SDHC_CLKIN).
+ *
+ * This function sets the SDHC external clock frequency (SDHC_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetSdhcExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < SDHC_EXT_CLK_COUNT);
+
+ g_sdhcClkInFreq[srcInstance] = freq;
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+#endif
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K40D10_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK50D10/fsl_clock_MK50D10.c b/KSDK_1.2.0/platform/system/src/clock/MK50D10/fsl_clock_MK50D10.c
new file mode 100755
index 0000000..74bc257
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK50D10/fsl_clock_MK50D10.c
@@ -0,0 +1,1075 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+#if FSL_FEATURE_SOC_ENET_COUNT
+uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT]; /* ENET_1588_CLKIN */
+#endif
+uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT]; /* SDHC_CLKIN */
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+#endif
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 1U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlexBusClock:
+ *frequency = CLOCK_SYS_GetFlexbusFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexbusFreq
+ * Description : Gets the clock frequency for FLEXBUS module
+ * This function gets the clock frequency for FLEXBUS module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexbusFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv3(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG) / 2U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq() / 2U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetRmiiFreq
+ * Description : Gets the clock frequency for ENET module RMII clock.
+ * This function gets the clock frequency for ENET module RMII clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance)
+{
+ /* get the sim clock source setting*/
+ if (CLOCK_HAL_GetRmiiSrc(SIM, instance) == kClockRmiiSrcExtalClk)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq(); /* OSCERCLK */
+ }
+ else
+ {
+ return g_enet1588ClkInFreq[0]; /* ENET_1588_CLKIN */
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetTimeStampFreq
+ * Description : Gets the clock frequency for ENET module TIME clock.
+ * This function gets the clock frequency for ENET module TIME clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_time_src_t src;
+
+ src = CLOCK_HAL_GetTimeSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTimeSrcCoreSysClk: /* Core/System clock. */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockTimeSrcPllFllSel: /* FLL/PLL/IRC48M. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTimeSrcOsc0erClk: /* OSCERCLK. */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTimeSrcExt: /* ENET 1588 clock in. */
+ freq = g_enet1588ClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+#endif
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSdhcFreq
+ * Description : Gets the clock frequency for SDHC module
+ * This function gets the clock frequency for SDHC module
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_sdhc_src_t src;
+
+ src = CLOCK_HAL_GetSdhcSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockSdhcSrcCoreSysClk: /* Core/system clock */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockSdhcSrcPllFllSel: /* Clock selected by SOPT2[PLLFLLSEL]. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockSdhcSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSdhcSrcExt: /* External bypass clock (SDHC0_CLKIN) */
+ freq = g_sdhcClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+ kSimClockGateDac1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/* FlexCAN instance table. */
+static const sim_clock_gate_name_t flexcanGateTable[] =
+{
+ kSimClockGateFlexcan0,
+ kSimClockGateFlexcan1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFlexcanClock
+ * Description : Enable the clock for Flexcan module
+ * This function enables the clock for Flexcan module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, flexcanGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFlexcanClock
+ * Description : Disable the clock for Flexcan module
+ * This function disables the clock for Flexcan module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, flexcanGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanGateCmd
+ * Description : Get the the clock gate state for Flexcan module
+ * This function will get the clock gate state for Flexcan module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, flexcanGateTable[instance]);
+}
+#endif
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+ kSimClockGateSpi2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3,
+ kSimClockGateUart4,
+ kSimClockGateUart5
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK50D10/fsl_clock_MK50D10.h b/KSDK_1.2.0/platform/system/src/clock/MK50D10/fsl_clock_MK50D10.h
new file mode 100755
index 0000000..30036f0
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK50D10/fsl_clock_MK50D10.h
@@ -0,0 +1,2048 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K50D10_H__)
+#define __FSL_CLOCK_K50D10_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k50d10*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief ENET external clock source count. */
+#define ENET_EXT_CLK_COUNT 1
+/*! @brief SDHC external clock source count. */
+#define SDHC_EXT_CLK_COUNT 1
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*! @brief ENET external clock frequency(ENET_1588_CLKIN) */
+extern uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT];
+#endif
+/*! @brief SDHC external clock frequency(SDHC_CLKIN). */
+extern uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT];
+#if FSL_FEATURE_SOC_USB_COUNT
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+#endif
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k50d10_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @} */
+/*! @addtogroup clock_manager*/
+/*! @{*/
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function sets divide value OUTDIV3.
+ *
+ * @param outdiv3 Outdivider3 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv3(uint8_t outdiv3)
+{
+ CLOCK_HAL_SetOutDiv3(SIM, outdiv3);
+}
+
+/*!
+ * @brief Gets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function gets divide value OUTDIV3.
+ *
+ * @return Outdivider3 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv3(void)
+{
+ return CLOCK_HAL_GetOutDiv3(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Gets ethernet RMII clock source.
+ *
+ * This function gets the ethernet RMII clock source.
+ *
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_rmii_src_t CLOCK_SYS_GetEnetRmiiSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetRmiiSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets ethernet RMII clock source.
+ *
+ * This function sets the ethernet RMII clock source.
+ *
+ * @param instance module device instance.
+ * @param rmiiSrc RMII clock source.
+ */
+static inline void CLOCK_SYS_SetEnetRmiiSrc(uint32_t instance, clock_rmii_src_t rmiiSrc)
+{
+ CLOCK_HAL_SetRmiiSrc(SIM, instance, rmiiSrc);
+}
+
+/*!
+ * @brief Gets ethernet RMII clock frequency.
+ *
+ * This function gets the ethernet RMII clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance);
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc);
+#endif
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Set the ethernet timestamp clock source selection.
+ *
+ * This function sets the ethernet timestamp clock source selection.
+ *
+ * @param instance module device instance.
+ * @param timeSrc Ethernet timestamp clock source.
+ */
+static inline void CLOCK_SYS_SetEnetTimeStampSrc(uint32_t instance, clock_time_src_t timeSrc)
+{
+ CLOCK_HAL_SetTimeSrc(SIM, instance, timeSrc);
+}
+
+/*!
+ * @brief Get the ethernet timestamp clock source selection.
+ *
+ * This function gets the ethernet timestamp clock source selection.
+ *
+ * @param instance IP instance.
+ *
+ * @return Current source.
+ */
+static inline clock_time_src_t CLOCK_SYS_GetEnetTimeStampSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTimeSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets ethernet timestamp clock frequency.
+ *
+ * This function gets the ethernet timestamp clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance);
+#endif
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+#endif
+
+/*!
+ * @brief Gets the clock frequency for SDHC.
+ *
+ * This function gets the clock frequency for SDHC.
+ * @param instance module device instance
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance);
+
+/*!
+ * @brief Set the SDHC clock source selection.
+ *
+ * This function sets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetSdhcSrc( uint32_t instance,
+ clock_sdhc_src_t setting)
+{
+ CLOCK_HAL_SetSdhcSrc(SIM, instance, setting);
+}
+
+/*!
+ * @brief Get the SDHC clock source selection.
+ *
+ * This function gets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_sdhc_src_t CLOCK_SYS_GetSdhcSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetSdhcSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+#if FSL_FEATURE_SOC_OPAMP_COUNT
+/*!
+ * @brief Enable the clock for OPAMP module.
+ *
+ * This function enables the clock for OPAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableOpampClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateOpamp);
+}
+
+/*!
+ * @brief Disable the clock for OPAMP module.
+ *
+ * This function disables the clock for OPAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableOpampClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateOpamp);
+}
+
+/*!
+ * @brief Get the the clock gate state for OPAMP module.
+ *
+ * This function will get the clock gate state for OPAMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetOpampGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateOpamp);
+}
+#endif
+
+#if FSL_FEATURE_SOC_TRIAMP_COUNT
+/*!
+ * @brief Enable the clock for TRIAMP module.
+ *
+ * This function enables the clock for TRIAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTriampClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTriamp);
+}
+
+/*!
+ * @brief Disable the clock for TRIAMP module.
+ *
+ * This function disables the clock for TRIAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTriampClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTriamp);
+}
+
+/*!
+ * @brief Get the the clock gate state for TRIAMP module.
+ *
+ * This function will get the clock gate state for TRIAMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTriampGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTriamp);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for MPU module.
+ *
+ * This function enables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableMpuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Disable the clock for MPU module.
+ *
+ * This function disables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableMpuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for MPU module.
+ *
+ * This function will get the clock gate state for MPU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetMpuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXBUS module.
+ *
+ * This function enables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXBUS module.
+ *
+ * This function disables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXBUS module.
+ *
+ * This function will get the clock gate state for FLEXBUS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexbusGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+#if FSL_FEATURE_SOC_RNG_COUNT
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+ * @brief Enable the clock for SLCD module.
+ *
+ * This function enables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Disable the clock for SLCD module.
+ *
+ * This function disables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SLCD module.
+ *
+ * This function will get the clock gate state for SLCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSlcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD default clock.
+ *
+ * This function gets the frequency for SLCD default clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdDefaultFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate clock.
+ *
+ * This function gets the frequency for SLCD alternate clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAltFreq(uint32_t instance)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Enable the clock for ENET module.
+ *
+ * This function enables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEnetClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Disable the clock for ENET module.
+ *
+ * This function disables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEnetClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Get the the clock gate state for ENET module.
+ *
+ * This function will get the clock gate state for ENET module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEnetGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEnet0);
+}
+#endif
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance);
+#endif
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SDHC module.
+ *
+ * This function enables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Disable the clock for SDHC module.
+ *
+ * This function disables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SDHC module.
+ *
+ * This function will get the clock gate state for SDHC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSdhcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Enable the clock for LLWU module.
+ *
+ * This function enables the clock for LLWU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLlwuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLlwu0);
+}
+
+/*!
+ * @brief Disable the clock for LLWU module.
+ *
+ * This function disables the clock for LLWU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLlwuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLlwu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LLWU module.
+ *
+ * This function will get the clock gate state for LLWU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLlwuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLlwu0);
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Set the ENET external clock frequency(ENET_1588_CLKIN).
+ *
+ * This function sets the ENET external clock frequency (ENET_1588_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetEnetExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < ENET_EXT_CLK_COUNT);
+
+ g_enet1588ClkInFreq[srcInstance] = freq;
+}
+#endif
+
+/*!
+ * @brief Set the SDHC external clock frequency(SDHC_CLKIN).
+ *
+ * This function sets the SDHC external clock frequency (SDHC_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetSdhcExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < SDHC_EXT_CLK_COUNT);
+
+ g_sdhcClkInFreq[srcInstance] = freq;
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+#endif
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K50D10_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK51D10/fsl_clock_MK51D10.c b/KSDK_1.2.0/platform/system/src/clock/MK51D10/fsl_clock_MK51D10.c
new file mode 100755
index 0000000..74bc257
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK51D10/fsl_clock_MK51D10.c
@@ -0,0 +1,1075 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+#if FSL_FEATURE_SOC_ENET_COUNT
+uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT]; /* ENET_1588_CLKIN */
+#endif
+uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT]; /* SDHC_CLKIN */
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+#endif
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 1U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlexBusClock:
+ *frequency = CLOCK_SYS_GetFlexbusFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexbusFreq
+ * Description : Gets the clock frequency for FLEXBUS module
+ * This function gets the clock frequency for FLEXBUS module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexbusFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv3(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG) / 2U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq() / 2U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetRmiiFreq
+ * Description : Gets the clock frequency for ENET module RMII clock.
+ * This function gets the clock frequency for ENET module RMII clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance)
+{
+ /* get the sim clock source setting*/
+ if (CLOCK_HAL_GetRmiiSrc(SIM, instance) == kClockRmiiSrcExtalClk)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq(); /* OSCERCLK */
+ }
+ else
+ {
+ return g_enet1588ClkInFreq[0]; /* ENET_1588_CLKIN */
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetTimeStampFreq
+ * Description : Gets the clock frequency for ENET module TIME clock.
+ * This function gets the clock frequency for ENET module TIME clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_time_src_t src;
+
+ src = CLOCK_HAL_GetTimeSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTimeSrcCoreSysClk: /* Core/System clock. */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockTimeSrcPllFllSel: /* FLL/PLL/IRC48M. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTimeSrcOsc0erClk: /* OSCERCLK. */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTimeSrcExt: /* ENET 1588 clock in. */
+ freq = g_enet1588ClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+#endif
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSdhcFreq
+ * Description : Gets the clock frequency for SDHC module
+ * This function gets the clock frequency for SDHC module
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_sdhc_src_t src;
+
+ src = CLOCK_HAL_GetSdhcSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockSdhcSrcCoreSysClk: /* Core/system clock */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockSdhcSrcPllFllSel: /* Clock selected by SOPT2[PLLFLLSEL]. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockSdhcSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSdhcSrcExt: /* External bypass clock (SDHC0_CLKIN) */
+ freq = g_sdhcClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+ kSimClockGateDac1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/* FlexCAN instance table. */
+static const sim_clock_gate_name_t flexcanGateTable[] =
+{
+ kSimClockGateFlexcan0,
+ kSimClockGateFlexcan1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFlexcanClock
+ * Description : Enable the clock for Flexcan module
+ * This function enables the clock for Flexcan module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, flexcanGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFlexcanClock
+ * Description : Disable the clock for Flexcan module
+ * This function disables the clock for Flexcan module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, flexcanGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanGateCmd
+ * Description : Get the the clock gate state for Flexcan module
+ * This function will get the clock gate state for Flexcan module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, flexcanGateTable[instance]);
+}
+#endif
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+ kSimClockGateSpi2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3,
+ kSimClockGateUart4,
+ kSimClockGateUart5
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK51D10/fsl_clock_MK51D10.h b/KSDK_1.2.0/platform/system/src/clock/MK51D10/fsl_clock_MK51D10.h
new file mode 100755
index 0000000..f4a5057
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK51D10/fsl_clock_MK51D10.h
@@ -0,0 +1,2048 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K51D10_H__)
+#define __FSL_CLOCK_K51D10_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k51d10*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief ENET external clock source count. */
+#define ENET_EXT_CLK_COUNT 1
+/*! @brief SDHC external clock source count. */
+#define SDHC_EXT_CLK_COUNT 1
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*! @brief ENET external clock frequency(ENET_1588_CLKIN) */
+extern uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT];
+#endif
+/*! @brief SDHC external clock frequency(SDHC_CLKIN). */
+extern uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT];
+#if FSL_FEATURE_SOC_USB_COUNT
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+#endif
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k51d10_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @} */
+/*! @addtogroup clock_manager*/
+/*! @{*/
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function sets divide value OUTDIV3.
+ *
+ * @param outdiv3 Outdivider3 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv3(uint8_t outdiv3)
+{
+ CLOCK_HAL_SetOutDiv3(SIM, outdiv3);
+}
+
+/*!
+ * @brief Gets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function gets divide value OUTDIV3.
+ *
+ * @return Outdivider3 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv3(void)
+{
+ return CLOCK_HAL_GetOutDiv3(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Gets ethernet RMII clock source.
+ *
+ * This function gets the ethernet RMII clock source.
+ *
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_rmii_src_t CLOCK_SYS_GetEnetRmiiSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetRmiiSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets ethernet RMII clock source.
+ *
+ * This function sets the ethernet RMII clock source.
+ *
+ * @param instance module device instance.
+ * @param rmiiSrc RMII clock source.
+ */
+static inline void CLOCK_SYS_SetEnetRmiiSrc(uint32_t instance, clock_rmii_src_t rmiiSrc)
+{
+ CLOCK_HAL_SetRmiiSrc(SIM, instance, rmiiSrc);
+}
+
+/*!
+ * @brief Gets ethernet RMII clock frequency.
+ *
+ * This function gets the ethernet RMII clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance);
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc);
+#endif
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Set the ethernet timestamp clock source selection.
+ *
+ * This function sets the ethernet timestamp clock source selection.
+ *
+ * @param instance module device instance.
+ * @param timeSrc Ethernet timestamp clock source.
+ */
+static inline void CLOCK_SYS_SetEnetTimeStampSrc(uint32_t instance, clock_time_src_t timeSrc)
+{
+ CLOCK_HAL_SetTimeSrc(SIM, instance, timeSrc);
+}
+
+/*!
+ * @brief Get the ethernet timestamp clock source selection.
+ *
+ * This function gets the ethernet timestamp clock source selection.
+ *
+ * @param instance IP instance.
+ *
+ * @return Current source.
+ */
+static inline clock_time_src_t CLOCK_SYS_GetEnetTimeStampSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTimeSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets ethernet timestamp clock frequency.
+ *
+ * This function gets the ethernet timestamp clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance);
+#endif
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+#endif
+
+/*!
+ * @brief Gets the clock frequency for SDHC.
+ *
+ * This function gets the clock frequency for SDHC.
+ * @param instance module device instance
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance);
+
+/*!
+ * @brief Set the SDHC clock source selection.
+ *
+ * This function sets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetSdhcSrc( uint32_t instance,
+ clock_sdhc_src_t setting)
+{
+ CLOCK_HAL_SetSdhcSrc(SIM, instance, setting);
+}
+
+/*!
+ * @brief Get the SDHC clock source selection.
+ *
+ * This function gets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_sdhc_src_t CLOCK_SYS_GetSdhcSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetSdhcSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+#if FSL_FEATURE_SOC_OPAMP_COUNT
+/*!
+ * @brief Enable the clock for OPAMP module.
+ *
+ * This function enables the clock for OPAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableOpampClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateOpamp);
+}
+
+/*!
+ * @brief Disable the clock for OPAMP module.
+ *
+ * This function disables the clock for OPAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableOpampClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateOpamp);
+}
+
+/*!
+ * @brief Get the the clock gate state for OPAMP module.
+ *
+ * This function will get the clock gate state for OPAMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetOpampGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateOpamp);
+}
+#endif
+
+#if FSL_FEATURE_SOC_TRIAMP_COUNT
+/*!
+ * @brief Enable the clock for TRIAMP module.
+ *
+ * This function enables the clock for TRIAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTriampClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTriamp);
+}
+
+/*!
+ * @brief Disable the clock for TRIAMP module.
+ *
+ * This function disables the clock for TRIAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTriampClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTriamp);
+}
+
+/*!
+ * @brief Get the the clock gate state for TRIAMP module.
+ *
+ * This function will get the clock gate state for TRIAMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTriampGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTriamp);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for MPU module.
+ *
+ * This function enables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableMpuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Disable the clock for MPU module.
+ *
+ * This function disables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableMpuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for MPU module.
+ *
+ * This function will get the clock gate state for MPU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetMpuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXBUS module.
+ *
+ * This function enables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXBUS module.
+ *
+ * This function disables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXBUS module.
+ *
+ * This function will get the clock gate state for FLEXBUS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexbusGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+#if FSL_FEATURE_SOC_RNG_COUNT
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+ * @brief Enable the clock for SLCD module.
+ *
+ * This function enables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Disable the clock for SLCD module.
+ *
+ * This function disables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SLCD module.
+ *
+ * This function will get the clock gate state for SLCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSlcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD default clock.
+ *
+ * This function gets the frequency for SLCD default clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdDefaultFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate clock.
+ *
+ * This function gets the frequency for SLCD alternate clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAltFreq(uint32_t instance)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Enable the clock for ENET module.
+ *
+ * This function enables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEnetClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Disable the clock for ENET module.
+ *
+ * This function disables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEnetClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Get the the clock gate state for ENET module.
+ *
+ * This function will get the clock gate state for ENET module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEnetGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEnet0);
+}
+#endif
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance);
+#endif
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SDHC module.
+ *
+ * This function enables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Disable the clock for SDHC module.
+ *
+ * This function disables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SDHC module.
+ *
+ * This function will get the clock gate state for SDHC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSdhcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Enable the clock for LLWU module.
+ *
+ * This function enables the clock for LLWU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLlwuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLlwu0);
+}
+
+/*!
+ * @brief Disable the clock for LLWU module.
+ *
+ * This function disables the clock for LLWU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLlwuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLlwu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LLWU module.
+ *
+ * This function will get the clock gate state for LLWU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLlwuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLlwu0);
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Set the ENET external clock frequency(ENET_1588_CLKIN).
+ *
+ * This function sets the ENET external clock frequency (ENET_1588_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetEnetExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < ENET_EXT_CLK_COUNT);
+
+ g_enet1588ClkInFreq[srcInstance] = freq;
+}
+#endif
+
+/*!
+ * @brief Set the SDHC external clock frequency(SDHC_CLKIN).
+ *
+ * This function sets the SDHC external clock frequency (SDHC_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetSdhcExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < SDHC_EXT_CLK_COUNT);
+
+ g_sdhcClkInFreq[srcInstance] = freq;
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+#endif
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K51D10_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK52D10/fsl_clock_MK52D10.c b/KSDK_1.2.0/platform/system/src/clock/MK52D10/fsl_clock_MK52D10.c
new file mode 100755
index 0000000..74bc257
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK52D10/fsl_clock_MK52D10.c
@@ -0,0 +1,1075 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+#if FSL_FEATURE_SOC_ENET_COUNT
+uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT]; /* ENET_1588_CLKIN */
+#endif
+uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT]; /* SDHC_CLKIN */
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+#endif
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 1U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlexBusClock:
+ *frequency = CLOCK_SYS_GetFlexbusFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexbusFreq
+ * Description : Gets the clock frequency for FLEXBUS module
+ * This function gets the clock frequency for FLEXBUS module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexbusFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv3(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG) / 2U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq() / 2U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetRmiiFreq
+ * Description : Gets the clock frequency for ENET module RMII clock.
+ * This function gets the clock frequency for ENET module RMII clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance)
+{
+ /* get the sim clock source setting*/
+ if (CLOCK_HAL_GetRmiiSrc(SIM, instance) == kClockRmiiSrcExtalClk)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq(); /* OSCERCLK */
+ }
+ else
+ {
+ return g_enet1588ClkInFreq[0]; /* ENET_1588_CLKIN */
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetTimeStampFreq
+ * Description : Gets the clock frequency for ENET module TIME clock.
+ * This function gets the clock frequency for ENET module TIME clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_time_src_t src;
+
+ src = CLOCK_HAL_GetTimeSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTimeSrcCoreSysClk: /* Core/System clock. */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockTimeSrcPllFllSel: /* FLL/PLL/IRC48M. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTimeSrcOsc0erClk: /* OSCERCLK. */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTimeSrcExt: /* ENET 1588 clock in. */
+ freq = g_enet1588ClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+#endif
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSdhcFreq
+ * Description : Gets the clock frequency for SDHC module
+ * This function gets the clock frequency for SDHC module
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_sdhc_src_t src;
+
+ src = CLOCK_HAL_GetSdhcSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockSdhcSrcCoreSysClk: /* Core/system clock */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockSdhcSrcPllFllSel: /* Clock selected by SOPT2[PLLFLLSEL]. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockSdhcSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSdhcSrcExt: /* External bypass clock (SDHC0_CLKIN) */
+ freq = g_sdhcClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+ kSimClockGateDac1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/* FlexCAN instance table. */
+static const sim_clock_gate_name_t flexcanGateTable[] =
+{
+ kSimClockGateFlexcan0,
+ kSimClockGateFlexcan1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFlexcanClock
+ * Description : Enable the clock for Flexcan module
+ * This function enables the clock for Flexcan module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, flexcanGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFlexcanClock
+ * Description : Disable the clock for Flexcan module
+ * This function disables the clock for Flexcan module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, flexcanGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanGateCmd
+ * Description : Get the the clock gate state for Flexcan module
+ * This function will get the clock gate state for Flexcan module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, flexcanGateTable[instance]);
+}
+#endif
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+ kSimClockGateSpi2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3,
+ kSimClockGateUart4,
+ kSimClockGateUart5
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK52D10/fsl_clock_MK52D10.h b/KSDK_1.2.0/platform/system/src/clock/MK52D10/fsl_clock_MK52D10.h
new file mode 100755
index 0000000..d29559c
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK52D10/fsl_clock_MK52D10.h
@@ -0,0 +1,2048 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K52D10_H__)
+#define __FSL_CLOCK_K52D10_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k52d10*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief ENET external clock source count. */
+#define ENET_EXT_CLK_COUNT 1
+/*! @brief SDHC external clock source count. */
+#define SDHC_EXT_CLK_COUNT 1
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*! @brief ENET external clock frequency(ENET_1588_CLKIN) */
+extern uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT];
+#endif
+/*! @brief SDHC external clock frequency(SDHC_CLKIN). */
+extern uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT];
+#if FSL_FEATURE_SOC_USB_COUNT
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+#endif
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k52d10_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @} */
+/*! @addtogroup clock_manager*/
+/*! @{*/
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function sets divide value OUTDIV3.
+ *
+ * @param outdiv3 Outdivider3 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv3(uint8_t outdiv3)
+{
+ CLOCK_HAL_SetOutDiv3(SIM, outdiv3);
+}
+
+/*!
+ * @brief Gets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function gets divide value OUTDIV3.
+ *
+ * @return Outdivider3 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv3(void)
+{
+ return CLOCK_HAL_GetOutDiv3(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Gets ethernet RMII clock source.
+ *
+ * This function gets the ethernet RMII clock source.
+ *
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_rmii_src_t CLOCK_SYS_GetEnetRmiiSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetRmiiSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets ethernet RMII clock source.
+ *
+ * This function sets the ethernet RMII clock source.
+ *
+ * @param instance module device instance.
+ * @param rmiiSrc RMII clock source.
+ */
+static inline void CLOCK_SYS_SetEnetRmiiSrc(uint32_t instance, clock_rmii_src_t rmiiSrc)
+{
+ CLOCK_HAL_SetRmiiSrc(SIM, instance, rmiiSrc);
+}
+
+/*!
+ * @brief Gets ethernet RMII clock frequency.
+ *
+ * This function gets the ethernet RMII clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance);
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc);
+#endif
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Set the ethernet timestamp clock source selection.
+ *
+ * This function sets the ethernet timestamp clock source selection.
+ *
+ * @param instance module device instance.
+ * @param timeSrc Ethernet timestamp clock source.
+ */
+static inline void CLOCK_SYS_SetEnetTimeStampSrc(uint32_t instance, clock_time_src_t timeSrc)
+{
+ CLOCK_HAL_SetTimeSrc(SIM, instance, timeSrc);
+}
+
+/*!
+ * @brief Get the ethernet timestamp clock source selection.
+ *
+ * This function gets the ethernet timestamp clock source selection.
+ *
+ * @param instance IP instance.
+ *
+ * @return Current source.
+ */
+static inline clock_time_src_t CLOCK_SYS_GetEnetTimeStampSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTimeSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets ethernet timestamp clock frequency.
+ *
+ * This function gets the ethernet timestamp clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance);
+#endif
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+#endif
+
+/*!
+ * @brief Gets the clock frequency for SDHC.
+ *
+ * This function gets the clock frequency for SDHC.
+ * @param instance module device instance
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance);
+
+/*!
+ * @brief Set the SDHC clock source selection.
+ *
+ * This function sets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetSdhcSrc( uint32_t instance,
+ clock_sdhc_src_t setting)
+{
+ CLOCK_HAL_SetSdhcSrc(SIM, instance, setting);
+}
+
+/*!
+ * @brief Get the SDHC clock source selection.
+ *
+ * This function gets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_sdhc_src_t CLOCK_SYS_GetSdhcSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetSdhcSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+#if FSL_FEATURE_SOC_OPAMP_COUNT
+/*!
+ * @brief Enable the clock for OPAMP module.
+ *
+ * This function enables the clock for OPAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableOpampClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateOpamp);
+}
+
+/*!
+ * @brief Disable the clock for OPAMP module.
+ *
+ * This function disables the clock for OPAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableOpampClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateOpamp);
+}
+
+/*!
+ * @brief Get the the clock gate state for OPAMP module.
+ *
+ * This function will get the clock gate state for OPAMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetOpampGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateOpamp);
+}
+#endif
+
+#if FSL_FEATURE_SOC_TRIAMP_COUNT
+/*!
+ * @brief Enable the clock for TRIAMP module.
+ *
+ * This function enables the clock for TRIAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTriampClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTriamp);
+}
+
+/*!
+ * @brief Disable the clock for TRIAMP module.
+ *
+ * This function disables the clock for TRIAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTriampClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTriamp);
+}
+
+/*!
+ * @brief Get the the clock gate state for TRIAMP module.
+ *
+ * This function will get the clock gate state for TRIAMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTriampGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTriamp);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for MPU module.
+ *
+ * This function enables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableMpuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Disable the clock for MPU module.
+ *
+ * This function disables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableMpuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for MPU module.
+ *
+ * This function will get the clock gate state for MPU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetMpuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXBUS module.
+ *
+ * This function enables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXBUS module.
+ *
+ * This function disables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXBUS module.
+ *
+ * This function will get the clock gate state for FLEXBUS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexbusGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+#if FSL_FEATURE_SOC_RNG_COUNT
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+ * @brief Enable the clock for SLCD module.
+ *
+ * This function enables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Disable the clock for SLCD module.
+ *
+ * This function disables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SLCD module.
+ *
+ * This function will get the clock gate state for SLCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSlcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD default clock.
+ *
+ * This function gets the frequency for SLCD default clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdDefaultFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate clock.
+ *
+ * This function gets the frequency for SLCD alternate clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAltFreq(uint32_t instance)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Enable the clock for ENET module.
+ *
+ * This function enables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEnetClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Disable the clock for ENET module.
+ *
+ * This function disables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEnetClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Get the the clock gate state for ENET module.
+ *
+ * This function will get the clock gate state for ENET module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEnetGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEnet0);
+}
+#endif
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance);
+#endif
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SDHC module.
+ *
+ * This function enables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Disable the clock for SDHC module.
+ *
+ * This function disables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SDHC module.
+ *
+ * This function will get the clock gate state for SDHC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSdhcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Enable the clock for LLWU module.
+ *
+ * This function enables the clock for LLWU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLlwuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLlwu0);
+}
+
+/*!
+ * @brief Disable the clock for LLWU module.
+ *
+ * This function disables the clock for LLWU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLlwuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLlwu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LLWU module.
+ *
+ * This function will get the clock gate state for LLWU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLlwuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLlwu0);
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Set the ENET external clock frequency(ENET_1588_CLKIN).
+ *
+ * This function sets the ENET external clock frequency (ENET_1588_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetEnetExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < ENET_EXT_CLK_COUNT);
+
+ g_enet1588ClkInFreq[srcInstance] = freq;
+}
+#endif
+
+/*!
+ * @brief Set the SDHC external clock frequency(SDHC_CLKIN).
+ *
+ * This function sets the SDHC external clock frequency (SDHC_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetSdhcExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < SDHC_EXT_CLK_COUNT);
+
+ g_sdhcClkInFreq[srcInstance] = freq;
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+#endif
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K52D10_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK53D10/fsl_clock_MK53D10.c b/KSDK_1.2.0/platform/system/src/clock/MK53D10/fsl_clock_MK53D10.c
new file mode 100755
index 0000000..74bc257
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK53D10/fsl_clock_MK53D10.c
@@ -0,0 +1,1075 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+#if FSL_FEATURE_SOC_ENET_COUNT
+uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT]; /* ENET_1588_CLKIN */
+#endif
+uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT]; /* SDHC_CLKIN */
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+#endif
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 1U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlexBusClock:
+ *frequency = CLOCK_SYS_GetFlexbusFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexbusFreq
+ * Description : Gets the clock frequency for FLEXBUS module
+ * This function gets the clock frequency for FLEXBUS module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexbusFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv3(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG) / 2U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq() / 2U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetRmiiFreq
+ * Description : Gets the clock frequency for ENET module RMII clock.
+ * This function gets the clock frequency for ENET module RMII clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance)
+{
+ /* get the sim clock source setting*/
+ if (CLOCK_HAL_GetRmiiSrc(SIM, instance) == kClockRmiiSrcExtalClk)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq(); /* OSCERCLK */
+ }
+ else
+ {
+ return g_enet1588ClkInFreq[0]; /* ENET_1588_CLKIN */
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetTimeStampFreq
+ * Description : Gets the clock frequency for ENET module TIME clock.
+ * This function gets the clock frequency for ENET module TIME clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_time_src_t src;
+
+ src = CLOCK_HAL_GetTimeSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTimeSrcCoreSysClk: /* Core/System clock. */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockTimeSrcPllFllSel: /* FLL/PLL/IRC48M. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTimeSrcOsc0erClk: /* OSCERCLK. */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTimeSrcExt: /* ENET 1588 clock in. */
+ freq = g_enet1588ClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+#endif
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSdhcFreq
+ * Description : Gets the clock frequency for SDHC module
+ * This function gets the clock frequency for SDHC module
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_sdhc_src_t src;
+
+ src = CLOCK_HAL_GetSdhcSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockSdhcSrcCoreSysClk: /* Core/system clock */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockSdhcSrcPllFllSel: /* Clock selected by SOPT2[PLLFLLSEL]. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockSdhcSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSdhcSrcExt: /* External bypass clock (SDHC0_CLKIN) */
+ freq = g_sdhcClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+ kSimClockGateDac1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/* FlexCAN instance table. */
+static const sim_clock_gate_name_t flexcanGateTable[] =
+{
+ kSimClockGateFlexcan0,
+ kSimClockGateFlexcan1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFlexcanClock
+ * Description : Enable the clock for Flexcan module
+ * This function enables the clock for Flexcan module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, flexcanGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFlexcanClock
+ * Description : Disable the clock for Flexcan module
+ * This function disables the clock for Flexcan module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, flexcanGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanGateCmd
+ * Description : Get the the clock gate state for Flexcan module
+ * This function will get the clock gate state for Flexcan module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, flexcanGateTable[instance]);
+}
+#endif
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+ kSimClockGateSpi2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3,
+ kSimClockGateUart4,
+ kSimClockGateUart5
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK53D10/fsl_clock_MK53D10.h b/KSDK_1.2.0/platform/system/src/clock/MK53D10/fsl_clock_MK53D10.h
new file mode 100755
index 0000000..9b5421d
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK53D10/fsl_clock_MK53D10.h
@@ -0,0 +1,2048 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K53D10_H__)
+#define __FSL_CLOCK_K53D10_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k53d10*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief ENET external clock source count. */
+#define ENET_EXT_CLK_COUNT 1
+/*! @brief SDHC external clock source count. */
+#define SDHC_EXT_CLK_COUNT 1
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*! @brief ENET external clock frequency(ENET_1588_CLKIN) */
+extern uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT];
+#endif
+/*! @brief SDHC external clock frequency(SDHC_CLKIN). */
+extern uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT];
+#if FSL_FEATURE_SOC_USB_COUNT
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+#endif
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k53d10_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @} */
+/*! @addtogroup clock_manager*/
+/*! @{*/
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function sets divide value OUTDIV3.
+ *
+ * @param outdiv3 Outdivider3 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv3(uint8_t outdiv3)
+{
+ CLOCK_HAL_SetOutDiv3(SIM, outdiv3);
+}
+
+/*!
+ * @brief Gets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function gets divide value OUTDIV3.
+ *
+ * @return Outdivider3 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv3(void)
+{
+ return CLOCK_HAL_GetOutDiv3(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Gets ethernet RMII clock source.
+ *
+ * This function gets the ethernet RMII clock source.
+ *
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_rmii_src_t CLOCK_SYS_GetEnetRmiiSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetRmiiSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets ethernet RMII clock source.
+ *
+ * This function sets the ethernet RMII clock source.
+ *
+ * @param instance module device instance.
+ * @param rmiiSrc RMII clock source.
+ */
+static inline void CLOCK_SYS_SetEnetRmiiSrc(uint32_t instance, clock_rmii_src_t rmiiSrc)
+{
+ CLOCK_HAL_SetRmiiSrc(SIM, instance, rmiiSrc);
+}
+
+/*!
+ * @brief Gets ethernet RMII clock frequency.
+ *
+ * This function gets the ethernet RMII clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance);
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc);
+#endif
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Set the ethernet timestamp clock source selection.
+ *
+ * This function sets the ethernet timestamp clock source selection.
+ *
+ * @param instance module device instance.
+ * @param timeSrc Ethernet timestamp clock source.
+ */
+static inline void CLOCK_SYS_SetEnetTimeStampSrc(uint32_t instance, clock_time_src_t timeSrc)
+{
+ CLOCK_HAL_SetTimeSrc(SIM, instance, timeSrc);
+}
+
+/*!
+ * @brief Get the ethernet timestamp clock source selection.
+ *
+ * This function gets the ethernet timestamp clock source selection.
+ *
+ * @param instance IP instance.
+ *
+ * @return Current source.
+ */
+static inline clock_time_src_t CLOCK_SYS_GetEnetTimeStampSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTimeSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets ethernet timestamp clock frequency.
+ *
+ * This function gets the ethernet timestamp clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance);
+#endif
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+#endif
+
+/*!
+ * @brief Gets the clock frequency for SDHC.
+ *
+ * This function gets the clock frequency for SDHC.
+ * @param instance module device instance
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance);
+
+/*!
+ * @brief Set the SDHC clock source selection.
+ *
+ * This function sets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetSdhcSrc( uint32_t instance,
+ clock_sdhc_src_t setting)
+{
+ CLOCK_HAL_SetSdhcSrc(SIM, instance, setting);
+}
+
+/*!
+ * @brief Get the SDHC clock source selection.
+ *
+ * This function gets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_sdhc_src_t CLOCK_SYS_GetSdhcSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetSdhcSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+#if FSL_FEATURE_SOC_OPAMP_COUNT
+/*!
+ * @brief Enable the clock for OPAMP module.
+ *
+ * This function enables the clock for OPAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableOpampClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateOpamp);
+}
+
+/*!
+ * @brief Disable the clock for OPAMP module.
+ *
+ * This function disables the clock for OPAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableOpampClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateOpamp);
+}
+
+/*!
+ * @brief Get the the clock gate state for OPAMP module.
+ *
+ * This function will get the clock gate state for OPAMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetOpampGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateOpamp);
+}
+#endif
+
+#if FSL_FEATURE_SOC_TRIAMP_COUNT
+/*!
+ * @brief Enable the clock for TRIAMP module.
+ *
+ * This function enables the clock for TRIAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTriampClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTriamp);
+}
+
+/*!
+ * @brief Disable the clock for TRIAMP module.
+ *
+ * This function disables the clock for TRIAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTriampClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTriamp);
+}
+
+/*!
+ * @brief Get the the clock gate state for TRIAMP module.
+ *
+ * This function will get the clock gate state for TRIAMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTriampGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTriamp);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for MPU module.
+ *
+ * This function enables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableMpuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Disable the clock for MPU module.
+ *
+ * This function disables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableMpuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for MPU module.
+ *
+ * This function will get the clock gate state for MPU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetMpuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXBUS module.
+ *
+ * This function enables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXBUS module.
+ *
+ * This function disables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXBUS module.
+ *
+ * This function will get the clock gate state for FLEXBUS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexbusGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+#if FSL_FEATURE_SOC_RNG_COUNT
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+ * @brief Enable the clock for SLCD module.
+ *
+ * This function enables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Disable the clock for SLCD module.
+ *
+ * This function disables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SLCD module.
+ *
+ * This function will get the clock gate state for SLCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSlcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD default clock.
+ *
+ * This function gets the frequency for SLCD default clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdDefaultFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate clock.
+ *
+ * This function gets the frequency for SLCD alternate clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAltFreq(uint32_t instance)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Enable the clock for ENET module.
+ *
+ * This function enables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEnetClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Disable the clock for ENET module.
+ *
+ * This function disables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEnetClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Get the the clock gate state for ENET module.
+ *
+ * This function will get the clock gate state for ENET module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEnetGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEnet0);
+}
+#endif
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance);
+#endif
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SDHC module.
+ *
+ * This function enables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Disable the clock for SDHC module.
+ *
+ * This function disables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SDHC module.
+ *
+ * This function will get the clock gate state for SDHC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSdhcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Enable the clock for LLWU module.
+ *
+ * This function enables the clock for LLWU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLlwuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLlwu0);
+}
+
+/*!
+ * @brief Disable the clock for LLWU module.
+ *
+ * This function disables the clock for LLWU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLlwuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLlwu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LLWU module.
+ *
+ * This function will get the clock gate state for LLWU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLlwuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLlwu0);
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Set the ENET external clock frequency(ENET_1588_CLKIN).
+ *
+ * This function sets the ENET external clock frequency (ENET_1588_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetEnetExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < ENET_EXT_CLK_COUNT);
+
+ g_enet1588ClkInFreq[srcInstance] = freq;
+}
+#endif
+
+/*!
+ * @brief Set the SDHC external clock frequency(SDHC_CLKIN).
+ *
+ * This function sets the SDHC external clock frequency (SDHC_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetSdhcExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < SDHC_EXT_CLK_COUNT);
+
+ g_sdhcClkInFreq[srcInstance] = freq;
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+#endif
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K53D10_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK60D10/fsl_clock_MK60D10.c b/KSDK_1.2.0/platform/system/src/clock/MK60D10/fsl_clock_MK60D10.c
new file mode 100755
index 0000000..74bc257
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK60D10/fsl_clock_MK60D10.c
@@ -0,0 +1,1075 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+#if FSL_FEATURE_SOC_ENET_COUNT
+uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT]; /* ENET_1588_CLKIN */
+#endif
+uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT]; /* SDHC_CLKIN */
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+#endif
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 1U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlexBusClock:
+ *frequency = CLOCK_SYS_GetFlexbusFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexbusFreq
+ * Description : Gets the clock frequency for FLEXBUS module
+ * This function gets the clock frequency for FLEXBUS module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexbusFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv3(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG) / 2U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq() / 2U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetRmiiFreq
+ * Description : Gets the clock frequency for ENET module RMII clock.
+ * This function gets the clock frequency for ENET module RMII clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance)
+{
+ /* get the sim clock source setting*/
+ if (CLOCK_HAL_GetRmiiSrc(SIM, instance) == kClockRmiiSrcExtalClk)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq(); /* OSCERCLK */
+ }
+ else
+ {
+ return g_enet1588ClkInFreq[0]; /* ENET_1588_CLKIN */
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetTimeStampFreq
+ * Description : Gets the clock frequency for ENET module TIME clock.
+ * This function gets the clock frequency for ENET module TIME clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_time_src_t src;
+
+ src = CLOCK_HAL_GetTimeSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTimeSrcCoreSysClk: /* Core/System clock. */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockTimeSrcPllFllSel: /* FLL/PLL/IRC48M. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTimeSrcOsc0erClk: /* OSCERCLK. */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTimeSrcExt: /* ENET 1588 clock in. */
+ freq = g_enet1588ClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+#endif
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSdhcFreq
+ * Description : Gets the clock frequency for SDHC module
+ * This function gets the clock frequency for SDHC module
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_sdhc_src_t src;
+
+ src = CLOCK_HAL_GetSdhcSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockSdhcSrcCoreSysClk: /* Core/system clock */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockSdhcSrcPllFllSel: /* Clock selected by SOPT2[PLLFLLSEL]. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockSdhcSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSdhcSrcExt: /* External bypass clock (SDHC0_CLKIN) */
+ freq = g_sdhcClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+ kSimClockGateDac1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/* FlexCAN instance table. */
+static const sim_clock_gate_name_t flexcanGateTable[] =
+{
+ kSimClockGateFlexcan0,
+ kSimClockGateFlexcan1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFlexcanClock
+ * Description : Enable the clock for Flexcan module
+ * This function enables the clock for Flexcan module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, flexcanGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFlexcanClock
+ * Description : Disable the clock for Flexcan module
+ * This function disables the clock for Flexcan module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, flexcanGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanGateCmd
+ * Description : Get the the clock gate state for Flexcan module
+ * This function will get the clock gate state for Flexcan module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(flexcanGateTable)/sizeof(flexcanGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, flexcanGateTable[instance]);
+}
+#endif
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+ kSimClockGateSpi2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3,
+ kSimClockGateUart4,
+ kSimClockGateUart5
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK60D10/fsl_clock_MK60D10.h b/KSDK_1.2.0/platform/system/src/clock/MK60D10/fsl_clock_MK60D10.h
new file mode 100755
index 0000000..b8da475
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK60D10/fsl_clock_MK60D10.h
@@ -0,0 +1,2048 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K60D10_H__)
+#define __FSL_CLOCK_K60D10_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k60d10*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief ENET external clock source count. */
+#define ENET_EXT_CLK_COUNT 1
+/*! @brief SDHC external clock source count. */
+#define SDHC_EXT_CLK_COUNT 1
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*! @brief ENET external clock frequency(ENET_1588_CLKIN) */
+extern uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT];
+#endif
+/*! @brief SDHC external clock frequency(SDHC_CLKIN). */
+extern uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT];
+#if FSL_FEATURE_SOC_USB_COUNT
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+#endif
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k60d10_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @} */
+/*! @addtogroup clock_manager*/
+/*! @{*/
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function sets divide value OUTDIV3.
+ *
+ * @param outdiv3 Outdivider3 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv3(uint8_t outdiv3)
+{
+ CLOCK_HAL_SetOutDiv3(SIM, outdiv3);
+}
+
+/*!
+ * @brief Gets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function gets divide value OUTDIV3.
+ *
+ * @return Outdivider3 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv3(void)
+{
+ return CLOCK_HAL_GetOutDiv3(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Gets ethernet RMII clock source.
+ *
+ * This function gets the ethernet RMII clock source.
+ *
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_rmii_src_t CLOCK_SYS_GetEnetRmiiSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetRmiiSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets ethernet RMII clock source.
+ *
+ * This function sets the ethernet RMII clock source.
+ *
+ * @param instance module device instance.
+ * @param rmiiSrc RMII clock source.
+ */
+static inline void CLOCK_SYS_SetEnetRmiiSrc(uint32_t instance, clock_rmii_src_t rmiiSrc)
+{
+ CLOCK_HAL_SetRmiiSrc(SIM, instance, rmiiSrc);
+}
+
+/*!
+ * @brief Gets ethernet RMII clock frequency.
+ *
+ * This function gets the ethernet RMII clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance);
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc);
+#endif
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Set the ethernet timestamp clock source selection.
+ *
+ * This function sets the ethernet timestamp clock source selection.
+ *
+ * @param instance module device instance.
+ * @param timeSrc Ethernet timestamp clock source.
+ */
+static inline void CLOCK_SYS_SetEnetTimeStampSrc(uint32_t instance, clock_time_src_t timeSrc)
+{
+ CLOCK_HAL_SetTimeSrc(SIM, instance, timeSrc);
+}
+
+/*!
+ * @brief Get the ethernet timestamp clock source selection.
+ *
+ * This function gets the ethernet timestamp clock source selection.
+ *
+ * @param instance IP instance.
+ *
+ * @return Current source.
+ */
+static inline clock_time_src_t CLOCK_SYS_GetEnetTimeStampSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTimeSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets ethernet timestamp clock frequency.
+ *
+ * This function gets the ethernet timestamp clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance);
+#endif
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+#endif
+
+/*!
+ * @brief Gets the clock frequency for SDHC.
+ *
+ * This function gets the clock frequency for SDHC.
+ * @param instance module device instance
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance);
+
+/*!
+ * @brief Set the SDHC clock source selection.
+ *
+ * This function sets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetSdhcSrc( uint32_t instance,
+ clock_sdhc_src_t setting)
+{
+ CLOCK_HAL_SetSdhcSrc(SIM, instance, setting);
+}
+
+/*!
+ * @brief Get the SDHC clock source selection.
+ *
+ * This function gets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_sdhc_src_t CLOCK_SYS_GetSdhcSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetSdhcSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+#if FSL_FEATURE_SOC_OPAMP_COUNT
+/*!
+ * @brief Enable the clock for OPAMP module.
+ *
+ * This function enables the clock for OPAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableOpampClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateOpamp);
+}
+
+/*!
+ * @brief Disable the clock for OPAMP module.
+ *
+ * This function disables the clock for OPAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableOpampClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateOpamp);
+}
+
+/*!
+ * @brief Get the the clock gate state for OPAMP module.
+ *
+ * This function will get the clock gate state for OPAMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetOpampGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateOpamp);
+}
+#endif
+
+#if FSL_FEATURE_SOC_TRIAMP_COUNT
+/*!
+ * @brief Enable the clock for TRIAMP module.
+ *
+ * This function enables the clock for TRIAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTriampClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTriamp);
+}
+
+/*!
+ * @brief Disable the clock for TRIAMP module.
+ *
+ * This function disables the clock for TRIAMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTriampClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTriamp);
+}
+
+/*!
+ * @brief Get the the clock gate state for TRIAMP module.
+ *
+ * This function will get the clock gate state for TRIAMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTriampGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTriamp);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for MPU module.
+ *
+ * This function enables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableMpuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Disable the clock for MPU module.
+ *
+ * This function disables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableMpuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for MPU module.
+ *
+ * This function will get the clock gate state for MPU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetMpuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXBUS module.
+ *
+ * This function enables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXBUS module.
+ *
+ * This function disables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXBUS module.
+ *
+ * This function will get the clock gate state for FLEXBUS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexbusGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+#if FSL_FEATURE_SOC_RNG_COUNT
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+ * @brief Enable the clock for SLCD module.
+ *
+ * This function enables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Disable the clock for SLCD module.
+ *
+ * This function disables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SLCD module.
+ *
+ * This function will get the clock gate state for SLCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSlcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD default clock.
+ *
+ * This function gets the frequency for SLCD default clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdDefaultFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate clock.
+ *
+ * This function gets the frequency for SLCD alternate clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAltFreq(uint32_t instance)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Enable the clock for ENET module.
+ *
+ * This function enables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEnetClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Disable the clock for ENET module.
+ *
+ * This function disables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEnetClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Get the the clock gate state for ENET module.
+ *
+ * This function will get the clock gate state for ENET module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEnetGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEnet0);
+}
+#endif
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+#endif
+
+#if FSL_FEATURE_SOC_FLEXCAN_COUNT
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance);
+#endif
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SDHC module.
+ *
+ * This function enables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Disable the clock for SDHC module.
+ *
+ * This function disables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SDHC module.
+ *
+ * This function will get the clock gate state for SDHC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSdhcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Enable the clock for LLWU module.
+ *
+ * This function enables the clock for LLWU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLlwuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLlwu0);
+}
+
+/*!
+ * @brief Disable the clock for LLWU module.
+ *
+ * This function disables the clock for LLWU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLlwuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLlwu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LLWU module.
+ *
+ * This function will get the clock gate state for LLWU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLlwuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLlwu0);
+}
+
+#if FSL_FEATURE_SOC_ENET_COUNT
+/*!
+ * @brief Set the ENET external clock frequency(ENET_1588_CLKIN).
+ *
+ * This function sets the ENET external clock frequency (ENET_1588_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetEnetExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < ENET_EXT_CLK_COUNT);
+
+ g_enet1588ClkInFreq[srcInstance] = freq;
+}
+#endif
+
+/*!
+ * @brief Set the SDHC external clock frequency(SDHC_CLKIN).
+ *
+ * This function sets the SDHC external clock frequency (SDHC_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetSdhcExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < SDHC_EXT_CLK_COUNT);
+
+ g_sdhcClkInFreq[srcInstance] = freq;
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+#endif
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequency value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K60D10_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK63F12/fsl_clock_MK63F12.c b/KSDK_1.2.0/platform/system/src/clock/MK63F12/fsl_clock_MK63F12.c
new file mode 100755
index 0000000..0bd613c
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK63F12/fsl_clock_MK63F12.c
@@ -0,0 +1,1026 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT]; /* ENET_1588_CLKIN */
+uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT]; /* SDHC_CLKIN */
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 2U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlexBusClock:
+ *frequency = CLOCK_SYS_GetFlexbusFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kIrc48mClock:
+ *frequency = CPU_INTERNAL_IRC_48M;
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexbusFreq
+ * Description : Gets the clock frequency for FLEXBUS module
+ * This function gets the clock frequency for FLEXBUS moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexbusFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv3(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockPllFllSelIrc48M:
+ freq = CPU_INTERNAL_IRC_48M;
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG) / 2U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq() / 2U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx prescaler/glitch filter clock frequency.
+ * This function gets the LPTMRx prescaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetRmiiFreq
+ * Description : Gets the clock frequency for ENET module RMII clock.
+ * This function gets the clock frequency for ENET moudle RMII clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance)
+{
+ /* get the sim clock source setting*/
+ if (CLOCK_HAL_GetRmiiSrc(SIM, instance) == kClockRmiiSrcExtalClk)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq(); /* OSCERCLK */
+ }
+ else
+ {
+ return g_enet1588ClkInFreq[0]; /* ENET_1588_CLKIN */
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetTimeStampFreq
+ * Description : Gets the clock frequency for ENET module TIME clock.
+ * This function gets the clock frequency for ENET moudle TIME clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_time_src_t src;
+
+ src = CLOCK_HAL_GetTimeSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTimeSrcCoreSysClk: /* Core/System clock. */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockTimeSrcPllFllSel: /* FLL/PLL/IRC48M. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTimeSrcOsc0erClk: /* OSCERCLK. */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTimeSrcExt: /* ENET 1588 clock in. */
+ freq = g_enet1588ClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSdhcFreq
+ * Description : Gets the clock frequency for SDHC module
+ * This function gets the clock frequency for SDHC moudle
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_sdhc_src_t src;
+
+ src = CLOCK_HAL_GetSdhcSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockSdhcSrcCoreSysClk: /* Core/system clock */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockSdhcSrcPllFllSel: /* Clock selected by SOPT2[PLLFLLSEL]. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockSdhcSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSdhcSrcExt: /* External bypass clock (SDHC0_CLKIN) */
+ freq = g_sdhcClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+ kSimClockGateDac1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+ kSimClockGateFtm3
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+ kSimClockGateSpi2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+ kSimClockGateI2c2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3,
+ kSimClockGateUart4,
+ kSimClockGateUart5
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK63F12/fsl_clock_MK63F12.h b/KSDK_1.2.0/platform/system/src/clock/MK63F12/fsl_clock_MK63F12.h
new file mode 100755
index 0000000..8a546ad
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK63F12/fsl_clock_MK63F12.h
@@ -0,0 +1,1834 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_MK63F12_H__)
+#define __FSL_CLOCK_MK63F12_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k63f12 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/*! @brief ENET external clock source count. */
+#define ENET_EXT_CLK_COUNT 1
+/*! @brief SDHC external clock source count. */
+#define SDHC_EXT_CLK_COUNT 1
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+/*! @brief ENET external clock frequency(ENET_1588_CLKIN) */
+extern uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT];
+/*! @brief SDHC external clock frequency(SDHC_CLKIN). */
+extern uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT];
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k63f12_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function sets divide value OUTDIV3.
+ *
+ * @param outdiv3 Outdivider3 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv3(uint8_t outdiv3)
+{
+ CLOCK_HAL_SetOutDiv3(SIM, outdiv3);
+}
+
+/*!
+ * @brief Gets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function gets divide value OUTDIV3.
+ *
+ * @return Outdivider3 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv3(void)
+{
+ return CLOCK_HAL_GetOutDiv3(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets ethernet RMII clock source.
+ *
+ * This function gets the ethernet RMII clock source.
+ *
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_rmii_src_t CLOCK_SYS_GetEnetRmiiSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetRmiiSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets ethernet RMII clock source.
+ *
+ * This function sets the ethernet RMII clock source.
+ *
+ * @param instance module device instance.
+ * @param rmiiSrc RMII clock source.
+ */
+static inline void CLOCK_SYS_SetEnetRmiiSrc(uint32_t instance, clock_rmii_src_t rmiiSrc)
+{
+ CLOCK_HAL_SetRmiiSrc(SIM, instance, rmiiSrc);
+}
+
+/*!
+ * @brief Gets ethernet RMII clock frequency.
+ *
+ * This function gets the ethernet RMII clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance);
+
+/*!
+ * @brief Set the ethernet timestamp clock source selection.
+ *
+ * This function sets the ethernet timestamp clock source selection.
+ *
+ * @param instance module device instance.
+ * @param timeSrc Ethernet timestamp clock source.
+ */
+static inline void CLOCK_SYS_SetEnetTimeStampSrc(uint32_t instance, clock_time_src_t timeSrc)
+{
+ CLOCK_HAL_SetTimeSrc(SIM, instance, timeSrc);
+}
+
+/*!
+ * @brief Get the ethernet timestamp clock source selection.
+ *
+ * This function gets the ethernet timestamp clock source selection.
+ *
+ * @param instance IP instance.
+ *
+ * @return Current source.
+ */
+static inline clock_time_src_t CLOCK_SYS_GetEnetTimeStampSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTimeSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets ethernet timestamp clock frequency.
+ *
+ * This function gets the ethernet timestamp clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS moduel instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc);
+
+/*!
+ * @brief Gets the clock frequency for SDHC.
+ *
+ * This function gets the clock frequency for SDHC.
+ * @param instance module device instance
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance);
+
+/*!
+ * @brief Set the SDHC clock source selection.
+ *
+ * This function sets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetSdhcSrc( uint32_t instance,
+ clock_sdhc_src_t setting)
+{
+ CLOCK_HAL_SetSdhcSrc(SIM, instance, setting);
+}
+
+/*!
+ * @brief Get the SDHC clock source selection.
+ *
+ * This function gets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_sdhc_src_t CLOCK_SYS_GetSdhcSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetSdhcSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for MPU module.
+ *
+ * This function enables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableMpuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Disable the clock for MPU module.
+ *
+ * This function disables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableMpuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for MPU module.
+ *
+ * This function will get the clock gate state for MPU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetMpuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXBUS module.
+ *
+ * This function enables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXBUS module.
+ *
+ * This function disables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXBUS module.
+ *
+ * This function will get the clock gate state for FLEXBUS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexbusGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for ENET module.
+ *
+ * This function enables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEnetClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Disable the clock for ENET module.
+ *
+ * This function disables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEnetClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Get the the clock gate state for ENET module.
+ *
+ * This function will get the clock gate state for ENET module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEnetGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexcan0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexcan0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexcan0);
+}
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SDHC module.
+ *
+ * This function enables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Disable the clock for SDHC module.
+ *
+ * This function disables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SDHC module.
+ *
+ * This function will get the clock gate state for SDHC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSdhcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Set the ENET external clock frequency(ENET_1588_CLKIN).
+ *
+ * This function sets the ENET external clock frequency (ENET_1588_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetEnetExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < ENET_EXT_CLK_COUNT);
+
+ g_enet1588ClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the SDHC external clock frequency(SDHC_CLKIN).
+ *
+ * This function sets the SDHC external clock frequency (SDHC_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetSdhcExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < SDHC_EXT_CLK_COUNT);
+
+ g_sdhcClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_MK63F12_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK64F12/fsl_clock_MK64F12.c b/KSDK_1.2.0/platform/system/src/clock/MK64F12/fsl_clock_MK64F12.c
new file mode 100755
index 0000000..0bd613c
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK64F12/fsl_clock_MK64F12.c
@@ -0,0 +1,1026 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT]; /* ENET_1588_CLKIN */
+uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT]; /* SDHC_CLKIN */
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 2U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlexBusClock:
+ *frequency = CLOCK_SYS_GetFlexbusFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kIrc48mClock:
+ *frequency = CPU_INTERNAL_IRC_48M;
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexbusFreq
+ * Description : Gets the clock frequency for FLEXBUS module
+ * This function gets the clock frequency for FLEXBUS moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexbusFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv3(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockPllFllSelIrc48M:
+ freq = CPU_INTERNAL_IRC_48M;
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG) / 2U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq() / 2U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx prescaler/glitch filter clock frequency.
+ * This function gets the LPTMRx prescaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetRmiiFreq
+ * Description : Gets the clock frequency for ENET module RMII clock.
+ * This function gets the clock frequency for ENET moudle RMII clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance)
+{
+ /* get the sim clock source setting*/
+ if (CLOCK_HAL_GetRmiiSrc(SIM, instance) == kClockRmiiSrcExtalClk)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq(); /* OSCERCLK */
+ }
+ else
+ {
+ return g_enet1588ClkInFreq[0]; /* ENET_1588_CLKIN */
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetTimeStampFreq
+ * Description : Gets the clock frequency for ENET module TIME clock.
+ * This function gets the clock frequency for ENET moudle TIME clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_time_src_t src;
+
+ src = CLOCK_HAL_GetTimeSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTimeSrcCoreSysClk: /* Core/System clock. */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockTimeSrcPllFllSel: /* FLL/PLL/IRC48M. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTimeSrcOsc0erClk: /* OSCERCLK. */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTimeSrcExt: /* ENET 1588 clock in. */
+ freq = g_enet1588ClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSdhcFreq
+ * Description : Gets the clock frequency for SDHC module
+ * This function gets the clock frequency for SDHC moudle
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_sdhc_src_t src;
+
+ src = CLOCK_HAL_GetSdhcSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockSdhcSrcCoreSysClk: /* Core/system clock */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockSdhcSrcPllFllSel: /* Clock selected by SOPT2[PLLFLLSEL]. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockSdhcSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSdhcSrcExt: /* External bypass clock (SDHC0_CLKIN) */
+ freq = g_sdhcClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+ kSimClockGateDac1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+ kSimClockGateFtm3
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+ kSimClockGateSpi2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+ kSimClockGateI2c2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3,
+ kSimClockGateUart4,
+ kSimClockGateUart5
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK64F12/fsl_clock_MK64F12.h b/KSDK_1.2.0/platform/system/src/clock/MK64F12/fsl_clock_MK64F12.h
new file mode 100755
index 0000000..f678feb
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK64F12/fsl_clock_MK64F12.h
@@ -0,0 +1,1834 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K64F12_H__)
+#define __FSL_CLOCK_K64F12_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k64f12 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/*! @brief ENET external clock source count. */
+#define ENET_EXT_CLK_COUNT 1
+/*! @brief SDHC external clock source count. */
+#define SDHC_EXT_CLK_COUNT 1
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+/*! @brief ENET external clock frequency(ENET_1588_CLKIN) */
+extern uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT];
+/*! @brief SDHC external clock frequency(SDHC_CLKIN). */
+extern uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT];
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k64f12_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function sets divide value OUTDIV3.
+ *
+ * @param outdiv3 Outdivider3 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv3(uint8_t outdiv3)
+{
+ CLOCK_HAL_SetOutDiv3(SIM, outdiv3);
+}
+
+/*!
+ * @brief Gets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function gets divide value OUTDIV3.
+ *
+ * @return Outdivider3 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv3(void)
+{
+ return CLOCK_HAL_GetOutDiv3(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets ethernet RMII clock source.
+ *
+ * This function gets the ethernet RMII clock source.
+ *
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_rmii_src_t CLOCK_SYS_GetEnetRmiiSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetRmiiSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets ethernet RMII clock source.
+ *
+ * This function sets the ethernet RMII clock source.
+ *
+ * @param instance module device instance.
+ * @param rmiiSrc RMII clock source.
+ */
+static inline void CLOCK_SYS_SetEnetRmiiSrc(uint32_t instance, clock_rmii_src_t rmiiSrc)
+{
+ CLOCK_HAL_SetRmiiSrc(SIM, instance, rmiiSrc);
+}
+
+/*!
+ * @brief Gets ethernet RMII clock frequency.
+ *
+ * This function gets the ethernet RMII clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance);
+
+/*!
+ * @brief Set the ethernet timestamp clock source selection.
+ *
+ * This function sets the ethernet timestamp clock source selection.
+ *
+ * @param instance module device instance.
+ * @param timeSrc Ethernet timestamp clock source.
+ */
+static inline void CLOCK_SYS_SetEnetTimeStampSrc(uint32_t instance, clock_time_src_t timeSrc)
+{
+ CLOCK_HAL_SetTimeSrc(SIM, instance, timeSrc);
+}
+
+/*!
+ * @brief Get the ethernet timestamp clock source selection.
+ *
+ * This function gets the ethernet timestamp clock source selection.
+ *
+ * @param instance IP instance.
+ *
+ * @return Current source.
+ */
+static inline clock_time_src_t CLOCK_SYS_GetEnetTimeStampSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTimeSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets ethernet timestamp clock frequency.
+ *
+ * This function gets the ethernet timestamp clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS moduel instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc);
+
+/*!
+ * @brief Gets the clock frequency for SDHC.
+ *
+ * This function gets the clock frequency for SDHC.
+ * @param instance module device instance
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance);
+
+/*!
+ * @brief Set the SDHC clock source selection.
+ *
+ * This function sets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetSdhcSrc( uint32_t instance,
+ clock_sdhc_src_t setting)
+{
+ CLOCK_HAL_SetSdhcSrc(SIM, instance, setting);
+}
+
+/*!
+ * @brief Get the SDHC clock source selection.
+ *
+ * This function gets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_sdhc_src_t CLOCK_SYS_GetSdhcSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetSdhcSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for MPU module.
+ *
+ * This function enables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableMpuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Disable the clock for MPU module.
+ *
+ * This function disables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableMpuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for MPU module.
+ *
+ * This function will get the clock gate state for MPU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetMpuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXBUS module.
+ *
+ * This function enables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXBUS module.
+ *
+ * This function disables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXBUS module.
+ *
+ * This function will get the clock gate state for FLEXBUS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexbusGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for ENET module.
+ *
+ * This function enables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEnetClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Disable the clock for ENET module.
+ *
+ * This function disables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEnetClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Get the the clock gate state for ENET module.
+ *
+ * This function will get the clock gate state for ENET module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEnetGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexcan0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexcan0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexcan0);
+}
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SDHC module.
+ *
+ * This function enables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Disable the clock for SDHC module.
+ *
+ * This function disables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SDHC module.
+ *
+ * This function will get the clock gate state for SDHC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSdhcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Set the ENET external clock frequency(ENET_1588_CLKIN).
+ *
+ * This function sets the ENET external clock frequency (ENET_1588_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetEnetExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < ENET_EXT_CLK_COUNT);
+
+ g_enet1588ClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the SDHC external clock frequency(SDHC_CLKIN).
+ *
+ * This function sets the SDHC external clock frequency (SDHC_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetSdhcExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < SDHC_EXT_CLK_COUNT);
+
+ g_sdhcClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K64F12_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK65F18/fsl_clock_MK65F18.c b/KSDK_1.2.0/platform/system/src/clock/MK65F18/fsl_clock_MK65F18.c
new file mode 100755
index 0000000..26a52a0
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK65F18/fsl_clock_MK65F18.c
@@ -0,0 +1,1275 @@
+/*
+ * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT]; /* ENET_1588_CLKIN */
+uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT]; /* SDHC_CLKIN */
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+ CLOCK_HAL_SetPllFllDiv(SIM, simConfig->pllflldiv, simConfig->pllfllfrac);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 3U, 7U, 7U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlexBusClock:
+ *frequency = CLOCK_SYS_GetFlexbusFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kOsc0ErClockUndiv:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgExtPllClock:
+ *frequency = CLOCK_HAL_GetExtPllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kIrc48mClock:
+ *frequency = CPU_INTERNAL_IRC_48M;
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexbusFreq
+ * Description : Gets the clock frequency for FLEXBUS module
+ * This function gets the clock frequency for FLEXBUS module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexbusFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv3(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockPllFllSelUsb1pfd:
+ freq = CLOCK_HAL_GetExtPllClk(MCG);
+ break;
+ case kClockPllFllSelIrc48M:
+ freq = CPU_INTERNAL_IRC_48M;
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllDivClockFreq
+ * Description : Gets the PLL/FLL clock divided by the fractional divider.
+ * This function gets the frequency of the PLL/FLL clock divided
+ * by the fractional divider configured by SIM_CLKDIV3[PLLFLLFRAC, PLLFLLDIV].
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllDivClockFreq(void)
+{
+ uint32_t freq;
+ uint8_t pllflldiv, pllfllfrac;
+
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetPllFllDiv(SIM, &pllflldiv, &pllfllfrac);
+ return freq * (pllfllfrac + 1) / (pllflldiv + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq
+ * Description : Gets OSC0ERCLKUDIV.
+ * This function gets the OSC0 external reference undivided frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq()
+ >> OSC_HAL_GetExternalRefClkDiv(g_oscBase[0]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+ uint32_t freq;
+ uint8_t tracediv, tracefrac;
+
+ if (kClockTraceSrcMcgoutClkDiv == src)
+ {
+ freq = CLOCK_HAL_GetOutClk(MCG);
+ CLOCK_HAL_GetTraceDiv(SIM, &tracediv, &tracefrac);
+ return freq * (tracefrac + 1) / (tracediv + 1);
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ }
+ return freq / 2U;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClkUndiv: /* OSC0ERCLKUDIV clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmfFreq
+ * Description : Gets the clock frequency for TPM module.
+ * This function gets the clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_tpm_src_t src;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTpmSrcPllFllSelDiv: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllDivClockFreq();
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmExternalFreq
+ * Description : Gets the external clock frequency for TPM module.
+ * This function gets the external clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t src = CLOCK_SYS_GetTpmExternalSrc(instance);
+
+ if (kSimTpmClkSel0 == src)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpuartFreq
+ * Description : Gets the clock frequency for LPUART module.
+ * This function gets the clock frequency for LPUART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance)
+{
+ clock_lpuart_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetLpuartSrc(SIM, instance);
+ switch (src)
+ {
+ case kClockLpuartSrcPllFllSel:
+ freq = CLOCK_SYS_GetPllFllDivClockFreq();
+ break;
+ case kClockLpuartSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpuartSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetRmiiFreq
+ * Description : Gets the clock frequency for ENET module RMII clock.
+ * This function gets the clock frequency for ENET moudle RMII clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance)
+{
+ /* get the sim clock source setting*/
+ if (CLOCK_HAL_GetRmiiSrc(SIM, instance) == kClockRmiiSrcExtalClk)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq(); /* OSCERCLK */
+ }
+ else
+ {
+ return g_enet1588ClkInFreq[0]; /* ENET_1588_CLKIN */
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetTimeStampFreq
+ * Description : Gets the clock frequency for ENET module TIME clock.
+ * This function gets the clock frequency for ENET moudle TIME clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_time_src_t src;
+
+ src = CLOCK_HAL_GetTimeSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTimeSrcCoreSysClk: /* Core/System clock. */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockTimeSrcPllFllSel: /* FLL/PLL/IRC48M. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTimeSrcOsc0erClk: /* OSCERCLK. */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTimeSrcExt: /* ENET 1588 clock in. */
+ freq = g_enet1588ClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbhsSlowClockFreq
+ * Description : Gets the slow clock frequency for USB HS/USB PHY module.
+ * This function gets the clock frequency for USB HS/USB PHY module,
+ * used to detect wakeup and resume events.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbhsSlowClockFreq(uint32_t instance) {
+
+ if (CLOCK_HAL_GetUsbhsSlowClockSrc(SIM, instance) == kClockUsbhsSlowClkSrcMcgIrClk)
+ {
+ return CLOCK_SYS_GetInternalRefClockFreq(); /* MCGIRCLK */
+ }
+ else
+ {
+ return CLOCK_SYS_GetRtcFreq(0U); /* RTC 32.768kHz clock */
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSdhcFreq
+ * Description : Gets the clock frequency for SDHC module
+ * This function gets the clock frequency for SDHC moudle
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_sdhc_src_t src;
+
+ src = CLOCK_HAL_GetSdhcSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockSdhcSrcCoreSysClk: /* Core/system clock */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockSdhcSrcPllFllSel: /* Clock selected by SOPT2[PLLFLLSEL]. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockSdhcSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSdhcSrcExt: /* External bypass clock (SDHC0_CLKIN) */
+ freq = g_sdhcClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllFllSel:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+ kSimClockGateDac1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+ kSimClockGateFtm3
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t canGateTable[] =
+{
+ kSimClockGateFlexcan0,
+ kSimClockGateFlexcan1
+};
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFlexcanClock
+ * Description : Enable the clock for FLEXCAN module
+ * This function enables the clock for FLEXCAN module.
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(canGateTable)/sizeof(canGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, canGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFlexcanClock
+ * Description : Disable the clock for FLEXCAN module
+ * This function disables the clock for FLEXCAN module.
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(canGateTable)/sizeof(canGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, canGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanGateCmd
+ * Description : Get the the clock gate state for FLEXCAN module
+ * This function will get the clock gate state for FLEXCAN module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(canGateTable)/sizeof(canGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, canGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+ kSimClockGateSpi2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+ kSimClockGateI2c2,
+ kSimClockGateI2c3,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3,
+ kSimClockGateUart4
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/* TPM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm1,
+ kSimClockGateTpm2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableTpmClock
+ * Description : Enable the clock for TPM module
+ * This function enables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableTpmClock
+ * Description : Disable the clock for TPM module
+ * This function disables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmGateCmd
+ * Description : Get the the clock gate state for TPM module
+ * This function will get the clock gate state for TPM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK65F18/fsl_clock_MK65F18.h b/KSDK_1.2.0/platform/system/src/clock/MK65F18/fsl_clock_MK65F18.h
new file mode 100755
index 0000000..dd6d428
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK65F18/fsl_clock_MK65F18.h
@@ -0,0 +1,2222 @@
+/*
+ * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K65F18_H__)
+#define __FSL_CLOCK_K65F18_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k64f12 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/*! @brief ENET external clock source count. */
+#define ENET_EXT_CLK_COUNT 1
+/*! @brief SDHC external clock source count. */
+#define SDHC_EXT_CLK_COUNT 1
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+
+
+/*! @brief ENET external clock frequency(ENET_1588_CLKIN) */
+extern uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT];
+/*! @brief SDHC external clock frequency(SDHC_CLKIN). */
+extern uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT];
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ uint8_t pllflldiv, pllfllfrac; /*!< PLL/FLL fractional divider setting */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k65f18_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function sets divide value OUTDIV3.
+ *
+ * @param outdiv3 Outdivider3 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv3(uint8_t outdiv3)
+{
+ CLOCK_HAL_SetOutDiv3(SIM, outdiv3);
+}
+
+/*!
+ * @brief Gets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function gets divide value OUTDIV3.
+ *
+ * @return Outdivider3 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv3(void)
+{
+ return CLOCK_HAL_GetOutDiv3(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Gets the PLL/FLL clock divided by the fractional divider.
+ *
+ * This function gets the frequency of the PLL/FLL clock divided
+ * by the fractional divider configured by SIM_CLKDIV3[PLLFLLFRAC, PLLFLLDIV].
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllDivClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets the OSC0ERCLK_UNDIV frequency.
+ *
+ * This function gets the undivided OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+/*!
+ * @brief Gets ethernet RMII clock source.
+ *
+ * This function gets the ethernet RMII clock source.
+ *
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_rmii_src_t CLOCK_SYS_GetEnetRmiiSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetRmiiSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets ethernet RMII clock source.
+ *
+ * This function sets the ethernet RMII clock source.
+ *
+ * @param instance module device instance.
+ * @param rmiiSrc RMII clock source.
+ */
+static inline void CLOCK_SYS_SetEnetRmiiSrc(uint32_t instance, clock_rmii_src_t rmiiSrc)
+{
+ CLOCK_HAL_SetRmiiSrc(SIM, instance, rmiiSrc);
+}
+
+/*!
+ * @brief Gets ethernet RMII clock frequency.
+ *
+ * This function gets the ethernet RMII clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance);
+
+/*!
+ * @brief Set the ethernet timestamp clock source selection.
+ *
+ * This function sets the ethernet timestamp clock source selection.
+ *
+ * @param instance module device instance.
+ * @param timeSrc Ethernet timestamp clock source.
+ */
+static inline void CLOCK_SYS_SetEnetTimeStampSrc(uint32_t instance, clock_time_src_t timeSrc)
+{
+ CLOCK_HAL_SetTimeSrc(SIM, instance, timeSrc);
+}
+
+/*!
+ * @brief Get the ethernet timestamp clock source selection.
+ *
+ * This function gets the ethernet timestamp clock source selection.
+ *
+ * @param instance IP instance.
+ *
+ * @return Current source.
+ */
+static inline clock_time_src_t CLOCK_SYS_GetEnetTimeStampSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTimeSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets ethernet timestamp clock frequency.
+ *
+ * This function gets the ethernet timestamp clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock source for LPUART module
+ *
+ * This function gets the clock source for LPUART module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_lpuart_src_t CLOCK_SYS_GetLpuartSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpuartSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for LPUART module
+ *
+ * This function sets the clock source for LPUART module.
+ * @param instance module device instance
+ * @param lpuartSrc Clock source.
+ */
+static inline void CLOCK_SYS_SetLpuartSrc(uint32_t instance, clock_lpuart_src_t lpuartSrc)
+{
+ CLOCK_HAL_SetLpuartSrc(SIM, instance, lpuartSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for LPUART module
+ *
+ * This function gets the clock frequency for LPUART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS moduel instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Gets the slow clock source for USB HS/USB PHY module
+ *
+ * This function gets the slow clock source for USB HS/USB PHY module,
+ * used to detect wakeup and resume events.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbhs_slowclk_src_t CLOCK_SYS_GetUsbhsSlowClockSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbhsSlowClockSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB HS/USB PHY module
+ *
+ * This function sets the clock source for USB HS/USB PHY module,
+ * used to detect wakeup and resume events.
+ * @param instance module device instance.
+ * @param usbhsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbhsSlowClockSrc(uint32_t instance, clock_usbhs_slowclk_src_t usbhsSrc)
+{
+ CLOCK_HAL_SetUsbhsSlowClockSrc(SIM, instance, usbhsSrc);
+}
+
+/*!
+ * @brief Gets the slow clock frequency for USB HS/USB PHY module
+ *
+ * This function gets the clock frequency for USB HS/USB PHY module,
+ * used to detect wakeup and resume events.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbhsSlowClockFreq(uint32_t instance);
+
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc);
+
+/*!
+ * @brief Gets the clock frequency for SDHC.
+ *
+ * This function gets the clock frequency for SDHC.
+ * @param instance module device instance
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance);
+
+/*!
+ * @brief Set the SDHC clock source selection.
+ *
+ * This function sets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetSdhcSrc( uint32_t instance,
+ clock_sdhc_src_t setting)
+{
+ CLOCK_HAL_SetSdhcSrc(SIM, instance, setting);
+}
+
+/*!
+ * @brief Get the SDHC clock source selection.
+ *
+ * This function gets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_sdhc_src_t CLOCK_SYS_GetSdhcSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetSdhcSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for MPU module.
+ *
+ * This function enables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableMpuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Disable the clock for MPU module.
+ *
+ * This function disables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableMpuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for MPU module.
+ *
+ * This function will get the clock gate state for MPU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetMpuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXBUS module.
+ *
+ * This function enables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXBUS module.
+ *
+ * This function disables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXBUS module.
+ *
+ * This function will get the clock gate state for FLEXBUS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexbusGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Enable the clock for SDRAMC module.
+ *
+ * This function enables the clock for SDRAMC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSdramcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSdramc0);
+}
+
+/*!
+ * @brief Disable the clock for SDRAMC module.
+ *
+ * This function disables the clock for SDRAMC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSdramcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSdramc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SDRAMC module.
+ *
+ * This function will get the clock gate state for SDRAMC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSdramcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSdramc0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for ENET module.
+ *
+ * This function enables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEnetClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Disable the clock for ENET module.
+ *
+ * This function disables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEnetClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Get the the clock gate state for ENET module.
+ *
+ * This function will get the clock gate state for ENET module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEnetGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Enable the clock for USBHS module.
+ *
+ * This function enables the clock for USBHS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbhsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbhs0);
+}
+
+/*!
+ * @brief Disable the clock for USBHS module.
+ *
+ * This function disables the clock for USBHS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbhsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbhs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBHS module.
+ *
+ * This function will get the clock gate state for USBHS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbhsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbhs0);
+}
+
+/*!
+ * @brief Enable the clock for USBPHY module.
+ *
+ * This function enables the clock for USBPHY module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbphyClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbhsphy0);
+}
+
+/*!
+ * @brief Disable the clock for USBPHY module.
+ *
+ * This function disables the clock for USBPHY module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbphyClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbhsphy0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBPHY module.
+ *
+ * This function will get the clock gate state for USBPHY module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbphyGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbhsphy0);
+}
+
+/*!
+ * @brief Enable the clock for USBHSDCD module.
+ *
+ * This function enables the clock for USBHSDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbhsdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbhsdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBHSDCD module.
+ *
+ * This function disables the clock for USBHSDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbhsdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbhsdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBHSDCD module.
+ *
+ * This function will get the clock gate state for USBHSDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbhsdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbhsdcd0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPUART module.
+ *
+ * This function enables the clock for LPUART module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLpuartClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Disable the clock for LPUART module.
+ *
+ * This function disables the clock for LPUART module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLpuartClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPUART module.
+ *
+ * This function will get the clock gate state for LPUART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Enable the clock for SDHC module.
+ *
+ * This function enables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Disable the clock for SDHC module.
+ *
+ * This function disables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SDHC module.
+ *
+ * This function will get the clock gate state for SDHC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSdhcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Set the ENET external clock frequency(ENET_1588_CLKIN).
+ *
+ * This function sets the ENET external clock frequency (ENET_1588_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetEnetExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < ENET_EXT_CLK_COUNT);
+
+ g_enet1588ClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the SDHC external clock frequency(SDHC_CLKIN).
+ *
+ * This function sets the SDHC external clock frequency (SDHC_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetSdhcExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < SDHC_EXT_CLK_COUNT);
+
+ g_sdhcClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K65F18_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK66F18/fsl_clock_MK66F18.c b/KSDK_1.2.0/platform/system/src/clock/MK66F18/fsl_clock_MK66F18.c
new file mode 100755
index 0000000..26a52a0
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK66F18/fsl_clock_MK66F18.c
@@ -0,0 +1,1275 @@
+/*
+ * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT]; /* ENET_1588_CLKIN */
+uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT]; /* SDHC_CLKIN */
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+ CLOCK_HAL_SetPllFllDiv(SIM, simConfig->pllflldiv, simConfig->pllfllfrac);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 3U, 7U, 7U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlexBusClock:
+ *frequency = CLOCK_SYS_GetFlexbusFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kOsc0ErClockUndiv:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgExtPllClock:
+ *frequency = CLOCK_HAL_GetExtPllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kIrc48mClock:
+ *frequency = CPU_INTERNAL_IRC_48M;
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexbusFreq
+ * Description : Gets the clock frequency for FLEXBUS module
+ * This function gets the clock frequency for FLEXBUS module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexbusFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv3(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockPllFllSelUsb1pfd:
+ freq = CLOCK_HAL_GetExtPllClk(MCG);
+ break;
+ case kClockPllFllSelIrc48M:
+ freq = CPU_INTERNAL_IRC_48M;
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllDivClockFreq
+ * Description : Gets the PLL/FLL clock divided by the fractional divider.
+ * This function gets the frequency of the PLL/FLL clock divided
+ * by the fractional divider configured by SIM_CLKDIV3[PLLFLLFRAC, PLLFLLDIV].
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllDivClockFreq(void)
+{
+ uint32_t freq;
+ uint8_t pllflldiv, pllfllfrac;
+
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetPllFllDiv(SIM, &pllflldiv, &pllfllfrac);
+ return freq * (pllfllfrac + 1) / (pllflldiv + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq
+ * Description : Gets OSC0ERCLKUDIV.
+ * This function gets the OSC0 external reference undivided frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq()
+ >> OSC_HAL_GetExternalRefClkDiv(g_oscBase[0]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+ uint32_t freq;
+ uint8_t tracediv, tracefrac;
+
+ if (kClockTraceSrcMcgoutClkDiv == src)
+ {
+ freq = CLOCK_HAL_GetOutClk(MCG);
+ CLOCK_HAL_GetTraceDiv(SIM, &tracediv, &tracefrac);
+ return freq * (tracefrac + 1) / (tracediv + 1);
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ }
+ return freq / 2U;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClkUndiv: /* OSC0ERCLKUDIV clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmfFreq
+ * Description : Gets the clock frequency for TPM module.
+ * This function gets the clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_tpm_src_t src;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTpmSrcPllFllSelDiv: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllDivClockFreq();
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmExternalFreq
+ * Description : Gets the external clock frequency for TPM module.
+ * This function gets the external clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t src = CLOCK_SYS_GetTpmExternalSrc(instance);
+
+ if (kSimTpmClkSel0 == src)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpuartFreq
+ * Description : Gets the clock frequency for LPUART module.
+ * This function gets the clock frequency for LPUART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance)
+{
+ clock_lpuart_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetLpuartSrc(SIM, instance);
+ switch (src)
+ {
+ case kClockLpuartSrcPllFllSel:
+ freq = CLOCK_SYS_GetPllFllDivClockFreq();
+ break;
+ case kClockLpuartSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpuartSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetRmiiFreq
+ * Description : Gets the clock frequency for ENET module RMII clock.
+ * This function gets the clock frequency for ENET moudle RMII clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance)
+{
+ /* get the sim clock source setting*/
+ if (CLOCK_HAL_GetRmiiSrc(SIM, instance) == kClockRmiiSrcExtalClk)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq(); /* OSCERCLK */
+ }
+ else
+ {
+ return g_enet1588ClkInFreq[0]; /* ENET_1588_CLKIN */
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEnetTimeStampFreq
+ * Description : Gets the clock frequency for ENET module TIME clock.
+ * This function gets the clock frequency for ENET moudle TIME clock.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_time_src_t src;
+
+ src = CLOCK_HAL_GetTimeSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTimeSrcCoreSysClk: /* Core/System clock. */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockTimeSrcPllFllSel: /* FLL/PLL/IRC48M. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTimeSrcOsc0erClk: /* OSCERCLK. */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTimeSrcExt: /* ENET 1588 clock in. */
+ freq = g_enet1588ClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbhsSlowClockFreq
+ * Description : Gets the slow clock frequency for USB HS/USB PHY module.
+ * This function gets the clock frequency for USB HS/USB PHY module,
+ * used to detect wakeup and resume events.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbhsSlowClockFreq(uint32_t instance) {
+
+ if (CLOCK_HAL_GetUsbhsSlowClockSrc(SIM, instance) == kClockUsbhsSlowClkSrcMcgIrClk)
+ {
+ return CLOCK_SYS_GetInternalRefClockFreq(); /* MCGIRCLK */
+ }
+ else
+ {
+ return CLOCK_SYS_GetRtcFreq(0U); /* RTC 32.768kHz clock */
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSdhcFreq
+ * Description : Gets the clock frequency for SDHC module
+ * This function gets the clock frequency for SDHC moudle
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_sdhc_src_t src;
+
+ src = CLOCK_HAL_GetSdhcSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockSdhcSrcCoreSysClk: /* Core/system clock */
+ freq = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kClockSdhcSrcPllFllSel: /* Clock selected by SOPT2[PLLFLLSEL]. */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockSdhcSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSdhcSrcExt: /* External bypass clock (SDHC0_CLKIN) */
+ freq = g_sdhcClkInFreq[0];
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllFllSel:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+ kSimClockGateDac1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+ kSimClockGateFtm3
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t canGateTable[] =
+{
+ kSimClockGateFlexcan0,
+ kSimClockGateFlexcan1
+};
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFlexcanClock
+ * Description : Enable the clock for FLEXCAN module
+ * This function enables the clock for FLEXCAN module.
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(canGateTable)/sizeof(canGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, canGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFlexcanClock
+ * Description : Disable the clock for FLEXCAN module
+ * This function disables the clock for FLEXCAN module.
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ assert(instance < sizeof(canGateTable)/sizeof(canGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, canGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanGateCmd
+ * Description : Get the the clock gate state for FLEXCAN module
+ * This function will get the clock gate state for FLEXCAN module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(canGateTable)/sizeof(canGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, canGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+ kSimClockGateSpi2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+ kSimClockGateI2c2,
+ kSimClockGateI2c3,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3,
+ kSimClockGateUart4
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/* TPM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm1,
+ kSimClockGateTpm2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableTpmClock
+ * Description : Enable the clock for TPM module
+ * This function enables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableTpmClock
+ * Description : Disable the clock for TPM module
+ * This function disables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmGateCmd
+ * Description : Get the the clock gate state for TPM module
+ * This function will get the clock gate state for TPM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MK66F18/fsl_clock_MK66F18.h b/KSDK_1.2.0/platform/system/src/clock/MK66F18/fsl_clock_MK66F18.h
new file mode 100755
index 0000000..8fca5cd
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MK66F18/fsl_clock_MK66F18.h
@@ -0,0 +1,2222 @@
+/*
+ * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_K66F18_H__)
+#define __FSL_CLOCK_K66F18_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_k64f12 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/*! @brief ENET external clock source count. */
+#define ENET_EXT_CLK_COUNT 1
+/*! @brief SDHC external clock source count. */
+#define SDHC_EXT_CLK_COUNT 1
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+
+
+/*! @brief ENET external clock frequency(ENET_1588_CLKIN) */
+extern uint32_t g_enet1588ClkInFreq[ENET_EXT_CLK_COUNT];
+/*! @brief SDHC external clock frequency(SDHC_CLKIN). */
+extern uint32_t g_sdhcClkInFreq[SDHC_EXT_CLK_COUNT];
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ uint8_t pllflldiv, pllfllfrac; /*!< PLL/FLL fractional divider setting */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_k66f18_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function sets divide value OUTDIV3.
+ *
+ * @param outdiv3 Outdivider3 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv3(uint8_t outdiv3)
+{
+ CLOCK_HAL_SetOutDiv3(SIM, outdiv3);
+}
+
+/*!
+ * @brief Gets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function gets divide value OUTDIV3.
+ *
+ * @return Outdivider3 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv3(void)
+{
+ return CLOCK_HAL_GetOutDiv3(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Gets the PLL/FLL clock divided by the fractional divider.
+ *
+ * This function gets the frequency of the PLL/FLL clock divided
+ * by the fractional divider configured by SIM_CLKDIV3[PLLFLLFRAC, PLLFLLDIV].
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllDivClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets the OSC0ERCLK_UNDIV frequency.
+ *
+ * This function gets the undivided OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+/*!
+ * @brief Gets ethernet RMII clock source.
+ *
+ * This function gets the ethernet RMII clock source.
+ *
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_rmii_src_t CLOCK_SYS_GetEnetRmiiSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetRmiiSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets ethernet RMII clock source.
+ *
+ * This function sets the ethernet RMII clock source.
+ *
+ * @param instance module device instance.
+ * @param rmiiSrc RMII clock source.
+ */
+static inline void CLOCK_SYS_SetEnetRmiiSrc(uint32_t instance, clock_rmii_src_t rmiiSrc)
+{
+ CLOCK_HAL_SetRmiiSrc(SIM, instance, rmiiSrc);
+}
+
+/*!
+ * @brief Gets ethernet RMII clock frequency.
+ *
+ * This function gets the ethernet RMII clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance);
+
+/*!
+ * @brief Set the ethernet timestamp clock source selection.
+ *
+ * This function sets the ethernet timestamp clock source selection.
+ *
+ * @param instance module device instance.
+ * @param timeSrc Ethernet timestamp clock source.
+ */
+static inline void CLOCK_SYS_SetEnetTimeStampSrc(uint32_t instance, clock_time_src_t timeSrc)
+{
+ CLOCK_HAL_SetTimeSrc(SIM, instance, timeSrc);
+}
+
+/*!
+ * @brief Get the ethernet timestamp clock source selection.
+ *
+ * This function gets the ethernet timestamp clock source selection.
+ *
+ * @param instance IP instance.
+ *
+ * @return Current source.
+ */
+static inline clock_time_src_t CLOCK_SYS_GetEnetTimeStampSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTimeSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets ethernet timestamp clock frequency.
+ *
+ * This function gets the ethernet timestamp clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock source for LPUART module
+ *
+ * This function gets the clock source for LPUART module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_lpuart_src_t CLOCK_SYS_GetLpuartSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpuartSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for LPUART module
+ *
+ * This function sets the clock source for LPUART module.
+ * @param instance module device instance
+ * @param lpuartSrc Clock source.
+ */
+static inline void CLOCK_SYS_SetLpuartSrc(uint32_t instance, clock_lpuart_src_t lpuartSrc)
+{
+ CLOCK_HAL_SetLpuartSrc(SIM, instance, lpuartSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for LPUART module
+ *
+ * This function gets the clock frequency for LPUART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS moduel instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Gets the slow clock source for USB HS/USB PHY module
+ *
+ * This function gets the slow clock source for USB HS/USB PHY module,
+ * used to detect wakeup and resume events.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbhs_slowclk_src_t CLOCK_SYS_GetUsbhsSlowClockSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbhsSlowClockSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB HS/USB PHY module
+ *
+ * This function sets the clock source for USB HS/USB PHY module,
+ * used to detect wakeup and resume events.
+ * @param instance module device instance.
+ * @param usbhsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbhsSlowClockSrc(uint32_t instance, clock_usbhs_slowclk_src_t usbhsSrc)
+{
+ CLOCK_HAL_SetUsbhsSlowClockSrc(SIM, instance, usbhsSrc);
+}
+
+/*!
+ * @brief Gets the slow clock frequency for USB HS/USB PHY module
+ *
+ * This function gets the clock frequency for USB HS/USB PHY module,
+ * used to detect wakeup and resume events.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbhsSlowClockFreq(uint32_t instance);
+
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc);
+
+/*!
+ * @brief Gets the clock frequency for SDHC.
+ *
+ * This function gets the clock frequency for SDHC.
+ * @param instance module device instance
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance);
+
+/*!
+ * @brief Set the SDHC clock source selection.
+ *
+ * This function sets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetSdhcSrc( uint32_t instance,
+ clock_sdhc_src_t setting)
+{
+ CLOCK_HAL_SetSdhcSrc(SIM, instance, setting);
+}
+
+/*!
+ * @brief Get the SDHC clock source selection.
+ *
+ * This function gets the SDHC clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_sdhc_src_t CLOCK_SYS_GetSdhcSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetSdhcSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for MPU module.
+ *
+ * This function enables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableMpuClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Disable the clock for MPU module.
+ *
+ * This function disables the clock for MPU module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableMpuClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Get the the clock gate state for MPU module.
+ *
+ * This function will get the clock gate state for MPU module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetMpuGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateMpu0);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXBUS module.
+ *
+ * This function enables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXBUS module.
+ *
+ * This function disables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXBUS module.
+ *
+ * This function will get the clock gate state for FLEXBUS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexbusGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Enable the clock for SDRAMC module.
+ *
+ * This function enables the clock for SDRAMC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSdramcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSdramc0);
+}
+
+/*!
+ * @brief Disable the clock for SDRAMC module.
+ *
+ * This function disables the clock for SDRAMC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSdramcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSdramc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SDRAMC module.
+ *
+ * This function will get the clock gate state for SDRAMC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSdramcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSdramc0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for ENET module.
+ *
+ * This function enables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEnetClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Disable the clock for ENET module.
+ *
+ * This function disables the clock for ENET module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEnetClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Get the the clock gate state for ENET module.
+ *
+ * This function will get the clock gate state for ENET module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEnetGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEnet0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Enable the clock for USBHS module.
+ *
+ * This function enables the clock for USBHS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbhsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbhs0);
+}
+
+/*!
+ * @brief Disable the clock for USBHS module.
+ *
+ * This function disables the clock for USBHS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbhsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbhs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBHS module.
+ *
+ * This function will get the clock gate state for USBHS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbhsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbhs0);
+}
+
+/*!
+ * @brief Enable the clock for USBPHY module.
+ *
+ * This function enables the clock for USBPHY module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbphyClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbhsphy0);
+}
+
+/*!
+ * @brief Disable the clock for USBPHY module.
+ *
+ * This function disables the clock for USBPHY module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbphyClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbhsphy0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBPHY module.
+ *
+ * This function will get the clock gate state for USBPHY module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbphyGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbhsphy0);
+}
+
+/*!
+ * @brief Enable the clock for USBHSDCD module.
+ *
+ * This function enables the clock for USBHSDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbhsdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbhsdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBHSDCD module.
+ *
+ * This function disables the clock for USBHSDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbhsdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbhsdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBHSDCD module.
+ *
+ * This function will get the clock gate state for USBHSDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbhsdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbhsdcd0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFlexcanClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPUART module.
+ *
+ * This function enables the clock for LPUART module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLpuartClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Disable the clock for LPUART module.
+ *
+ * This function disables the clock for LPUART module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLpuartClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPUART module.
+ *
+ * This function will get the clock gate state for LPUART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Enable the clock for SDHC module.
+ *
+ * This function enables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Disable the clock for SDHC module.
+ *
+ * This function disables the clock for SDHC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSdhcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SDHC module.
+ *
+ * This function will get the clock gate state for SDHC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSdhcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSdhc0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Set the ENET external clock frequency(ENET_1588_CLKIN).
+ *
+ * This function sets the ENET external clock frequency (ENET_1588_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetEnetExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < ENET_EXT_CLK_COUNT);
+
+ g_enet1588ClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the SDHC external clock frequency(SDHC_CLKIN).
+ *
+ * This function sets the SDHC external clock frequency (SDHC_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetSdhcExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < SDHC_EXT_CLK_COUNT);
+
+ g_sdhcClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_K66F18_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL02Z4/fsl_clock_MKL02Z4.c b/KSDK_1.2.0/platform/system/src/clock/MKL02Z4/fsl_clock_MKL02Z4.c
new file mode 100755
index 0000000..ef0df2f
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL02Z4/fsl_clock_MKL02Z4.c
@@ -0,0 +1,723 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_sim_hal.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_osc_hal.h"
+#include "fsl_clock_manager.h"
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ 0U,
+ 0U,
+ simConfig->outdiv4);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+
+ CLOCK_HAL_SetOutDiv(SIM, 1U, 0U, 0U, 7U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+ /*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFllClockFreq
+ * Description : Gets the MCGFLLCLK.
+ * This function gets the frequency of the MCGFLLCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFllClockFreq(void)
+{
+ return CLOCK_HAL_GetFllClk(MCG);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCopFreq
+ * Description : Gets COP clock frequency.
+ * This function gets the COP clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc)
+{
+ if (kClockCopSrcLpoClk == copSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmfFreq
+ * Description : Gets the clock frequency for TPM module.
+ * This function gets the clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_tpm_src_t src;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTpmSrcFll: /* FLL */
+ freq = CLOCK_SYS_GetFllClockFreq();
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmExternalFreq
+ * Description : Gets the external clock frequency for TPM module.
+ * This function gets the external clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t src = CLOCK_SYS_GetTpmExternalSrc(instance);
+
+ if (kSimTpmClkSel0 == src)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpifFreq
+ * Description : Gets the clock frequency for SPI module.
+ * This function gets the clock frequency for SPI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cfFreq
+ * Description : Gets the clock frequency for I2C module.
+ * This function gets the clock frequency for I2C moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpsciFreq
+ * Description : Gets the clock frequency for LPSCI module.
+ * This function gets the clock frequency for LPSCI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_lpsci_src_t src;
+
+ src = CLOCK_HAL_GetLpsciSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockLpsciSrcFll: /* FLL */
+ freq = CLOCK_SYS_GetFllClockFreq();
+ break;
+ case kClockLpsciSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpsciSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Lpsci instance table. */
+static const sim_clock_gate_name_t lpsciGateTable[] =
+{
+ kSimClockGateLpsci0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function disable the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetLpsciGateCmd
+ * Description : Get the the clock gate state for LPSCI module
+ * This function will get the clock gate state for LPSCI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function enables the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, lpsciGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm0,
+ kSimClockGateTpm1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableTpmClock
+ * Description : Enable the clock for TPM module
+ * This function enables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableTpmClock
+ * Description : Disable the clock for TPM module
+ * This function disables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmGateCmd
+ * Description : Get the the clock gate state for TPM module
+ * This function will get the clock gate state for TPM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL02Z4/fsl_clock_MKL02Z4.h b/KSDK_1.2.0/platform/system/src/clock/MKL02Z4/fsl_clock_MKL02Z4.h
new file mode 100755
index 0000000..cf7837d
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL02Z4/fsl_clock_MKL02Z4.h
@@ -0,0 +1,675 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KL02Z4_H__)
+#define __FSL_CLOCK_KL02Z4_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kl02z4 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ uint8_t outdiv1, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kl02z4_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get the MCGFLLCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGFLLCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFllClockFreq(void);
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+
+/*!
+ * @brief Gets the COP clock frequency.
+ *
+ * This function gets the COP clock frequency.
+ *
+ * @param instance module device instance
+ * @param copSrc COP clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance);
+
+ /*!
+ * @brief Gets the clock frequency for LPSCI module.
+ *
+ * This function gets the clock frequency for LPSCI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance);
+
+/*!
+ * @brief Set the LPSCI clock source selection.
+ *
+ * This function sets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @param lpsciSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetLpsciSrc(uint32_t instance, clock_lpsci_src_t lpsciSrc)
+{
+ CLOCK_HAL_SetLpsciSrc(SIM, instance, lpsciSrc);
+}
+
+/*!
+ * @brief Get the LPSCI clock source selection.
+ *
+ * This function gets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_lpsci_src_t CLOCK_SYS_GetLpsciSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpsciSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPSCI module.
+ *
+ * This function enables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for LPSCI module.
+ *
+ * This function disables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for LPSCI module.
+ *
+ * This function will get the clock gate state for LPSCI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock frequency(TPM_CLKx).
+ *
+ * This function sets the TPM external clock frequency (TPM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetTpmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < TPM_EXT_CLK_COUNT);
+
+ g_tpmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KL02Z4_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL03Z4/fsl_clock_MKL03Z4.c b/KSDK_1.2.0/platform/system/src/clock/MKL03Z4/fsl_clock_MKL03Z4.c
new file mode 100755
index 0000000..fe9a81d
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL03Z4/fsl_clock_MKL03Z4.c
@@ -0,0 +1,704 @@
+/*
+* Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* o Redistributions of source code must retain the above copyright notice, this list
+* of conditions and the following disclaimer.
+*
+* o Redistributions in binary form must reproduce the above copyright notice, this
+* list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+* contributors may be used to endorse or promote products derived from this
+* software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcglite_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+* README:
+* This file should provide these APIs:
+* 1. APIs to get the frequency of output clocks in Reference Manual ->
+* Chapter Clock Distribution -> Figure Clocking diagram.
+* 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+* -> Module clocks.
+*/
+
+/*******************************************************************************
+* Definitions
+******************************************************************************/
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+
+/*******************************************************************************
+* Code
+******************************************************************************/
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ 0U,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 1U, 0U, 0U, 7U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgliteMode(&config->mcgliteConfig);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kIrc48mClock:
+ *frequency = kMcgliteConst48M;
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetCoreClockFreq
+* Description : Gets the core clock frequency.
+* This function gets the core clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetSystemClockFreq
+* Description : Gets the systen clock frequency.
+* This function gets the systen clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetBusClockFreq
+* Description : Gets the bus clock frequency.
+* This function gets the bus clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetFlashClockFreq
+* Description : Gets the flash clock frequency.
+* This function gets the flash clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetRtcOutFreq
+* Description : Gets the RTC_CLKOUT frequency.
+* This function gets RTC_CLKOUT clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return 1U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcFreq
+ * Description : Gets rtc clock frequency.
+ * This function gets rtc clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetExternalRefClockFreq
+* Description : Gets the ERCLK32K clock frequency.
+* This function gets the external reference (ERCLK32K) clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+* Description : Gets OSC0ERCLK.
+* This function gets the OSC0 external reference frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmFreq
+* Description : Gets the clock frequency for TPM module.
+* This function gets the clock frequency for TPM moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+
+ clock_tpm_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockTpmSrcIrc48M: /* IRC48M */
+ freq = kMcgliteConst48M;
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCER clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIR clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetLpuartFreq
+* Description : Gets the clock frequency for LPUART module.
+* This function gets the clock frequency for LPUART moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance)
+{
+
+ clock_lpuart_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetLpuartSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockLpuartSrcIrc48M: /* IRC48M */
+ freq = kMcgliteConst48M;
+ break;
+ case kClockLpuartSrcOsc0erClk: /* OSCER clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpuartSrcMcgIrClk: /* MCGIR clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmExternalFreq
+* Description : Gets Tpm external clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t sel = SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+
+ if (kSimTpmClkSel0 == sel)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnablePortClock
+* Description : Enable the clock for PORT module
+* This function enables the clock for PORT moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisablePortClock
+* Description : Disable the clock for PORT module
+* This function disables the clock for PORT moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetPortGateCmd
+* Description : Get the the clock gate state for PORT module
+* This function will get the clock gate state for PORT moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableAdcClock
+* Description : Enable the clock for ADC module
+* This function enables the clock for ADC moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableAdcClock
+* Description : Disable the clock for ADC module
+* This function disables the clock for ADC moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetAdcGateCmd
+* Description : Get the the clock gate state for ADC module
+* This function will get the clock gate state for ADC moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableSpiClock
+* Description : Enable the clock for SPI module
+* This function enables the clock for SPI moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableSpiClock
+* Description : Disable the clock for SPI module
+* This function disables the clock for SPI moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetSpiGateCmd
+* Description : Get the the clock gate state for SPI module
+* This function will get the clock gate state for SPI moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableI2cClock
+* Description : Enable the clock for I2C module
+* This function enables the clock for I2C moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableI2cClock
+* Description : Disable the clock for I2C module
+* This function disables the clock for I2C moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetI2cGateCmd
+* Description : Get the the clock gate state for I2C module
+* This function will get the clock gate state for I2C moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Lpuart instance table. */
+static const sim_clock_gate_name_t lpuartGateTable[] =
+{
+ kSimClockGateLpuart0
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_EnableUartClock
+* Description : Enable the clock for UART module
+* This function enables the clock for UART moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableLpuartClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, lpuartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_DisableUartClock
+* Description : Disable the clock for UART module
+* This function enables the clock for UART moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableLpuartClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, lpuartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_GetUartGateCmd
+* Description : Get the the clock gate state for UART module
+* This function will get the clock gate state for UART moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, lpuartGateTable[instance]);
+}
+
+/* TPM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm0,
+ kSimClockGateTpm1,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableTpmClock
+* Description : Enable the clock for TPM module
+* This function enables the clock for TPM moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableTpmClock
+* Description : Disable the clock for TPM module
+* This function disables the clock for TPM moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmGateCmd
+* Description : Get the the clock gate state for TPM module
+* This function will get the clock gate state for TPM moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+* EOF
+******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL03Z4/fsl_clock_MKL03Z4.h b/KSDK_1.2.0/platform/system/src/clock/MKL03Z4/fsl_clock_MKL03Z4.h
new file mode 100755
index 0000000..4dcccca
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL03Z4/fsl_clock_MKL03Z4.h
@@ -0,0 +1,812 @@
+/*
+* Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* o Redistributions of source code must retain the above copyright notice, this list
+* of conditions and the following disclaimer.
+*
+* o Redistributions in binary form must reproduce the above copyright notice, this
+* list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+* contributors may be used to endorse or promote products derived from this
+* software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#if !defined(__FSL_CLOCK_KL03Z4_H__)
+#define __FSL_CLOCK_KL03Z4_H__
+
+#include "fsl_mcglite_hal.h"
+#include "fsl_mcglite_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kl03z4 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+* Definitions
+******************************************************************************/
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kl03z4_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+* API
+******************************************************************************/
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+* @brief Get internal reference clock frequency.
+*
+* This function gets the internal reference clock frequency.
+*
+* @return Current clock frequency.
+*/
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+* @brief Gets the OSC0ERCLK frequency.
+*
+* This function gets the OSC0 external reference frequency.
+*
+* @return Current frequency.
+*/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance);
+
+/*!
+* @brief Gets RTC_CLKOUT frequency.
+*
+* This function gets the frequency of RTC_CLKOUT.
+*
+* @return Current frequency.
+*/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+* @brief Gets RTC_CLKOUT source.
+*
+* This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+*
+* @return Current source.
+*/
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+* @brief Gets RTC_CLKOUT source.
+*
+* This function sets the source of RTC_CLKOUT.
+*
+* @param src RTC_CLKOUT source to set.
+*/
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmFreq
+* Description : Gets the clock frequency for TPM module.
+* This function gets the clock frequency for TPM module.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock source for LPUART module
+ *
+ * This function gets the clock source for LPUART module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_lpuart_src_t CLOCK_SYS_GetLpuartSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpuartSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for LPUART module
+ *
+ * This function sets the clock source for LPUART module.
+ * @param instance module device instance
+ * @param lpuartSrc Clock source.
+ */
+static inline void CLOCK_SYS_SetLpuartSrc(uint32_t instance, clock_lpuart_src_t lpuartSrc)
+{
+ CLOCK_HAL_SetLpuartSrc(SIM, instance, lpuartSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for LPUART module
+ *
+ * This function gets the clock frequency for LPUART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance);
+
+
+/*!
+* @brief Gets the clock frequency for FTF module. (Flash Memory)
+*
+* This function gets the clock frequency for FTF module. (Flash Memory)
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for CMP module.
+*
+* This function gets the clock frequency for CMP module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for VREF module.
+*
+* This function gets the clock frequency for VREF module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for SPI module
+*
+* This function gets the clock frequency for SPI module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for I2C module
+*
+* This function gets the clock frequency for I2C module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets ADC alternate clock frequency.
+*
+* This function gets the ADC alternate clock frequency.
+*
+* @param instance module device instance
+* @return freq Current frequency.
+*/
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for UART module
+*
+* This function gets the clock frequency for UART module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+* @brief Gets the clock frequency for GPIO module
+*
+* This function gets the clock frequency for GPIO module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+* @brief Enable the clock for PORT module.
+*
+* This function enables the clock for PORT module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for PORT module.
+*
+* This function disables the clock for PORT module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for PORT module.
+*
+* This function will get the clock gate state for PORT module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for FTF module.
+*
+* This function enables the clock for FTF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Disable the clock for FTF module.
+*
+* This function disables the clock for FTF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Get the the clock gate state for FTF module.
+*
+* This function will get the clock gate state for FTF module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Enable the clock for ADC module.
+*
+* This function enables the clock for ADC module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for ADC module.
+*
+* This function disables the clock for ADC module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for ADC module.
+*
+* This function will get the clock gate state for ADC module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for CMP module.
+*
+* This function enables the clock for CMP module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Disable the clock for CMP module.
+*
+* This function disables the clock for CMP module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Get the the clock gate state for CMP module.
+*
+* This function will get the clock gate state for CMP module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Enable the clock for VREF module.
+*
+* This function enables the clock for VREF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+* @brief Disable the clock for VREF module.
+*
+* This function disables the clock for VREF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+* @brief Get the the clock gate state for VREF module.
+*
+* This function will get the clock gate state for VREF module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+* @brief Enable the clock for LPTIMER module.
+*
+* This function enables the clock for LPTIMER module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Disable the clock for LPTIMER module.
+*
+* This function disables the clock for LPTIMER module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Get the the clock gate state for LPTIMER module.
+*
+* This function will get the clock gate state for LPTIMER module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Enable the clock for RTC module.
+*
+* This function enables the clock for RTC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Disable the clock for RTC module.
+*
+* This function disables the clock for RTC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Get the the clock gate state for RTC module.
+*
+* This function will get the clock gate state for RTC module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Enable the clock for SPI module.
+*
+* This function enables the clock for SPI module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for SPI module.
+*
+* This function disables the clock for SPI module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for SPI module.
+*
+* This function will get the clock gate state for SPI module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for I2C module.
+*
+* This function enables the clock for I2C module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for I2C module.
+*
+* This function disables the clock for I2C module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for I2C module.
+*
+* This function will get the clock gate state for I2C module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for UART module.
+*
+* This function enables the clock for UART module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableLpuartClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for UART module.
+*
+* This function disables the clock for UART module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableLpuartClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for UART module.
+*
+* This function will get the clock gate state for UART module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance);
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmExternalFreq
+* Description : Gets Tpm external clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableTpmClock
+* Description : Enable the clock for TPM module
+* This function enables the clock for TPM module
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableTpmClock
+* Description : Disable the clock for TPM module
+* This function disables the clock for TPM module
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmGateCmd
+* Description : Get the the clock gate state for TPM module
+* This function will get the clock gate state for TPM module.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+
+
+/*!
+ * @brief Set the TPM external clock frequency(TPM_CLKx).
+ *
+ * This function sets the TPM external clock frequency (TPM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetTpmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < TPM_EXT_CLK_COUNT);
+
+ g_tpmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+
+#endif /* __FSL_CLOCK_KL03Z4__H__ */
+/*******************************************************************************
+* EOF
+******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL14Z4/fsl_clock_MKL14Z4.c b/KSDK_1.2.0/platform/system/src/clock/MKL14Z4/fsl_clock_MKL14Z4.c
new file mode 100755
index 0000000..ff253b4
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL14Z4/fsl_clock_MKL14Z4.c
@@ -0,0 +1,986 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_sim_hal.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_clock_manager.h"
+#include "fsl_os_abstraction.h"
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ 0U,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFreq
+ * Description : Internal function to get the frequency by clock name
+ * This function will get/calculate the clock frequency based on clock name
+ * and current configuration of clock generator.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+
+ CLOCK_HAL_SetOutDiv(SIM, 2U, 0U, 0U, 5U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+ /*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ freq >>= 1U; /* divided by 2 for special divider */
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return CLOCK_SYS_GetExternalRefClock32kFreq() >> 15U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCopFreq
+ * Description : Gets cop clock frequency.
+ * This function gets the cop clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc)
+{
+ if (kClockCopSrcLpoClk == copSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcFreq
+ * Description : Gets rtc clock frequency.
+ * This function gets rtc clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmfFreq
+ * Description : Gets the clock frequency for TPM module.
+ * This function gets the clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_tpm_src_t src;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTpmSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmExternalFreq
+ * Description : Gets the external clock frequency for TPM module.
+ * This function gets the external clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t src = CLOCK_SYS_GetTpmExternalSrc(instance);
+
+ if (kSimTpmClkSel0 == src)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ return freq;
+ }
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpifFreq
+ * Description : Gets the clock frequency for SPI module.
+ * This function gets the clock frequency for SPI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cfFreq
+ * Description : Gets the clock frequency for I2C module.
+ * This function gets the clock frequency for I2C moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpsciFreq
+ * Description : Gets the clock frequency for LPSCI module.
+ * This function gets the clock frequency for LPSCI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_lpsci_src_t src;
+
+ src = CLOCK_HAL_GetLpsciSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockLpsciSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockLpsciSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpsciSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+#if FSL_FEATURE_SOC_DAC_COUNT
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+#endif
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Lpsci instance table. */
+static const sim_clock_gate_name_t lpsciGateTable[] =
+{
+ kSimClockGateLpsci0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function disable the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetLpsciGateCmd
+ * Description : Get the the clock gate state for LPSCI module
+ * This function will get the clock gate state for LPSCI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function enables the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, lpsciGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ (sim_clock_gate_name_t)(-1),
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm0,
+ kSimClockGateTpm1,
+ kSimClockGateTpm2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableTpmClock
+ * Description : Enable the clock for TPM module
+ * This function enables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableTpmClock
+ * Description : Disable the clock for TPM module
+ * This function disables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmGateCmd
+ * Description : Get the the clock gate state for TPM module
+ * This function will get the clock gate state for TPM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL14Z4/fsl_clock_MKL14Z4.h b/KSDK_1.2.0/platform/system/src/clock/MKL14Z4/fsl_clock_MKL14Z4.h
new file mode 100755
index 0000000..cde5df6
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL14Z4/fsl_clock_MKL14Z4.h
@@ -0,0 +1,1115 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KL14Z4_H__)
+#define __FSL_CLOCK_KL14Z4_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kl14z4 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kl14z4_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the COP clock frequency.
+ *
+ * This function gets the COP clock frequency.
+ *
+ * @param instance module device instance
+ * @param copSrc COP clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc);
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+ #if FSL_FEATURE_SOC_USB_COUNT
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function sets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @param usbfsSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Get the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function gets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+#endif
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance);
+
+ /*!
+ * @brief Gets the clock frequency for LPSCI module.
+ *
+ * This function gets the clock frequency for LPSCI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance);
+
+/*!
+ * @brief Set the LPSCI clock source selection.
+ *
+ * This function sets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @param lpsciSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetLpsciSrc(uint32_t instance, clock_lpsci_src_t lpsciSrc)
+{
+ CLOCK_HAL_SetLpsciSrc(SIM, instance, lpsciSrc);
+}
+
+/*!
+ * @brief Get the LPSCI clock source selection.
+ *
+ * This function gets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_lpsci_src_t CLOCK_SYS_GetLpsciSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpsciSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the UART clock frequency.
+ *
+ * This function gets the UART clock frequency.
+ *
+ * @param instance IP instance.
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+#if FSL_FEATURE_SOC_DAC_COUNT
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+#endif
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+#if FSL_FEATURE_SOC_TSI_COUNT
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+ #if FSL_FEATURE_SOC_USB_COUNT
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPSCI module.
+ *
+ * This function enables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for LPSCI module.
+ *
+ * This function disables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for LPSCI module.
+ *
+ * This function will get the clock gate state for LPSCI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the TPM external clock frequency(TPM_CLKx).
+ *
+ * This function sets the TPM external clock frequency (TPM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetTpmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < TPM_EXT_CLK_COUNT);
+
+ g_tpmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KL14Z4_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL15Z4/fsl_clock_MKL15Z4.c b/KSDK_1.2.0/platform/system/src/clock/MKL15Z4/fsl_clock_MKL15Z4.c
new file mode 100755
index 0000000..ff253b4
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL15Z4/fsl_clock_MKL15Z4.c
@@ -0,0 +1,986 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_sim_hal.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_clock_manager.h"
+#include "fsl_os_abstraction.h"
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ 0U,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFreq
+ * Description : Internal function to get the frequency by clock name
+ * This function will get/calculate the clock frequency based on clock name
+ * and current configuration of clock generator.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+
+ CLOCK_HAL_SetOutDiv(SIM, 2U, 0U, 0U, 5U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+ /*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ freq >>= 1U; /* divided by 2 for special divider */
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return CLOCK_SYS_GetExternalRefClock32kFreq() >> 15U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCopFreq
+ * Description : Gets cop clock frequency.
+ * This function gets the cop clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc)
+{
+ if (kClockCopSrcLpoClk == copSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcFreq
+ * Description : Gets rtc clock frequency.
+ * This function gets rtc clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmfFreq
+ * Description : Gets the clock frequency for TPM module.
+ * This function gets the clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_tpm_src_t src;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTpmSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmExternalFreq
+ * Description : Gets the external clock frequency for TPM module.
+ * This function gets the external clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t src = CLOCK_SYS_GetTpmExternalSrc(instance);
+
+ if (kSimTpmClkSel0 == src)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ return freq;
+ }
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpifFreq
+ * Description : Gets the clock frequency for SPI module.
+ * This function gets the clock frequency for SPI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cfFreq
+ * Description : Gets the clock frequency for I2C module.
+ * This function gets the clock frequency for I2C moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpsciFreq
+ * Description : Gets the clock frequency for LPSCI module.
+ * This function gets the clock frequency for LPSCI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_lpsci_src_t src;
+
+ src = CLOCK_HAL_GetLpsciSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockLpsciSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockLpsciSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpsciSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+#if FSL_FEATURE_SOC_DAC_COUNT
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+#endif
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Lpsci instance table. */
+static const sim_clock_gate_name_t lpsciGateTable[] =
+{
+ kSimClockGateLpsci0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function disable the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetLpsciGateCmd
+ * Description : Get the the clock gate state for LPSCI module
+ * This function will get the clock gate state for LPSCI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function enables the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, lpsciGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ (sim_clock_gate_name_t)(-1),
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm0,
+ kSimClockGateTpm1,
+ kSimClockGateTpm2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableTpmClock
+ * Description : Enable the clock for TPM module
+ * This function enables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableTpmClock
+ * Description : Disable the clock for TPM module
+ * This function disables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmGateCmd
+ * Description : Get the the clock gate state for TPM module
+ * This function will get the clock gate state for TPM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL15Z4/fsl_clock_MKL15Z4.h b/KSDK_1.2.0/platform/system/src/clock/MKL15Z4/fsl_clock_MKL15Z4.h
new file mode 100755
index 0000000..a631e82
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL15Z4/fsl_clock_MKL15Z4.h
@@ -0,0 +1,1115 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KL15Z4_H__)
+#define __FSL_CLOCK_KL15Z4_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kl15z4 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kl15z4_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the COP clock frequency.
+ *
+ * This function gets the COP clock frequency.
+ *
+ * @param instance module device instance
+ * @param copSrc COP clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc);
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+ #if FSL_FEATURE_SOC_USB_COUNT
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function sets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @param usbfsSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Get the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function gets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+#endif
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance);
+
+ /*!
+ * @brief Gets the clock frequency for LPSCI module.
+ *
+ * This function gets the clock frequency for LPSCI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance);
+
+/*!
+ * @brief Set the LPSCI clock source selection.
+ *
+ * This function sets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @param lpsciSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetLpsciSrc(uint32_t instance, clock_lpsci_src_t lpsciSrc)
+{
+ CLOCK_HAL_SetLpsciSrc(SIM, instance, lpsciSrc);
+}
+
+/*!
+ * @brief Get the LPSCI clock source selection.
+ *
+ * This function gets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_lpsci_src_t CLOCK_SYS_GetLpsciSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpsciSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the UART clock frequency.
+ *
+ * This function gets the UART clock frequency.
+ *
+ * @param instance IP instance.
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+#if FSL_FEATURE_SOC_DAC_COUNT
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+#endif
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+#if FSL_FEATURE_SOC_TSI_COUNT
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+ #if FSL_FEATURE_SOC_USB_COUNT
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPSCI module.
+ *
+ * This function enables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for LPSCI module.
+ *
+ * This function disables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for LPSCI module.
+ *
+ * This function will get the clock gate state for LPSCI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the TPM external clock frequency(TPM_CLKx).
+ *
+ * This function sets the TPM external clock frequency (TPM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetTpmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < TPM_EXT_CLK_COUNT);
+
+ g_tpmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KL15Z4_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL16Z4/fsl_clock_MKL16Z4.c b/KSDK_1.2.0/platform/system/src/clock/MKL16Z4/fsl_clock_MKL16Z4.c
new file mode 100755
index 0000000..71d7a5b
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL16Z4/fsl_clock_MKL16Z4.c
@@ -0,0 +1,1012 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_sim_hal.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_clock_manager.h"
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+#endif
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ 0U,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+
+ CLOCK_HAL_SetOutDiv(SIM, 2U, 0U, 0U, 5U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+ /*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ freq >>= 1U; /* divided by 2 for special divider */
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return CLOCK_SYS_GetExternalRefClock32kFreq() >> 15U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCopFreq
+ * Description : Gets COP clock frequency.
+ * This function gets the COP clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc)
+{
+ if (kClockCopSrcLpoClk == copSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcFreq
+ * Description : Gets rtc clock frequency.
+ * This function gets rtc clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmfFreq
+ * Description : Gets the clock frequency for TPM module.
+ * This function gets the clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_tpm_src_t src;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTpmSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmExternalFreq
+ * Description : Gets the external clock frequency for TPM module.
+ * This function gets the external clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t src = CLOCK_SYS_GetTpmExternalSrc(instance);
+
+ if (kSimTpmClkSel0 == src)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ return freq;
+ }
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpifFreq
+ * Description : Gets the clock frequency for SPI module.
+ * This function gets the clock frequency for SPI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cfFreq
+ * Description : Gets the clock frequency for I2C module.
+ * This function gets the clock frequency for I2C moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpsciFreq
+ * Description : Gets the clock frequency for LPSCI module.
+ * This function gets the clock frequency for LPSCI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_lpsci_src_t src;
+
+ src = CLOCK_HAL_GetLpsciSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockLpsciSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockLpsciSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpsciSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Lpsci instance table. */
+static const sim_clock_gate_name_t lpsciGateTable[] =
+{
+ kSimClockGateLpsci0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function disable the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetLpsciGateCmd
+ * Description : Get the the clock gate state for LPSCI module
+ * This function will get the clock gate state for LPSCI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function enables the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, lpsciGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ (sim_clock_gate_name_t)(-1),
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm0,
+ kSimClockGateTpm1,
+ kSimClockGateTpm2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableTpmClock
+ * Description : Enable the clock for TPM module
+ * This function enables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableTpmClock
+ * Description : Disable the clock for TPM module
+ * This function disables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmGateCmd
+ * Description : Get the the clock gate state for TPM module
+ * This function will get the clock gate state for TPM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL16Z4/fsl_clock_MKL16Z4.h b/KSDK_1.2.0/platform/system/src/clock/MKL16Z4/fsl_clock_MKL16Z4.h
new file mode 100755
index 0000000..e2a4d49
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL16Z4/fsl_clock_MKL16Z4.h
@@ -0,0 +1,1237 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KL16Z4_H__)
+#define __FSL_CLOCK_KL16Z4_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kl16z4 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+#if FSL_FEATURE_SOC_USB_COUNT
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+#endif
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kl16z4_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the COP clock frequency.
+ *
+ * This function gets the COP clock frequency.
+ *
+ * @param instance module device instance
+ * @param copSrc COP clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function sets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @param usbfsSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Get the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function gets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance);
+
+ /*!
+ * @brief Gets the clock frequency for LPSCI module.
+ *
+ * This function gets the clock frequency for LPSCI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance);
+
+/*!
+ * @brief Set the LPSCI clock source selection.
+ *
+ * This function sets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @param lpsciSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetLpsciSrc(uint32_t instance, clock_lpsci_src_t lpsciSrc)
+{
+ CLOCK_HAL_SetLpsciSrc(SIM, instance, lpsciSrc);
+}
+
+/*!
+ * @brief Get the LPSCI clock source selection.
+ *
+ * This function gets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_lpsci_src_t CLOCK_SYS_GetLpsciSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpsciSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the UART clock frequency.
+ *
+ * This function gets the UART clock frequency.
+ *
+ * @param instance IP instance.
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+ * @brief Enable the clock for SLCD module.
+ *
+ * This function enables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Disable the clock for SLCD module.
+ *
+ * This function disables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SLCD module.
+ *
+ * This function will get the clock gate state for SLCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSlcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD default clock.
+ *
+ * This function gets the frequency for SLCD default clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdDefaultFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate clock.
+ *
+ * This function gets the frequency for SLCD alternate clock (ALTSOURCE = 0).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAltFreq(uint32_t instance)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate 2 clock.
+ *
+ * This function gets the frequency for SLCD alternate 2 clock (ALTSOURCE = 1).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAlt2Freq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+#endif// FSL_FEATURE_SOC_LCD_COUNT
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPSCI module.
+ *
+ * This function enables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for LPSCI module.
+ *
+ * This function disables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for LPSCI module.
+ *
+ * This function will get the clock gate state for LPSCI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Set the TPM external clock frequency(TPM_CLKx).
+ *
+ * This function sets the TPM external clock frequency (TPM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetTpmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < TPM_EXT_CLK_COUNT);
+
+ g_tpmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KL16Z4_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL17Z4/fsl_clock_MKL17Z4.c b/KSDK_1.2.0/platform/system/src/clock/MKL17Z4/fsl_clock_MKL17Z4.c
new file mode 100755
index 0000000..d74eea3
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL17Z4/fsl_clock_MKL17Z4.c
@@ -0,0 +1,840 @@
+/*
+* Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* o Redistributions of source code must retain the above copyright notice, this list
+* of conditions and the following disclaimer.
+*
+* o Redistributions in binary form must reproduce the above copyright notice, this
+* list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+* contributors may be used to endorse or promote products derived from this
+* software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcglite_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+* README:
+* This file should provide these APIs:
+* 1. APIs to get the frequency of output clocks in Reference Manual ->
+* Chapter Clock Distribution -> Figure Clocking diagram.
+* 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+* -> Module clocks.
+*/
+
+/*******************************************************************************
+* Definitions
+******************************************************************************/
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+#endif
+
+/*******************************************************************************
+* Code
+******************************************************************************/
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ 0U,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 1U, 0U, 0U, 7U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgliteMode(&config->mcgliteConfig);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kIrc48mClock:
+ *frequency = kMcgliteConst48M;
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetCoreClockFreq
+* Description : Gets the core clock frequency.
+* This function gets the core clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetSystemClockFreq
+* Description : Gets the systen clock frequency.
+* This function gets the systen clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetBusClockFreq
+* Description : Gets the bus clock frequency.
+* This function gets the bus clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetFlashClockFreq
+* Description : Gets the flash clock frequency.
+* This function gets the flash clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetRtcOutFreq
+* Description : Gets the RTC_CLKOUT frequency.
+* This function gets RTC_CLKOUT clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return 1U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetExternalRefClockFreq
+* Description : Gets the ERCLK32K clock frequency.
+* This function gets the external reference (ERCLK32K) clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+* Description : Gets OSC0ERCLK.
+* This function gets the OSC0 external reference frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetCopFreq
+* Description : Gets the clock frequency for COP module.
+* This function gets the clock frequency for COP moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetCopFreq(void)
+{
+ clock_cop_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetCopSrc(SIM);
+
+ switch (src)
+ {
+ case kClockCopSrcLpoClk:
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockCopSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockCopSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockCopSrcBusClk:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmFreq
+* Description : Gets the clock frequency for TPM module.
+* This function gets the clock frequency for TPM moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+
+ clock_tpm_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockTpmSrcIrc48M: /* IRC48M */
+ freq = kMcgliteConst48M;
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCER clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIR clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetLpuartFreq
+* Description : Gets the clock frequency for LPUART module.
+* This function gets the clock frequency for LPUART moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance)
+{
+ clock_lpuart_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetLpuartSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockLpuartSrcIrc48M: /* IRC48M */
+ freq = kMcgliteConst48M;
+ break;
+ case kClockLpuartSrcOsc0erClk: /* OSCER clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpuartSrcMcgIrClk: /* MCGIR clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmExternalFreq
+* Description : Gets Tpm external clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t sel = SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+
+ if (kSimTpmClkSel0 == sel)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ clock_usbfs_src_t src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0];
+ }
+ else
+ {
+ return kMcgliteConst48M;
+ }
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexioFreq
+ * Description : Gets the clock frequency for FLEXIO.
+ * This function gets the clock frequency for FLEXIO.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexioFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_flexio_src_t src = CLOCK_HAL_GetFlexioSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockFlexioSrcIrc48M:
+ freq = kMcgliteConst48M;
+ break;
+ case kClockFlexioSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockFlexioSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcSysClk: /*!< SYSCLK */
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kClockSaiSrcOsc0erClk: /*!< OSC0ERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcMcgIrClk: /*!< MCGIRCLK */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockSaiSrcIrc48M: /*!< MCGPCLK/IRC48M. */
+ freq = kMcgliteConst48M;
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiFreq
+ * Description : Gets the clock frequency for SPI.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ assert(instance < SPI_INSTANCE_COUNT);
+
+ if (0U == instance)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetSystemClockFreq();
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnablePortClock
+* Description : Enable the clock for PORT module
+* This function enables the clock for PORT moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisablePortClock
+* Description : Disable the clock for PORT module
+* This function disables the clock for PORT moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetPortGateCmd
+* Description : Get the the clock gate state for PORT module
+* This function will get the clock gate state for PORT moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableAdcClock
+* Description : Enable the clock for ADC module
+* This function enables the clock for ADC moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableAdcClock
+* Description : Disable the clock for ADC module
+* This function disables the clock for ADC moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetAdcGateCmd
+* Description : Get the the clock gate state for ADC module
+* This function will get the clock gate state for ADC moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableSpiClock
+* Description : Enable the clock for SPI module
+* This function enables the clock for SPI moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableSpiClock
+* Description : Disable the clock for SPI module
+* This function disables the clock for SPI moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetSpiGateCmd
+* Description : Get the the clock gate state for SPI module
+* This function will get the clock gate state for SPI moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableI2cClock
+* Description : Enable the clock for I2C module
+* This function enables the clock for I2C moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableI2cClock
+* Description : Disable the clock for I2C module
+* This function disables the clock for I2C moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetI2cGateCmd
+* Description : Get the the clock gate state for I2C module
+* This function will get the clock gate state for I2C moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Lpuart instance table. */
+static const sim_clock_gate_name_t lpuartGateTable[] =
+{
+ kSimClockGateLpuart0,
+ kSimClockGateLpuart1
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_EnableLpuartClock
+* Description : Enable the clock for UART module
+* This function enables the clock for UART moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableLpuartClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, lpuartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_DisableLpuartClock
+* Description : Disable the clock for UART module
+* This function enables the clock for UART moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableLpuartClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, lpuartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_GetLpuartGateCmd
+* Description : Get the the clock gate state for UART module
+* This function will get the clock gate state for UART moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, lpuartGateTable[instance]);
+}
+
+/* TPM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm0,
+ kSimClockGateTpm1,
+ kSimClockGateTpm2,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableTpmClock
+* Description : Enable the clock for TPM module
+* This function enables the clock for TPM moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableTpmClock
+* Description : Disable the clock for TPM module
+* This function disables the clock for TPM moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmGateCmd
+* Description : Get the the clock gate state for TPM module
+* This function will get the clock gate state for TPM moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+* EOF
+******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL17Z4/fsl_clock_MKL17Z4.h b/KSDK_1.2.0/platform/system/src/clock/MKL17Z4/fsl_clock_MKL17Z4.h
new file mode 100755
index 0000000..9cd8843
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL17Z4/fsl_clock_MKL17Z4.h
@@ -0,0 +1,1323 @@
+/*
+* Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* o Redistributions of source code must retain the above copyright notice, this list
+* of conditions and the following disclaimer.
+*
+* o Redistributions in binary form must reproduce the above copyright notice, this
+* list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+* contributors may be used to endorse or promote products derived from this
+* software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#if !defined(__FSL_CLOCK_MKL17Z4_H__)
+#define __FSL_CLOCK_MKL17Z4_H__
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcglite_hal.h"
+#include "fsl_mcglite_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kl17z4 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+* Definitions
+******************************************************************************/
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+#if FSL_FEATURE_SOC_USB_COUNT
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+#endif
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kl17z4_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+* API
+******************************************************************************/
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+* @brief Get internal reference clock frequency.
+*
+* This function gets the internal reference clock frequency.
+*
+* @return Current clock frequency.
+*/
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+* @brief Gets the OSC0ERCLK frequency.
+*
+* This function gets the OSC0 external reference frequency.
+*
+* @return Current frequency.
+*/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+* @brief Gets RTC_CLKOUT frequency.
+*
+* This function gets the frequency of RTC_CLKOUT.
+*
+* @return Current frequency.
+*/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+* @brief Gets RTC_CLKOUT source.
+*
+* This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+*
+* @return Current source.
+*/
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+* @brief Gets RTC_CLKOUT source.
+*
+* This function sets the source of RTC_CLKOUT.
+*
+* @param src RTC_CLKOUT source to set.
+*/
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+ /*!
+ * @brief Gets rtc clock frequency.
+ *
+ * This function gets the rtc clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets COP clock frequency.
+ *
+ * This function gets the COP clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetCopFreq(void);
+
+/*!
+ * @brief Set the COP clock source selection.
+ *
+ * This function sets the COP clock source selection.
+ *
+ * @param copSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetCopSrc(clock_cop_src_t copSrc)
+{
+ CLOCK_HAL_SetCopSrc(SIM, copSrc);
+}
+
+/*!
+ * @brief Get the COP clock source selection.
+ *
+ * This function gets the COP clock source selection.
+ *
+ * @return Current selection.
+ */
+static inline clock_cop_src_t CLOCK_SYS_GetCopSrc(void)
+{
+ return CLOCK_HAL_GetCopSrc(SIM);
+}
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function sets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @param usbfsSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Get the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function gets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Gets the clock source for LPUART module
+ *
+ * This function gets the clock source for LPUART module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_lpuart_src_t CLOCK_SYS_GetLpuartSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpuartSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for LPUART module
+ *
+ * This function sets the clock source for LPUART module.
+ * @param instance module device instance
+ * @param lpuartSrc Clock source.
+ */
+static inline void CLOCK_SYS_SetLpuartSrc(uint32_t instance, clock_lpuart_src_t lpuartSrc)
+{
+ CLOCK_HAL_SetLpuartSrc(SIM, instance, lpuartSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for LPUART module
+ *
+ * This function gets the clock frequency for LPUART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FLEXIO clock frequency.
+ *
+ * This function gets the FLEXIO clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexioFreq(uint32_t instance);
+
+/*!
+ * @brief Set the FLEXIO clock source selection.
+ *
+ * This function sets the FLEXIO clock source selection.
+ *
+ * @param instance IP instance.
+ * @param flexioSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetFlexioSrc(uint32_t instance, clock_flexio_src_t flexioSrc)
+{
+ CLOCK_HAL_SetFlexioSrc(SIM, instance, flexioSrc);
+}
+
+/*!
+ * @brief Get the FLEXIO clock source selection.
+ *
+ * This function gets the FLEXIO clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_flexio_src_t CLOCK_SYS_GetFlexioSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetFlexioSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+ * @brief Gets the frequency for SLCD default clock.
+ *
+ * This function gets the frequency for SLCD default clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdDefaultFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate clock.
+ *
+ * This function gets the frequency for SLCD alternate clock (ALTSOURCE = 0).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAltFreq(uint32_t instance)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate 2 clock.
+ *
+ * This function gets the frequency for SLCD alternate 2 clock (ALTSOURCE = 1).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAlt2Freq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+#endif// FSL_FEATURE_SOC_LCD_COUNT
+
+/*!
+* @brief Gets the clock frequency for FTF module. (Flash Memory)
+*
+* This function gets the clock frequency for FTF module. (Flash Memory)
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for CMP module.
+*
+* This function gets the clock frequency for CMP module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for VREF module.
+*
+* This function gets the clock frequency for VREF module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for SPI module
+*
+* This function gets the clock frequency for SPI module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+* @brief Gets the clock frequency for I2C module
+*
+* This function gets the clock frequency for I2C module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets ADC alternate clock frequency.
+*
+* This function gets the ADC alternate clock frequency.
+*
+* @param instance module device instance
+* @return freq Current frequency.
+*/
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for UART module
+*
+* This function gets the clock frequency for UART module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Enable the clock for PORT module.
+*
+* This function enables the clock for PORT module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for PORT module.
+*
+* This function disables the clock for PORT module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for PORT module.
+*
+* This function will get the clock gate state for PORT module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+* @brief Enable the clock for SLCD module.
+*
+* This function enables the clock for SLCD module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+* @brief Disable the clock for SLCD module.
+*
+* This function disables the clock for SLCD module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+* @brief Get the the clock gate state for SLCD module.
+*
+* This function will get the clock gate state for SLCD module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetSlcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSlcd0);
+}
+#endif// FSL_FEATURE_SOC_LCD_COUNT
+
+/*!
+* @brief Enable the clock for FTF module.
+*
+* This function enables the clock for FTF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Disable the clock for FTF module.
+*
+* This function disables the clock for FTF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Get the the clock gate state for FTF module.
+*
+* This function will get the clock gate state for FTF module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Enable the clock for ADC module.
+*
+* This function enables the clock for ADC module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for ADC module.
+*
+* This function disables the clock for ADC module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for ADC module.
+*
+* This function will get the clock gate state for ADC module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for CMP module.
+*
+* This function enables the clock for CMP module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Disable the clock for CMP module.
+*
+* This function disables the clock for CMP module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Get the the clock gate state for CMP module.
+*
+* This function will get the clock gate state for CMP module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Enable the clock for VREF module.
+*
+* This function enables the clock for VREF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+* @brief Disable the clock for VREF module.
+*
+* This function disables the clock for VREF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+* @brief Get the the clock gate state for VREF module.
+*
+* This function will get the clock gate state for VREF module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+* @brief Enable the clock for LPTIMER module.
+*
+* This function enables the clock for LPTIMER module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Disable the clock for LPTIMER module.
+*
+* This function disables the clock for LPTIMER module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Get the the clock gate state for LPTIMER module.
+*
+* This function will get the clock gate state for LPTIMER module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Enable the clock for RTC module.
+*
+* This function enables the clock for RTC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Disable the clock for RTC module.
+*
+* This function disables the clock for RTC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Get the the clock gate state for RTC module.
+*
+* This function will get the clock gate state for RTC module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Enable the clock for DAC module.
+*
+* This function enables the clock for DAC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDac0);
+}
+
+/*!
+* @brief Disable the clock for DAC module.
+*
+* This function disables the clock for DAC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDac0);
+}
+
+/*!
+* @brief Get the the clock gate state for DAC module.
+*
+* This function will get the clock gate state for DAC module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDac0);
+}
+
+/*!
+* @brief Enable the clock for SPI module.
+*
+* This function enables the clock for SPI module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for SPI module.
+*
+* This function disables the clock for SPI module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for SPI module.
+*
+* This function will get the clock gate state for SPI module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for I2C module.
+*
+* This function enables the clock for I2C module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for I2C module.
+*
+* This function disables the clock for I2C module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for I2C module.
+*
+* This function will get the clock gate state for I2C module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for LPUART module.
+*
+* This function enables the clock for LPUART module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableLpuartClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for LPUART module.
+*
+* This function disables the clock for LPUART module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableLpuartClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for LPUART module.
+*
+* This function will get the clock gate state for LPUART module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for UART module.
+*
+* This function enables the clock for UART module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUart2);
+}
+
+/*!
+* @brief Disable the clock for UART module.
+*
+* This function disables the clock for UART module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUart2);
+}
+
+/*!
+* @brief Get the the clock gate state for UART module.
+*
+* This function will get the clock gate state for UART module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM,kSimClockGateUart2);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+* @brief Enable the clock for FLEXIO module.
+*
+* This function enables the clock for FLEXIO module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableFlexioClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexio0);
+}
+
+/*!
+* @brief Disable the clock for FLEXIO module.
+*
+* This function disables the clock for FLEXIO module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableFlexioClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexio0);
+}
+
+/*!
+* @brief Get the clock gate state for FLEXIO module.
+*
+* This function will get the clock gate state for FLEXIO module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetFlexioGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM,kSimClockGateFlexio0);
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Set the TPM external clock frequency(TPM_CLKx).
+ *
+ * This function sets the TPM external clock frequency (TPM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetTpmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < TPM_EXT_CLK_COUNT);
+
+ g_tpmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+
+#endif /* __FSL_CLOCK_MKL17Z4__H__ */
+/*******************************************************************************
+* EOF
+******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL17Z644/fsl_clock_MKL17Z644.c b/KSDK_1.2.0/platform/system/src/clock/MKL17Z644/fsl_clock_MKL17Z644.c
new file mode 100755
index 0000000..d204e3a
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL17Z644/fsl_clock_MKL17Z644.c
@@ -0,0 +1,804 @@
+/*
+* Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* o Redistributions of source code must retain the above copyright notice, this list
+* of conditions and the following disclaimer.
+*
+* o Redistributions in binary form must reproduce the above copyright notice, this
+* list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+* contributors may be used to endorse or promote products derived from this
+* software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcglite_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+* README:
+* This file should provide these APIs:
+* 1. APIs to get the frequency of output clocks in Reference Manual ->
+* Chapter Clock Distribution -> Figure Clocking diagram.
+* 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+* -> Module clocks.
+*/
+
+/*******************************************************************************
+* Definitions
+******************************************************************************/
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+
+/*******************************************************************************
+* Code
+******************************************************************************/
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ 0U,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 1U, 0U, 0U, 7U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgliteMode(&config->mcgliteConfig);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kIrc48mClock:
+ *frequency = kMcgliteConst48M;
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetCoreClockFreq
+* Description : Gets the core clock frequency.
+* This function gets the core clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetSystemClockFreq
+* Description : Gets the systen clock frequency.
+* This function gets the systen clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetBusClockFreq
+* Description : Gets the bus clock frequency.
+* This function gets the bus clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetFlashClockFreq
+* Description : Gets the flash clock frequency.
+* This function gets the flash clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetRtcOutFreq
+* Description : Gets the RTC_CLKOUT frequency.
+* This function gets RTC_CLKOUT clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return 1U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetExternalRefClockFreq
+* Description : Gets the ERCLK32K clock frequency.
+* This function gets the external reference (ERCLK32K) clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+* Description : Gets OSC0ERCLK.
+* This function gets the OSC0 external reference frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetCopFreq
+* Description : Gets the clock frequency for COP module.
+* This function gets the clock frequency for COP moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetCopFreq(void)
+{
+ clock_cop_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetCopSrc(SIM);
+
+ switch (src)
+ {
+ case kClockCopSrcLpoClk:
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockCopSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockCopSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockCopSrcBusClk:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmFreq
+* Description : Gets the clock frequency for TPM module.
+* This function gets the clock frequency for TPM moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+
+ clock_tpm_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockTpmSrcIrc48M: /* IRC48M */
+ freq = kMcgliteConst48M;
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCER clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIR clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetLpuartFreq
+* Description : Gets the clock frequency for LPUART module.
+* This function gets the clock frequency for LPUART moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance)
+{
+ clock_lpuart_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetLpuartSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockLpuartSrcIrc48M: /* IRC48M */
+ freq = kMcgliteConst48M;
+ break;
+ case kClockLpuartSrcOsc0erClk: /* OSCER clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpuartSrcMcgIrClk: /* MCGIR clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmExternalFreq
+* Description : Gets Tpm external clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t sel = SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+
+ if (kSimTpmClkSel0 == sel)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ clock_usbfs_src_t src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0];
+ }
+ else
+ {
+ return kMcgliteConst48M;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexioFreq
+ * Description : Gets the clock frequency for FLEXIO.
+ * This function gets the clock frequency for FLEXIO.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexioFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_flexio_src_t src = CLOCK_HAL_GetFlexioSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockFlexioSrcIrc48M:
+ freq = kMcgliteConst48M;
+ break;
+ case kClockFlexioSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockFlexioSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiFreq
+ * Description : Gets the clock frequency for SPI.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ assert(instance < SPI_INSTANCE_COUNT);
+
+ if (0U == instance)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetSystemClockFreq();
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnablePortClock
+* Description : Enable the clock for PORT module
+* This function enables the clock for PORT moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisablePortClock
+* Description : Disable the clock for PORT module
+* This function disables the clock for PORT moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetPortGateCmd
+* Description : Get the the clock gate state for PORT module
+* This function will get the clock gate state for PORT moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableAdcClock
+* Description : Enable the clock for ADC module
+* This function enables the clock for ADC moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableAdcClock
+* Description : Disable the clock for ADC module
+* This function disables the clock for ADC moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetAdcGateCmd
+* Description : Get the the clock gate state for ADC module
+* This function will get the clock gate state for ADC moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableSpiClock
+* Description : Enable the clock for SPI module
+* This function enables the clock for SPI moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableSpiClock
+* Description : Disable the clock for SPI module
+* This function disables the clock for SPI moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetSpiGateCmd
+* Description : Get the the clock gate state for SPI module
+* This function will get the clock gate state for SPI moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableI2cClock
+* Description : Enable the clock for I2C module
+* This function enables the clock for I2C moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableI2cClock
+* Description : Disable the clock for I2C module
+* This function disables the clock for I2C moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetI2cGateCmd
+* Description : Get the the clock gate state for I2C module
+* This function will get the clock gate state for I2C moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Lpuart instance table. */
+static const sim_clock_gate_name_t lpuartGateTable[] =
+{
+ kSimClockGateLpuart0,
+ kSimClockGateLpuart1
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_EnableLpuartClock
+* Description : Enable the clock for UART module
+* This function enables the clock for UART moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableLpuartClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, lpuartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_DisableLpuartClock
+* Description : Disable the clock for UART module
+* This function enables the clock for UART moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableLpuartClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, lpuartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_GetLpuartGateCmd
+* Description : Get the the clock gate state for UART module
+* This function will get the clock gate state for UART moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, lpuartGateTable[instance]);
+}
+
+/* TPM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm0,
+ kSimClockGateTpm1,
+ kSimClockGateTpm2,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableTpmClock
+* Description : Enable the clock for TPM module
+* This function enables the clock for TPM moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableTpmClock
+* Description : Disable the clock for TPM module
+* This function disables the clock for TPM moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmGateCmd
+* Description : Get the the clock gate state for TPM module
+* This function will get the clock gate state for TPM moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+* EOF
+******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL17Z644/fsl_clock_MKL17Z644.h b/KSDK_1.2.0/platform/system/src/clock/MKL17Z644/fsl_clock_MKL17Z644.h
new file mode 100755
index 0000000..3c86cb9
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL17Z644/fsl_clock_MKL17Z644.h
@@ -0,0 +1,1193 @@
+/*
+* Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* o Redistributions of source code must retain the above copyright notice, this list
+* of conditions and the following disclaimer.
+*
+* o Redistributions in binary form must reproduce the above copyright notice, this
+* list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+* contributors may be used to endorse or promote products derived from this
+* software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#if !defined(__FSL_CLOCK_MKL17Z644_H__)
+#define __FSL_CLOCK_MKL17Z644_H__
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcglite_hal.h"
+#include "fsl_mcglite_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kl17z644 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+* Definitions
+******************************************************************************/
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kl17z644_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+* API
+******************************************************************************/
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+* @brief Get internal reference clock frequency.
+*
+* This function gets the internal reference clock frequency.
+*
+* @return Current clock frequency.
+*/
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+* @brief Gets the OSC0ERCLK frequency.
+*
+* This function gets the OSC0 external reference frequency.
+*
+* @return Current frequency.
+*/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+* @brief Gets RTC_CLKOUT frequency.
+*
+* This function gets the frequency of RTC_CLKOUT.
+*
+* @return Current frequency.
+*/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+* @brief Gets RTC_CLKOUT source.
+*
+* This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+*
+* @return Current source.
+*/
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+* @brief Gets RTC_CLKOUT source.
+*
+* This function sets the source of RTC_CLKOUT.
+*
+* @param src RTC_CLKOUT source to set.
+*/
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+ /*!
+ * @brief Gets rtc clock frequency.
+ *
+ * This function gets the rtc clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets COP clock frequency.
+ *
+ * This function gets the COP clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetCopFreq(void);
+
+/*!
+ * @brief Set the COP clock source selection.
+ *
+ * This function sets the COP clock source selection.
+ *
+ * @param copSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetCopSrc(clock_cop_src_t copSrc)
+{
+ CLOCK_HAL_SetCopSrc(SIM, copSrc);
+}
+
+/*!
+ * @brief Get the COP clock source selection.
+ *
+ * This function gets the COP clock source selection.
+ *
+ * @return Current selection.
+ */
+static inline clock_cop_src_t CLOCK_SYS_GetCopSrc(void)
+{
+ return CLOCK_HAL_GetCopSrc(SIM);
+}
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function sets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @param usbfsSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Get the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function gets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock source for LPUART module
+ *
+ * This function gets the clock source for LPUART module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_lpuart_src_t CLOCK_SYS_GetLpuartSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpuartSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for LPUART module
+ *
+ * This function sets the clock source for LPUART module.
+ * @param instance module device instance
+ * @param lpuartSrc Clock source.
+ */
+static inline void CLOCK_SYS_SetLpuartSrc(uint32_t instance, clock_lpuart_src_t lpuartSrc)
+{
+ CLOCK_HAL_SetLpuartSrc(SIM, instance, lpuartSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for LPUART module
+ *
+ * This function gets the clock frequency for LPUART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FLEXIO clock frequency.
+ *
+ * This function gets the FLEXIO clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexioFreq(uint32_t instance);
+
+/*!
+ * @brief Set the FLEXIO clock source selection.
+ *
+ * This function sets the FLEXIO clock source selection.
+ *
+ * @param instance IP instance.
+ * @param flexioSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetFlexioSrc(uint32_t instance, clock_flexio_src_t flexioSrc)
+{
+ CLOCK_HAL_SetFlexioSrc(SIM, instance, flexioSrc);
+}
+
+/*!
+ * @brief Get the FLEXIO clock source selection.
+ *
+ * This function gets the FLEXIO clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_flexio_src_t CLOCK_SYS_GetFlexioSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetFlexioSrc(SIM, instance);
+}
+
+/*!
+* @brief Gets the clock frequency for FTF module. (Flash Memory)
+*
+* This function gets the clock frequency for FTF module. (Flash Memory)
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for CMP module.
+*
+* This function gets the clock frequency for CMP module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for VREF module.
+*
+* This function gets the clock frequency for VREF module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for SPI module
+*
+* This function gets the clock frequency for SPI module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+* @brief Gets the clock frequency for I2C module
+*
+* This function gets the clock frequency for I2C module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets ADC alternate clock frequency.
+*
+* This function gets the ADC alternate clock frequency.
+*
+* @param instance module device instance
+* @return freq Current frequency.
+*/
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for UART module
+*
+* This function gets the clock frequency for UART module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Enable the clock for PORT module.
+*
+* This function enables the clock for PORT module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for PORT module.
+*
+* This function disables the clock for PORT module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for PORT module.
+*
+* This function will get the clock gate state for PORT module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for FTF module.
+*
+* This function enables the clock for FTF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Disable the clock for FTF module.
+*
+* This function disables the clock for FTF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Get the the clock gate state for FTF module.
+*
+* This function will get the clock gate state for FTF module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Enable the clock for ADC module.
+*
+* This function enables the clock for ADC module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for ADC module.
+*
+* This function disables the clock for ADC module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for ADC module.
+*
+* This function will get the clock gate state for ADC module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for CMP module.
+*
+* This function enables the clock for CMP module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Disable the clock for CMP module.
+*
+* This function disables the clock for CMP module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Get the the clock gate state for CMP module.
+*
+* This function will get the clock gate state for CMP module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Enable the clock for VREF module.
+*
+* This function enables the clock for VREF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+* @brief Disable the clock for VREF module.
+*
+* This function disables the clock for VREF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+* @brief Get the the clock gate state for VREF module.
+*
+* This function will get the clock gate state for VREF module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+* @brief Enable the clock for LPTIMER module.
+*
+* This function enables the clock for LPTIMER module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Disable the clock for LPTIMER module.
+*
+* This function disables the clock for LPTIMER module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Get the the clock gate state for LPTIMER module.
+*
+* This function will get the clock gate state for LPTIMER module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Enable the clock for RTC module.
+*
+* This function enables the clock for RTC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Disable the clock for RTC module.
+*
+* This function disables the clock for RTC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Get the the clock gate state for RTC module.
+*
+* This function will get the clock gate state for RTC module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Enable the clock for SPI module.
+*
+* This function enables the clock for SPI module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for SPI module.
+*
+* This function disables the clock for SPI module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for SPI module.
+*
+* This function will get the clock gate state for SPI module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for I2C module.
+*
+* This function enables the clock for I2C module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for I2C module.
+*
+* This function disables the clock for I2C module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for I2C module.
+*
+* This function will get the clock gate state for I2C module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for LPUART module.
+*
+* This function enables the clock for LPUART module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableLpuartClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for LPUART module.
+*
+* This function disables the clock for LPUART module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableLpuartClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for LPUART module.
+*
+* This function will get the clock gate state for LPUART module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for UART module.
+*
+* This function enables the clock for UART module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUart2);
+}
+
+/*!
+* @brief Disable the clock for UART module.
+*
+* This function disables the clock for UART module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUart2);
+}
+
+/*!
+* @brief Get the the clock gate state for UART module.
+*
+* This function will get the clock gate state for UART module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM,kSimClockGateUart2);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+* @brief Enable the clock for FLEXIO module.
+*
+* This function enables the clock for FLEXIO module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableFlexioClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexio0);
+}
+
+/*!
+* @brief Disable the clock for FLEXIO module.
+*
+* This function disables the clock for FLEXIO module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableFlexioClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexio0);
+}
+
+/*!
+* @brief Get the clock gate state for FLEXIO module.
+*
+* This function will get the clock gate state for FLEXIO module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetFlexioGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM,kSimClockGateFlexio0);
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the TPM external clock frequency(TPM_CLKx).
+ *
+ * This function sets the TPM external clock frequency (TPM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetTpmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < TPM_EXT_CLK_COUNT);
+
+ g_tpmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+
+#endif /* __FSL_CLOCK_MKL17Z644__H__ */
+/*******************************************************************************
+* EOF
+******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL24Z4/fsl_clock_MKL24Z4.c b/KSDK_1.2.0/platform/system/src/clock/MKL24Z4/fsl_clock_MKL24Z4.c
new file mode 100755
index 0000000..ff253b4
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL24Z4/fsl_clock_MKL24Z4.c
@@ -0,0 +1,986 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_sim_hal.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_clock_manager.h"
+#include "fsl_os_abstraction.h"
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ 0U,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFreq
+ * Description : Internal function to get the frequency by clock name
+ * This function will get/calculate the clock frequency based on clock name
+ * and current configuration of clock generator.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+
+ CLOCK_HAL_SetOutDiv(SIM, 2U, 0U, 0U, 5U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+ /*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ freq >>= 1U; /* divided by 2 for special divider */
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return CLOCK_SYS_GetExternalRefClock32kFreq() >> 15U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCopFreq
+ * Description : Gets cop clock frequency.
+ * This function gets the cop clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc)
+{
+ if (kClockCopSrcLpoClk == copSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcFreq
+ * Description : Gets rtc clock frequency.
+ * This function gets rtc clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmfFreq
+ * Description : Gets the clock frequency for TPM module.
+ * This function gets the clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_tpm_src_t src;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTpmSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmExternalFreq
+ * Description : Gets the external clock frequency for TPM module.
+ * This function gets the external clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t src = CLOCK_SYS_GetTpmExternalSrc(instance);
+
+ if (kSimTpmClkSel0 == src)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ return freq;
+ }
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpifFreq
+ * Description : Gets the clock frequency for SPI module.
+ * This function gets the clock frequency for SPI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cfFreq
+ * Description : Gets the clock frequency for I2C module.
+ * This function gets the clock frequency for I2C moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpsciFreq
+ * Description : Gets the clock frequency for LPSCI module.
+ * This function gets the clock frequency for LPSCI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_lpsci_src_t src;
+
+ src = CLOCK_HAL_GetLpsciSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockLpsciSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockLpsciSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpsciSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+#if FSL_FEATURE_SOC_DAC_COUNT
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+#endif
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Lpsci instance table. */
+static const sim_clock_gate_name_t lpsciGateTable[] =
+{
+ kSimClockGateLpsci0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function disable the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetLpsciGateCmd
+ * Description : Get the the clock gate state for LPSCI module
+ * This function will get the clock gate state for LPSCI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function enables the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, lpsciGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ (sim_clock_gate_name_t)(-1),
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm0,
+ kSimClockGateTpm1,
+ kSimClockGateTpm2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableTpmClock
+ * Description : Enable the clock for TPM module
+ * This function enables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableTpmClock
+ * Description : Disable the clock for TPM module
+ * This function disables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmGateCmd
+ * Description : Get the the clock gate state for TPM module
+ * This function will get the clock gate state for TPM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL24Z4/fsl_clock_MKL24Z4.h b/KSDK_1.2.0/platform/system/src/clock/MKL24Z4/fsl_clock_MKL24Z4.h
new file mode 100755
index 0000000..6cd3a2e
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL24Z4/fsl_clock_MKL24Z4.h
@@ -0,0 +1,1115 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KL24Z4_H__)
+#define __FSL_CLOCK_KL24Z4_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kl24z4 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kl24z4_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the COP clock frequency.
+ *
+ * This function gets the COP clock frequency.
+ *
+ * @param instance module device instance
+ * @param copSrc COP clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc);
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+ #if FSL_FEATURE_SOC_USB_COUNT
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function sets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @param usbfsSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Get the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function gets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+#endif
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance);
+
+ /*!
+ * @brief Gets the clock frequency for LPSCI module.
+ *
+ * This function gets the clock frequency for LPSCI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance);
+
+/*!
+ * @brief Set the LPSCI clock source selection.
+ *
+ * This function sets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @param lpsciSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetLpsciSrc(uint32_t instance, clock_lpsci_src_t lpsciSrc)
+{
+ CLOCK_HAL_SetLpsciSrc(SIM, instance, lpsciSrc);
+}
+
+/*!
+ * @brief Get the LPSCI clock source selection.
+ *
+ * This function gets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_lpsci_src_t CLOCK_SYS_GetLpsciSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpsciSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the UART clock frequency.
+ *
+ * This function gets the UART clock frequency.
+ *
+ * @param instance IP instance.
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+#if FSL_FEATURE_SOC_DAC_COUNT
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+#endif
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+#if FSL_FEATURE_SOC_TSI_COUNT
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+ #if FSL_FEATURE_SOC_USB_COUNT
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPSCI module.
+ *
+ * This function enables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for LPSCI module.
+ *
+ * This function disables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for LPSCI module.
+ *
+ * This function will get the clock gate state for LPSCI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the TPM external clock frequency(TPM_CLKx).
+ *
+ * This function sets the TPM external clock frequency (TPM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetTpmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < TPM_EXT_CLK_COUNT);
+
+ g_tpmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KL24Z4_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL25Z4/fsl_clock_MKL25Z4.c b/KSDK_1.2.0/platform/system/src/clock/MKL25Z4/fsl_clock_MKL25Z4.c
new file mode 100755
index 0000000..ff253b4
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL25Z4/fsl_clock_MKL25Z4.c
@@ -0,0 +1,986 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_sim_hal.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_clock_manager.h"
+#include "fsl_os_abstraction.h"
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ 0U,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFreq
+ * Description : Internal function to get the frequency by clock name
+ * This function will get/calculate the clock frequency based on clock name
+ * and current configuration of clock generator.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+
+ CLOCK_HAL_SetOutDiv(SIM, 2U, 0U, 0U, 5U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+ /*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ freq >>= 1U; /* divided by 2 for special divider */
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return CLOCK_SYS_GetExternalRefClock32kFreq() >> 15U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCopFreq
+ * Description : Gets cop clock frequency.
+ * This function gets the cop clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc)
+{
+ if (kClockCopSrcLpoClk == copSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcFreq
+ * Description : Gets rtc clock frequency.
+ * This function gets rtc clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmfFreq
+ * Description : Gets the clock frequency for TPM module.
+ * This function gets the clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_tpm_src_t src;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTpmSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmExternalFreq
+ * Description : Gets the external clock frequency for TPM module.
+ * This function gets the external clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t src = CLOCK_SYS_GetTpmExternalSrc(instance);
+
+ if (kSimTpmClkSel0 == src)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ return freq;
+ }
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpifFreq
+ * Description : Gets the clock frequency for SPI module.
+ * This function gets the clock frequency for SPI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cfFreq
+ * Description : Gets the clock frequency for I2C module.
+ * This function gets the clock frequency for I2C moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpsciFreq
+ * Description : Gets the clock frequency for LPSCI module.
+ * This function gets the clock frequency for LPSCI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_lpsci_src_t src;
+
+ src = CLOCK_HAL_GetLpsciSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockLpsciSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockLpsciSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpsciSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+#if FSL_FEATURE_SOC_DAC_COUNT
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+#endif
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Lpsci instance table. */
+static const sim_clock_gate_name_t lpsciGateTable[] =
+{
+ kSimClockGateLpsci0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function disable the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetLpsciGateCmd
+ * Description : Get the the clock gate state for LPSCI module
+ * This function will get the clock gate state for LPSCI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function enables the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, lpsciGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ (sim_clock_gate_name_t)(-1),
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm0,
+ kSimClockGateTpm1,
+ kSimClockGateTpm2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableTpmClock
+ * Description : Enable the clock for TPM module
+ * This function enables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableTpmClock
+ * Description : Disable the clock for TPM module
+ * This function disables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmGateCmd
+ * Description : Get the the clock gate state for TPM module
+ * This function will get the clock gate state for TPM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL25Z4/fsl_clock_MKL25Z4.h b/KSDK_1.2.0/platform/system/src/clock/MKL25Z4/fsl_clock_MKL25Z4.h
new file mode 100755
index 0000000..734bd8d
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL25Z4/fsl_clock_MKL25Z4.h
@@ -0,0 +1,1115 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KL25Z4_H__)
+#define __FSL_CLOCK_KL25Z4_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kl25z4 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kl25z4_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the COP clock frequency.
+ *
+ * This function gets the COP clock frequency.
+ *
+ * @param instance module device instance
+ * @param copSrc COP clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc);
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+ #if FSL_FEATURE_SOC_USB_COUNT
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function sets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @param usbfsSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Get the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function gets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+#endif
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance);
+
+ /*!
+ * @brief Gets the clock frequency for LPSCI module.
+ *
+ * This function gets the clock frequency for LPSCI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance);
+
+/*!
+ * @brief Set the LPSCI clock source selection.
+ *
+ * This function sets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @param lpsciSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetLpsciSrc(uint32_t instance, clock_lpsci_src_t lpsciSrc)
+{
+ CLOCK_HAL_SetLpsciSrc(SIM, instance, lpsciSrc);
+}
+
+/*!
+ * @brief Get the LPSCI clock source selection.
+ *
+ * This function gets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_lpsci_src_t CLOCK_SYS_GetLpsciSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpsciSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the UART clock frequency.
+ *
+ * This function gets the UART clock frequency.
+ *
+ * @param instance IP instance.
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+#if FSL_FEATURE_SOC_DAC_COUNT
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+#endif
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+#if FSL_FEATURE_SOC_TSI_COUNT
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+ #if FSL_FEATURE_SOC_USB_COUNT
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+#endif
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPSCI module.
+ *
+ * This function enables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for LPSCI module.
+ *
+ * This function disables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for LPSCI module.
+ *
+ * This function will get the clock gate state for LPSCI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the TPM external clock frequency(TPM_CLKx).
+ *
+ * This function sets the TPM external clock frequency (TPM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetTpmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < TPM_EXT_CLK_COUNT);
+
+ g_tpmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KL25Z4_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL26Z4/fsl_clock_MKL26Z4.c b/KSDK_1.2.0/platform/system/src/clock/MKL26Z4/fsl_clock_MKL26Z4.c
new file mode 100755
index 0000000..71d7a5b
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL26Z4/fsl_clock_MKL26Z4.c
@@ -0,0 +1,1012 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_sim_hal.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_clock_manager.h"
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+#endif
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ 0U,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+
+ CLOCK_HAL_SetOutDiv(SIM, 2U, 0U, 0U, 5U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+ /*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ freq >>= 1U; /* divided by 2 for special divider */
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return CLOCK_SYS_GetExternalRefClock32kFreq() >> 15U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCopFreq
+ * Description : Gets COP clock frequency.
+ * This function gets the COP clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc)
+{
+ if (kClockCopSrcLpoClk == copSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcFreq
+ * Description : Gets rtc clock frequency.
+ * This function gets rtc clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmfFreq
+ * Description : Gets the clock frequency for TPM module.
+ * This function gets the clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_tpm_src_t src;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTpmSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmExternalFreq
+ * Description : Gets the external clock frequency for TPM module.
+ * This function gets the external clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t src = CLOCK_SYS_GetTpmExternalSrc(instance);
+
+ if (kSimTpmClkSel0 == src)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ return freq;
+ }
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpifFreq
+ * Description : Gets the clock frequency for SPI module.
+ * This function gets the clock frequency for SPI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cfFreq
+ * Description : Gets the clock frequency for I2C module.
+ * This function gets the clock frequency for I2C moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpsciFreq
+ * Description : Gets the clock frequency for LPSCI module.
+ * This function gets the clock frequency for LPSCI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_lpsci_src_t src;
+
+ src = CLOCK_HAL_GetLpsciSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockLpsciSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockLpsciSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpsciSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Lpsci instance table. */
+static const sim_clock_gate_name_t lpsciGateTable[] =
+{
+ kSimClockGateLpsci0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function disable the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetLpsciGateCmd
+ * Description : Get the the clock gate state for LPSCI module
+ * This function will get the clock gate state for LPSCI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function enables the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, lpsciGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ (sim_clock_gate_name_t)(-1),
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm0,
+ kSimClockGateTpm1,
+ kSimClockGateTpm2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableTpmClock
+ * Description : Enable the clock for TPM module
+ * This function enables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableTpmClock
+ * Description : Disable the clock for TPM module
+ * This function disables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmGateCmd
+ * Description : Get the the clock gate state for TPM module
+ * This function will get the clock gate state for TPM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL26Z4/fsl_clock_MKL26Z4.h b/KSDK_1.2.0/platform/system/src/clock/MKL26Z4/fsl_clock_MKL26Z4.h
new file mode 100755
index 0000000..69fa4d6
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL26Z4/fsl_clock_MKL26Z4.h
@@ -0,0 +1,1237 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KL26Z4_H__)
+#define __FSL_CLOCK_KL26Z4_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kl26z4 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+#if FSL_FEATURE_SOC_USB_COUNT
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+#endif
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kl26z4_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the COP clock frequency.
+ *
+ * This function gets the COP clock frequency.
+ *
+ * @param instance module device instance
+ * @param copSrc COP clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function sets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @param usbfsSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Get the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function gets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance);
+
+ /*!
+ * @brief Gets the clock frequency for LPSCI module.
+ *
+ * This function gets the clock frequency for LPSCI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance);
+
+/*!
+ * @brief Set the LPSCI clock source selection.
+ *
+ * This function sets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @param lpsciSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetLpsciSrc(uint32_t instance, clock_lpsci_src_t lpsciSrc)
+{
+ CLOCK_HAL_SetLpsciSrc(SIM, instance, lpsciSrc);
+}
+
+/*!
+ * @brief Get the LPSCI clock source selection.
+ *
+ * This function gets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_lpsci_src_t CLOCK_SYS_GetLpsciSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpsciSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the UART clock frequency.
+ *
+ * This function gets the UART clock frequency.
+ *
+ * @param instance IP instance.
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+ * @brief Enable the clock for SLCD module.
+ *
+ * This function enables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Disable the clock for SLCD module.
+ *
+ * This function disables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SLCD module.
+ *
+ * This function will get the clock gate state for SLCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSlcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD default clock.
+ *
+ * This function gets the frequency for SLCD default clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdDefaultFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate clock.
+ *
+ * This function gets the frequency for SLCD alternate clock (ALTSOURCE = 0).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAltFreq(uint32_t instance)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate 2 clock.
+ *
+ * This function gets the frequency for SLCD alternate 2 clock (ALTSOURCE = 1).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAlt2Freq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+#endif// FSL_FEATURE_SOC_LCD_COUNT
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPSCI module.
+ *
+ * This function enables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for LPSCI module.
+ *
+ * This function disables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for LPSCI module.
+ *
+ * This function will get the clock gate state for LPSCI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Set the TPM external clock frequency(TPM_CLKx).
+ *
+ * This function sets the TPM external clock frequency (TPM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetTpmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < TPM_EXT_CLK_COUNT);
+
+ g_tpmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KL26Z4_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL27Z4/fsl_clock_MKL27Z4.c b/KSDK_1.2.0/platform/system/src/clock/MKL27Z4/fsl_clock_MKL27Z4.c
new file mode 100755
index 0000000..d74eea3
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL27Z4/fsl_clock_MKL27Z4.c
@@ -0,0 +1,840 @@
+/*
+* Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* o Redistributions of source code must retain the above copyright notice, this list
+* of conditions and the following disclaimer.
+*
+* o Redistributions in binary form must reproduce the above copyright notice, this
+* list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+* contributors may be used to endorse or promote products derived from this
+* software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcglite_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+* README:
+* This file should provide these APIs:
+* 1. APIs to get the frequency of output clocks in Reference Manual ->
+* Chapter Clock Distribution -> Figure Clocking diagram.
+* 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+* -> Module clocks.
+*/
+
+/*******************************************************************************
+* Definitions
+******************************************************************************/
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+#endif
+
+/*******************************************************************************
+* Code
+******************************************************************************/
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ 0U,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 1U, 0U, 0U, 7U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgliteMode(&config->mcgliteConfig);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kIrc48mClock:
+ *frequency = kMcgliteConst48M;
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetCoreClockFreq
+* Description : Gets the core clock frequency.
+* This function gets the core clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetSystemClockFreq
+* Description : Gets the systen clock frequency.
+* This function gets the systen clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetBusClockFreq
+* Description : Gets the bus clock frequency.
+* This function gets the bus clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetFlashClockFreq
+* Description : Gets the flash clock frequency.
+* This function gets the flash clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetRtcOutFreq
+* Description : Gets the RTC_CLKOUT frequency.
+* This function gets RTC_CLKOUT clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return 1U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetExternalRefClockFreq
+* Description : Gets the ERCLK32K clock frequency.
+* This function gets the external reference (ERCLK32K) clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+* Description : Gets OSC0ERCLK.
+* This function gets the OSC0 external reference frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetCopFreq
+* Description : Gets the clock frequency for COP module.
+* This function gets the clock frequency for COP moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetCopFreq(void)
+{
+ clock_cop_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetCopSrc(SIM);
+
+ switch (src)
+ {
+ case kClockCopSrcLpoClk:
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockCopSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockCopSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockCopSrcBusClk:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmFreq
+* Description : Gets the clock frequency for TPM module.
+* This function gets the clock frequency for TPM moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+
+ clock_tpm_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockTpmSrcIrc48M: /* IRC48M */
+ freq = kMcgliteConst48M;
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCER clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIR clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetLpuartFreq
+* Description : Gets the clock frequency for LPUART module.
+* This function gets the clock frequency for LPUART moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance)
+{
+ clock_lpuart_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetLpuartSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockLpuartSrcIrc48M: /* IRC48M */
+ freq = kMcgliteConst48M;
+ break;
+ case kClockLpuartSrcOsc0erClk: /* OSCER clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpuartSrcMcgIrClk: /* MCGIR clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmExternalFreq
+* Description : Gets Tpm external clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t sel = SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+
+ if (kSimTpmClkSel0 == sel)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ clock_usbfs_src_t src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0];
+ }
+ else
+ {
+ return kMcgliteConst48M;
+ }
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexioFreq
+ * Description : Gets the clock frequency for FLEXIO.
+ * This function gets the clock frequency for FLEXIO.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexioFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_flexio_src_t src = CLOCK_HAL_GetFlexioSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockFlexioSrcIrc48M:
+ freq = kMcgliteConst48M;
+ break;
+ case kClockFlexioSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockFlexioSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcSysClk: /*!< SYSCLK */
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kClockSaiSrcOsc0erClk: /*!< OSC0ERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcMcgIrClk: /*!< MCGIRCLK */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockSaiSrcIrc48M: /*!< MCGPCLK/IRC48M. */
+ freq = kMcgliteConst48M;
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiFreq
+ * Description : Gets the clock frequency for SPI.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ assert(instance < SPI_INSTANCE_COUNT);
+
+ if (0U == instance)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetSystemClockFreq();
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnablePortClock
+* Description : Enable the clock for PORT module
+* This function enables the clock for PORT moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisablePortClock
+* Description : Disable the clock for PORT module
+* This function disables the clock for PORT moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetPortGateCmd
+* Description : Get the the clock gate state for PORT module
+* This function will get the clock gate state for PORT moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableAdcClock
+* Description : Enable the clock for ADC module
+* This function enables the clock for ADC moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableAdcClock
+* Description : Disable the clock for ADC module
+* This function disables the clock for ADC moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetAdcGateCmd
+* Description : Get the the clock gate state for ADC module
+* This function will get the clock gate state for ADC moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableSpiClock
+* Description : Enable the clock for SPI module
+* This function enables the clock for SPI moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableSpiClock
+* Description : Disable the clock for SPI module
+* This function disables the clock for SPI moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetSpiGateCmd
+* Description : Get the the clock gate state for SPI module
+* This function will get the clock gate state for SPI moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableI2cClock
+* Description : Enable the clock for I2C module
+* This function enables the clock for I2C moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableI2cClock
+* Description : Disable the clock for I2C module
+* This function disables the clock for I2C moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetI2cGateCmd
+* Description : Get the the clock gate state for I2C module
+* This function will get the clock gate state for I2C moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Lpuart instance table. */
+static const sim_clock_gate_name_t lpuartGateTable[] =
+{
+ kSimClockGateLpuart0,
+ kSimClockGateLpuart1
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_EnableLpuartClock
+* Description : Enable the clock for UART module
+* This function enables the clock for UART moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableLpuartClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, lpuartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_DisableLpuartClock
+* Description : Disable the clock for UART module
+* This function enables the clock for UART moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableLpuartClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, lpuartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_GetLpuartGateCmd
+* Description : Get the the clock gate state for UART module
+* This function will get the clock gate state for UART moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, lpuartGateTable[instance]);
+}
+
+/* TPM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm0,
+ kSimClockGateTpm1,
+ kSimClockGateTpm2,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableTpmClock
+* Description : Enable the clock for TPM module
+* This function enables the clock for TPM moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableTpmClock
+* Description : Disable the clock for TPM module
+* This function disables the clock for TPM moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmGateCmd
+* Description : Get the the clock gate state for TPM module
+* This function will get the clock gate state for TPM moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+* EOF
+******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL27Z4/fsl_clock_MKL27Z4.h b/KSDK_1.2.0/platform/system/src/clock/MKL27Z4/fsl_clock_MKL27Z4.h
new file mode 100755
index 0000000..fe0e389
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL27Z4/fsl_clock_MKL27Z4.h
@@ -0,0 +1,1323 @@
+/*
+* Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* o Redistributions of source code must retain the above copyright notice, this list
+* of conditions and the following disclaimer.
+*
+* o Redistributions in binary form must reproduce the above copyright notice, this
+* list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+* contributors may be used to endorse or promote products derived from this
+* software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#if !defined(__FSL_CLOCK_MKL27Z4_H__)
+#define __FSL_CLOCK_MKL27Z4_H__
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcglite_hal.h"
+#include "fsl_mcglite_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kl27z4 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+* Definitions
+******************************************************************************/
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+#if FSL_FEATURE_SOC_USB_COUNT
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+#endif
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kl27z4_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+* API
+******************************************************************************/
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+* @brief Get internal reference clock frequency.
+*
+* This function gets the internal reference clock frequency.
+*
+* @return Current clock frequency.
+*/
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+* @brief Gets the OSC0ERCLK frequency.
+*
+* This function gets the OSC0 external reference frequency.
+*
+* @return Current frequency.
+*/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+* @brief Gets RTC_CLKOUT frequency.
+*
+* This function gets the frequency of RTC_CLKOUT.
+*
+* @return Current frequency.
+*/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+* @brief Gets RTC_CLKOUT source.
+*
+* This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+*
+* @return Current source.
+*/
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+* @brief Gets RTC_CLKOUT source.
+*
+* This function sets the source of RTC_CLKOUT.
+*
+* @param src RTC_CLKOUT source to set.
+*/
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+ /*!
+ * @brief Gets rtc clock frequency.
+ *
+ * This function gets the rtc clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets COP clock frequency.
+ *
+ * This function gets the COP clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetCopFreq(void);
+
+/*!
+ * @brief Set the COP clock source selection.
+ *
+ * This function sets the COP clock source selection.
+ *
+ * @param copSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetCopSrc(clock_cop_src_t copSrc)
+{
+ CLOCK_HAL_SetCopSrc(SIM, copSrc);
+}
+
+/*!
+ * @brief Get the COP clock source selection.
+ *
+ * This function gets the COP clock source selection.
+ *
+ * @return Current selection.
+ */
+static inline clock_cop_src_t CLOCK_SYS_GetCopSrc(void)
+{
+ return CLOCK_HAL_GetCopSrc(SIM);
+}
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function sets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @param usbfsSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Get the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function gets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Gets the clock source for LPUART module
+ *
+ * This function gets the clock source for LPUART module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_lpuart_src_t CLOCK_SYS_GetLpuartSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpuartSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for LPUART module
+ *
+ * This function sets the clock source for LPUART module.
+ * @param instance module device instance
+ * @param lpuartSrc Clock source.
+ */
+static inline void CLOCK_SYS_SetLpuartSrc(uint32_t instance, clock_lpuart_src_t lpuartSrc)
+{
+ CLOCK_HAL_SetLpuartSrc(SIM, instance, lpuartSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for LPUART module
+ *
+ * This function gets the clock frequency for LPUART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FLEXIO clock frequency.
+ *
+ * This function gets the FLEXIO clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexioFreq(uint32_t instance);
+
+/*!
+ * @brief Set the FLEXIO clock source selection.
+ *
+ * This function sets the FLEXIO clock source selection.
+ *
+ * @param instance IP instance.
+ * @param flexioSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetFlexioSrc(uint32_t instance, clock_flexio_src_t flexioSrc)
+{
+ CLOCK_HAL_SetFlexioSrc(SIM, instance, flexioSrc);
+}
+
+/*!
+ * @brief Get the FLEXIO clock source selection.
+ *
+ * This function gets the FLEXIO clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_flexio_src_t CLOCK_SYS_GetFlexioSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetFlexioSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+ * @brief Gets the frequency for SLCD default clock.
+ *
+ * This function gets the frequency for SLCD default clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdDefaultFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate clock.
+ *
+ * This function gets the frequency for SLCD alternate clock (ALTSOURCE = 0).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAltFreq(uint32_t instance)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate 2 clock.
+ *
+ * This function gets the frequency for SLCD alternate 2 clock (ALTSOURCE = 1).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAlt2Freq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+#endif// FSL_FEATURE_SOC_LCD_COUNT
+
+/*!
+* @brief Gets the clock frequency for FTF module. (Flash Memory)
+*
+* This function gets the clock frequency for FTF module. (Flash Memory)
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for CMP module.
+*
+* This function gets the clock frequency for CMP module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for VREF module.
+*
+* This function gets the clock frequency for VREF module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for SPI module
+*
+* This function gets the clock frequency for SPI module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+* @brief Gets the clock frequency for I2C module
+*
+* This function gets the clock frequency for I2C module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets ADC alternate clock frequency.
+*
+* This function gets the ADC alternate clock frequency.
+*
+* @param instance module device instance
+* @return freq Current frequency.
+*/
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for UART module
+*
+* This function gets the clock frequency for UART module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Enable the clock for PORT module.
+*
+* This function enables the clock for PORT module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for PORT module.
+*
+* This function disables the clock for PORT module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for PORT module.
+*
+* This function will get the clock gate state for PORT module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+* @brief Enable the clock for SLCD module.
+*
+* This function enables the clock for SLCD module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+* @brief Disable the clock for SLCD module.
+*
+* This function disables the clock for SLCD module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+* @brief Get the the clock gate state for SLCD module.
+*
+* This function will get the clock gate state for SLCD module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetSlcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSlcd0);
+}
+#endif// FSL_FEATURE_SOC_LCD_COUNT
+
+/*!
+* @brief Enable the clock for FTF module.
+*
+* This function enables the clock for FTF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Disable the clock for FTF module.
+*
+* This function disables the clock for FTF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Get the the clock gate state for FTF module.
+*
+* This function will get the clock gate state for FTF module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Enable the clock for ADC module.
+*
+* This function enables the clock for ADC module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for ADC module.
+*
+* This function disables the clock for ADC module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for ADC module.
+*
+* This function will get the clock gate state for ADC module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for CMP module.
+*
+* This function enables the clock for CMP module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Disable the clock for CMP module.
+*
+* This function disables the clock for CMP module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Get the the clock gate state for CMP module.
+*
+* This function will get the clock gate state for CMP module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Enable the clock for VREF module.
+*
+* This function enables the clock for VREF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+* @brief Disable the clock for VREF module.
+*
+* This function disables the clock for VREF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+* @brief Get the the clock gate state for VREF module.
+*
+* This function will get the clock gate state for VREF module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+* @brief Enable the clock for LPTIMER module.
+*
+* This function enables the clock for LPTIMER module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Disable the clock for LPTIMER module.
+*
+* This function disables the clock for LPTIMER module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Get the the clock gate state for LPTIMER module.
+*
+* This function will get the clock gate state for LPTIMER module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Enable the clock for RTC module.
+*
+* This function enables the clock for RTC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Disable the clock for RTC module.
+*
+* This function disables the clock for RTC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Get the the clock gate state for RTC module.
+*
+* This function will get the clock gate state for RTC module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Enable the clock for DAC module.
+*
+* This function enables the clock for DAC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDac0);
+}
+
+/*!
+* @brief Disable the clock for DAC module.
+*
+* This function disables the clock for DAC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDac0);
+}
+
+/*!
+* @brief Get the the clock gate state for DAC module.
+*
+* This function will get the clock gate state for DAC module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDac0);
+}
+
+/*!
+* @brief Enable the clock for SPI module.
+*
+* This function enables the clock for SPI module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for SPI module.
+*
+* This function disables the clock for SPI module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for SPI module.
+*
+* This function will get the clock gate state for SPI module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for I2C module.
+*
+* This function enables the clock for I2C module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for I2C module.
+*
+* This function disables the clock for I2C module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for I2C module.
+*
+* This function will get the clock gate state for I2C module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for LPUART module.
+*
+* This function enables the clock for LPUART module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableLpuartClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for LPUART module.
+*
+* This function disables the clock for LPUART module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableLpuartClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for LPUART module.
+*
+* This function will get the clock gate state for LPUART module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for UART module.
+*
+* This function enables the clock for UART module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUart2);
+}
+
+/*!
+* @brief Disable the clock for UART module.
+*
+* This function disables the clock for UART module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUart2);
+}
+
+/*!
+* @brief Get the the clock gate state for UART module.
+*
+* This function will get the clock gate state for UART module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM,kSimClockGateUart2);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+* @brief Enable the clock for FLEXIO module.
+*
+* This function enables the clock for FLEXIO module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableFlexioClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexio0);
+}
+
+/*!
+* @brief Disable the clock for FLEXIO module.
+*
+* This function disables the clock for FLEXIO module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableFlexioClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexio0);
+}
+
+/*!
+* @brief Get the clock gate state for FLEXIO module.
+*
+* This function will get the clock gate state for FLEXIO module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetFlexioGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM,kSimClockGateFlexio0);
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Set the TPM external clock frequency(TPM_CLKx).
+ *
+ * This function sets the TPM external clock frequency (TPM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetTpmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < TPM_EXT_CLK_COUNT);
+
+ g_tpmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+
+#endif /* __FSL_CLOCK_MKL27Z4__H__ */
+/*******************************************************************************
+* EOF
+******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL27Z644/fsl_clock_MKL27Z644.c b/KSDK_1.2.0/platform/system/src/clock/MKL27Z644/fsl_clock_MKL27Z644.c
new file mode 100755
index 0000000..d204e3a
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL27Z644/fsl_clock_MKL27Z644.c
@@ -0,0 +1,804 @@
+/*
+* Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* o Redistributions of source code must retain the above copyright notice, this list
+* of conditions and the following disclaimer.
+*
+* o Redistributions in binary form must reproduce the above copyright notice, this
+* list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+* contributors may be used to endorse or promote products derived from this
+* software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcglite_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+* README:
+* This file should provide these APIs:
+* 1. APIs to get the frequency of output clocks in Reference Manual ->
+* Chapter Clock Distribution -> Figure Clocking diagram.
+* 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+* -> Module clocks.
+*/
+
+/*******************************************************************************
+* Definitions
+******************************************************************************/
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+
+/*******************************************************************************
+* Code
+******************************************************************************/
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ 0U,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 1U, 0U, 0U, 7U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgliteMode(&config->mcgliteConfig);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kIrc48mClock:
+ *frequency = kMcgliteConst48M;
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetCoreClockFreq
+* Description : Gets the core clock frequency.
+* This function gets the core clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetSystemClockFreq
+* Description : Gets the systen clock frequency.
+* This function gets the systen clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetBusClockFreq
+* Description : Gets the bus clock frequency.
+* This function gets the bus clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetFlashClockFreq
+* Description : Gets the flash clock frequency.
+* This function gets the flash clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetRtcOutFreq
+* Description : Gets the RTC_CLKOUT frequency.
+* This function gets RTC_CLKOUT clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return 1U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetExternalRefClockFreq
+* Description : Gets the ERCLK32K clock frequency.
+* This function gets the external reference (ERCLK32K) clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+* Description : Gets OSC0ERCLK.
+* This function gets the OSC0 external reference frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetCopFreq
+* Description : Gets the clock frequency for COP module.
+* This function gets the clock frequency for COP moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetCopFreq(void)
+{
+ clock_cop_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetCopSrc(SIM);
+
+ switch (src)
+ {
+ case kClockCopSrcLpoClk:
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockCopSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockCopSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockCopSrcBusClk:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmFreq
+* Description : Gets the clock frequency for TPM module.
+* This function gets the clock frequency for TPM moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+
+ clock_tpm_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockTpmSrcIrc48M: /* IRC48M */
+ freq = kMcgliteConst48M;
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCER clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIR clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetLpuartFreq
+* Description : Gets the clock frequency for LPUART module.
+* This function gets the clock frequency for LPUART moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance)
+{
+ clock_lpuart_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetLpuartSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockLpuartSrcIrc48M: /* IRC48M */
+ freq = kMcgliteConst48M;
+ break;
+ case kClockLpuartSrcOsc0erClk: /* OSCER clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpuartSrcMcgIrClk: /* MCGIR clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmExternalFreq
+* Description : Gets Tpm external clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t sel = SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+
+ if (kSimTpmClkSel0 == sel)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ clock_usbfs_src_t src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0];
+ }
+ else
+ {
+ return kMcgliteConst48M;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexioFreq
+ * Description : Gets the clock frequency for FLEXIO.
+ * This function gets the clock frequency for FLEXIO.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexioFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_flexio_src_t src = CLOCK_HAL_GetFlexioSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockFlexioSrcIrc48M:
+ freq = kMcgliteConst48M;
+ break;
+ case kClockFlexioSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockFlexioSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiFreq
+ * Description : Gets the clock frequency for SPI.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ assert(instance < SPI_INSTANCE_COUNT);
+
+ if (0U == instance)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetSystemClockFreq();
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnablePortClock
+* Description : Enable the clock for PORT module
+* This function enables the clock for PORT moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisablePortClock
+* Description : Disable the clock for PORT module
+* This function disables the clock for PORT moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetPortGateCmd
+* Description : Get the the clock gate state for PORT module
+* This function will get the clock gate state for PORT moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableAdcClock
+* Description : Enable the clock for ADC module
+* This function enables the clock for ADC moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableAdcClock
+* Description : Disable the clock for ADC module
+* This function disables the clock for ADC moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetAdcGateCmd
+* Description : Get the the clock gate state for ADC module
+* This function will get the clock gate state for ADC moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableSpiClock
+* Description : Enable the clock for SPI module
+* This function enables the clock for SPI moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableSpiClock
+* Description : Disable the clock for SPI module
+* This function disables the clock for SPI moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetSpiGateCmd
+* Description : Get the the clock gate state for SPI module
+* This function will get the clock gate state for SPI moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableI2cClock
+* Description : Enable the clock for I2C module
+* This function enables the clock for I2C moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableI2cClock
+* Description : Disable the clock for I2C module
+* This function disables the clock for I2C moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetI2cGateCmd
+* Description : Get the the clock gate state for I2C module
+* This function will get the clock gate state for I2C moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Lpuart instance table. */
+static const sim_clock_gate_name_t lpuartGateTable[] =
+{
+ kSimClockGateLpuart0,
+ kSimClockGateLpuart1
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_EnableLpuartClock
+* Description : Enable the clock for UART module
+* This function enables the clock for UART moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableLpuartClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, lpuartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_DisableLpuartClock
+* Description : Disable the clock for UART module
+* This function enables the clock for UART moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableLpuartClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, lpuartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_GetLpuartGateCmd
+* Description : Get the the clock gate state for UART module
+* This function will get the clock gate state for UART moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, lpuartGateTable[instance]);
+}
+
+/* TPM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm0,
+ kSimClockGateTpm1,
+ kSimClockGateTpm2,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableTpmClock
+* Description : Enable the clock for TPM module
+* This function enables the clock for TPM moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableTpmClock
+* Description : Disable the clock for TPM module
+* This function disables the clock for TPM moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmGateCmd
+* Description : Get the the clock gate state for TPM module
+* This function will get the clock gate state for TPM moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+* EOF
+******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL27Z644/fsl_clock_MKL27Z644.h b/KSDK_1.2.0/platform/system/src/clock/MKL27Z644/fsl_clock_MKL27Z644.h
new file mode 100755
index 0000000..894244c
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL27Z644/fsl_clock_MKL27Z644.h
@@ -0,0 +1,1193 @@
+/*
+* Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* o Redistributions of source code must retain the above copyright notice, this list
+* of conditions and the following disclaimer.
+*
+* o Redistributions in binary form must reproduce the above copyright notice, this
+* list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+* contributors may be used to endorse or promote products derived from this
+* software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#if !defined(__FSL_CLOCK_MKL27Z644_H__)
+#define __FSL_CLOCK_MKL27Z644_H__
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcglite_hal.h"
+#include "fsl_mcglite_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kl27z644 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+* Definitions
+******************************************************************************/
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kl27z644_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+* API
+******************************************************************************/
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+* @brief Get internal reference clock frequency.
+*
+* This function gets the internal reference clock frequency.
+*
+* @return Current clock frequency.
+*/
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+* @brief Gets the OSC0ERCLK frequency.
+*
+* This function gets the OSC0 external reference frequency.
+*
+* @return Current frequency.
+*/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+* @brief Gets RTC_CLKOUT frequency.
+*
+* This function gets the frequency of RTC_CLKOUT.
+*
+* @return Current frequency.
+*/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+* @brief Gets RTC_CLKOUT source.
+*
+* This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+*
+* @return Current source.
+*/
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+* @brief Gets RTC_CLKOUT source.
+*
+* This function sets the source of RTC_CLKOUT.
+*
+* @param src RTC_CLKOUT source to set.
+*/
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+ /*!
+ * @brief Gets rtc clock frequency.
+ *
+ * This function gets the rtc clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets COP clock frequency.
+ *
+ * This function gets the COP clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetCopFreq(void);
+
+/*!
+ * @brief Set the COP clock source selection.
+ *
+ * This function sets the COP clock source selection.
+ *
+ * @param copSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetCopSrc(clock_cop_src_t copSrc)
+{
+ CLOCK_HAL_SetCopSrc(SIM, copSrc);
+}
+
+/*!
+ * @brief Get the COP clock source selection.
+ *
+ * This function gets the COP clock source selection.
+ *
+ * @return Current selection.
+ */
+static inline clock_cop_src_t CLOCK_SYS_GetCopSrc(void)
+{
+ return CLOCK_HAL_GetCopSrc(SIM);
+}
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function sets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @param usbfsSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Get the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function gets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock source for LPUART module
+ *
+ * This function gets the clock source for LPUART module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_lpuart_src_t CLOCK_SYS_GetLpuartSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpuartSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for LPUART module
+ *
+ * This function sets the clock source for LPUART module.
+ * @param instance module device instance
+ * @param lpuartSrc Clock source.
+ */
+static inline void CLOCK_SYS_SetLpuartSrc(uint32_t instance, clock_lpuart_src_t lpuartSrc)
+{
+ CLOCK_HAL_SetLpuartSrc(SIM, instance, lpuartSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for LPUART module
+ *
+ * This function gets the clock frequency for LPUART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FLEXIO clock frequency.
+ *
+ * This function gets the FLEXIO clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexioFreq(uint32_t instance);
+
+/*!
+ * @brief Set the FLEXIO clock source selection.
+ *
+ * This function sets the FLEXIO clock source selection.
+ *
+ * @param instance IP instance.
+ * @param flexioSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetFlexioSrc(uint32_t instance, clock_flexio_src_t flexioSrc)
+{
+ CLOCK_HAL_SetFlexioSrc(SIM, instance, flexioSrc);
+}
+
+/*!
+ * @brief Get the FLEXIO clock source selection.
+ *
+ * This function gets the FLEXIO clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_flexio_src_t CLOCK_SYS_GetFlexioSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetFlexioSrc(SIM, instance);
+}
+
+/*!
+* @brief Gets the clock frequency for FTF module. (Flash Memory)
+*
+* This function gets the clock frequency for FTF module. (Flash Memory)
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for CMP module.
+*
+* This function gets the clock frequency for CMP module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for VREF module.
+*
+* This function gets the clock frequency for VREF module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for SPI module
+*
+* This function gets the clock frequency for SPI module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+* @brief Gets the clock frequency for I2C module
+*
+* This function gets the clock frequency for I2C module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets ADC alternate clock frequency.
+*
+* This function gets the ADC alternate clock frequency.
+*
+* @param instance module device instance
+* @return freq Current frequency.
+*/
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for UART module
+*
+* This function gets the clock frequency for UART module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Enable the clock for PORT module.
+*
+* This function enables the clock for PORT module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for PORT module.
+*
+* This function disables the clock for PORT module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for PORT module.
+*
+* This function will get the clock gate state for PORT module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for FTF module.
+*
+* This function enables the clock for FTF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Disable the clock for FTF module.
+*
+* This function disables the clock for FTF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Get the the clock gate state for FTF module.
+*
+* This function will get the clock gate state for FTF module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Enable the clock for ADC module.
+*
+* This function enables the clock for ADC module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for ADC module.
+*
+* This function disables the clock for ADC module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for ADC module.
+*
+* This function will get the clock gate state for ADC module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for CMP module.
+*
+* This function enables the clock for CMP module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Disable the clock for CMP module.
+*
+* This function disables the clock for CMP module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Get the the clock gate state for CMP module.
+*
+* This function will get the clock gate state for CMP module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Enable the clock for VREF module.
+*
+* This function enables the clock for VREF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+* @brief Disable the clock for VREF module.
+*
+* This function disables the clock for VREF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+* @brief Get the the clock gate state for VREF module.
+*
+* This function will get the clock gate state for VREF module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+* @brief Enable the clock for LPTIMER module.
+*
+* This function enables the clock for LPTIMER module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Disable the clock for LPTIMER module.
+*
+* This function disables the clock for LPTIMER module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Get the the clock gate state for LPTIMER module.
+*
+* This function will get the clock gate state for LPTIMER module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Enable the clock for RTC module.
+*
+* This function enables the clock for RTC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Disable the clock for RTC module.
+*
+* This function disables the clock for RTC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Get the the clock gate state for RTC module.
+*
+* This function will get the clock gate state for RTC module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Enable the clock for SPI module.
+*
+* This function enables the clock for SPI module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for SPI module.
+*
+* This function disables the clock for SPI module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for SPI module.
+*
+* This function will get the clock gate state for SPI module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for I2C module.
+*
+* This function enables the clock for I2C module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for I2C module.
+*
+* This function disables the clock for I2C module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for I2C module.
+*
+* This function will get the clock gate state for I2C module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for LPUART module.
+*
+* This function enables the clock for LPUART module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableLpuartClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for LPUART module.
+*
+* This function disables the clock for LPUART module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableLpuartClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for LPUART module.
+*
+* This function will get the clock gate state for LPUART module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for UART module.
+*
+* This function enables the clock for UART module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUart2);
+}
+
+/*!
+* @brief Disable the clock for UART module.
+*
+* This function disables the clock for UART module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUart2);
+}
+
+/*!
+* @brief Get the the clock gate state for UART module.
+*
+* This function will get the clock gate state for UART module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM,kSimClockGateUart2);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+* @brief Enable the clock for FLEXIO module.
+*
+* This function enables the clock for FLEXIO module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableFlexioClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexio0);
+}
+
+/*!
+* @brief Disable the clock for FLEXIO module.
+*
+* This function disables the clock for FLEXIO module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableFlexioClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexio0);
+}
+
+/*!
+* @brief Get the clock gate state for FLEXIO module.
+*
+* This function will get the clock gate state for FLEXIO module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetFlexioGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM,kSimClockGateFlexio0);
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+
+/*!
+ * @brief Set the TPM external clock frequency(TPM_CLKx).
+ *
+ * This function sets the TPM external clock frequency (TPM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetTpmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < TPM_EXT_CLK_COUNT);
+
+ g_tpmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+
+#endif /* __FSL_CLOCK_MKL27Z644__H__ */
+/*******************************************************************************
+* EOF
+******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL33Z4/fsl_clock_MKL33Z4.c b/KSDK_1.2.0/platform/system/src/clock/MKL33Z4/fsl_clock_MKL33Z4.c
new file mode 100755
index 0000000..d74eea3
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL33Z4/fsl_clock_MKL33Z4.c
@@ -0,0 +1,840 @@
+/*
+* Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* o Redistributions of source code must retain the above copyright notice, this list
+* of conditions and the following disclaimer.
+*
+* o Redistributions in binary form must reproduce the above copyright notice, this
+* list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+* contributors may be used to endorse or promote products derived from this
+* software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcglite_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+* README:
+* This file should provide these APIs:
+* 1. APIs to get the frequency of output clocks in Reference Manual ->
+* Chapter Clock Distribution -> Figure Clocking diagram.
+* 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+* -> Module clocks.
+*/
+
+/*******************************************************************************
+* Definitions
+******************************************************************************/
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+#endif
+
+/*******************************************************************************
+* Code
+******************************************************************************/
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ 0U,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 1U, 0U, 0U, 7U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgliteMode(&config->mcgliteConfig);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kIrc48mClock:
+ *frequency = kMcgliteConst48M;
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetCoreClockFreq
+* Description : Gets the core clock frequency.
+* This function gets the core clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetSystemClockFreq
+* Description : Gets the systen clock frequency.
+* This function gets the systen clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetBusClockFreq
+* Description : Gets the bus clock frequency.
+* This function gets the bus clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetFlashClockFreq
+* Description : Gets the flash clock frequency.
+* This function gets the flash clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetRtcOutFreq
+* Description : Gets the RTC_CLKOUT frequency.
+* This function gets RTC_CLKOUT clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return 1U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetExternalRefClockFreq
+* Description : Gets the ERCLK32K clock frequency.
+* This function gets the external reference (ERCLK32K) clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+* Description : Gets OSC0ERCLK.
+* This function gets the OSC0 external reference frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetCopFreq
+* Description : Gets the clock frequency for COP module.
+* This function gets the clock frequency for COP moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetCopFreq(void)
+{
+ clock_cop_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetCopSrc(SIM);
+
+ switch (src)
+ {
+ case kClockCopSrcLpoClk:
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockCopSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockCopSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockCopSrcBusClk:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmFreq
+* Description : Gets the clock frequency for TPM module.
+* This function gets the clock frequency for TPM moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+
+ clock_tpm_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockTpmSrcIrc48M: /* IRC48M */
+ freq = kMcgliteConst48M;
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCER clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIR clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetLpuartFreq
+* Description : Gets the clock frequency for LPUART module.
+* This function gets the clock frequency for LPUART moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance)
+{
+ clock_lpuart_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetLpuartSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockLpuartSrcIrc48M: /* IRC48M */
+ freq = kMcgliteConst48M;
+ break;
+ case kClockLpuartSrcOsc0erClk: /* OSCER clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpuartSrcMcgIrClk: /* MCGIR clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmExternalFreq
+* Description : Gets Tpm external clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t sel = SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+
+ if (kSimTpmClkSel0 == sel)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ clock_usbfs_src_t src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0];
+ }
+ else
+ {
+ return kMcgliteConst48M;
+ }
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexioFreq
+ * Description : Gets the clock frequency for FLEXIO.
+ * This function gets the clock frequency for FLEXIO.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexioFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_flexio_src_t src = CLOCK_HAL_GetFlexioSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockFlexioSrcIrc48M:
+ freq = kMcgliteConst48M;
+ break;
+ case kClockFlexioSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockFlexioSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcSysClk: /*!< SYSCLK */
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kClockSaiSrcOsc0erClk: /*!< OSC0ERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcMcgIrClk: /*!< MCGIRCLK */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockSaiSrcIrc48M: /*!< MCGPCLK/IRC48M. */
+ freq = kMcgliteConst48M;
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiFreq
+ * Description : Gets the clock frequency for SPI.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ assert(instance < SPI_INSTANCE_COUNT);
+
+ if (0U == instance)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetSystemClockFreq();
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnablePortClock
+* Description : Enable the clock for PORT module
+* This function enables the clock for PORT moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisablePortClock
+* Description : Disable the clock for PORT module
+* This function disables the clock for PORT moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetPortGateCmd
+* Description : Get the the clock gate state for PORT module
+* This function will get the clock gate state for PORT moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableAdcClock
+* Description : Enable the clock for ADC module
+* This function enables the clock for ADC moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableAdcClock
+* Description : Disable the clock for ADC module
+* This function disables the clock for ADC moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetAdcGateCmd
+* Description : Get the the clock gate state for ADC module
+* This function will get the clock gate state for ADC moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableSpiClock
+* Description : Enable the clock for SPI module
+* This function enables the clock for SPI moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableSpiClock
+* Description : Disable the clock for SPI module
+* This function disables the clock for SPI moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetSpiGateCmd
+* Description : Get the the clock gate state for SPI module
+* This function will get the clock gate state for SPI moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableI2cClock
+* Description : Enable the clock for I2C module
+* This function enables the clock for I2C moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableI2cClock
+* Description : Disable the clock for I2C module
+* This function disables the clock for I2C moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetI2cGateCmd
+* Description : Get the the clock gate state for I2C module
+* This function will get the clock gate state for I2C moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Lpuart instance table. */
+static const sim_clock_gate_name_t lpuartGateTable[] =
+{
+ kSimClockGateLpuart0,
+ kSimClockGateLpuart1
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_EnableLpuartClock
+* Description : Enable the clock for UART module
+* This function enables the clock for UART moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableLpuartClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, lpuartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_DisableLpuartClock
+* Description : Disable the clock for UART module
+* This function enables the clock for UART moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableLpuartClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, lpuartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_GetLpuartGateCmd
+* Description : Get the the clock gate state for UART module
+* This function will get the clock gate state for UART moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, lpuartGateTable[instance]);
+}
+
+/* TPM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm0,
+ kSimClockGateTpm1,
+ kSimClockGateTpm2,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableTpmClock
+* Description : Enable the clock for TPM module
+* This function enables the clock for TPM moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableTpmClock
+* Description : Disable the clock for TPM module
+* This function disables the clock for TPM moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmGateCmd
+* Description : Get the the clock gate state for TPM module
+* This function will get the clock gate state for TPM moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+* EOF
+******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL33Z4/fsl_clock_MKL33Z4.h b/KSDK_1.2.0/platform/system/src/clock/MKL33Z4/fsl_clock_MKL33Z4.h
new file mode 100755
index 0000000..488f9ba
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL33Z4/fsl_clock_MKL33Z4.h
@@ -0,0 +1,1323 @@
+/*
+* Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* o Redistributions of source code must retain the above copyright notice, this list
+* of conditions and the following disclaimer.
+*
+* o Redistributions in binary form must reproduce the above copyright notice, this
+* list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+* contributors may be used to endorse or promote products derived from this
+* software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#if !defined(__FSL_CLOCK_MKL33Z4_H__)
+#define __FSL_CLOCK_MKL33Z4_H__
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcglite_hal.h"
+#include "fsl_mcglite_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kl33z4 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+* Definitions
+******************************************************************************/
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+#if FSL_FEATURE_SOC_USB_COUNT
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+#endif
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kl33z4_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+* API
+******************************************************************************/
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+* @brief Get internal reference clock frequency.
+*
+* This function gets the internal reference clock frequency.
+*
+* @return Current clock frequency.
+*/
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+* @brief Gets the OSC0ERCLK frequency.
+*
+* This function gets the OSC0 external reference frequency.
+*
+* @return Current frequency.
+*/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+* @brief Gets RTC_CLKOUT frequency.
+*
+* This function gets the frequency of RTC_CLKOUT.
+*
+* @return Current frequency.
+*/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+* @brief Gets RTC_CLKOUT source.
+*
+* This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+*
+* @return Current source.
+*/
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+* @brief Gets RTC_CLKOUT source.
+*
+* This function sets the source of RTC_CLKOUT.
+*
+* @param src RTC_CLKOUT source to set.
+*/
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+ /*!
+ * @brief Gets rtc clock frequency.
+ *
+ * This function gets the rtc clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets COP clock frequency.
+ *
+ * This function gets the COP clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetCopFreq(void);
+
+/*!
+ * @brief Set the COP clock source selection.
+ *
+ * This function sets the COP clock source selection.
+ *
+ * @param copSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetCopSrc(clock_cop_src_t copSrc)
+{
+ CLOCK_HAL_SetCopSrc(SIM, copSrc);
+}
+
+/*!
+ * @brief Get the COP clock source selection.
+ *
+ * This function gets the COP clock source selection.
+ *
+ * @return Current selection.
+ */
+static inline clock_cop_src_t CLOCK_SYS_GetCopSrc(void)
+{
+ return CLOCK_HAL_GetCopSrc(SIM);
+}
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function sets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @param usbfsSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Get the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function gets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Gets the clock source for LPUART module
+ *
+ * This function gets the clock source for LPUART module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_lpuart_src_t CLOCK_SYS_GetLpuartSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpuartSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for LPUART module
+ *
+ * This function sets the clock source for LPUART module.
+ * @param instance module device instance
+ * @param lpuartSrc Clock source.
+ */
+static inline void CLOCK_SYS_SetLpuartSrc(uint32_t instance, clock_lpuart_src_t lpuartSrc)
+{
+ CLOCK_HAL_SetLpuartSrc(SIM, instance, lpuartSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for LPUART module
+ *
+ * This function gets the clock frequency for LPUART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FLEXIO clock frequency.
+ *
+ * This function gets the FLEXIO clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexioFreq(uint32_t instance);
+
+/*!
+ * @brief Set the FLEXIO clock source selection.
+ *
+ * This function sets the FLEXIO clock source selection.
+ *
+ * @param instance IP instance.
+ * @param flexioSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetFlexioSrc(uint32_t instance, clock_flexio_src_t flexioSrc)
+{
+ CLOCK_HAL_SetFlexioSrc(SIM, instance, flexioSrc);
+}
+
+/*!
+ * @brief Get the FLEXIO clock source selection.
+ *
+ * This function gets the FLEXIO clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_flexio_src_t CLOCK_SYS_GetFlexioSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetFlexioSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+ * @brief Gets the frequency for SLCD default clock.
+ *
+ * This function gets the frequency for SLCD default clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdDefaultFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate clock.
+ *
+ * This function gets the frequency for SLCD alternate clock (ALTSOURCE = 0).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAltFreq(uint32_t instance)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate 2 clock.
+ *
+ * This function gets the frequency for SLCD alternate 2 clock (ALTSOURCE = 1).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAlt2Freq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+#endif// FSL_FEATURE_SOC_LCD_COUNT
+
+/*!
+* @brief Gets the clock frequency for FTF module. (Flash Memory)
+*
+* This function gets the clock frequency for FTF module. (Flash Memory)
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for CMP module.
+*
+* This function gets the clock frequency for CMP module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for VREF module.
+*
+* This function gets the clock frequency for VREF module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for SPI module
+*
+* This function gets the clock frequency for SPI module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+* @brief Gets the clock frequency for I2C module
+*
+* This function gets the clock frequency for I2C module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets ADC alternate clock frequency.
+*
+* This function gets the ADC alternate clock frequency.
+*
+* @param instance module device instance
+* @return freq Current frequency.
+*/
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for UART module
+*
+* This function gets the clock frequency for UART module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Enable the clock for PORT module.
+*
+* This function enables the clock for PORT module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for PORT module.
+*
+* This function disables the clock for PORT module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for PORT module.
+*
+* This function will get the clock gate state for PORT module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+* @brief Enable the clock for SLCD module.
+*
+* This function enables the clock for SLCD module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+* @brief Disable the clock for SLCD module.
+*
+* This function disables the clock for SLCD module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+* @brief Get the the clock gate state for SLCD module.
+*
+* This function will get the clock gate state for SLCD module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetSlcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSlcd0);
+}
+#endif// FSL_FEATURE_SOC_LCD_COUNT
+
+/*!
+* @brief Enable the clock for FTF module.
+*
+* This function enables the clock for FTF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Disable the clock for FTF module.
+*
+* This function disables the clock for FTF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Get the the clock gate state for FTF module.
+*
+* This function will get the clock gate state for FTF module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Enable the clock for ADC module.
+*
+* This function enables the clock for ADC module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for ADC module.
+*
+* This function disables the clock for ADC module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for ADC module.
+*
+* This function will get the clock gate state for ADC module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for CMP module.
+*
+* This function enables the clock for CMP module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Disable the clock for CMP module.
+*
+* This function disables the clock for CMP module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Get the the clock gate state for CMP module.
+*
+* This function will get the clock gate state for CMP module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Enable the clock for VREF module.
+*
+* This function enables the clock for VREF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+* @brief Disable the clock for VREF module.
+*
+* This function disables the clock for VREF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+* @brief Get the the clock gate state for VREF module.
+*
+* This function will get the clock gate state for VREF module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+* @brief Enable the clock for LPTIMER module.
+*
+* This function enables the clock for LPTIMER module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Disable the clock for LPTIMER module.
+*
+* This function disables the clock for LPTIMER module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Get the the clock gate state for LPTIMER module.
+*
+* This function will get the clock gate state for LPTIMER module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Enable the clock for RTC module.
+*
+* This function enables the clock for RTC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Disable the clock for RTC module.
+*
+* This function disables the clock for RTC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Get the the clock gate state for RTC module.
+*
+* This function will get the clock gate state for RTC module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Enable the clock for DAC module.
+*
+* This function enables the clock for DAC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDac0);
+}
+
+/*!
+* @brief Disable the clock for DAC module.
+*
+* This function disables the clock for DAC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDac0);
+}
+
+/*!
+* @brief Get the the clock gate state for DAC module.
+*
+* This function will get the clock gate state for DAC module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDac0);
+}
+
+/*!
+* @brief Enable the clock for SPI module.
+*
+* This function enables the clock for SPI module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for SPI module.
+*
+* This function disables the clock for SPI module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for SPI module.
+*
+* This function will get the clock gate state for SPI module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for I2C module.
+*
+* This function enables the clock for I2C module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for I2C module.
+*
+* This function disables the clock for I2C module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for I2C module.
+*
+* This function will get the clock gate state for I2C module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for LPUART module.
+*
+* This function enables the clock for LPUART module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableLpuartClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for LPUART module.
+*
+* This function disables the clock for LPUART module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableLpuartClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for LPUART module.
+*
+* This function will get the clock gate state for LPUART module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for UART module.
+*
+* This function enables the clock for UART module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUart2);
+}
+
+/*!
+* @brief Disable the clock for UART module.
+*
+* This function disables the clock for UART module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUart2);
+}
+
+/*!
+* @brief Get the the clock gate state for UART module.
+*
+* This function will get the clock gate state for UART module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM,kSimClockGateUart2);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+* @brief Enable the clock for FLEXIO module.
+*
+* This function enables the clock for FLEXIO module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableFlexioClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexio0);
+}
+
+/*!
+* @brief Disable the clock for FLEXIO module.
+*
+* This function disables the clock for FLEXIO module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableFlexioClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexio0);
+}
+
+/*!
+* @brief Get the clock gate state for FLEXIO module.
+*
+* This function will get the clock gate state for FLEXIO module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetFlexioGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM,kSimClockGateFlexio0);
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Set the TPM external clock frequency(TPM_CLKx).
+ *
+ * This function sets the TPM external clock frequency (TPM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetTpmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < TPM_EXT_CLK_COUNT);
+
+ g_tpmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+
+#endif /* __FSL_CLOCK_MKL33Z4__H__ */
+/*******************************************************************************
+* EOF
+******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL34Z4/fsl_clock_MKL34Z4.c b/KSDK_1.2.0/platform/system/src/clock/MKL34Z4/fsl_clock_MKL34Z4.c
new file mode 100755
index 0000000..71d7a5b
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL34Z4/fsl_clock_MKL34Z4.c
@@ -0,0 +1,1012 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_sim_hal.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_clock_manager.h"
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+#endif
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ 0U,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+
+ CLOCK_HAL_SetOutDiv(SIM, 2U, 0U, 0U, 5U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+ /*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ freq >>= 1U; /* divided by 2 for special divider */
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return CLOCK_SYS_GetExternalRefClock32kFreq() >> 15U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCopFreq
+ * Description : Gets COP clock frequency.
+ * This function gets the COP clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc)
+{
+ if (kClockCopSrcLpoClk == copSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcFreq
+ * Description : Gets rtc clock frequency.
+ * This function gets rtc clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmfFreq
+ * Description : Gets the clock frequency for TPM module.
+ * This function gets the clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_tpm_src_t src;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTpmSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmExternalFreq
+ * Description : Gets the external clock frequency for TPM module.
+ * This function gets the external clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t src = CLOCK_SYS_GetTpmExternalSrc(instance);
+
+ if (kSimTpmClkSel0 == src)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ return freq;
+ }
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpifFreq
+ * Description : Gets the clock frequency for SPI module.
+ * This function gets the clock frequency for SPI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cfFreq
+ * Description : Gets the clock frequency for I2C module.
+ * This function gets the clock frequency for I2C moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpsciFreq
+ * Description : Gets the clock frequency for LPSCI module.
+ * This function gets the clock frequency for LPSCI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_lpsci_src_t src;
+
+ src = CLOCK_HAL_GetLpsciSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockLpsciSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockLpsciSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpsciSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Lpsci instance table. */
+static const sim_clock_gate_name_t lpsciGateTable[] =
+{
+ kSimClockGateLpsci0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function disable the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetLpsciGateCmd
+ * Description : Get the the clock gate state for LPSCI module
+ * This function will get the clock gate state for LPSCI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function enables the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, lpsciGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ (sim_clock_gate_name_t)(-1),
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm0,
+ kSimClockGateTpm1,
+ kSimClockGateTpm2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableTpmClock
+ * Description : Enable the clock for TPM module
+ * This function enables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableTpmClock
+ * Description : Disable the clock for TPM module
+ * This function disables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmGateCmd
+ * Description : Get the the clock gate state for TPM module
+ * This function will get the clock gate state for TPM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL34Z4/fsl_clock_MKL34Z4.h b/KSDK_1.2.0/platform/system/src/clock/MKL34Z4/fsl_clock_MKL34Z4.h
new file mode 100755
index 0000000..4efb54c
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL34Z4/fsl_clock_MKL34Z4.h
@@ -0,0 +1,1237 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KL34Z4_H__)
+#define __FSL_CLOCK_KL34Z4_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kl34z4 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+#if FSL_FEATURE_SOC_USB_COUNT
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+#endif
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kl34z4_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the COP clock frequency.
+ *
+ * This function gets the COP clock frequency.
+ *
+ * @param instance module device instance
+ * @param copSrc COP clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function sets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @param usbfsSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Get the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function gets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance);
+
+ /*!
+ * @brief Gets the clock frequency for LPSCI module.
+ *
+ * This function gets the clock frequency for LPSCI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance);
+
+/*!
+ * @brief Set the LPSCI clock source selection.
+ *
+ * This function sets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @param lpsciSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetLpsciSrc(uint32_t instance, clock_lpsci_src_t lpsciSrc)
+{
+ CLOCK_HAL_SetLpsciSrc(SIM, instance, lpsciSrc);
+}
+
+/*!
+ * @brief Get the LPSCI clock source selection.
+ *
+ * This function gets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_lpsci_src_t CLOCK_SYS_GetLpsciSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpsciSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the UART clock frequency.
+ *
+ * This function gets the UART clock frequency.
+ *
+ * @param instance IP instance.
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+ * @brief Enable the clock for SLCD module.
+ *
+ * This function enables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Disable the clock for SLCD module.
+ *
+ * This function disables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SLCD module.
+ *
+ * This function will get the clock gate state for SLCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSlcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD default clock.
+ *
+ * This function gets the frequency for SLCD default clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdDefaultFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate clock.
+ *
+ * This function gets the frequency for SLCD alternate clock (ALTSOURCE = 0).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAltFreq(uint32_t instance)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate 2 clock.
+ *
+ * This function gets the frequency for SLCD alternate 2 clock (ALTSOURCE = 1).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAlt2Freq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+#endif// FSL_FEATURE_SOC_LCD_COUNT
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPSCI module.
+ *
+ * This function enables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for LPSCI module.
+ *
+ * This function disables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for LPSCI module.
+ *
+ * This function will get the clock gate state for LPSCI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Set the TPM external clock frequency(TPM_CLKx).
+ *
+ * This function sets the TPM external clock frequency (TPM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetTpmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < TPM_EXT_CLK_COUNT);
+
+ g_tpmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KL34Z4_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL36Z4/fsl_clock_MKL36Z4.c b/KSDK_1.2.0/platform/system/src/clock/MKL36Z4/fsl_clock_MKL36Z4.c
new file mode 100755
index 0000000..71d7a5b
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL36Z4/fsl_clock_MKL36Z4.c
@@ -0,0 +1,1012 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_sim_hal.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_clock_manager.h"
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+#endif
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ 0U,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+
+ CLOCK_HAL_SetOutDiv(SIM, 2U, 0U, 0U, 5U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+ /*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ freq >>= 1U; /* divided by 2 for special divider */
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return CLOCK_SYS_GetExternalRefClock32kFreq() >> 15U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCopFreq
+ * Description : Gets COP clock frequency.
+ * This function gets the COP clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc)
+{
+ if (kClockCopSrcLpoClk == copSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcFreq
+ * Description : Gets rtc clock frequency.
+ * This function gets rtc clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmfFreq
+ * Description : Gets the clock frequency for TPM module.
+ * This function gets the clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_tpm_src_t src;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTpmSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmExternalFreq
+ * Description : Gets the external clock frequency for TPM module.
+ * This function gets the external clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t src = CLOCK_SYS_GetTpmExternalSrc(instance);
+
+ if (kSimTpmClkSel0 == src)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ return freq;
+ }
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpifFreq
+ * Description : Gets the clock frequency for SPI module.
+ * This function gets the clock frequency for SPI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cfFreq
+ * Description : Gets the clock frequency for I2C module.
+ * This function gets the clock frequency for I2C moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpsciFreq
+ * Description : Gets the clock frequency for LPSCI module.
+ * This function gets the clock frequency for LPSCI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_lpsci_src_t src;
+
+ src = CLOCK_HAL_GetLpsciSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockLpsciSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockLpsciSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpsciSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Lpsci instance table. */
+static const sim_clock_gate_name_t lpsciGateTable[] =
+{
+ kSimClockGateLpsci0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function disable the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetLpsciGateCmd
+ * Description : Get the the clock gate state for LPSCI module
+ * This function will get the clock gate state for LPSCI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function enables the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, lpsciGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ (sim_clock_gate_name_t)(-1),
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm0,
+ kSimClockGateTpm1,
+ kSimClockGateTpm2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableTpmClock
+ * Description : Enable the clock for TPM module
+ * This function enables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableTpmClock
+ * Description : Disable the clock for TPM module
+ * This function disables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmGateCmd
+ * Description : Get the the clock gate state for TPM module
+ * This function will get the clock gate state for TPM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL36Z4/fsl_clock_MKL36Z4.h b/KSDK_1.2.0/platform/system/src/clock/MKL36Z4/fsl_clock_MKL36Z4.h
new file mode 100755
index 0000000..5824784
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL36Z4/fsl_clock_MKL36Z4.h
@@ -0,0 +1,1237 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KL36Z4_H__)
+#define __FSL_CLOCK_KL36Z4_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kl36z4 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+#if FSL_FEATURE_SOC_USB_COUNT
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+#endif
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kl36z4_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the COP clock frequency.
+ *
+ * This function gets the COP clock frequency.
+ *
+ * @param instance module device instance
+ * @param copSrc COP clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function sets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @param usbfsSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Get the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function gets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance);
+
+ /*!
+ * @brief Gets the clock frequency for LPSCI module.
+ *
+ * This function gets the clock frequency for LPSCI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance);
+
+/*!
+ * @brief Set the LPSCI clock source selection.
+ *
+ * This function sets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @param lpsciSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetLpsciSrc(uint32_t instance, clock_lpsci_src_t lpsciSrc)
+{
+ CLOCK_HAL_SetLpsciSrc(SIM, instance, lpsciSrc);
+}
+
+/*!
+ * @brief Get the LPSCI clock source selection.
+ *
+ * This function gets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_lpsci_src_t CLOCK_SYS_GetLpsciSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpsciSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the UART clock frequency.
+ *
+ * This function gets the UART clock frequency.
+ *
+ * @param instance IP instance.
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+ * @brief Enable the clock for SLCD module.
+ *
+ * This function enables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Disable the clock for SLCD module.
+ *
+ * This function disables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SLCD module.
+ *
+ * This function will get the clock gate state for SLCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSlcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD default clock.
+ *
+ * This function gets the frequency for SLCD default clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdDefaultFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate clock.
+ *
+ * This function gets the frequency for SLCD alternate clock (ALTSOURCE = 0).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAltFreq(uint32_t instance)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate 2 clock.
+ *
+ * This function gets the frequency for SLCD alternate 2 clock (ALTSOURCE = 1).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAlt2Freq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+#endif// FSL_FEATURE_SOC_LCD_COUNT
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPSCI module.
+ *
+ * This function enables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for LPSCI module.
+ *
+ * This function disables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for LPSCI module.
+ *
+ * This function will get the clock gate state for LPSCI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Set the TPM external clock frequency(TPM_CLKx).
+ *
+ * This function sets the TPM external clock frequency (TPM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetTpmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < TPM_EXT_CLK_COUNT);
+
+ g_tpmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KL36Z4_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL43Z4/fsl_clock_MKL43Z4.c b/KSDK_1.2.0/platform/system/src/clock/MKL43Z4/fsl_clock_MKL43Z4.c
new file mode 100755
index 0000000..d74eea3
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL43Z4/fsl_clock_MKL43Z4.c
@@ -0,0 +1,840 @@
+/*
+* Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* o Redistributions of source code must retain the above copyright notice, this list
+* of conditions and the following disclaimer.
+*
+* o Redistributions in binary form must reproduce the above copyright notice, this
+* list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+* contributors may be used to endorse or promote products derived from this
+* software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcglite_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+* README:
+* This file should provide these APIs:
+* 1. APIs to get the frequency of output clocks in Reference Manual ->
+* Chapter Clock Distribution -> Figure Clocking diagram.
+* 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+* -> Module clocks.
+*/
+
+/*******************************************************************************
+* Definitions
+******************************************************************************/
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+#endif
+
+/*******************************************************************************
+* Code
+******************************************************************************/
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ 0U,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 1U, 0U, 0U, 7U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgliteMode(&config->mcgliteConfig);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kIrc48mClock:
+ *frequency = kMcgliteConst48M;
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetCoreClockFreq
+* Description : Gets the core clock frequency.
+* This function gets the core clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetSystemClockFreq
+* Description : Gets the systen clock frequency.
+* This function gets the systen clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetBusClockFreq
+* Description : Gets the bus clock frequency.
+* This function gets the bus clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetFlashClockFreq
+* Description : Gets the flash clock frequency.
+* This function gets the flash clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetRtcOutFreq
+* Description : Gets the RTC_CLKOUT frequency.
+* This function gets RTC_CLKOUT clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return 1U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetExternalRefClockFreq
+* Description : Gets the ERCLK32K clock frequency.
+* This function gets the external reference (ERCLK32K) clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+* Description : Gets OSC0ERCLK.
+* This function gets the OSC0 external reference frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetCopFreq
+* Description : Gets the clock frequency for COP module.
+* This function gets the clock frequency for COP moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetCopFreq(void)
+{
+ clock_cop_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetCopSrc(SIM);
+
+ switch (src)
+ {
+ case kClockCopSrcLpoClk:
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockCopSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockCopSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockCopSrcBusClk:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmFreq
+* Description : Gets the clock frequency for TPM module.
+* This function gets the clock frequency for TPM moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+
+ clock_tpm_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockTpmSrcIrc48M: /* IRC48M */
+ freq = kMcgliteConst48M;
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCER clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIR clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetLpuartFreq
+* Description : Gets the clock frequency for LPUART module.
+* This function gets the clock frequency for LPUART moudle.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance)
+{
+ clock_lpuart_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetLpuartSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockLpuartSrcIrc48M: /* IRC48M */
+ freq = kMcgliteConst48M;
+ break;
+ case kClockLpuartSrcOsc0erClk: /* OSCER clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpuartSrcMcgIrClk: /* MCGIR clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmExternalFreq
+* Description : Gets Tpm external clock frequency.
+*
+*END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t sel = SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+
+ if (kSimTpmClkSel0 == sel)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ clock_usbfs_src_t src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0];
+ }
+ else
+ {
+ return kMcgliteConst48M;
+ }
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexioFreq
+ * Description : Gets the clock frequency for FLEXIO.
+ * This function gets the clock frequency for FLEXIO.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexioFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_flexio_src_t src = CLOCK_HAL_GetFlexioSrc(SIM, instance);
+
+ switch (src)
+ {
+ case kClockFlexioSrcIrc48M:
+ freq = kMcgliteConst48M;
+ break;
+ case kClockFlexioSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockFlexioSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcSysClk: /*!< SYSCLK */
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kClockSaiSrcOsc0erClk: /*!< OSC0ERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcMcgIrClk: /*!< MCGIRCLK */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockSaiSrcIrc48M: /*!< MCGPCLK/IRC48M. */
+ freq = kMcgliteConst48M;
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiFreq
+ * Description : Gets the clock frequency for SPI.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ assert(instance < SPI_INSTANCE_COUNT);
+
+ if (0U == instance)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetSystemClockFreq();
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnablePortClock
+* Description : Enable the clock for PORT module
+* This function enables the clock for PORT moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisablePortClock
+* Description : Disable the clock for PORT module
+* This function disables the clock for PORT moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetPortGateCmd
+* Description : Get the the clock gate state for PORT module
+* This function will get the clock gate state for PORT moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableAdcClock
+* Description : Enable the clock for ADC module
+* This function enables the clock for ADC moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableAdcClock
+* Description : Disable the clock for ADC module
+* This function disables the clock for ADC moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetAdcGateCmd
+* Description : Get the the clock gate state for ADC module
+* This function will get the clock gate state for ADC moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableSpiClock
+* Description : Enable the clock for SPI module
+* This function enables the clock for SPI moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableSpiClock
+* Description : Disable the clock for SPI module
+* This function disables the clock for SPI moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetSpiGateCmd
+* Description : Get the the clock gate state for SPI module
+* This function will get the clock gate state for SPI moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableI2cClock
+* Description : Enable the clock for I2C module
+* This function enables the clock for I2C moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableI2cClock
+* Description : Disable the clock for I2C module
+* This function disables the clock for I2C moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetI2cGateCmd
+* Description : Get the the clock gate state for I2C module
+* This function will get the clock gate state for I2C moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Lpuart instance table. */
+static const sim_clock_gate_name_t lpuartGateTable[] =
+{
+ kSimClockGateLpuart0,
+ kSimClockGateLpuart1
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_EnableLpuartClock
+* Description : Enable the clock for UART module
+* This function enables the clock for UART moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableLpuartClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, lpuartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_DisableLpuartClock
+* Description : Disable the clock for UART module
+* This function enables the clock for UART moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableLpuartClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, lpuartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : SIM_HAL_GetLpuartGateCmd
+* Description : Get the the clock gate state for UART module
+* This function will get the clock gate state for UART moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(lpuartGateTable)/sizeof(lpuartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, lpuartGateTable[instance]);
+}
+
+/* TPM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm0,
+ kSimClockGateTpm1,
+ kSimClockGateTpm2,
+};
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_EnableTpmClock
+* Description : Enable the clock for TPM module
+* This function enables the clock for TPM moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_DisableTpmClock
+* Description : Disable the clock for TPM module
+* This function disables the clock for TPM moudle
+*
+*END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+*
+* Function Name : CLOCK_SYS_GetTpmGateCmd
+* Description : Get the the clock gate state for TPM module
+* This function will get the clock gate state for TPM moudle.
+*
+*END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+* EOF
+******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL43Z4/fsl_clock_MKL43Z4.h b/KSDK_1.2.0/platform/system/src/clock/MKL43Z4/fsl_clock_MKL43Z4.h
new file mode 100755
index 0000000..4786b28
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL43Z4/fsl_clock_MKL43Z4.h
@@ -0,0 +1,1323 @@
+/*
+* Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* o Redistributions of source code must retain the above copyright notice, this list
+* of conditions and the following disclaimer.
+*
+* o Redistributions in binary form must reproduce the above copyright notice, this
+* list of conditions and the following disclaimer in the documentation and/or
+* other materials provided with the distribution.
+*
+* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+* contributors may be used to endorse or promote products derived from this
+* software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#if !defined(__FSL_CLOCK_MKL43Z4_H__)
+#define __FSL_CLOCK_MKL43Z4_H__
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcglite_hal.h"
+#include "fsl_mcglite_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kl43z4 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+* Definitions
+******************************************************************************/
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+#if FSL_FEATURE_SOC_USB_COUNT
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+#endif
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kl43z4_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+* API
+******************************************************************************/
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+* @brief Get internal reference clock frequency.
+*
+* This function gets the internal reference clock frequency.
+*
+* @return Current clock frequency.
+*/
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+* @brief Gets the OSC0ERCLK frequency.
+*
+* This function gets the OSC0 external reference frequency.
+*
+* @return Current frequency.
+*/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+* @brief Gets RTC_CLKOUT frequency.
+*
+* This function gets the frequency of RTC_CLKOUT.
+*
+* @return Current frequency.
+*/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+* @brief Gets RTC_CLKOUT source.
+*
+* This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+*
+* @return Current source.
+*/
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+* @brief Gets RTC_CLKOUT source.
+*
+* This function sets the source of RTC_CLKOUT.
+*
+* @param src RTC_CLKOUT source to set.
+*/
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+ /*!
+ * @brief Gets rtc clock frequency.
+ *
+ * This function gets the rtc clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets COP clock frequency.
+ *
+ * This function gets the COP clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetCopFreq(void);
+
+/*!
+ * @brief Set the COP clock source selection.
+ *
+ * This function sets the COP clock source selection.
+ *
+ * @param copSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetCopSrc(clock_cop_src_t copSrc)
+{
+ CLOCK_HAL_SetCopSrc(SIM, copSrc);
+}
+
+/*!
+ * @brief Get the COP clock source selection.
+ *
+ * This function gets the COP clock source selection.
+ *
+ * @return Current selection.
+ */
+static inline clock_cop_src_t CLOCK_SYS_GetCopSrc(void)
+{
+ return CLOCK_HAL_GetCopSrc(SIM);
+}
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function sets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @param usbfsSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Get the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function gets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Gets the clock source for LPUART module
+ *
+ * This function gets the clock source for LPUART module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_lpuart_src_t CLOCK_SYS_GetLpuartSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpuartSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for LPUART module
+ *
+ * This function sets the clock source for LPUART module.
+ * @param instance module device instance
+ * @param lpuartSrc Clock source.
+ */
+static inline void CLOCK_SYS_SetLpuartSrc(uint32_t instance, clock_lpuart_src_t lpuartSrc)
+{
+ CLOCK_HAL_SetLpuartSrc(SIM, instance, lpuartSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for LPUART module
+ *
+ * This function gets the clock frequency for LPUART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FLEXIO clock frequency.
+ *
+ * This function gets the FLEXIO clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexioFreq(uint32_t instance);
+
+/*!
+ * @brief Set the FLEXIO clock source selection.
+ *
+ * This function sets the FLEXIO clock source selection.
+ *
+ * @param instance IP instance.
+ * @param flexioSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetFlexioSrc(uint32_t instance, clock_flexio_src_t flexioSrc)
+{
+ CLOCK_HAL_SetFlexioSrc(SIM, instance, flexioSrc);
+}
+
+/*!
+ * @brief Get the FLEXIO clock source selection.
+ *
+ * This function gets the FLEXIO clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_flexio_src_t CLOCK_SYS_GetFlexioSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetFlexioSrc(SIM, instance);
+}
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+ * @brief Gets the frequency for SLCD default clock.
+ *
+ * This function gets the frequency for SLCD default clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdDefaultFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate clock.
+ *
+ * This function gets the frequency for SLCD alternate clock (ALTSOURCE = 0).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAltFreq(uint32_t instance)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate 2 clock.
+ *
+ * This function gets the frequency for SLCD alternate 2 clock (ALTSOURCE = 1).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAlt2Freq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+#endif// FSL_FEATURE_SOC_LCD_COUNT
+
+/*!
+* @brief Gets the clock frequency for FTF module. (Flash Memory)
+*
+* This function gets the clock frequency for FTF module. (Flash Memory)
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for CMP module.
+*
+* This function gets the clock frequency for CMP module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for VREF module.
+*
+* This function gets the clock frequency for VREF module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for SPI module
+*
+* This function gets the clock frequency for SPI module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+* @brief Gets the clock frequency for I2C module
+*
+* This function gets the clock frequency for I2C module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Gets ADC alternate clock frequency.
+*
+* This function gets the ADC alternate clock frequency.
+*
+* @param instance module device instance
+* @return freq Current frequency.
+*/
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+* @brief Gets the clock frequency for UART module
+*
+* This function gets the clock frequency for UART module.
+* @param instance module device instance
+* @return freq clock frequency for this module
+*/
+static inline uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+* @brief Enable the clock for PORT module.
+*
+* This function enables the clock for PORT module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for PORT module.
+*
+* This function disables the clock for PORT module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for PORT module.
+*
+* This function will get the clock gate state for PORT module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+* @brief Enable the clock for SLCD module.
+*
+* This function enables the clock for SLCD module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+* @brief Disable the clock for SLCD module.
+*
+* This function disables the clock for SLCD module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+* @brief Get the the clock gate state for SLCD module.
+*
+* This function will get the clock gate state for SLCD module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetSlcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSlcd0);
+}
+#endif// FSL_FEATURE_SOC_LCD_COUNT
+
+/*!
+* @brief Enable the clock for FTF module.
+*
+* This function enables the clock for FTF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Disable the clock for FTF module.
+*
+* This function disables the clock for FTF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Get the the clock gate state for FTF module.
+*
+* This function will get the clock gate state for FTF module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+* @brief Enable the clock for ADC module.
+*
+* This function enables the clock for ADC module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for ADC module.
+*
+* This function disables the clock for ADC module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for ADC module.
+*
+* This function will get the clock gate state for ADC module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for CMP module.
+*
+* This function enables the clock for CMP module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Disable the clock for CMP module.
+*
+* This function disables the clock for CMP module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Get the the clock gate state for CMP module.
+*
+* This function will get the clock gate state for CMP module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp0);
+}
+
+/*!
+* @brief Enable the clock for VREF module.
+*
+* This function enables the clock for VREF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+* @brief Disable the clock for VREF module.
+*
+* This function disables the clock for VREF module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+* @brief Get the the clock gate state for VREF module.
+*
+* This function will get the clock gate state for VREF module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+* @brief Enable the clock for LPTIMER module.
+*
+* This function enables the clock for LPTIMER module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Disable the clock for LPTIMER module.
+*
+* This function disables the clock for LPTIMER module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Get the the clock gate state for LPTIMER module.
+*
+* This function will get the clock gate state for LPTIMER module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+* @brief Enable the clock for RTC module.
+*
+* This function enables the clock for RTC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Disable the clock for RTC module.
+*
+* This function disables the clock for RTC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Get the the clock gate state for RTC module.
+*
+* This function will get the clock gate state for RTC module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+* @brief Enable the clock for DAC module.
+*
+* This function enables the clock for DAC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDac0);
+}
+
+/*!
+* @brief Disable the clock for DAC module.
+*
+* This function disables the clock for DAC module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDac0);
+}
+
+/*!
+* @brief Get the the clock gate state for DAC module.
+*
+* This function will get the clock gate state for DAC module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDac0);
+}
+
+/*!
+* @brief Enable the clock for SPI module.
+*
+* This function enables the clock for SPI module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for SPI module.
+*
+* This function disables the clock for SPI module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for SPI module.
+*
+* This function will get the clock gate state for SPI module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for I2C module.
+*
+* This function enables the clock for I2C module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for I2C module.
+*
+* This function disables the clock for I2C module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for I2C module.
+*
+* This function will get the clock gate state for I2C module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for LPUART module.
+*
+* This function enables the clock for LPUART module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_EnableLpuartClock(uint32_t instance);
+
+/*!
+* @brief Disable the clock for LPUART module.
+*
+* This function disables the clock for LPUART module.
+* @param instance module device instance
+*/
+void CLOCK_SYS_DisableLpuartClock(uint32_t instance);
+
+/*!
+* @brief Get the the clock gate state for LPUART module.
+*
+* This function will get the clock gate state for LPUART module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance);
+
+/*!
+* @brief Enable the clock for UART module.
+*
+* This function enables the clock for UART module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUart2);
+}
+
+/*!
+* @brief Disable the clock for UART module.
+*
+* This function disables the clock for UART module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUart2);
+}
+
+/*!
+* @brief Get the the clock gate state for UART module.
+*
+* This function will get the clock gate state for UART module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM,kSimClockGateUart2);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+* @brief Enable the clock for FLEXIO module.
+*
+* This function enables the clock for FLEXIO module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_EnableFlexioClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexio0);
+}
+
+/*!
+* @brief Disable the clock for FLEXIO module.
+*
+* This function disables the clock for FLEXIO module.
+* @param instance module device instance
+*/
+static inline void CLOCK_SYS_DisableFlexioClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexio0);
+}
+
+/*!
+* @brief Get the clock gate state for FLEXIO module.
+*
+* This function will get the clock gate state for FLEXIO module.
+* @param instance module device instance
+* @return state true - ungated(Enabled), false - gated (Disabled)
+*/
+static inline bool CLOCK_SYS_GetFlexioGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM,kSimClockGateFlexio0);
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Set the TPM external clock frequency(TPM_CLKx).
+ *
+ * This function sets the TPM external clock frequency (TPM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetTpmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < TPM_EXT_CLK_COUNT);
+
+ g_tpmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+
+#endif /* __FSL_CLOCK_MKL43Z4__H__ */
+/*******************************************************************************
+* EOF
+******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL46Z4/fsl_clock_MKL46Z4.c b/KSDK_1.2.0/platform/system/src/clock/MKL46Z4/fsl_clock_MKL46Z4.c
new file mode 100755
index 0000000..5dd24cc
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL46Z4/fsl_clock_MKL46Z4.c
@@ -0,0 +1,1012 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_sim_hal.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_clock_manager.h"
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+#endif
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ 0U,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+
+ CLOCK_HAL_SetOutDiv(SIM, 2U, 0U, 0U, 5U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+ /*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ freq >>= 1U; /* divided by 2 for special divider */
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return CLOCK_SYS_GetExternalRefClock32kFreq() >> 15U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCopFreq
+ * Description : Gets COP clock frequency.
+ * This function gets the COP clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc)
+{
+ if (kClockCopSrcLpoClk == copSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcFreq
+ * Description : Gets rtc clock frequency.
+ * This function gets rtc clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmfFreq
+ * Description : Gets the clock frequency for TPM module.
+ * This function gets the clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_tpm_src_t src;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTpmSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmExternalFreq
+ * Description : Gets the external clock frequency for TPM module.
+ * This function gets the external clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t src = CLOCK_SYS_GetTpmExternalSrc(instance);
+
+ if (kSimTpmClkSel0 == src)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ return freq;
+ }
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpifFreq
+ * Description : Gets the clock frequency for SPI module.
+ * This function gets the clock frequency for SPI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cfFreq
+ * Description : Gets the clock frequency for I2C module.
+ * This function gets the clock frequency for I2C moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpsciFreq
+ * Description : Gets the clock frequency for LPSCI module.
+ * This function gets the clock frequency for LPSCI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_lpsci_src_t src;
+
+ src = CLOCK_HAL_GetLpsciSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockLpsciSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockLpsciSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpsciSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Lpsci instance table. */
+static const sim_clock_gate_name_t lpsciGateTable[] =
+{
+ kSimClockGateLpsci0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function disable the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetLpsciGateCmd
+ * Description : Get the the clock gate state for LPSCI module
+ * This function will get the clock gate state for LPSCI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function enables the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, lpsciGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ (sim_clock_gate_name_t)(-1),
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm0,
+ kSimClockGateTpm1,
+ kSimClockGateTpm2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableTpmClock
+ * Description : Enable the clock for TPM module
+ * This function enables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableTpmClock
+ * Description : Disable the clock for TPM module
+ * This function disables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmGateCmd
+ * Description : Get the the clock gate state for TPM module
+ * This function will get the clock gate state for TPM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKL46Z4/fsl_clock_MKL46Z4.h b/KSDK_1.2.0/platform/system/src/clock/MKL46Z4/fsl_clock_MKL46Z4.h
new file mode 100755
index 0000000..58b44b5
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKL46Z4/fsl_clock_MKL46Z4.h
@@ -0,0 +1,1237 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KL46Z4_H__)
+#define __FSL_CLOCK_KL46Z4_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kl46z4 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+#if FSL_FEATURE_SOC_USB_COUNT
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+#endif
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kl46z4_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the COP clock frequency.
+ *
+ * This function gets the COP clock frequency.
+ *
+ * @param instance module device instance
+ * @param copSrc COP clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function sets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @param usbfsSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Get the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function gets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance);
+
+ /*!
+ * @brief Gets the clock frequency for LPSCI module.
+ *
+ * This function gets the clock frequency for LPSCI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance);
+
+/*!
+ * @brief Set the LPSCI clock source selection.
+ *
+ * This function sets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @param lpsciSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetLpsciSrc(uint32_t instance, clock_lpsci_src_t lpsciSrc)
+{
+ CLOCK_HAL_SetLpsciSrc(SIM, instance, lpsciSrc);
+}
+
+/*!
+ * @brief Get the LPSCI clock source selection.
+ *
+ * This function gets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_lpsci_src_t CLOCK_SYS_GetLpsciSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpsciSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the UART clock frequency.
+ *
+ * This function gets the UART clock frequency.
+ *
+ * @param instance IP instance.
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+ * @brief Enable the clock for SLCD module.
+ *
+ * This function enables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Disable the clock for SLCD module.
+ *
+ * This function disables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SLCD module.
+ *
+ * This function will get the clock gate state for SLCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSlcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD default clock.
+ *
+ * This function gets the frequency for SLCD default clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdDefaultFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate clock.
+ *
+ * This function gets the frequency for SLCD alternate clock (ALTSOURCE = 0).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAltFreq(uint32_t instance)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate 2 clock.
+ *
+ * This function gets the frequency for SLCD alternate 2 clock (ALTSOURCE = 1).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAlt2Freq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+#endif// FSL_FEATURE_SOC_LCD_COUNT
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPSCI module.
+ *
+ * This function enables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for LPSCI module.
+ *
+ * This function disables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for LPSCI module.
+ *
+ * This function will get the clock gate state for LPSCI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Set the TPM external clock frequency(TPM_CLKx).
+ *
+ * This function sets the TPM external clock frequency (TPM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetTpmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < TPM_EXT_CLK_COUNT);
+
+ g_tpmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KL46Z4_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV10Z7/fsl_clock_MKV10Z7.c b/KSDK_1.2.0/platform/system/src/clock/MKV10Z7/fsl_clock_MKV10Z7.c
new file mode 100755
index 0000000..09b9a81
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV10Z7/fsl_clock_MKV10Z7.c
@@ -0,0 +1,806 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ 0U,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetOutDiv5(SIM, simConfig->outdiv5);
+ CLOCK_HAL_SetOutDiv5ENCmd(SIM, simConfig->outdiv5Enable);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 0U, 0U, 4U);
+ CLOCK_HAL_SetOutDiv5(SIM, 3U);
+ CLOCK_HAL_SetOutDiv5ENCmd(SIM, true);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOutdiv5ClockFreq
+ * Description : Gets the OUTDIV5 output clock for ADC.
+ * This function gets the the OUTDIV5 output clock for ADC.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOutdiv5ClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv5(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcAltFreq
+ * Description : Gets the ADC alternate clock frequency.
+ * This function gets the ADC alternate clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ clock_adc_alt_src_t adcAltClkSel;
+ uint32_t adcAltClkValue = 0;
+
+ adcAltClkSel = CLOCK_HAL_GetAdcAltClkSrc(SIM, instance);
+ switch(adcAltClkSel)
+ {
+ case 0:
+ adcAltClkValue = CLOCK_SYS_GetOutdiv5ClockFreq(); /* OUTDIV5 output */
+ break;
+ case 1:
+ adcAltClkValue = CLOCK_SYS_GetInternalRefClockFreq(); /* MCGIRC output */
+ break;
+ case 2:
+ adcAltClkValue = CLOCK_SYS_GetOsc0ExternalRefClockFreq(); /* OSCERCLK output */
+ break;
+ default:
+ adcAltClkValue = 0;
+ break;
+ }
+ return adcAltClkValue;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmFixedFreq
+ * Description : Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ uint32_t ftmFixedFreq;
+ clock_ftm_fixedfreq_src_t ftmFixedFreqSel;
+ ftmFixedFreqSel = (clock_ftm_fixedfreq_src_t)CLOCK_HAL_GetFtmFixFreqClkSrc(SIM);
+ switch(ftmFixedFreqSel)
+ {
+ case kClockFtmClkMcgFfClk:
+ ftmFixedFreq = CLOCK_HAL_GetFixedFreqClk(MCG);
+ break;
+ case kClockFtmClkMcgIrClk:
+ ftmFixedFreq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockFtmClkOsc0erClk:
+ ftmFixedFreq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ ftmFixedFreq = 0;
+ break;
+ }
+ return ftmFixedFreq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_HAL_GetInternalRefClk(MCG); /* For KV10Z7, it's MCGIRCLK */
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG IRC clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else if (kSimFtmClkSel1 == sel)
+ {
+ return g_ftmClkFreq[1];
+ }
+ else
+ {
+ return g_ftmClkFreq[2];
+ }
+}
+
+/* ----------------------------CLOCK SYS GATE CONTROL--------------------------*/
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV10Z7/fsl_clock_MKV10Z7.h b/KSDK_1.2.0/platform/system/src/clock/MKV10Z7/fsl_clock_MKV10Z7.h
new file mode 100755
index 0000000..64de6a9
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV10Z7/fsl_clock_MKV10Z7.h
@@ -0,0 +1,926 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KV10Z7_H__)
+#define __FSL_CLOCK_KV10Z7_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kv10z7 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 3
+
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv4, outdiv5; /*!< OUTDIV setting. */
+ bool outdiv5Enable; /*!< OUTDIV5EN. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kv10z7_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider5 setting(OUTDIV5).
+ *
+ * This function sets divide value OUTDIV5.
+ *
+ * @param outdiv5 Outdivider5 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv5(uint8_t outdiv5)
+{
+ CLOCK_HAL_SetOutDiv5(SIM, outdiv5);
+}
+
+/*!
+ * @brief Gets the clock out divider5 setting(OUTDIV5).
+ *
+ * This function gets divide value OUTDIV5.
+ *
+ * @return Outdivider5 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv5(void)
+{
+ return CLOCK_HAL_GetOutDiv5(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the OUTDIV5 output clock for ADC.
+ *
+ * This function gets the OUTDIV5 output clock for ADC.
+ *
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOutdiv5ClockFreq(void);
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KV10Z7_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV30F12810/fsl_clock_MKV30F12810.c b/KSDK_1.2.0/platform/system/src/clock/MKV30F12810/fsl_clock_MKV30F12810.c
new file mode 100755
index 0000000..33c45e4
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV30F12810/fsl_clock_MKV30F12810.c
@@ -0,0 +1,809 @@
+/*
+ * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+
+ CLOCK_HAL_SetOutDiv(SIM, 1U, 1U, 0U, 7U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kOsc0ErClockUndiv:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelIrc48M:
+ freq = CPU_INTERNAL_IRC_48M;
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq
+ * Description : Gets OSC0ERCLKUDIV.
+ * This function gets the OSC0 external reference undivided frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq()
+ >> OSC_HAL_GetExternalRefClkDiv(g_oscBase[0]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG);
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClkUndiv: /* OSC0ERCLKUDIV clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV30F12810/fsl_clock_MKV30F12810.h b/KSDK_1.2.0/platform/system/src/clock/MKV30F12810/fsl_clock_MKV30F12810.h
new file mode 100755
index 0000000..8550d86
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV30F12810/fsl_clock_MKV30F12810.h
@@ -0,0 +1,1119 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KV30F12810_H__)
+#define __FSL_CLOCK_KV30F12810_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kv30f12810 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kv30f12810_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets the OSC0ERCLK_UNDIV frequency.
+ *
+ * This function gets the undivided OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void);
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate 2 clock frequency.
+ *
+ * This function gets the ADC alternate 2 clock frequency (ALTCLK2).
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAlt2Freq(uint32_t instance)
+{
+ return CPU_INTERNAL_IRC_48M;
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KV30F12810_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV31F12810/fsl_clock_MKV31F12810.c b/KSDK_1.2.0/platform/system/src/clock/MKV31F12810/fsl_clock_MKV31F12810.c
new file mode 100755
index 0000000..449f397
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV31F12810/fsl_clock_MKV31F12810.c
@@ -0,0 +1,848 @@
+/*
+ * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+
+ CLOCK_HAL_SetOutDiv(SIM, 1U, 1U, 0U, 7U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kOsc0ErClockUndiv:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kIrc48mClock:
+ *frequency = CPU_INTERNAL_IRC_48M;
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelIrc48M:
+ freq = CPU_INTERNAL_IRC_48M;
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq
+ * Description : Gets OSC0ERCLKUDIV.
+ * This function gets the OSC0 external reference undevided frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq()
+ >> OSC_HAL_GetExternalRefClkDiv(g_oscBase[0]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG);
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx prescaler/glitch filter clock frequency.
+ * This function gets the LPTMRx prescaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClkUndiv: /* OSC0ERCLKUDIV clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpuartFreq
+ * Description : Gets the clock frequency for LPUART module.
+ * This function gets the clock frequency for LPUART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance)
+{
+ clock_lpuart_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetLpuartSrc(SIM, instance);
+ switch (src)
+ {
+ case kClockLpuartSrcPllFllSel:
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockLpuartSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpuartSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV31F12810/fsl_clock_MKV31F12810.h b/KSDK_1.2.0/platform/system/src/clock/MKV31F12810/fsl_clock_MKV31F12810.h
new file mode 100755
index 0000000..56524d3
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV31F12810/fsl_clock_MKV31F12810.h
@@ -0,0 +1,1198 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KV31F12810_H__)
+#define __FSL_CLOCK_KV31F12810_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kv31f12810 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kv31f12810_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets the OSC0ERCLK_UNDIV frequency.
+ *
+ * This function gets the undivided OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void);
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock source for LPUART module
+ *
+ * This function gets the clock source for LPUART module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_lpuart_src_t CLOCK_SYS_GetLpuartSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpuartSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for LPUART module
+ *
+ * This function sets the clock source for LPUART module.
+ * @param instance module device instance
+ * @param lpuartSrc Clock source.
+ */
+static inline void CLOCK_SYS_SetLpuartSrc(uint32_t instance, clock_lpuart_src_t lpuartSrc)
+{
+ CLOCK_HAL_SetLpuartSrc(SIM, instance, lpuartSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for LPUART module
+ *
+ * This function gets the clock frequency for LPUART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate 2 clock frequency.
+ *
+ * This function gets the ADC alternate 2 clock frequency (ALTCLK2).
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAlt2Freq(uint32_t instance)
+{
+ return CPU_INTERNAL_IRC_48M;
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPUART module.
+ *
+ * This function enables the clock for LPUART module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLpuartClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Disable the clock for LPUART module.
+ *
+ * This function disables the clock for LPUART module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLpuartClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPUART module.
+ *
+ * This function will get the clock gate state for LPUART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KV31F12810_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV31F25612/fsl_clock_MKV31F25612.c b/KSDK_1.2.0/platform/system/src/clock/MKV31F25612/fsl_clock_MKV31F25612.c
new file mode 100755
index 0000000..154a432
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV31F25612/fsl_clock_MKV31F25612.c
@@ -0,0 +1,854 @@
+/*
+ * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+
+ CLOCK_HAL_SetOutDiv(SIM, 1U, 3U, 0U, 7U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kOsc0ErClockUndiv:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kIrc48mClock:
+ *frequency = CPU_INTERNAL_IRC_48M;
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockPllFllSelIrc48M:
+ freq = CPU_INTERNAL_IRC_48M;
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq
+ * Description : Gets OSC0ERCLKUDIV.
+ * This function gets the OSC0 external reference undevided frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq()
+ >> OSC_HAL_GetExternalRefClkDiv(g_oscBase[0]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG);
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClkUndiv: /* OSC0ERCLKUDIV clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpuartFreq
+ * Description : Gets the clock frequency for LPUART module.
+ * This function gets the clock frequency for LPUART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance)
+{
+ clock_lpuart_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetLpuartSrc(SIM, instance);
+ switch (src)
+ {
+ case kClockLpuartSrcPllFllSel:
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockLpuartSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpuartSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV31F25612/fsl_clock_MKV31F25612.h b/KSDK_1.2.0/platform/system/src/clock/MKV31F25612/fsl_clock_MKV31F25612.h
new file mode 100755
index 0000000..a3101ab
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV31F25612/fsl_clock_MKV31F25612.h
@@ -0,0 +1,1232 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KV31F25612_H__)
+#define __FSL_CLOCK_KV31F25612_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kv31f25612 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kv31f25612_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets the OSC0ERCLK_UNDIV frequency.
+ *
+ * This function gets the undivided OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void);
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock source for LPUART module
+ *
+ * This function gets the clock source for LPUART module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_lpuart_src_t CLOCK_SYS_GetLpuartSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpuartSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for LPUART module
+ *
+ * This function sets the clock source for LPUART module.
+ * @param instance module device instance
+ * @param lpuartSrc Clock source.
+ */
+static inline void CLOCK_SYS_SetLpuartSrc(uint32_t instance, clock_lpuart_src_t lpuartSrc)
+{
+ CLOCK_HAL_SetLpuartSrc(SIM, instance, lpuartSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for LPUART module
+ *
+ * This function gets the clock frequency for LPUART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate 2 clock frequency.
+ *
+ * This function gets the ADC alternate 2 clock frequency (ALTCLK2).
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAlt2Freq(uint32_t instance)
+{
+ return CPU_INTERNAL_IRC_48M;
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPUART module.
+ *
+ * This function enables the clock for LPUART module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLpuartClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Disable the clock for LPUART module.
+ *
+ * This function disables the clock for LPUART module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLpuartClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPUART module.
+ *
+ * This function will get the clock gate state for LPUART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KV31F25612_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV31F51212/fsl_clock_MKV31F51212.c b/KSDK_1.2.0/platform/system/src/clock/MKV31F51212/fsl_clock_MKV31F51212.c
new file mode 100755
index 0000000..b5c1285
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV31F51212/fsl_clock_MKV31F51212.c
@@ -0,0 +1,871 @@
+/*
+ * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+
+ CLOCK_HAL_SetOutDiv(SIM, 1U, 3U, 3U, 7U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlexBusClock:
+ *frequency = CLOCK_SYS_GetFlexbusFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kOsc0ErClockUndiv:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kIrc48mClock:
+ *frequency = CPU_INTERNAL_IRC_48M;
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexbusFreq
+ * Description : Gets the clock frequency for FLEXBUS module
+ * This function gets the clock frequency for FLEXBUS moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexbusFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv3(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockPllFllSelIrc48M:
+ freq = CPU_INTERNAL_IRC_48M;
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq
+ * Description : Gets OSC0ERCLKUDIV.
+ * This function gets the OSC0 external reference undevided frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq()
+ >> OSC_HAL_GetExternalRefClkDiv(g_oscBase[0]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG);
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClkUndiv: /* OSC0ERCLKUDIV clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpuartFreq
+ * Description : Gets the clock frequency for LPUART module.
+ * This function gets the clock frequency for LPUART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance)
+{
+ clock_lpuart_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetLpuartSrc(SIM, instance);
+ switch (src)
+ {
+ case kClockLpuartSrcPllFllSel:
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockLpuartSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpuartSrcMcgIrClk:
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0,
+ kSimClockGateAdc1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0,
+ kSimClockGateDac1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+ kSimClockGateFtm3
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV31F51212/fsl_clock_MKV31F51212.h b/KSDK_1.2.0/platform/system/src/clock/MKV31F51212/fsl_clock_MKV31F51212.h
new file mode 100755
index 0000000..8cb88c2
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV31F51212/fsl_clock_MKV31F51212.h
@@ -0,0 +1,1299 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KV31F51212_H__)
+#define __FSL_CLOCK_KV31F51212_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kv31f51212 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kv31f51212_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function sets divide value OUTDIV3.
+ *
+ * @param outdiv3 Outdivider3 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv3(uint8_t outdiv3)
+{
+ CLOCK_HAL_SetOutDiv3(SIM, outdiv3);
+}
+
+/*!
+ * @brief Gets the clock out divider3 setting(OUTDIV3).
+ *
+ * This function gets divide value OUTDIV3.
+ *
+ * @return Outdivider3 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv3(void)
+{
+ return CLOCK_HAL_GetOutDiv3(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets the OSC0ERCLK_UNDIV frequency.
+ *
+ * This function gets the undivided OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void);
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock source for LPUART module
+ *
+ * This function gets the clock source for LPUART module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_lpuart_src_t CLOCK_SYS_GetLpuartSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpuartSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for LPUART module
+ *
+ * This function sets the clock source for LPUART module.
+ * @param instance module device instance
+ * @param lpuartSrc Clock source.
+ */
+static inline void CLOCK_SYS_SetLpuartSrc(uint32_t instance, clock_lpuart_src_t lpuartSrc)
+{
+ CLOCK_HAL_SetLpuartSrc(SIM, instance, lpuartSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for LPUART module
+ *
+ * This function gets the clock frequency for LPUART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpuartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate 2 clock frequency.
+ *
+ * This function gets the ADC alternate 2 clock frequency (ALTCLK2).
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAlt2Freq(uint32_t instance)
+{
+ return CPU_INTERNAL_IRC_48M;
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Enable the clock for FLEXBUS module.
+ *
+ * This function enables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Disable the clock for FLEXBUS module.
+ *
+ * This function disables the clock for FLEXBUS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexbusClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXBUS module.
+ *
+ * This function will get the clock gate state for FLEXBUS module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexbusGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFlexbus0);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPUART module.
+ *
+ * This function enables the clock for LPUART module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLpuartClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Disable the clock for LPUART module.
+ *
+ * This function disables the clock for LPUART module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLpuartClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPUART module.
+ *
+ * This function will get the clock gate state for LPUART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLpuartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLpuart0);
+}
+
+/*!
+ * @brief Set the FTM external clock frequency(FTM_CLKx).
+ *
+ * This function sets the FTM external clock frequency (FTM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetFtmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < FTM_EXT_CLK_COUNT);
+
+ g_ftmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KV31F51212_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV40F15/fsl_clock_MKV40F15.c b/KSDK_1.2.0/platform/system/src/clock/MKV40F15/fsl_clock_MKV40F15.c
new file mode 100755
index 0000000..0412a4a
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV40F15/fsl_clock_MKV40F15.c
@@ -0,0 +1,765 @@
+/*
+ * Copyright (c) 2014 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_osc_hal.h"
+#include "fsl_clock_manager.h"
+#include "fsl_mcg_hal_modes.h"
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/* Table of base addresses for instances. */
+extern SIM_Type * const g_simBase[];
+extern MCG_Type * const g_mcgBase[];
+
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDmaFreq
+ * Description : Gets the clock frequency for DMA module
+ * This function gets the clock frequency for DMA moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetDmaFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kSystemClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDmamuxFreq
+ * Description : Gets the clock frequency for DMAMUX module
+ * This function gets the clock frequency for DMAMUX moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetDmamuxFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFreq
+ * Description : Gets the clock frequency for PORT module
+ * This function gets the clock frequency for PORT moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kLpoClock, &freq);
+ return freq;
+}
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*! @brief CLOCK name config table for KV46*/
+const clock_name_config_t kClockNameConfigTable [] = {
+ {false, kSystemClock, kClockDividerOutdiv1}, /* Core clock divider */
+ {false, kSystemClock, kClockDividerOutdiv1}, /* System clock divider */
+ {false, kSystemClock, kClockDividerOutdiv1}, /* Not used for KV4x */
+ {false, kSystemClock, kClockDividerOutdiv4}, /* Bus clock divider */
+ {false, kSystemClock, kClockDividerOutdiv1}, /* Not used for KV4x*/
+ {false, kSystemClock, kClockDividerOutdiv4}, /* Flash clock divider */
+ {false, kSystemClock, kClockDividerOutdiv2} /* Fast peripheral clock divider */
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSysClkFreq
+ * Description : Internal function to get the system clock frequency
+ * This function will check the clock name configuration table for specific
+ * chip family and find out the supported clock name for that chip family
+ * then it will call the mcg hal function to get the basic system clock,
+ * calculate the clock frequency for specified clock name.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_GetSysClkFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ const clock_name_config_t *table = &kClockNameConfigTable[clockName];
+
+ /* check if we need to use a reference clock*/
+ if (table->useOtherRefClock)
+ {
+ /* get other specified ref clock*/
+ if ( kClockManagerSuccess != CLOCK_SYS_GetFreq(table->otherRefClockName,
+ frequency) )
+ {
+ return kClockManagerNoSuchClockName;
+ }
+ else
+ {
+ return kClockManagerSuccess;
+ }
+ }
+ else
+ {
+ /* get default ref clock */
+ if ((table->dividerName)==kClockDividerOutdiv1)
+ {
+ *frequency =(CLOCK_HAL_GetOutClk(g_mcgBase[0])/(CLOCK_HAL_GetOutDiv1(SIM) + 1));
+ }
+ else if ((table->dividerName)==kClockDividerOutdiv2)
+ {
+ *frequency =(CLOCK_HAL_GetOutClk(g_mcgBase[0])/(CLOCK_HAL_GetOutDiv2(SIM) + 1));
+ }
+ else if ((table->dividerName)==kClockDividerOutdiv4)
+ {
+ *frequency =(CLOCK_HAL_GetOutClk(g_mcgBase[0])/(CLOCK_HAL_GetOutDiv4(SIM) + 1));
+ }
+ return kClockManagerSuccess;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 2U, 5U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kFastPeripheralClock:
+ returnCode = CLOCK_SYS_GetSysClkFreq(clockName, frequency);
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kOsc0ErClockUndiv:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+#if FSL_FEATURE_MCG_HAS_IRC_48M
+ case kIrc48mClock:
+ *frequency = CPU_INTERNAL_IRC_48M;
+ break;
+#endif
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFastPeripheralClockFreq
+ * Description : Gets the fast peripheral clock frequency.
+ * This function gets the fast peripheral clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFastPeripheralClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq()
+ >> OSC_HAL_GetExternalRefClkDiv(g_oscBase[0]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq
+ * Description : Gets OSC0ERCLKUDIV.
+ * This function gets the OSC0 external reference undivided frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx prescaler/glitch filter clock frequency.
+ * This function gets the LPTMRx prescaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClkUndiv: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEwmFreq
+ * Description : Gets the clock frequency for Ewm module
+ * This function gets the clock frequency for Ewm moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kLpoClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtfFreq
+ * Description : Gets the clock frequency for FTF module. (Flash Memory)
+ * This function gets the clock frequency for FTF moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFlashClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCrcFreq
+ * Description : Gets the clock frequency for CRC module
+ * This function gets the clock frequency for CRC moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kSystemClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcFreq
+ * Description : Gets the clock frequency for ADC module
+ * This function gets the clock frequency for ADC moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetAdcFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kMcgIrClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCmpFreq
+ * Description : Gets the clock frequency for CMP module
+ * This function gets the clock frequency for CMP moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPdbFreq
+ * Description : Gets the clock frequency for PDB module
+ * This function gets the clock frequency for PDB moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPwmFreq
+ * Description : Gets the clock frequency for eFlexPWM module
+ * This function gets the clock frequency for eFlexPWM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPwmFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPitFreq
+ * Description : Gets the clock frequency for Pit module.
+ * This function gets the clock frequency for Pit moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiFreq
+ * Description : Gets the clock frequency for SPI module.
+ * This function gets the clock frequency for SPI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cFreq
+ * Description : Gets the clock frequency for I2C module.
+ * This function gets the clock frequency for I2C moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetGpioFreq
+ * Description : Gets the clock frequency for GPIO module.
+ * This function gets the clock frequency for GPIO moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kSystemClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEncFreq
+ * Description : Gets the clock frequency for ENC module.
+ * This function gets the clock frequency for ENC moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEncFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetXbarFreq
+ * Description : Gets the clock frequency for XBAR module.
+ * This function gets the clock frequency for XBAR moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetXbarFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAoiFreq
+ * Description : Gets the clock frequency for AOI module.
+ * This function gets the clock frequency for AOI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetAoiFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint8_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ uint32_t freq = 0;
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+ }
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV40F15/fsl_clock_MKV40F15.h b/KSDK_1.2.0/platform/system/src/clock/MKV40F15/fsl_clock_MKV40F15.h
new file mode 100755
index 0000000..dbad983
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV40F15/fsl_clock_MKV40F15.h
@@ -0,0 +1,1267 @@
+/*
+ * Copyright (c) 2014 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KV40F15_H__)
+#define __FSL_CLOCK_KV40F15_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+#define FTM_EXT_CLK_COUNT 2 /* FTM external clock source count. */
+
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK */
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+} sim_config_t;
+
+/*! @brief Clock name configuration table structure*/
+typedef struct ClockNameConfig {
+ bool useOtherRefClock; /*!< if it uses the other ref clock*/
+ clock_names_t otherRefClockName; /*!< other ref clock name*/
+ clock_divider_names_t dividerName; /*!< clock divider name*/
+} clock_name_config_t;
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the fast peripheral clock frequency.
+ *
+ * This function gets the fast peripheral clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFastPeripheralClockFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selecton of ERCLK32K.
+ *
+ * This function sets the clock selecton of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selecton of ERCLK32K.
+ *
+ * This function gets the clock selecton of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets the OSC0ERCLK_UNDIV frequency.
+ *
+ * This function gets the undivided OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void);
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for DMA module.
+ *
+ * This function gets the clock frequence for DMA moudle.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetDmaFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for DMAMUX module.
+ *
+ * This function gets the clock frequence for DMAMUX moudle.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetDmamuxFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequence for EWM moudle.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequence for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequence for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for ADC module.
+ *
+ * This function gets the clock frequence for ADC module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetAdcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequence for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequence for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for eFlexPWM module.
+ *
+ * This function gets the clock frequence for eFlexPWM module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetPwmFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFastPeripheralClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequence for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequence for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequence for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequence for UART module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequence for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for ENC module
+ *
+ * This function gets the clock frequence for ENC module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetEncFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for XBAR module
+ *
+ * This function gets the clock frequence for XBAR module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetXbarFreq(uint32_t instance);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets the clock frequency for AOI module
+ *
+ * This function gets the clock frequence for AOI module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetAoiFreq(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableDmaClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableDmaClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetDmaGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableDmamuxClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableDmamuxClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetDmamuxGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableEwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableEwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetEwmGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableFtfClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableFtfClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetFtfGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableCrcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableCrcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetCrcGateCmd(g_simBase[0], instance);
+}
+
+
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ SIM_HAL_EnableAdcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ SIM_HAL_DisableAdcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetAdcGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableCmpClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableCmpClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetCmpGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ SIM_HAL_EnableDacClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ SIM_HAL_DisableDacClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetDacGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnablePdbClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisablePdbClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetPdbGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ SIM_HAL_EnableFtmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ SIM_HAL_DisableFtmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetFtmGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnablePitClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisablePitClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetPitGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableLptmrClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableLptmrClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetLptmrGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ SIM_HAL_EnableFlexcanClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ SIM_HAL_DisableFlexcanClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetFlexcanGateCmd(g_simBase[0], instance);
+}
+
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint8_t instance, clock_flexcan_src_t flexcanSrc);
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ SIM_HAL_EnableSpiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ SIM_HAL_DisableSpiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetSpiGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ SIM_HAL_EnableI2cClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ SIM_HAL_DisableI2cClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetI2cGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ SIM_HAL_EnableUartClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ SIM_HAL_DisableUartClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetUartGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for eFlexPWM module.
+ *
+ * This function enables the clock for eFlexPWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePwmClock(uint32_t instance)
+{
+ SIM_HAL_EnablePwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for eFlexPWM module.
+ *
+ * This function disables the clock for eFlexPWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePwmClock(uint32_t instance)
+{
+ SIM_HAL_DisablePwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for eFlexPWM module.
+ *
+ * This function will get the clock gate state for eFlexPWM moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetPwmGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for AOI module.
+ *
+ * This function enables the clock for AOI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableAoiClock(uint32_t instance)
+{
+ SIM_HAL_EnableAoiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for AOI module.
+ *
+ * This function disables the clock for AOI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableAoiClock(uint32_t instance)
+{
+ SIM_HAL_DisableAoiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for AOI module.
+ *
+ * This function will get the clock gate state for AOI moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetAoiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetAoiGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for XBAR module.
+ *
+ * This function enables the clock for XBAR moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableXbarClock(uint32_t instance)
+{
+ SIM_HAL_EnableXbarClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for XBAR module.
+ *
+ * This function disables the clock for XBAR moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableXbarClock(uint32_t instance)
+{
+ SIM_HAL_DisableXbarClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for XBAR module.
+ *
+ * This function will get the clock gate state for XBAR moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetXbarGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetXbarGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for ENC module.
+ *
+ * This function enables the clock for ENC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEncClock(uint32_t instance)
+{
+ SIM_HAL_EnableEncClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for ENC module.
+ *
+ * This function disables the clock for ENC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEncClock(uint32_t instance)
+{
+ SIM_HAL_DisableEncClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for ENC module.
+ *
+ * This function will get the clock gate state for ENC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEncGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetEncGateCmd(g_simBase[0], instance);
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KV40F15_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV43F15/fsl_clock_MKV43F15.c b/KSDK_1.2.0/platform/system/src/clock/MKV43F15/fsl_clock_MKV43F15.c
new file mode 100755
index 0000000..9d76fd3
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV43F15/fsl_clock_MKV43F15.c
@@ -0,0 +1,765 @@
+/*
+ * Copyright (c) 2014 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_osc_hal.h"
+#include "fsl_clock_manager.h"
+#include "fsl_mcg_hal_modes.h"
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/* Table of base addresses for instances. */
+extern SIM_Type * const g_simBase[];
+extern MCG_Type * const g_mcgBase[];
+
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDmaFreq
+ * Description : Gets the clock frequency for DMA module
+ * This function gets the clock frequency for DMA moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetDmaFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kSystemClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDmamuxFreq
+ * Description : Gets the clock frequency for DMAMUX module
+ * This function gets the clock frequency for DMAMUX moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetDmamuxFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFreq
+ * Description : Gets the clock frequency for PORT module
+ * This function gets the clock frequency for PORT moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kLpoClock, &freq);
+ return freq;
+}
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*! @brief CLOCK name config table for KV46*/
+const clock_name_config_t kClockNameConfigTable [] = {
+ {false, kSystemClock, kClockDividerOutdiv1}, /* Core clock divider */
+ {false, kSystemClock, kClockDividerOutdiv1}, /* System clock divider */
+ {false, kSystemClock, kClockDividerOutdiv1}, /* Not used for KV4x */
+ {false, kSystemClock, kClockDividerOutdiv4}, /* Bus clock divider */
+ {false, kSystemClock, kClockDividerOutdiv1}, /* Not used for KV4x*/
+ {false, kSystemClock, kClockDividerOutdiv4}, /* Flash clock divider */
+ {false, kSystemClock, kClockDividerOutdiv2} /* Fast peripheral clock divider */
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSysClkFreq
+ * Description : Internal function to get the system clock frequency
+ * This function will check the clock name configuration table for specific
+ * chip family and find out the supported clock name for that chip family
+ * then it will call the mcg hal function to get the basic system clock,
+ * calculate the clock frequency for specified clock name.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_GetSysClkFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ const clock_name_config_t *table = &kClockNameConfigTable[clockName];
+
+ /* check if we need to use a reference clock*/
+ if (table->useOtherRefClock)
+ {
+ /* get other specified ref clock*/
+ if ( kClockManagerSuccess != CLOCK_SYS_GetFreq(table->otherRefClockName,
+ frequency) )
+ {
+ return kClockManagerNoSuchClockName;
+ }
+ else
+ {
+ return kClockManagerSuccess;
+ }
+ }
+ else
+ {
+ /* get default ref clock */
+ if ((table->dividerName)==kClockDividerOutdiv1)
+ {
+ *frequency =(CLOCK_HAL_GetOutClk(g_mcgBase[0])/(CLOCK_HAL_GetOutDiv1(SIM) + 1));
+ }
+ else if ((table->dividerName)==kClockDividerOutdiv2)
+ {
+ *frequency =(CLOCK_HAL_GetOutClk(g_mcgBase[0])/(CLOCK_HAL_GetOutDiv2(SIM) + 1));
+ }
+ else if ((table->dividerName)==kClockDividerOutdiv4)
+ {
+ *frequency =(CLOCK_HAL_GetOutClk(g_mcgBase[0])/(CLOCK_HAL_GetOutDiv4(SIM) + 1));
+ }
+ return kClockManagerSuccess;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 2U, 5U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kFastPeripheralClock:
+ returnCode = CLOCK_SYS_GetSysClkFreq(clockName, frequency);
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kOsc0ErClockUndiv:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+#if FSL_FEATURE_MCG_HAS_IRC_48M
+ case kIrc48mClock:
+ *frequency = CPU_INTERNAL_IRC_48M;
+ break;
+#endif
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFastPeripheralClockFreq
+ * Description : Gets the fast peripheral clock frequency.
+ * This function gets the fast peripheral clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFastPeripheralClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq()
+ >> OSC_HAL_GetExternalRefClkDiv(g_oscBase[0]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq
+ * Description : Gets OSC0ERCLKUDIV.
+ * This function gets the OSC0 external reference undivided frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx prescaler/glitch filter clock frequency.
+ * This function gets the LPTMRx prescaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClkUndiv: /* OSCERCLK_UNDIV clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEwmFreq
+ * Description : Gets the clock frequency for Ewm module
+ * This function gets the clock frequency for Ewm moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kLpoClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtfFreq
+ * Description : Gets the clock frequency for FTF module. (Flash Memory)
+ * This function gets the clock frequency for FTF moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFlashClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCrcFreq
+ * Description : Gets the clock frequency for CRC module
+ * This function gets the clock frequency for CRC moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kSystemClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcFreq
+ * Description : Gets the clock frequency for ADC module
+ * This function gets the clock frequency for ADC moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetAdcFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kMcgIrClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCmpFreq
+ * Description : Gets the clock frequency for CMP module
+ * This function gets the clock frequency for CMP moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPdbFreq
+ * Description : Gets the clock frequency for PDB module
+ * This function gets the clock frequency for PDB moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPwmFreq
+ * Description : Gets the clock frequency for eFlexPWM module
+ * This function gets the clock frequency for eFlexPWM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPwmFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPitFreq
+ * Description : Gets the clock frequency for Pit module.
+ * This function gets the clock frequency for Pit moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiFreq
+ * Description : Gets the clock frequency for SPI module.
+ * This function gets the clock frequency for SPI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cFreq
+ * Description : Gets the clock frequency for I2C module.
+ * This function gets the clock frequency for I2C moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetGpioFreq
+ * Description : Gets the clock frequency for GPIO module.
+ * This function gets the clock frequency for GPIO moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kSystemClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEncFreq
+ * Description : Gets the clock frequency for ENC module.
+ * This function gets the clock frequency for ENC moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEncFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetXbarFreq
+ * Description : Gets the clock frequency for XBAR module.
+ * This function gets the clock frequency for XBAR moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetXbarFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAoiFreq
+ * Description : Gets the clock frequency for AOI module.
+ * This function gets the clock frequency for AOI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetAoiFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint8_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ uint32_t freq = 0;
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+ }
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV43F15/fsl_clock_MKV43F15.h b/KSDK_1.2.0/platform/system/src/clock/MKV43F15/fsl_clock_MKV43F15.h
new file mode 100755
index 0000000..6f0d4c8
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV43F15/fsl_clock_MKV43F15.h
@@ -0,0 +1,1267 @@
+/*
+ * Copyright (c) 2014 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KV43F15_H__)
+#define __FSL_CLOCK_KV43F15_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+#define FTM_EXT_CLK_COUNT 2 /* FTM external clock source count. */
+
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK */
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+} sim_config_t;
+
+/*! @brief Clock name configuration table structure*/
+typedef struct ClockNameConfig {
+ bool useOtherRefClock; /*!< if it uses the other ref clock*/
+ clock_names_t otherRefClockName; /*!< other ref clock name*/
+ clock_divider_names_t dividerName; /*!< clock divider name*/
+} clock_name_config_t;
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the fast peripheral clock frequency.
+ *
+ * This function gets the fast peripheral clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFastPeripheralClockFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selecton of ERCLK32K.
+ *
+ * This function sets the clock selecton of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selecton of ERCLK32K.
+ *
+ * This function gets the clock selecton of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets the OSC0ERCLK_UNDIV frequency.
+ *
+ * This function gets the undivided OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void);
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for DMA module.
+ *
+ * This function gets the clock frequence for DMA moudle.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetDmaFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for DMAMUX module.
+ *
+ * This function gets the clock frequence for DMAMUX moudle.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetDmamuxFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequence for EWM moudle.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequence for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequence for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for ADC module.
+ *
+ * This function gets the clock frequence for ADC module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetAdcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequence for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequence for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for eFlexPWM module.
+ *
+ * This function gets the clock frequence for eFlexPWM module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetPwmFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFastPeripheralClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequence for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequence for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequence for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequence for UART module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequence for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for ENC module
+ *
+ * This function gets the clock frequence for ENC module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetEncFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for XBAR module
+ *
+ * This function gets the clock frequence for XBAR module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetXbarFreq(uint32_t instance);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets the clock frequency for AOI module
+ *
+ * This function gets the clock frequence for AOI module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetAoiFreq(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableDmaClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableDmaClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetDmaGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableDmamuxClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableDmamuxClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetDmamuxGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableEwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableEwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetEwmGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableFtfClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableFtfClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetFtfGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableCrcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableCrcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetCrcGateCmd(g_simBase[0], instance);
+}
+
+
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ SIM_HAL_EnableAdcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ SIM_HAL_DisableAdcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetAdcGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableCmpClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableCmpClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetCmpGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ SIM_HAL_EnableDacClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ SIM_HAL_DisableDacClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetDacGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnablePdbClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisablePdbClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetPdbGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ SIM_HAL_EnableFtmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ SIM_HAL_DisableFtmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetFtmGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnablePitClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisablePitClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetPitGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableLptmrClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableLptmrClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetLptmrGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ SIM_HAL_EnableFlexcanClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ SIM_HAL_DisableFlexcanClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetFlexcanGateCmd(g_simBase[0], instance);
+}
+
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint8_t instance, clock_flexcan_src_t flexcanSrc);
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ SIM_HAL_EnableSpiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ SIM_HAL_DisableSpiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetSpiGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ SIM_HAL_EnableI2cClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ SIM_HAL_DisableI2cClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetI2cGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ SIM_HAL_EnableUartClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ SIM_HAL_DisableUartClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetUartGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for eFlexPWM module.
+ *
+ * This function enables the clock for eFlexPWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePwmClock(uint32_t instance)
+{
+ SIM_HAL_EnablePwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for eFlexPWM module.
+ *
+ * This function disables the clock for eFlexPWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePwmClock(uint32_t instance)
+{
+ SIM_HAL_DisablePwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for eFlexPWM module.
+ *
+ * This function will get the clock gate state for eFlexPWM moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetPwmGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for AOI module.
+ *
+ * This function enables the clock for AOI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableAoiClock(uint32_t instance)
+{
+ SIM_HAL_EnableAoiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for AOI module.
+ *
+ * This function disables the clock for AOI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableAoiClock(uint32_t instance)
+{
+ SIM_HAL_DisableAoiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for AOI module.
+ *
+ * This function will get the clock gate state for AOI moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetAoiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetAoiGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for XBAR module.
+ *
+ * This function enables the clock for XBAR moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableXbarClock(uint32_t instance)
+{
+ SIM_HAL_EnableXbarClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for XBAR module.
+ *
+ * This function disables the clock for XBAR moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableXbarClock(uint32_t instance)
+{
+ SIM_HAL_DisableXbarClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for XBAR module.
+ *
+ * This function will get the clock gate state for XBAR moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetXbarGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetXbarGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for ENC module.
+ *
+ * This function enables the clock for ENC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEncClock(uint32_t instance)
+{
+ SIM_HAL_EnableEncClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for ENC module.
+ *
+ * This function disables the clock for ENC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEncClock(uint32_t instance)
+{
+ SIM_HAL_DisableEncClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for ENC module.
+ *
+ * This function will get the clock gate state for ENC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEncGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetEncGateCmd(g_simBase[0], instance);
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KV43F15_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV44F15/fsl_clock_MKV44F15.c b/KSDK_1.2.0/platform/system/src/clock/MKV44F15/fsl_clock_MKV44F15.c
new file mode 100755
index 0000000..9d76fd3
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV44F15/fsl_clock_MKV44F15.c
@@ -0,0 +1,765 @@
+/*
+ * Copyright (c) 2014 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_osc_hal.h"
+#include "fsl_clock_manager.h"
+#include "fsl_mcg_hal_modes.h"
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/* Table of base addresses for instances. */
+extern SIM_Type * const g_simBase[];
+extern MCG_Type * const g_mcgBase[];
+
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDmaFreq
+ * Description : Gets the clock frequency for DMA module
+ * This function gets the clock frequency for DMA moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetDmaFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kSystemClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDmamuxFreq
+ * Description : Gets the clock frequency for DMAMUX module
+ * This function gets the clock frequency for DMAMUX moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetDmamuxFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFreq
+ * Description : Gets the clock frequency for PORT module
+ * This function gets the clock frequency for PORT moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kLpoClock, &freq);
+ return freq;
+}
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*! @brief CLOCK name config table for KV46*/
+const clock_name_config_t kClockNameConfigTable [] = {
+ {false, kSystemClock, kClockDividerOutdiv1}, /* Core clock divider */
+ {false, kSystemClock, kClockDividerOutdiv1}, /* System clock divider */
+ {false, kSystemClock, kClockDividerOutdiv1}, /* Not used for KV4x */
+ {false, kSystemClock, kClockDividerOutdiv4}, /* Bus clock divider */
+ {false, kSystemClock, kClockDividerOutdiv1}, /* Not used for KV4x*/
+ {false, kSystemClock, kClockDividerOutdiv4}, /* Flash clock divider */
+ {false, kSystemClock, kClockDividerOutdiv2} /* Fast peripheral clock divider */
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSysClkFreq
+ * Description : Internal function to get the system clock frequency
+ * This function will check the clock name configuration table for specific
+ * chip family and find out the supported clock name for that chip family
+ * then it will call the mcg hal function to get the basic system clock,
+ * calculate the clock frequency for specified clock name.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_GetSysClkFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ const clock_name_config_t *table = &kClockNameConfigTable[clockName];
+
+ /* check if we need to use a reference clock*/
+ if (table->useOtherRefClock)
+ {
+ /* get other specified ref clock*/
+ if ( kClockManagerSuccess != CLOCK_SYS_GetFreq(table->otherRefClockName,
+ frequency) )
+ {
+ return kClockManagerNoSuchClockName;
+ }
+ else
+ {
+ return kClockManagerSuccess;
+ }
+ }
+ else
+ {
+ /* get default ref clock */
+ if ((table->dividerName)==kClockDividerOutdiv1)
+ {
+ *frequency =(CLOCK_HAL_GetOutClk(g_mcgBase[0])/(CLOCK_HAL_GetOutDiv1(SIM) + 1));
+ }
+ else if ((table->dividerName)==kClockDividerOutdiv2)
+ {
+ *frequency =(CLOCK_HAL_GetOutClk(g_mcgBase[0])/(CLOCK_HAL_GetOutDiv2(SIM) + 1));
+ }
+ else if ((table->dividerName)==kClockDividerOutdiv4)
+ {
+ *frequency =(CLOCK_HAL_GetOutClk(g_mcgBase[0])/(CLOCK_HAL_GetOutDiv4(SIM) + 1));
+ }
+ return kClockManagerSuccess;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 2U, 5U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kFastPeripheralClock:
+ returnCode = CLOCK_SYS_GetSysClkFreq(clockName, frequency);
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kOsc0ErClockUndiv:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+#if FSL_FEATURE_MCG_HAS_IRC_48M
+ case kIrc48mClock:
+ *frequency = CPU_INTERNAL_IRC_48M;
+ break;
+#endif
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFastPeripheralClockFreq
+ * Description : Gets the fast peripheral clock frequency.
+ * This function gets the fast peripheral clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFastPeripheralClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq()
+ >> OSC_HAL_GetExternalRefClkDiv(g_oscBase[0]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq
+ * Description : Gets OSC0ERCLKUDIV.
+ * This function gets the OSC0 external reference undivided frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx prescaler/glitch filter clock frequency.
+ * This function gets the LPTMRx prescaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClkUndiv: /* OSCERCLK_UNDIV clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEwmFreq
+ * Description : Gets the clock frequency for Ewm module
+ * This function gets the clock frequency for Ewm moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kLpoClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtfFreq
+ * Description : Gets the clock frequency for FTF module. (Flash Memory)
+ * This function gets the clock frequency for FTF moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFlashClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCrcFreq
+ * Description : Gets the clock frequency for CRC module
+ * This function gets the clock frequency for CRC moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kSystemClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcFreq
+ * Description : Gets the clock frequency for ADC module
+ * This function gets the clock frequency for ADC moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetAdcFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kMcgIrClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCmpFreq
+ * Description : Gets the clock frequency for CMP module
+ * This function gets the clock frequency for CMP moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPdbFreq
+ * Description : Gets the clock frequency for PDB module
+ * This function gets the clock frequency for PDB moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPwmFreq
+ * Description : Gets the clock frequency for eFlexPWM module
+ * This function gets the clock frequency for eFlexPWM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPwmFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPitFreq
+ * Description : Gets the clock frequency for Pit module.
+ * This function gets the clock frequency for Pit moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiFreq
+ * Description : Gets the clock frequency for SPI module.
+ * This function gets the clock frequency for SPI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cFreq
+ * Description : Gets the clock frequency for I2C module.
+ * This function gets the clock frequency for I2C moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetGpioFreq
+ * Description : Gets the clock frequency for GPIO module.
+ * This function gets the clock frequency for GPIO moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kSystemClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEncFreq
+ * Description : Gets the clock frequency for ENC module.
+ * This function gets the clock frequency for ENC moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEncFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetXbarFreq
+ * Description : Gets the clock frequency for XBAR module.
+ * This function gets the clock frequency for XBAR moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetXbarFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAoiFreq
+ * Description : Gets the clock frequency for AOI module.
+ * This function gets the clock frequency for AOI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetAoiFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint8_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ uint32_t freq = 0;
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+ }
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV44F15/fsl_clock_MKV44F15.h b/KSDK_1.2.0/platform/system/src/clock/MKV44F15/fsl_clock_MKV44F15.h
new file mode 100755
index 0000000..c2b1691
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV44F15/fsl_clock_MKV44F15.h
@@ -0,0 +1,1267 @@
+/*
+ * Copyright (c) 2014 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KV44F15_H__)
+#define __FSL_CLOCK_KV44F15_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+#define FTM_EXT_CLK_COUNT 2 /* FTM external clock source count. */
+
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK */
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+} sim_config_t;
+
+/*! @brief Clock name configuration table structure*/
+typedef struct ClockNameConfig {
+ bool useOtherRefClock; /*!< if it uses the other ref clock*/
+ clock_names_t otherRefClockName; /*!< other ref clock name*/
+ clock_divider_names_t dividerName; /*!< clock divider name*/
+} clock_name_config_t;
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the fast peripheral clock frequency.
+ *
+ * This function gets the fast peripheral clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFastPeripheralClockFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selecton of ERCLK32K.
+ *
+ * This function sets the clock selecton of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selecton of ERCLK32K.
+ *
+ * This function gets the clock selecton of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets the OSC0ERCLK_UNDIV frequency.
+ *
+ * This function gets the undivided OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void);
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for DMA module.
+ *
+ * This function gets the clock frequence for DMA moudle.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetDmaFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for DMAMUX module.
+ *
+ * This function gets the clock frequence for DMAMUX moudle.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetDmamuxFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequence for EWM moudle.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequence for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequence for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for ADC module.
+ *
+ * This function gets the clock frequence for ADC module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetAdcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequence for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequence for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for eFlexPWM module.
+ *
+ * This function gets the clock frequence for eFlexPWM module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetPwmFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFastPeripheralClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequence for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequence for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequence for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequence for UART module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequence for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for ENC module
+ *
+ * This function gets the clock frequence for ENC module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetEncFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for XBAR module
+ *
+ * This function gets the clock frequence for XBAR module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetXbarFreq(uint32_t instance);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets the clock frequency for AOI module
+ *
+ * This function gets the clock frequence for AOI module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetAoiFreq(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableDmaClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableDmaClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetDmaGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableDmamuxClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableDmamuxClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetDmamuxGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableEwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableEwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetEwmGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableFtfClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableFtfClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetFtfGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableCrcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableCrcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetCrcGateCmd(g_simBase[0], instance);
+}
+
+
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ SIM_HAL_EnableAdcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ SIM_HAL_DisableAdcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetAdcGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableCmpClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableCmpClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetCmpGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ SIM_HAL_EnableDacClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ SIM_HAL_DisableDacClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetDacGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnablePdbClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisablePdbClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetPdbGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ SIM_HAL_EnableFtmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ SIM_HAL_DisableFtmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetFtmGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnablePitClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisablePitClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetPitGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableLptmrClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableLptmrClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetLptmrGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ SIM_HAL_EnableFlexcanClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ SIM_HAL_DisableFlexcanClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetFlexcanGateCmd(g_simBase[0], instance);
+}
+
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint8_t instance, clock_flexcan_src_t flexcanSrc);
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ SIM_HAL_EnableSpiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ SIM_HAL_DisableSpiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetSpiGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ SIM_HAL_EnableI2cClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ SIM_HAL_DisableI2cClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetI2cGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ SIM_HAL_EnableUartClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ SIM_HAL_DisableUartClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetUartGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for eFlexPWM module.
+ *
+ * This function enables the clock for eFlexPWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePwmClock(uint32_t instance)
+{
+ SIM_HAL_EnablePwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for eFlexPWM module.
+ *
+ * This function disables the clock for eFlexPWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePwmClock(uint32_t instance)
+{
+ SIM_HAL_DisablePwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for eFlexPWM module.
+ *
+ * This function will get the clock gate state for eFlexPWM moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetPwmGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for AOI module.
+ *
+ * This function enables the clock for AOI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableAoiClock(uint32_t instance)
+{
+ SIM_HAL_EnableAoiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for AOI module.
+ *
+ * This function disables the clock for AOI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableAoiClock(uint32_t instance)
+{
+ SIM_HAL_DisableAoiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for AOI module.
+ *
+ * This function will get the clock gate state for AOI moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetAoiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetAoiGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for XBAR module.
+ *
+ * This function enables the clock for XBAR moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableXbarClock(uint32_t instance)
+{
+ SIM_HAL_EnableXbarClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for XBAR module.
+ *
+ * This function disables the clock for XBAR moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableXbarClock(uint32_t instance)
+{
+ SIM_HAL_DisableXbarClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for XBAR module.
+ *
+ * This function will get the clock gate state for XBAR moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetXbarGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetXbarGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for ENC module.
+ *
+ * This function enables the clock for ENC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEncClock(uint32_t instance)
+{
+ SIM_HAL_EnableEncClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for ENC module.
+ *
+ * This function disables the clock for ENC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEncClock(uint32_t instance)
+{
+ SIM_HAL_DisableEncClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for ENC module.
+ *
+ * This function will get the clock gate state for ENC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEncGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetEncGateCmd(g_simBase[0], instance);
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KV44F15_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV45F15/fsl_clock_MKV45F15.c b/KSDK_1.2.0/platform/system/src/clock/MKV45F15/fsl_clock_MKV45F15.c
new file mode 100755
index 0000000..9d76fd3
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV45F15/fsl_clock_MKV45F15.c
@@ -0,0 +1,765 @@
+/*
+ * Copyright (c) 2014 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_osc_hal.h"
+#include "fsl_clock_manager.h"
+#include "fsl_mcg_hal_modes.h"
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/* Table of base addresses for instances. */
+extern SIM_Type * const g_simBase[];
+extern MCG_Type * const g_mcgBase[];
+
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDmaFreq
+ * Description : Gets the clock frequency for DMA module
+ * This function gets the clock frequency for DMA moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetDmaFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kSystemClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDmamuxFreq
+ * Description : Gets the clock frequency for DMAMUX module
+ * This function gets the clock frequency for DMAMUX moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetDmamuxFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFreq
+ * Description : Gets the clock frequency for PORT module
+ * This function gets the clock frequency for PORT moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kLpoClock, &freq);
+ return freq;
+}
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*! @brief CLOCK name config table for KV46*/
+const clock_name_config_t kClockNameConfigTable [] = {
+ {false, kSystemClock, kClockDividerOutdiv1}, /* Core clock divider */
+ {false, kSystemClock, kClockDividerOutdiv1}, /* System clock divider */
+ {false, kSystemClock, kClockDividerOutdiv1}, /* Not used for KV4x */
+ {false, kSystemClock, kClockDividerOutdiv4}, /* Bus clock divider */
+ {false, kSystemClock, kClockDividerOutdiv1}, /* Not used for KV4x*/
+ {false, kSystemClock, kClockDividerOutdiv4}, /* Flash clock divider */
+ {false, kSystemClock, kClockDividerOutdiv2} /* Fast peripheral clock divider */
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSysClkFreq
+ * Description : Internal function to get the system clock frequency
+ * This function will check the clock name configuration table for specific
+ * chip family and find out the supported clock name for that chip family
+ * then it will call the mcg hal function to get the basic system clock,
+ * calculate the clock frequency for specified clock name.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_GetSysClkFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ const clock_name_config_t *table = &kClockNameConfigTable[clockName];
+
+ /* check if we need to use a reference clock*/
+ if (table->useOtherRefClock)
+ {
+ /* get other specified ref clock*/
+ if ( kClockManagerSuccess != CLOCK_SYS_GetFreq(table->otherRefClockName,
+ frequency) )
+ {
+ return kClockManagerNoSuchClockName;
+ }
+ else
+ {
+ return kClockManagerSuccess;
+ }
+ }
+ else
+ {
+ /* get default ref clock */
+ if ((table->dividerName)==kClockDividerOutdiv1)
+ {
+ *frequency =(CLOCK_HAL_GetOutClk(g_mcgBase[0])/(CLOCK_HAL_GetOutDiv1(SIM) + 1));
+ }
+ else if ((table->dividerName)==kClockDividerOutdiv2)
+ {
+ *frequency =(CLOCK_HAL_GetOutClk(g_mcgBase[0])/(CLOCK_HAL_GetOutDiv2(SIM) + 1));
+ }
+ else if ((table->dividerName)==kClockDividerOutdiv4)
+ {
+ *frequency =(CLOCK_HAL_GetOutClk(g_mcgBase[0])/(CLOCK_HAL_GetOutDiv4(SIM) + 1));
+ }
+ return kClockManagerSuccess;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 2U, 5U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kFastPeripheralClock:
+ returnCode = CLOCK_SYS_GetSysClkFreq(clockName, frequency);
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kOsc0ErClockUndiv:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+#if FSL_FEATURE_MCG_HAS_IRC_48M
+ case kIrc48mClock:
+ *frequency = CPU_INTERNAL_IRC_48M;
+ break;
+#endif
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFastPeripheralClockFreq
+ * Description : Gets the fast peripheral clock frequency.
+ * This function gets the fast peripheral clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFastPeripheralClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq()
+ >> OSC_HAL_GetExternalRefClkDiv(g_oscBase[0]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq
+ * Description : Gets OSC0ERCLKUDIV.
+ * This function gets the OSC0 external reference undivided frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx prescaler/glitch filter clock frequency.
+ * This function gets the LPTMRx prescaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClkUndiv: /* OSCERCLK_UNDIV clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEwmFreq
+ * Description : Gets the clock frequency for Ewm module
+ * This function gets the clock frequency for Ewm moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kLpoClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtfFreq
+ * Description : Gets the clock frequency for FTF module. (Flash Memory)
+ * This function gets the clock frequency for FTF moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFlashClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCrcFreq
+ * Description : Gets the clock frequency for CRC module
+ * This function gets the clock frequency for CRC moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kSystemClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcFreq
+ * Description : Gets the clock frequency for ADC module
+ * This function gets the clock frequency for ADC moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetAdcFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kMcgIrClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCmpFreq
+ * Description : Gets the clock frequency for CMP module
+ * This function gets the clock frequency for CMP moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPdbFreq
+ * Description : Gets the clock frequency for PDB module
+ * This function gets the clock frequency for PDB moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPwmFreq
+ * Description : Gets the clock frequency for eFlexPWM module
+ * This function gets the clock frequency for eFlexPWM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPwmFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPitFreq
+ * Description : Gets the clock frequency for Pit module.
+ * This function gets the clock frequency for Pit moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiFreq
+ * Description : Gets the clock frequency for SPI module.
+ * This function gets the clock frequency for SPI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cFreq
+ * Description : Gets the clock frequency for I2C module.
+ * This function gets the clock frequency for I2C moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetGpioFreq
+ * Description : Gets the clock frequency for GPIO module.
+ * This function gets the clock frequency for GPIO moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kSystemClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEncFreq
+ * Description : Gets the clock frequency for ENC module.
+ * This function gets the clock frequency for ENC moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEncFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetXbarFreq
+ * Description : Gets the clock frequency for XBAR module.
+ * This function gets the clock frequency for XBAR moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetXbarFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAoiFreq
+ * Description : Gets the clock frequency for AOI module.
+ * This function gets the clock frequency for AOI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetAoiFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint8_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ uint32_t freq = 0;
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+ }
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV45F15/fsl_clock_MKV45F15.h b/KSDK_1.2.0/platform/system/src/clock/MKV45F15/fsl_clock_MKV45F15.h
new file mode 100755
index 0000000..6df9cf8
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV45F15/fsl_clock_MKV45F15.h
@@ -0,0 +1,1267 @@
+/*
+ * Copyright (c) 2014 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KV45F15_H__)
+#define __FSL_CLOCK_KV45F15_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+#define FTM_EXT_CLK_COUNT 2 /* FTM external clock source count. */
+
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK */
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+} sim_config_t;
+
+/*! @brief Clock name configuration table structure*/
+typedef struct ClockNameConfig {
+ bool useOtherRefClock; /*!< if it uses the other ref clock*/
+ clock_names_t otherRefClockName; /*!< other ref clock name*/
+ clock_divider_names_t dividerName; /*!< clock divider name*/
+} clock_name_config_t;
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the fast peripheral clock frequency.
+ *
+ * This function gets the fast peripheral clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFastPeripheralClockFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selecton of ERCLK32K.
+ *
+ * This function sets the clock selecton of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selecton of ERCLK32K.
+ *
+ * This function gets the clock selecton of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets the OSC0ERCLK_UNDIV frequency.
+ *
+ * This function gets the undivided OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void);
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for DMA module.
+ *
+ * This function gets the clock frequence for DMA moudle.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetDmaFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for DMAMUX module.
+ *
+ * This function gets the clock frequence for DMAMUX moudle.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetDmamuxFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequence for EWM moudle.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequence for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequence for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for ADC module.
+ *
+ * This function gets the clock frequence for ADC module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetAdcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequence for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequence for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for eFlexPWM module.
+ *
+ * This function gets the clock frequence for eFlexPWM module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetPwmFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFastPeripheralClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequence for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequence for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequence for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequence for UART module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequence for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for ENC module
+ *
+ * This function gets the clock frequence for ENC module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetEncFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for XBAR module
+ *
+ * This function gets the clock frequence for XBAR module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetXbarFreq(uint32_t instance);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets the clock frequency for AOI module
+ *
+ * This function gets the clock frequence for AOI module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetAoiFreq(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableDmaClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableDmaClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetDmaGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableDmamuxClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableDmamuxClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetDmamuxGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableEwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableEwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetEwmGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableFtfClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableFtfClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetFtfGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableCrcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableCrcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetCrcGateCmd(g_simBase[0], instance);
+}
+
+
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ SIM_HAL_EnableAdcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ SIM_HAL_DisableAdcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetAdcGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableCmpClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableCmpClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetCmpGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ SIM_HAL_EnableDacClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ SIM_HAL_DisableDacClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetDacGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnablePdbClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisablePdbClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetPdbGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ SIM_HAL_EnableFtmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ SIM_HAL_DisableFtmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetFtmGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnablePitClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisablePitClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetPitGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableLptmrClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableLptmrClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetLptmrGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ SIM_HAL_EnableFlexcanClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ SIM_HAL_DisableFlexcanClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetFlexcanGateCmd(g_simBase[0], instance);
+}
+
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint8_t instance, clock_flexcan_src_t flexcanSrc);
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ SIM_HAL_EnableSpiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ SIM_HAL_DisableSpiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetSpiGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ SIM_HAL_EnableI2cClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ SIM_HAL_DisableI2cClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetI2cGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ SIM_HAL_EnableUartClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ SIM_HAL_DisableUartClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetUartGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for eFlexPWM module.
+ *
+ * This function enables the clock for eFlexPWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePwmClock(uint32_t instance)
+{
+ SIM_HAL_EnablePwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for eFlexPWM module.
+ *
+ * This function disables the clock for eFlexPWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePwmClock(uint32_t instance)
+{
+ SIM_HAL_DisablePwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for eFlexPWM module.
+ *
+ * This function will get the clock gate state for eFlexPWM moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetPwmGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for AOI module.
+ *
+ * This function enables the clock for AOI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableAoiClock(uint32_t instance)
+{
+ SIM_HAL_EnableAoiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for AOI module.
+ *
+ * This function disables the clock for AOI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableAoiClock(uint32_t instance)
+{
+ SIM_HAL_DisableAoiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for AOI module.
+ *
+ * This function will get the clock gate state for AOI moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetAoiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetAoiGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for XBAR module.
+ *
+ * This function enables the clock for XBAR moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableXbarClock(uint32_t instance)
+{
+ SIM_HAL_EnableXbarClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for XBAR module.
+ *
+ * This function disables the clock for XBAR moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableXbarClock(uint32_t instance)
+{
+ SIM_HAL_DisableXbarClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for XBAR module.
+ *
+ * This function will get the clock gate state for XBAR moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetXbarGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetXbarGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for ENC module.
+ *
+ * This function enables the clock for ENC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEncClock(uint32_t instance)
+{
+ SIM_HAL_EnableEncClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for ENC module.
+ *
+ * This function disables the clock for ENC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEncClock(uint32_t instance)
+{
+ SIM_HAL_DisableEncClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for ENC module.
+ *
+ * This function will get the clock gate state for ENC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEncGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetEncGateCmd(g_simBase[0], instance);
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KV45F15_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV46F15/fsl_clock_MKV46F15.c b/KSDK_1.2.0/platform/system/src/clock/MKV46F15/fsl_clock_MKV46F15.c
new file mode 100755
index 0000000..9d76fd3
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV46F15/fsl_clock_MKV46F15.c
@@ -0,0 +1,765 @@
+/*
+ * Copyright (c) 2014 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_osc_hal.h"
+#include "fsl_clock_manager.h"
+#include "fsl_mcg_hal_modes.h"
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/* Table of base addresses for instances. */
+extern SIM_Type * const g_simBase[];
+extern MCG_Type * const g_mcgBase[];
+
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDmaFreq
+ * Description : Gets the clock frequency for DMA module
+ * This function gets the clock frequency for DMA moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetDmaFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kSystemClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDmamuxFreq
+ * Description : Gets the clock frequency for DMAMUX module
+ * This function gets the clock frequency for DMAMUX moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetDmamuxFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFreq
+ * Description : Gets the clock frequency for PORT module
+ * This function gets the clock frequency for PORT moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kLpoClock, &freq);
+ return freq;
+}
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*! @brief CLOCK name config table for KV46*/
+const clock_name_config_t kClockNameConfigTable [] = {
+ {false, kSystemClock, kClockDividerOutdiv1}, /* Core clock divider */
+ {false, kSystemClock, kClockDividerOutdiv1}, /* System clock divider */
+ {false, kSystemClock, kClockDividerOutdiv1}, /* Not used for KV4x */
+ {false, kSystemClock, kClockDividerOutdiv4}, /* Bus clock divider */
+ {false, kSystemClock, kClockDividerOutdiv1}, /* Not used for KV4x*/
+ {false, kSystemClock, kClockDividerOutdiv4}, /* Flash clock divider */
+ {false, kSystemClock, kClockDividerOutdiv2} /* Fast peripheral clock divider */
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSysClkFreq
+ * Description : Internal function to get the system clock frequency
+ * This function will check the clock name configuration table for specific
+ * chip family and find out the supported clock name for that chip family
+ * then it will call the mcg hal function to get the basic system clock,
+ * calculate the clock frequency for specified clock name.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_GetSysClkFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ const clock_name_config_t *table = &kClockNameConfigTable[clockName];
+
+ /* check if we need to use a reference clock*/
+ if (table->useOtherRefClock)
+ {
+ /* get other specified ref clock*/
+ if ( kClockManagerSuccess != CLOCK_SYS_GetFreq(table->otherRefClockName,
+ frequency) )
+ {
+ return kClockManagerNoSuchClockName;
+ }
+ else
+ {
+ return kClockManagerSuccess;
+ }
+ }
+ else
+ {
+ /* get default ref clock */
+ if ((table->dividerName)==kClockDividerOutdiv1)
+ {
+ *frequency =(CLOCK_HAL_GetOutClk(g_mcgBase[0])/(CLOCK_HAL_GetOutDiv1(SIM) + 1));
+ }
+ else if ((table->dividerName)==kClockDividerOutdiv2)
+ {
+ *frequency =(CLOCK_HAL_GetOutClk(g_mcgBase[0])/(CLOCK_HAL_GetOutDiv2(SIM) + 1));
+ }
+ else if ((table->dividerName)==kClockDividerOutdiv4)
+ {
+ *frequency =(CLOCK_HAL_GetOutClk(g_mcgBase[0])/(CLOCK_HAL_GetOutDiv4(SIM) + 1));
+ }
+ return kClockManagerSuccess;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 2U, 5U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kFastPeripheralClock:
+ returnCode = CLOCK_SYS_GetSysClkFreq(clockName, frequency);
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kOsc0ErClockUndiv:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+#if FSL_FEATURE_MCG_HAS_IRC_48M
+ case kIrc48mClock:
+ *frequency = CPU_INTERNAL_IRC_48M;
+ break;
+#endif
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFastPeripheralClockFreq
+ * Description : Gets the fast peripheral clock frequency.
+ * This function gets the fast peripheral clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFastPeripheralClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq()
+ >> OSC_HAL_GetExternalRefClkDiv(g_oscBase[0]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq
+ * Description : Gets OSC0ERCLKUDIV.
+ * This function gets the OSC0 external reference undivided frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx prescaler/glitch filter clock frequency.
+ * This function gets the LPTMRx prescaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClkUndiv: /* OSCERCLK_UNDIV clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEwmFreq
+ * Description : Gets the clock frequency for Ewm module
+ * This function gets the clock frequency for Ewm moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kLpoClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtfFreq
+ * Description : Gets the clock frequency for FTF module. (Flash Memory)
+ * This function gets the clock frequency for FTF moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFlashClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCrcFreq
+ * Description : Gets the clock frequency for CRC module
+ * This function gets the clock frequency for CRC moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kSystemClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcFreq
+ * Description : Gets the clock frequency for ADC module
+ * This function gets the clock frequency for ADC moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetAdcFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kMcgIrClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCmpFreq
+ * Description : Gets the clock frequency for CMP module
+ * This function gets the clock frequency for CMP moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPdbFreq
+ * Description : Gets the clock frequency for PDB module
+ * This function gets the clock frequency for PDB moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPwmFreq
+ * Description : Gets the clock frequency for eFlexPWM module
+ * This function gets the clock frequency for eFlexPWM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPwmFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPitFreq
+ * Description : Gets the clock frequency for Pit module.
+ * This function gets the clock frequency for Pit moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiFreq
+ * Description : Gets the clock frequency for SPI module.
+ * This function gets the clock frequency for SPI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cFreq
+ * Description : Gets the clock frequency for I2C module.
+ * This function gets the clock frequency for I2C moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetGpioFreq
+ * Description : Gets the clock frequency for GPIO module.
+ * This function gets the clock frequency for GPIO moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kSystemClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetEncFreq
+ * Description : Gets the clock frequency for ENC module.
+ * This function gets the clock frequency for ENC moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetEncFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetXbarFreq
+ * Description : Gets the clock frequency for XBAR module.
+ * This function gets the clock frequency for XBAR moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetXbarFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAoiFreq
+ * Description : Gets the clock frequency for AOI module.
+ * This function gets the clock frequency for AOI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetAoiFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+ CLOCK_SYS_GetFreq(kBusClock, &freq);
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlexcanFreq
+ * Description : Gets FLEXCAN clock frequency.
+ * This function gets the FLEXCAN clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint8_t instance, clock_flexcan_src_t flexcanSrc)
+{
+ uint32_t freq = 0;
+ if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+ else
+ {
+ CLOCK_SYS_GetFreq(kFastPeripheralClock, &freq);
+ return freq;
+ }
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKV46F15/fsl_clock_MKV46F15.h b/KSDK_1.2.0/platform/system/src/clock/MKV46F15/fsl_clock_MKV46F15.h
new file mode 100755
index 0000000..1c17dcc
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKV46F15/fsl_clock_MKV46F15.h
@@ -0,0 +1,1267 @@
+/*
+ * Copyright (c) 2014 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KV46F15_H__)
+#define __FSL_CLOCK_KV46F15_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+#define FTM_EXT_CLK_COUNT 2 /* FTM external clock source count. */
+
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK */
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+} sim_config_t;
+
+/*! @brief Clock name configuration table structure*/
+typedef struct ClockNameConfig {
+ bool useOtherRefClock; /*!< if it uses the other ref clock*/
+ clock_names_t otherRefClockName; /*!< other ref clock name*/
+ clock_divider_names_t dividerName; /*!< clock divider name*/
+} clock_name_config_t;
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the fast peripheral clock frequency.
+ *
+ * This function gets the fast peripheral clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFastPeripheralClockFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selecton of ERCLK32K.
+ *
+ * This function sets the clock selecton of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selecton of ERCLK32K.
+ *
+ * This function gets the clock selecton of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets the OSC0ERCLK_UNDIV frequency.
+ *
+ * This function gets the undivided OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockUndivFreq(void);
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for DMA module.
+ *
+ * This function gets the clock frequence for DMA moudle.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetDmaFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for DMAMUX module.
+ *
+ * This function gets the clock frequence for DMAMUX moudle.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetDmamuxFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequence for EWM moudle.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequence for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequence for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for ADC module.
+ *
+ * This function gets the clock frequence for ADC module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetAdcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequence for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequence for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for eFlexPWM module.
+ *
+ * This function gets the clock frequence for eFlexPWM module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetPwmFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFastPeripheralClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequence for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequence for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequence for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequence for UART module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequence for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for ENC module
+ *
+ * This function gets the clock frequence for ENC module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetEncFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for XBAR module
+ *
+ * This function gets the clock frequence for XBAR module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetXbarFreq(uint32_t instance);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets the clock frequency for AOI module
+ *
+ * This function gets the clock frequence for AOI module.
+ * @param instance module device instance
+ * @return freq clock frequence for this module
+ */
+uint32_t CLOCK_SYS_GetAoiFreq(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableDmaClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableDmaClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetDmaGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableDmamuxClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableDmamuxClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetDmamuxGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableEwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableEwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetEwmGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableFtfClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableFtfClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetFtfGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableCrcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableCrcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetCrcGateCmd(g_simBase[0], instance);
+}
+
+
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ SIM_HAL_EnableAdcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ SIM_HAL_DisableAdcClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetAdcGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableCmpClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableCmpClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetCmpGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ SIM_HAL_EnableDacClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ SIM_HAL_DisableDacClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetDacGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnablePdbClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisablePdbClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetPdbGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ SIM_HAL_EnableFtmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ SIM_HAL_DisableFtmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetFtmGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnablePitClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisablePitClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetPitGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableLptmrClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableLptmrClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetLptmrGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for FLEXCAN module.
+ *
+ * This function enables the clock for FLEXCAN moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFlexcanClock(uint32_t instance)
+{
+ SIM_HAL_EnableFlexcanClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for FLEXCAN module.
+ *
+ * This function disables the clock for FLEXCAN moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFlexcanClock(uint32_t instance)
+{
+ SIM_HAL_DisableFlexcanClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for FLEXCAN module.
+ *
+ * This function will get the clock gate state for FLEXCAN moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFlexcanGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetFlexcanGateCmd(g_simBase[0], instance);
+}
+
+ /*!
+ * @brief Gets FLEXCAN clock frequency.
+ *
+ * This function gets the FLEXCAN clock frequency.
+ *
+ * @param instance module device instance
+ * @param flexcanSrc clock source
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexcanFreq(uint8_t instance, clock_flexcan_src_t flexcanSrc);
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ SIM_HAL_EnableSpiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ SIM_HAL_DisableSpiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetSpiGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ SIM_HAL_EnableI2cClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ SIM_HAL_DisableI2cClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetI2cGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ SIM_HAL_EnableUartClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ SIM_HAL_DisableUartClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetUartGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for eFlexPWM module.
+ *
+ * This function enables the clock for eFlexPWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePwmClock(uint32_t instance)
+{
+ SIM_HAL_EnablePwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for eFlexPWM module.
+ *
+ * This function disables the clock for eFlexPWM moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePwmClock(uint32_t instance)
+{
+ SIM_HAL_DisablePwmClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for eFlexPWM module.
+ *
+ * This function will get the clock gate state for eFlexPWM moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetPwmGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for AOI module.
+ *
+ * This function enables the clock for AOI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableAoiClock(uint32_t instance)
+{
+ SIM_HAL_EnableAoiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for AOI module.
+ *
+ * This function disables the clock for AOI moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableAoiClock(uint32_t instance)
+{
+ SIM_HAL_DisableAoiClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for AOI module.
+ *
+ * This function will get the clock gate state for AOI moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetAoiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetAoiGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for XBAR module.
+ *
+ * This function enables the clock for XBAR moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableXbarClock(uint32_t instance)
+{
+ SIM_HAL_EnableXbarClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for XBAR module.
+ *
+ * This function disables the clock for XBAR moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableXbarClock(uint32_t instance)
+{
+ SIM_HAL_DisableXbarClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for XBAR module.
+ *
+ * This function will get the clock gate state for XBAR moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetXbarGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetXbarGateCmd(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Enable the clock for ENC module.
+ *
+ * This function enables the clock for ENC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEncClock(uint32_t instance)
+{
+ SIM_HAL_EnableEncClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Disable the clock for ENC module.
+ *
+ * This function disables the clock for ENC moudle.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEncClock(uint32_t instance)
+{
+ SIM_HAL_DisableEncClock(g_simBase[0], instance);
+}
+
+/*!
+ * @brief Get the the clock gate state for ENC module.
+ *
+ * This function will get the clock gate state for ENC moudle.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEncGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetEncGateCmd(g_simBase[0], instance);
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KV46F15_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKW01Z4/fsl_clock_MKW01Z4.c b/KSDK_1.2.0/platform/system/src/clock/MKW01Z4/fsl_clock_MKW01Z4.c
new file mode 100755
index 0000000..7ea8af3
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKW01Z4/fsl_clock_MKW01Z4.c
@@ -0,0 +1,1012 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_sim_hal.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_clock_manager.h"
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT]; /* TPM_CLK */
+#if FSL_FEATURE_SOC_USB_COUNT
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+#endif
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ 0U,
+ 0U,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+
+ CLOCK_HAL_SetOutDiv(SIM, 2U, 0U, 0U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+ /*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the systen clock frequency.
+ * This function gets the systen clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ freq >>= 1U; /* divided by 2 for special divider */
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return CLOCK_SYS_GetExternalRefClock32kFreq() >> 15U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCopFreq
+ * Description : Gets COP clock frequency.
+ * This function gets the COP clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc)
+{
+ if (kClockCopSrcLpoClk == copSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcFreq
+ * Description : Gets rtc clock frequency.
+ * This function gets rtc clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmfFreq
+ * Description : Gets the clock frequency for TPM module.
+ * This function gets the clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_tpm_src_t src;
+
+ src = CLOCK_HAL_GetTpmSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockTpmSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockTpmSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockTpmSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmExternalFreq
+ * Description : Gets the external clock frequency for TPM module.
+ * This function gets the external clock frequency for TPM moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance)
+{
+ sim_tpm_clk_sel_t src = CLOCK_SYS_GetTpmExternalSrc(instance);
+
+ if (kSimTpmClkSel0 == src)
+ {
+ return g_tpmClkFreq[0];
+ }
+ else
+ {
+ return g_tpmClkFreq[1];
+ }
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ return freq;
+ }
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpifFreq
+ * Description : Gets the clock frequency for SPI module.
+ * This function gets the clock frequency for SPI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cfFreq
+ * Description : Gets the clock frequency for I2C module.
+ * This function gets the clock frequency for I2C moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetBusClockFreq(); /* BUS CLOCK */
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq(); /* SYSTEM CLOCK*/
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLpsciFreq
+ * Description : Gets the clock frequency for LPSCI module.
+ * This function gets the clock frequency for LPSCI moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance)
+{
+ uint32_t freq;
+ clock_lpsci_src_t src;
+
+ src = CLOCK_HAL_GetLpsciSrc(SIM, instance);
+
+ switch(src)
+ {
+ case kClockLpsciSrcPllFllSel: /* FLL/PLL */
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+ break;
+ case kClockLpsciSrcOsc0erClk: /* OSCERCLK */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockLpsciSrcMcgIrClk: /* MCGIRCLK. */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART moudle.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq = 0;
+
+ switch (instance)
+ {
+ case 0:
+ case 1:
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Lpsci instance table. */
+static const sim_clock_gate_name_t lpsciGateTable[] =
+{
+ kSimClockGateLpsci0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function disable the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetLpsciGateCmd
+ * Description : Get the the clock gate state for LPSCI module
+ * This function will get the clock gate state for LPSCI moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, lpsciGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableLpsciClock
+ * Description : Enable the clock for LPSCI module
+ * This function enables the clock for LPSCI moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance)
+{
+ assert(instance < sizeof(lpsciGateTable)/sizeof(lpsciGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, lpsciGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ (sim_clock_gate_name_t)(-1),
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t tpmGateTable[] =
+{
+ kSimClockGateTpm0,
+ kSimClockGateTpm1,
+ kSimClockGateTpm2
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableTpmClock
+ * Description : Enable the clock for TPM module
+ * This function enables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableTpmClock
+ * Description : Disable the clock for TPM module
+ * This function disables the clock for TPM moudle
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableTpmClock(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, tpmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTpmGateCmd
+ * Description : Get the the clock gate state for TPM module
+ * This function will get the clock gate state for TPM moudle.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(tpmGateTable)/sizeof(tpmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, tpmGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKW01Z4/fsl_clock_MKW01Z4.h b/KSDK_1.2.0/platform/system/src/clock/MKW01Z4/fsl_clock_MKW01Z4.h
new file mode 100755
index 0000000..5b8be7e
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKW01Z4/fsl_clock_MKW01Z4.h
@@ -0,0 +1,1236 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KW01Z4_H__)
+#define __FSL_CLOCK_KW01Z4_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kl46z4 */
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief TPM external clock source count. */
+#define TPM_EXT_CLK_COUNT 2
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+
+/*! @brief TPM external clock frequency(TPM_CLK). */
+extern uint32_t g_tpmClkFreq[TPM_EXT_CLK_COUNT];
+#if FSL_FEATURE_SOC_USB_COUNT
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+#endif
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} osc_user_config_kw01z4_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @}*/
+
+/*! @addtogroup clock_manager*/
+/*! @{*/
+
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the COP clock frequency.
+ *
+ * This function gets the COP clock frequency.
+ *
+ * @param instance module device instance
+ * @param copSrc COP clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetCopFreq(uint32_t instance, clock_cop_src_t copSrc);
+
+ /*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+/*!
+ * @brief Gets TPM clock frequency.
+ *
+ * This function gets the TPM clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM clock source selection.
+ *
+ * This function sets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @param tpmSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetTpmSrc(uint32_t instance, clock_tpm_src_t tpmSrc)
+{
+ CLOCK_HAL_SetTpmSrc(SIM, instance, tpmSrc);
+}
+
+/*!
+ * @brief Get the TPM clock source selection.
+ *
+ * This function gets the TPM clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_tpm_src_t CLOCK_SYS_GetTpmSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTpmSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the TPM external clock source frequency.
+ *
+ * This function gets the TPM external clock source frequency.
+ *
+ * @param instance IP instance.
+ * @return TPM external clock frequency.
+ */
+uint32_t CLOCK_SYS_GetTpmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @param src TPM external clock source.
+ */
+static inline void CLOCK_SYS_SetTpmExternalSrc(uint32_t instance, sim_tpm_clk_sel_t src)
+{
+ SIM_HAL_SetTpmExternalClkPinSelMode(SIM, instance, src);
+}
+
+/*!
+ * @brief Set the TPM external clock source selection.
+ *
+ * This function sets the TPM external clock source selection.
+ *
+ * @param instance IP instance.
+ * @return setting Current TPM external clock source.
+ */
+static inline sim_tpm_clk_sel_t CLOCK_SYS_GetTpmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetTpmExternalClkPinSelMode(SIM, instance);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function sets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @param usbfsSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Get the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * This function gets the selection of the clock source for the USB FS 48 MHz clock.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance);
+
+ /*!
+ * @brief Gets the clock frequency for LPSCI module.
+ *
+ * This function gets the clock frequency for LPSCI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetLpsciFreq(uint32_t instance);
+
+/*!
+ * @brief Set the LPSCI clock source selection.
+ *
+ * This function sets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @param lpsciSrc The value to set.
+ */
+static inline void CLOCK_SYS_SetLpsciSrc(uint32_t instance, clock_lpsci_src_t lpsciSrc)
+{
+ CLOCK_HAL_SetLpsciSrc(SIM, instance, lpsciSrc);
+}
+
+/*!
+ * @brief Get the LPSCI clock source selection.
+ *
+ * This function gets the LPSCI clock source selection.
+ *
+ * @param instance IP instance.
+ * @return Current selection.
+ */
+static inline clock_lpsci_src_t CLOCK_SYS_GetLpsciSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetLpsciSrc(SIM, instance);
+}
+
+/*!
+ * @brief Get the UART clock frequency.
+ *
+ * This function gets the UART clock frequency.
+ *
+ * @param instance IP instance.
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_LCD_COUNT
+/*!
+ * @brief Enable the clock for SLCD module.
+ *
+ * This function enables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Disable the clock for SLCD module.
+ *
+ * This function disables the clock for SLCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSlcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SLCD module.
+ *
+ * This function will get the clock gate state for SLCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSlcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSlcd0);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD default clock.
+ *
+ * This function gets the frequency for SLCD default clock.
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdDefaultFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetExternalRefClock32kFreq();
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate clock.
+ *
+ * This function gets the frequency for SLCD alternate clock (ALTSOURCE = 0).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAltFreq(uint32_t instance)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the frequency for SLCD alternate 2 clock.
+ *
+ * This function gets the frequency for SLCD alternate 2 clock (ALTSOURCE = 1).
+ *
+ * @param instance module device instance.
+ * @return freq clock frequency for this module.
+ */
+static inline uint32_t CLOCK_SYS_GetSlcdAlt2Freq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+#endif// FSL_FEATURE_SOC_LCD_COUNT
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp0);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for TPM module.
+ *
+ * This function enables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for TPM module.
+ *
+ * This function disables the clock for TPM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableTpmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for TPM module.
+ *
+ * This function will get the clock gate state for TPM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetTpmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for TSI module.
+ *
+ * This function enables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableTsiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Disable the clock for TSI module.
+ *
+ * This function disables the clock for TSI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableTsiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Get the the clock gate state for TSI module.
+ *
+ * This function will get the clock gate state for TSI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetTsiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateTsi0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for LPSCI module.
+ *
+ * This function enables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for LPSCI module.
+ *
+ * This function disables the clock for LPSCI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableLpsciClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for LPSCI module.
+ *
+ * This function will get the clock gate state for LPSCI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetLpsciGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+#if FSL_FEATURE_SOC_USB_COUNT
+/*!
+ * @brief Set the USB external clock frequency(USB_CLKIN).
+ *
+ * This function sets the USB external clock frequency (USB_CLKIN).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetUsbExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < USB_EXT_CLK_COUNT);
+
+ g_usbClkInFreq[srcInstance] = freq;
+}
+#endif// FSL_FEATURE_SOC_USB_COUNT
+
+/*!
+ * @brief Set the TPM external clock frequency(TPM_CLKx).
+ *
+ * This function sets the TPM external clock frequency (TPM_CLKx).
+ *
+ * @param srcInstance External source instance.
+ * @param freq Frequcney value.
+ */
+static inline void CLOCK_SYS_SetTpmExternalFreq(uint32_t srcInstance, uint32_t freq)
+{
+ assert(srcInstance < TPM_EXT_CLK_COUNT);
+
+ g_tpmClkFreq[srcInstance] = freq;
+}
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KW01Z4_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKW21D5/fsl_clock_MKW21D5.c b/KSDK_1.2.0/platform/system/src/clock/MKW21D5/fsl_clock_MKW21D5.c
new file mode 100755
index 0000000..4e8f36b
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKW21D5/fsl_clock_MKW21D5.c
@@ -0,0 +1,861 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_osc_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 1U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG) / 2U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq() / 2U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case 3:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case 4:
+ case 5:
+
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKW21D5/fsl_clock_MKW21D5.h b/KSDK_1.2.0/platform/system/src/clock/MKW21D5/fsl_clock_MKW21D5.h
new file mode 100755
index 0000000..3866c96
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKW21D5/fsl_clock_MKW21D5.h
@@ -0,0 +1,1436 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KW21DA5_H__)
+#define __FSL_CLOCK_KW21DA5_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kw21d5*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kw21d5_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @brief Default clock configuration number. */
+#define CLOCK_CONFIG_NUM 2
+
+/*! @brief Clock configuration index for VLPR mode. */
+#define CLOCK_CONFIG_INDEX_FOR_VLPR 0
+
+/*! @brief Clock configuration index for RUN mode. */
+#define CLOCK_CONFIG_INDEX_FOR_RUN 1
+
+/*! @} */
+/*! @addtogroup clock_manager*/
+/*! @{*/
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KW21DA5_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKW22D5/fsl_clock_MKW22D5.c b/KSDK_1.2.0/platform/system/src/clock/MKW22D5/fsl_clock_MKW22D5.c
new file mode 100755
index 0000000..8ab1d63
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKW22D5/fsl_clock_MKW22D5.c
@@ -0,0 +1,891 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_osc_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 1U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG) / 2U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq() / 2U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case 3:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case 4:
+ case 5:
+
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKW22D5/fsl_clock_MKW22D5.h b/KSDK_1.2.0/platform/system/src/clock/MKW22D5/fsl_clock_MKW22D5.h
new file mode 100755
index 0000000..bf386fd
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKW22D5/fsl_clock_MKW22D5.h
@@ -0,0 +1,1460 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KW22DA5_H__)
+#define __FSL_CLOCK_KW22DA5_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kw22d5*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kw22d5_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @brief Default clock configuration number. */
+#define CLOCK_CONFIG_NUM 2
+
+/*! @brief Clock configuration index for VLPR mode. */
+#define CLOCK_CONFIG_INDEX_FOR_VLPR 0
+
+/*! @brief Clock configuration index for RUN mode. */
+#define CLOCK_CONFIG_INDEX_FOR_RUN 1
+
+/*! @} */
+/*! @addtogroup clock_manager*/
+/*! @{*/
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KW22DA5_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKW24D5/fsl_clock_MKW24D5.c b/KSDK_1.2.0/platform/system/src/clock/MKW24D5/fsl_clock_MKW24D5.c
new file mode 100755
index 0000000..8ab1d63
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKW24D5/fsl_clock_MKW24D5.c
@@ -0,0 +1,891 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_device_registers.h"
+#include "fsl_mcg_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_osc_hal.h"
+#include "fsl_clock_manager.h"
+
+/*
+ * README:
+ * This file should provide these APIs:
+ * 1. APIs to get the frequency of output clocks in Reference Manual ->
+ * Chapter Clock Distribution -> Figure Clocking diagram.
+ * 2. APIs for IP modules listed in Reference Manual -> Chapter Clock Distribution
+ * -> Module clocks.
+ */
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT]; /* USB_CLKIN */
+uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT]; /* FTM_CLK0 */
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_FllStableDelay
+ * Description : This funtion is used to delay for FLL stable.
+ * According to datasheet, every time the FLL reference source or reference
+ * divider is changed, trim value is changed, DMX32 bit is changed, DRS bits
+ * are changed, or changing from FLL disabled (BLPE, BLPI) to FLL enabled
+ * (FEI, FEE, FBE, FBI), there should be 1ms delay for FLL stable. Please
+ * check datasheet for t(fll_aquire).
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_FllStableDelay(void)
+{
+ uint32_t coreClk = CLOCK_SYS_GetCoreClockFreq();
+
+ coreClk /= 3000U;
+
+ // Delay 1 ms.
+ while (coreClk--)
+ {
+ __asm ("nop");
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetSimConfigration
+ * Description : This funtion sets the SIM registers for clock transitiom.
+ *
+ *END**************************************************************************/
+static void CLOCK_SYS_SetSimConfigration(sim_config_t const *simConfig)
+{
+ CLOCK_HAL_SetOutDiv(SIM,
+ simConfig->outdiv1,
+ simConfig->outdiv2,
+ simConfig->outdiv3,
+ simConfig->outdiv4);
+
+ CLOCK_HAL_SetPllfllSel(SIM, simConfig->pllFllSel);
+
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, simConfig->er32kSrc);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetConfiguration
+ * Description : This funtion sets the system to target configuration, it
+ * only sets the clock modules registers for clock mode change, but not send
+ * notifications to drivers.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_SetConfiguration(clock_manager_user_config_t const* config)
+{
+ assert(NULL != config);
+
+ /* Set outdiv for safe output clock frequency. */
+ CLOCK_HAL_SetOutDiv(SIM, 0U, 1U, 1U, 4U);
+
+ /* Set MCG mode. */
+ CLOCK_SYS_SetMcgMode(&config->mcgConfig, CLOCK_SYS_FllStableDelay);
+
+ /* Set SIM setting. */
+ CLOCK_SYS_SetSimConfigration(&config->simConfig);
+
+ /* Set OSCERCLK setting. */
+ CLOCK_SYS_SetOscerConfigration(0, &config->oscerConfig);
+ SystemCoreClock = CLOCK_SYS_GetCoreClockFreq();
+
+ return kClockManagerSuccess;
+}
+
+clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
+ uint32_t *frequency)
+{
+ clock_manager_error_code_t returnCode = kClockManagerSuccess;
+
+ switch (clockName)
+ {
+ case kCoreClock:
+ case kSystemClock:
+ *frequency = CLOCK_SYS_GetCoreClockFreq();
+ break;
+ case kPlatformClock:
+ *frequency = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case kBusClock:
+ *frequency = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case kFlashClock:
+ *frequency = CLOCK_SYS_GetFlashClockFreq();
+ break;
+ case kOsc32kClock:
+ *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kOsc0ErClock:
+ *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kRtcoutClock:
+ *frequency = CLOCK_SYS_GetRtcOutFreq();
+ break;
+ case kMcgFfClock:
+ *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
+ break;
+ case kMcgFllClock:
+ *frequency = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kMcgPll0Clock:
+ *frequency = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kMcgOutClock:
+ *frequency = CLOCK_HAL_GetOutClk(MCG);
+ break;
+ case kMcgIrClock:
+ *frequency = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kLpoClock:
+ *frequency = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kSystickClock:
+ *frequency = CLOCK_SYS_GetSystickFreq();
+ break;
+ default:
+ *frequency = 0U;
+ returnCode = kClockManagerNoSuchClockName;
+ break;
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCoreClockFreq
+ * Description : Gets the core clock frequency.
+ * This function gets the core clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetCoreClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSystemClockFreq
+ * Description : Gets the system clock frequency.
+ * This function gets the system clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSystemClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv1(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetBusClockFreq
+ * Description : Gets the bus clock frequency.
+ * This function gets the bus clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetBusClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv2(SIM) + 1);
+}
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFlashClockFreq
+ * Description : Gets the flash clock frequency.
+ * This function gets the flash clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFlashClockFreq(void)
+{
+ return CLOCK_HAL_GetOutClk(MCG) / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPllFllClockFreq
+ * Description : Gets the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void)
+{
+ uint32_t freq;
+ clock_pllfll_sel_t src;
+
+ src = CLOCK_HAL_GetPllfllSel(SIM);
+
+ switch (src)
+ {
+ case kClockPllFllSelFll:
+ freq = CLOCK_HAL_GetFllClk(MCG);
+ break;
+ case kClockPllFllSelPll:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetRtcOutFreq
+ * Description : Gets the RTC_CLKOUT frequency.
+ * This function gets RTC_CLKOUT clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetRtcOutFreq(void)
+{
+ if (kClockRtcoutSrc1Hz == CLOCK_SYS_GetRtcOutSrc())
+ {
+ return g_xtalRtcClkFreq >> 15U;
+ }
+ else
+ {
+ return g_xtalRtcClkFreq;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetExternalRefClockFreq
+ * Description : Gets the ERCLK32K clock frequency.
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void)
+{
+ clock_er32k_src_t src;
+ uint32_t freq;
+
+ src = CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+ switch (src)
+ {
+ case kClockEr32kSrcOsc0: /* OSC 32k clock */
+ freq = (32768U == g_xtal0ClkFreq) ? 32768U : 0U;
+ break;
+ case kClockEr32kSrcRtc: /* RTC 32k clock */
+ freq = g_xtalRtcClkFreq;
+ break;
+ case kClockEr32kSrcLpo: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetOsc0ExternalRefClockFreq
+ * Description : Gets OSC0ERCLK.
+ * This function gets the OSC0 external reference frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void)
+{
+ if (OSC_HAL_GetExternalRefClkCmd(g_oscBase[0]))
+ {
+ return g_xtal0ClkFreq;
+ }
+ else
+ {
+ return 0U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetWdogFreq
+ * Description : Gets watch dog clock frequency.
+ * This function gets the watch dog clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc)
+{
+ if (kClockWdogSrcLpoClk == wdogSrc)
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetTraceFreq
+ * Description : Gets debug trace clock frequency.
+ * This function gets the debug trace clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance)
+{
+ clock_trace_src_t src = CLOCK_HAL_GetTraceClkSrc(SIM);
+
+ if (kClockTraceSrcMcgoutClk == src)
+ {
+ return CLOCK_HAL_GetOutClk(MCG) / 2U;
+ }
+ else
+ {
+ return CLOCK_SYS_GetCoreClockFreq() / 2U;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortFilterFreq
+ * Description : Gets PORTx digital input filter clock frequency.
+ * This function gets the PORTx digital input filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src)
+{
+ if (kClockPortFilterSrcBusClk == src)
+ {
+ return CLOCK_SYS_GetBusClockFreq();
+ }
+ else
+ {
+ return CLOCK_SYS_GetLpoClockFreq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetLptmrFreq
+ * Description : Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc)
+{
+ uint32_t freq;
+
+ switch (lptmrSrc)
+ {
+ case kClockLptmrSrcMcgIrClk: /* MCG out clock */
+ freq = CLOCK_HAL_GetInternalRefClk(MCG);
+ break;
+ case kClockLptmrSrcLpoClk: /* LPO clock */
+ freq = CLOCK_SYS_GetLpoClockFreq();
+ break;
+ case kClockLptmrSrcEr32kClk: /* ERCLK32K clock */
+ freq = CLOCK_SYS_GetExternalRefClock32kFreq();
+ break;
+ case kClockLptmrSrcOsc0erClk: /* OSCERCLK clock */
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUsbfFreq
+ * Description : Gets the clock frequency for USB FS OTG module.
+ * This function gets the clock frequency for USB FS OTG module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance)
+{
+ uint8_t usbdiv, usbfrac;
+ uint32_t freq;
+ clock_usbfs_src_t src;
+
+ src = CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+
+ if (kClockUsbfsSrcExt == src)
+ {
+ return g_usbClkInFreq[0]; /* USB_CLKIN */
+ }
+ else
+ {
+ freq = CLOCK_SYS_GetPllFllClockFreq();
+
+ CLOCK_HAL_GetUsbfsDiv(SIM, &usbdiv, &usbfrac);
+ return freq * (usbfrac + 1) / (usbdiv + 1);
+ }
+}
+
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetUartFreq
+ * Description : Gets the clock frequency for UART module.
+ * This function gets the clock frequency for UART module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
+{
+ uint32_t freq;
+
+ switch (instance)
+ {
+ case 0:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 1:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ case 2:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case 3:
+ freq = CLOCK_SYS_GetBusClockFreq();
+ break;
+ case 4:
+ case 5:
+
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSaiFreq
+ * Description : Gets the clock frequency for SAI module
+ * This function gets the clock frequency for SAI module.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc)
+{
+ uint32_t freq;
+ switch (saiSrc)
+ {
+ case kClockSaiSrcPllClk:
+ freq = CLOCK_HAL_GetPll0Clk(MCG);
+ break;
+ case kClockSaiSrcOsc0erClk:
+ freq = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+ break;
+ case kClockSaiSrcSysClk:
+ freq = CLOCK_SYS_GetSystemClockFreq();
+ break;
+ default:
+ freq = 0U;
+ break;
+ }
+
+ return freq;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmExternalFreq
+ * Description : Gets FTM external clock frequency.
+ *
+ *END**************************************************************************/
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance)
+{
+ sim_ftm_clk_sel_t sel = SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+
+ if (kSimFtmClkSel0 == sel)
+ {
+ return g_ftmClkFreq[0];
+ }
+ else
+ {
+ return g_ftmClkFreq[1];
+ }
+}
+
+/* PORT instance table. */
+static const sim_clock_gate_name_t portGateTable[] =
+{
+ kSimClockGatePortA,
+ kSimClockGatePortB,
+ kSimClockGatePortC,
+ kSimClockGatePortD,
+ kSimClockGatePortE
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnablePortClock
+ * Description : Enable the clock for PORT module
+ * This function enables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisablePortClock
+ * Description : Disable the clock for PORT module
+ * This function disables the clock for PORT module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisablePortClock(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, portGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetPortGateCmd
+ * Description : Get the the clock gate state for PORT module
+ * This function will get the clock gate state for PORT module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(portGateTable)/sizeof(portGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, portGateTable[instance]);
+}
+
+/* ADC instance table. */
+static const sim_clock_gate_name_t adcGateTable[] =
+{
+ kSimClockGateAdc0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableAdcClock
+ * Description : Enable the clock for ADC module
+ * This function enables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableAdcClock
+ * Description : Disable the clock for ADC module
+ * This function disables the clock for ADC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableAdcClock(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, adcGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetAdcGateCmd
+ * Description : Get the the clock gate state for ADC module
+ * This function will get the clock gate state for ADC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(adcGateTable)/sizeof(adcGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, adcGateTable[instance]);
+}
+
+/* DAC instance table. */
+static const sim_clock_gate_name_t dacGateTable[] =
+{
+ kSimClockGateDac0
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableDacClock
+ * Description : Enable the clock for DAC module
+ * This function enables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ SIM_HAL_EnableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableDacClock
+ * Description : Disable the clock for DAC module
+ * This function disables the clock for DAC module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableDacClock(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, dacGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetDacGateCmd
+ * Description : Get the the clock gate state for DAC module
+ * This function will get the clock gate state for DAC module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(dacGateTable)/sizeof(dacGateTable[0]));
+ return SIM_HAL_GetGateCmd(SIM, dacGateTable[instance]);
+}
+
+/* FTM instance table. */
+static const sim_clock_gate_name_t ftmGateTable[] =
+{
+ kSimClockGateFtm0,
+ kSimClockGateFtm1,
+ kSimClockGateFtm2,
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableFtmClock
+ * Description : Enable the clock for FTM module
+ * This function enables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableFtmClock
+ * Description : Disable the clock for FTM module
+ * This function disables the clock for FTM module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableFtmClock(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, ftmGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetFtmGateCmd
+ * Description : Get the the clock gate state for FTM module
+ * This function will get the clock gate state for FTM module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(ftmGateTable)/sizeof(ftmGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, ftmGateTable[instance]);
+}
+
+/* SPI instance table. */
+static const sim_clock_gate_name_t spiGateTable[] =
+{
+ kSimClockGateSpi0,
+ kSimClockGateSpi1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableSpiClock
+ * Description : Enable the clock for SPI module
+ * This function enables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableSpiClock
+ * Description : Disable the clock for SPI module
+ * This function disables the clock for SPI module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableSpiClock(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, spiGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetSpiGateCmd
+ * Description : Get the the clock gate state for SPI module
+ * This function will get the clock gate state for SPI module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(spiGateTable)/sizeof(spiGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, spiGateTable[instance]);
+}
+
+/* I2C instance table. */
+static const sim_clock_gate_name_t i2cGateTable[] =
+{
+ kSimClockGateI2c0,
+ kSimClockGateI2c1
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_EnableI2cClock
+ * Description : Enable the clock for I2C module
+ * This function enables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_DisableI2cClock
+ * Description : Disable the clock for I2C module
+ * This function disables the clock for I2C module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableI2cClock(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+ SIM_HAL_DisableClock(SIM, i2cGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetI2cGateCmd
+ * Description : Get the the clock gate state for I2C module
+ * This function will get the clock gate state for I2C module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(i2cGateTable)/sizeof(i2cGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, i2cGateTable[instance]);
+}
+
+/* Uart instance table. */
+static const sim_clock_gate_name_t uartGateTable[] =
+{
+ kSimClockGateUart0,
+ kSimClockGateUart1,
+ kSimClockGateUart2,
+ kSimClockGateUart3
+};
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_EnableUartClock
+ * Description : Enable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_EnableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_EnableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_DisableUartClock
+ * Description : Disable the clock for UART module
+ * This function enables the clock for UART module
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_DisableUartClock(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ SIM_HAL_DisableClock(SIM, uartGateTable[instance]);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : SIM_HAL_GetUartGateCmd
+ * Description : Get the the clock gate state for UART module
+ * This function will get the clock gate state for UART module.
+ *
+ *END**************************************************************************/
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance)
+{
+ assert(instance < sizeof(uartGateTable)/sizeof(uartGateTable[0]));
+
+ return SIM_HAL_GetGateCmd(SIM, uartGateTable[instance]);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/clock/MKW24D5/fsl_clock_MKW24D5.h b/KSDK_1.2.0/platform/system/src/clock/MKW24D5/fsl_clock_MKW24D5.h
new file mode 100755
index 0000000..3add713
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/MKW24D5/fsl_clock_MKW24D5.h
@@ -0,0 +1,1460 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__FSL_CLOCK_KW24DA5_H__)
+#define __FSL_CLOCK_KW24DA5_H__
+
+#include "fsl_mcg_hal.h"
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_osc_hal.h"
+
+/*! @addtogroup clock_manager_kw24d5*/
+/*! @{*/
+
+/*! @file*/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/*! @brief USB external clock source count. */
+#define USB_EXT_CLK_COUNT 1
+/*! @brief FTM external clock source count. */
+#define FTM_EXT_CLK_COUNT 2
+
+/*! @brief USB external clock frequency(USB_CLKIN). */
+extern uint32_t g_usbClkInFreq[USB_EXT_CLK_COUNT];
+/*! @brief FTM external clock frequency(FTM_CLK). */
+extern uint32_t g_ftmClkFreq[FTM_EXT_CLK_COUNT];
+
+/*!@brief SIM configuration structure for dynamic clock setting. */
+typedef struct SimConfig
+{
+ clock_pllfll_sel_t pllFllSel; /*!< PLL/FLL/IRC48M selection. */
+ clock_er32k_src_t er32kSrc; /*!< ERCLK32K source selection. */
+ uint8_t outdiv1, outdiv2, outdiv3, outdiv4; /*!< OUTDIV setting. */
+#if (defined(DOXYGEN_OUTPUT) && (DOXYGEN_OUTPUT))
+} sim_config_kw24d5_t;
+#else
+} sim_config_t;
+#endif
+
+/*! @brief Default clock configuration number. */
+#define CLOCK_CONFIG_NUM 2
+
+/*! @brief Clock configuration index for VLPR mode. */
+#define CLOCK_CONFIG_INDEX_FOR_VLPR 0
+
+/*! @brief Clock configuration index for RUN mode. */
+#define CLOCK_CONFIG_INDEX_FOR_RUN 1
+
+/*! @} */
+/*! @addtogroup clock_manager*/
+/*! @{*/
+/*******************************************************************************
+ * API
+ ******************************************************************************/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* __cplusplus*/
+
+/*!
+ * @brief Sets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function sets divide value OUTDIV1.
+ *
+ * @param outdiv1 Outdivider1 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv1(uint8_t outdiv1)
+{
+ CLOCK_HAL_SetOutDiv1(SIM, outdiv1);
+}
+
+/*!
+ * @brief Gets the clock out divider1 setting(OUTDIV1).
+ *
+ * This function gets divide value OUTDIV1.
+ *
+ * @return Outdivider1 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv1(void)
+{
+ return CLOCK_HAL_GetOutDiv1(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function sets divide value OUTDIV2.
+ *
+ * @param outdiv2 Outdivider2 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv2(uint8_t outdiv2)
+{
+ CLOCK_HAL_SetOutDiv2(SIM, outdiv2);
+}
+
+/*!
+ * @brief Gets the clock out divider2 setting(OUTDIV2).
+ *
+ * This function gets divide value OUTDIV2.
+ *
+ * @return Outdivider2 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv2(void)
+{
+ return CLOCK_HAL_GetOutDiv2(SIM);
+}
+
+/*!
+ * @brief Sets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function sets divide value OUTDIV4.
+ *
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv4(uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv4(SIM, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out divider4 setting(OUTDIV4).
+ *
+ * This function gets divide value OUTDIV4.
+ *
+ * @return Outdivider4 setting
+ */
+static inline uint8_t CLOCK_SYS_GetOutDiv4(void)
+{
+ return CLOCK_HAL_GetOutDiv4(SIM);
+}
+
+/*!
+ * @brief Sets the clock out dividers setting.
+ *
+ * This function sets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_SetOutDiv(uint8_t outdiv1, uint8_t outdiv2,
+ uint8_t outdiv3, uint8_t outdiv4)
+{
+ CLOCK_HAL_SetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Gets the clock out dividers setting.
+ *
+ * This function gets the setting for all clock out dividers at the same time.
+ *
+ * @param outdiv1 Outdivider1 setting
+ * @param outdiv2 Outdivider2 setting
+ * @param outdiv3 Outdivider3 setting
+ * @param outdiv4 Outdivider4 setting
+ */
+static inline void CLOCK_SYS_GetOutDiv(uint8_t *outdiv1, uint8_t *outdiv2,
+ uint8_t *outdiv3, uint8_t *outdiv4)
+{
+ CLOCK_HAL_GetOutDiv(SIM, outdiv1, outdiv2, outdiv3, outdiv4);
+}
+
+/*!
+ * @brief Get flexbus clock frequency.
+ *
+ * This function gets the flexbus clock frequency.
+ *
+ * @return Current flexbus clock frequency.
+ */
+uint32_t CLOCK_SYS_GetFlexbusFreq(void);
+
+/*!
+ * @brief Get the MCGPLLCLK/MCGFLLCLK/IRC48MCLK clock frequency.
+ *
+ * This function gets the frequency of the MCGPLLCLK/MCGFLLCLK/IRC48MCLK.
+ *
+ * @return Current clock frequency.
+ */
+uint32_t CLOCK_SYS_GetPllFllClockFreq(void);
+
+/*!
+ * @brief Set PLL/FLL clock selection.
+ *
+ * This function sets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @param setting The value to set.
+ */
+static inline void CLOCK_SYS_SetPllfllSel(clock_pllfll_sel_t setting)
+{
+ CLOCK_HAL_SetPllfllSel(SIM, setting);
+}
+
+/*!
+ * @brief Get PLL/FLL clock selection.
+ *
+ * This function gets the selection of the high frequency clock for
+ * various peripheral clocking options
+ *
+ * @return Current selection.
+ */
+static inline clock_pllfll_sel_t CLOCK_SYS_GetPllfllSel(void)
+{
+ return CLOCK_HAL_GetPllfllSel(SIM);
+}
+
+/*!
+ * @brief Gets the MCGFFCLK clock frequency.
+ *
+ * This function gets the MCG fixed frequency clock (MCGFFCLK) frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFixedFreqClockFreq(void)
+{
+ return CLOCK_HAL_GetFixedFreqClk(MCG);
+}
+
+/*!
+ * @brief Get internal reference clock frequency.
+ *
+ * This function gets the internal reference clock frequency.
+ *
+ * @return Current clock frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetInternalRefClockFreq(void)
+{
+ return CLOCK_HAL_GetInternalRefClk(MCG);
+}
+
+/*!
+ * @brief Gets the external reference 32k clock frequency.
+ *
+ * This function gets the external reference (ERCLK32K) clock frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetExternalRefClock32kFreq(void);
+
+/*!
+ * @brief Set the clock selection of ERCLK32K.
+ *
+ * This function sets the clock selection of ERCLK32K.
+ *
+ * @param src clock source.
+ */
+static inline void CLOCK_SYS_SetExternalRefClock32kSrc(clock_er32k_src_t src)
+{
+ CLOCK_HAL_SetExternalRefClock32kSrc(SIM, src);
+}
+
+/*!
+ * @brief Get the clock selection of ERCLK32K.
+ *
+ * This function gets the clock selection of ERCLK32K.
+ *
+ * @return Current selection.
+ */
+static inline clock_er32k_src_t CLOCK_SYS_GetExternalRefClock32kSrc(void)
+{
+ return CLOCK_HAL_GetExternalRefClock32kSrc(SIM);
+}
+
+/*!
+ * @brief Gets the OSC0ERCLK frequency.
+ *
+ * This function gets the OSC0 external reference frequency.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetOsc0ExternalRefClockFreq(void);
+
+/*!
+ * @brief Gets RTC input clock frequency.
+ *
+ * This function gets the RTC input clock frequency.
+ *
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetRtcFreq(uint32_t instance)
+{
+ return g_xtalRtcClkFreq;
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT frequency.
+ *
+ * This function gets the frequency of RTC_CLKOUT.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetRtcOutFreq(void);
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function gets the source of RTC_CLKOUT. It is determined by RTCCLKOUTSEL.
+ *
+ * @return Current source.
+ */
+static inline clock_rtcout_src_t CLOCK_SYS_GetRtcOutSrc(void)
+{
+ return CLOCK_HAL_GetRtcClkOutSel(SIM);
+}
+
+/*!
+ * @brief Gets RTC_CLKOUT source.
+ *
+ * This function sets the source of RTC_CLKOUT.
+ *
+ * @param src RTC_CLKOUT source to set.
+ */
+static inline void CLOCK_SYS_SetRtcOutSrc(clock_rtcout_src_t src)
+{
+ CLOCK_HAL_SetRtcClkOutSel(SIM, src);
+}
+
+/*!
+ * @brief Gets the watch dog clock frequency.
+ *
+ * This function gets the watch dog clock frequency.
+ *
+ * @param instance module device instance
+ * @param wdogSrc watch dog clock source selection, WDOG_STCTRLH[CLKSRC].
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetWdogFreq(uint32_t instance, clock_wdog_src_t wdogSrc);
+
+/*!
+ * @brief Gets the debug trace clock source.
+ *
+ * This function gets the debug trace clock source.
+ * @param instance module device instance
+ *
+ * @return Current source.
+ */
+static inline clock_trace_src_t CLOCK_SYS_GetTraceSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetTraceClkSrc(SIM);
+}
+
+/*!
+ * @brief Sets the debug trace clock source.
+ *
+ * This function sets the debug trace clock source.
+ * @param instance module device instance.
+ * @param src debug trace clock source.
+ */
+static inline void CLOCK_SYS_SetTraceSrc(uint32_t instance, clock_trace_src_t src)
+{
+ CLOCK_HAL_SetTraceClkSrc(SIM, src);
+}
+
+/*!
+ * @brief Gets the debug trace clock frequency.
+ *
+ * This function gets the debug trace clock frequency.
+ * @param instance module device instance
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetTraceFreq(uint32_t instance);
+
+/*!
+ * @brief Gets PORTx digital input filter clock frequency.
+ *
+ * This function gets the PORTx digital input filter clock frequency.
+ * @param instance module device instance.
+ * @param src PORTx source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetPortFilterFreq(uint32_t instance, clock_port_filter_src_t src);
+
+/*!
+ * @brief Gets LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * This function gets the LPTMRx pre-scaler/glitch filter clock frequency.
+ *
+ * @param instance module device instance
+ * @param lptmrSrc LPTMRx clock source selection.
+ *
+ * @return Current frequency.
+ */
+uint32_t CLOCK_SYS_GetLptmrFreq(uint32_t instance, clock_lptmr_src_t lptmrSrc);
+
+
+/*!
+ * @brief Gets the clock frequency for EWM module.
+ *
+ * This function gets the clock frequency for EWM module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetLpoClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for FTF module. (Flash Memory)
+ *
+ * This function gets the clock frequency for FTF module. (Flash Memory)
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFlashClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CRC module.
+ *
+ * This function gets the clock frequency for CRC module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMP module.
+ *
+ * This function gets the clock frequency for CMP module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for VREF module.
+ *
+ * This function gets the clock frequency for VREF module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PDB module.
+ *
+ * This function gets the clock frequency for PDB module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for PIT module.
+ *
+ * This function gets the clock frequency for PIT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for CMT module.
+ *
+ * This function gets the clock frequency for CMT module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock source for USB FS OTG module
+ *
+ * This function gets the clock source for USB FS OTG module.
+ * @param instance module device instance
+ * @return Clock source.
+ */
+static inline clock_usbfs_src_t CLOCK_SYS_GetUsbfsSrc(uint32_t instance)
+{
+ return CLOCK_HAL_GetUsbfsSrc(SIM, instance);
+}
+
+/*!
+ * @brief Sets the clock source for USB FS OTG module
+ *
+ * This function sets the clock source for USB FS OTG module.
+ * @param instance module device instance.
+ * @param usbfsSrc USB FS clock source setting.
+ */
+static inline void CLOCK_SYS_SetUsbfsSrc(uint32_t instance, clock_usbfs_src_t usbfsSrc)
+{
+ CLOCK_HAL_SetUsbfsSrc(SIM, instance, usbfsSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for USB FS OTG module
+ *
+ * This function gets the clock frequency for USB FS OTG module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUsbfsFreq(uint32_t instance);
+
+/*!
+ * @brief Set USB FS divider setting.
+ *
+ * This function sets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_SetUsbfsDiv(uint32_t instance,
+ uint8_t usbdiv,
+ uint8_t usbfrac)
+{
+ CLOCK_HAL_SetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+/*!
+ * @brief Get USB FS divider setting.
+ *
+ * This function gets USB FS divider setting.
+ * Divider output clock = Divider input clock * [ (USBFSFRAC+1) / (USBFSDIV+1) ]
+ *
+ * @param instance USB FS module instance.
+ * @param usbdiv Value of USBFSDIV.
+ * @param usbfrac Value of USBFSFRAC.
+ */
+static inline void CLOCK_SYS_GetUsbfsDiv(uint32_t instance,
+ uint8_t *usbdiv,
+ uint8_t *usbfrac)
+{
+ CLOCK_HAL_GetUsbfsDiv(SIM, usbdiv, usbfrac);
+}
+
+
+
+/*!
+ * @brief Gets the clock frequency for SAI.
+ *
+ * This function gets the clock frequency for SAI.
+ *
+ * @param instance module device instance.
+ * @param saiSrc SAI clock source selection according to its internal register.
+ * @return freq clock frequency for this module.
+ */
+uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance, clock_sai_src_t saiSrc);
+
+/*!
+ * @brief Gets the clock frequency for USB DCD module
+ *
+ * This function gets the clock frequency for USB DCD module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for SPI module
+ *
+ * This function gets the clock frequency for SPI module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets the clock frequency for I2C module
+ *
+ * This function gets the clock frequency for I2C module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets ADC alternate clock frequency.
+ *
+ * This function gets the ADC alternate clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetAdcAltFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
+}
+
+/*!
+ * @brief Gets FTM fixed frequency clock frequency.
+ *
+ * This function gets the FTM fixed frequency clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmFixedFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetFixedFreqClockFreq();
+}
+
+/*!
+ * @brief Gets FTM's system clock frequency.
+ *
+ * This function gets the FTM's system clock frequency.
+ *
+ * @param instance module device instance
+ * @return Current frequency.
+ */
+static inline uint32_t CLOCK_SYS_GetFtmSystemClockFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetBusClockFreq();
+}
+
+/*!
+ * @brief Gets FTM external clock frequency.
+ *
+ * This function gets the FTM external clock frequency.
+ *
+ * @param instance module device instance
+ * @return freq Current frequency.
+ */
+uint32_t CLOCK_SYS_GetFtmExternalFreq(uint32_t instance);
+
+/*!
+ * @brief Gets FTM external clock source.
+ *
+ * This function gets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @return Ftm external clock source.
+ */
+static inline sim_ftm_clk_sel_t CLOCK_SYS_GetFtmExternalSrc(uint32_t instance)
+{
+ return SIM_HAL_GetFtmExternalClkPinMode(SIM, instance);
+}
+
+/*!
+ * @brief Sets FTM external clock source.
+ *
+ * This function sets the FTM external clock source.
+ *
+ * @param instance module device instance.
+ * @param ftmSrc FTM clock source setting.
+ */
+static inline void CLOCK_SYS_SetFtmExternalSrc(uint32_t instance,
+ sim_ftm_clk_sel_t ftmSrc)
+{
+ SIM_HAL_SetFtmExternalClkPinMode(SIM, instance, ftmSrc);
+}
+
+/*!
+ * @brief Gets the clock frequency for UART module
+ *
+ * This function gets the clock frequency for UART module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance);
+
+/*!
+ * @brief Gets the clock frequency for GPIO module
+ *
+ * This function gets the clock frequency for GPIO module.
+ * @param instance module device instance
+ * @return freq clock frequency for this module
+ */
+static inline uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance)
+{
+ return CLOCK_SYS_GetSystemClockFreq();
+}
+
+/*!
+ * @brief Enable the clock for DMA module.
+ *
+ * This function enables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Disable the clock for DMA module.
+ *
+ * This function disables the clock for DMA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMA module.
+ *
+ * This function will get the clock gate state for DMA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDma0);
+}
+
+/*!
+ * @brief Enable the clock for DMAMUX module.
+ *
+ * This function enables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Disable the clock for DMAMUX module.
+ *
+ * This function disables the clock for DMAMUX module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableDmamuxClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Get the the clock gate state for DMAMUX module.
+ *
+ * This function will get the clock gate state for DMAMUX module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetDmamuxGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateDmamux0);
+}
+
+/*!
+ * @brief Enable the clock for PORT module.
+ *
+ * This function enables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnablePortClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for PORT module.
+ *
+ * This function disables the clock for PORT module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisablePortClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for PORT module.
+ *
+ * This function will get the clock gate state for PORT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetPortGateCmd(uint32_t instance);
+
+
+/*!
+ * @brief Enable the clock for EWM module.
+ *
+ * This function enables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableEwmClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Disable the clock for EWM module.
+ *
+ * This function disables the clock for EWM module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableEwmClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateEwm0);
+}
+
+/*!
+ * @brief Get the the clock gate state for EWM module.
+ *
+ * This function will get the clock gate state for EWM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetEwmGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateEwm0);
+}
+
+
+/*!
+ * @brief Enable the clock for FTF module.
+ *
+ * This function enables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableFtfClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Disable the clock for FTF module.
+ *
+ * This function disables the clock for FTF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableFtfClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Get the the clock gate state for FTF module.
+ *
+ * This function will get the clock gate state for FTF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetFtfGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateFtf0);
+}
+
+/*!
+ * @brief Enable the clock for CRC module.
+ *
+ * This function enables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCrcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Disable the clock for CRC module.
+ *
+ * This function disables the clock for CRC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCrcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CRC module.
+ *
+ * This function will get the clock gate state for CRC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCrcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCrc0);
+}
+
+/*!
+ * @brief Enable the clock for RNGA module.
+ *
+ * This function enables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRngaClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Disable the clock for RNGA module.
+ *
+ * This function disables the clock for RNGA module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRngaClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RNGA module.
+ *
+ * This function will get the clock gate state for RNGA module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRngaGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRnga0);
+}
+
+/*!
+ * @brief Enable the clock for ADC module.
+ *
+ * This function enables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for ADC module.
+ *
+ * This function disables the clock for ADC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableAdcClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for ADC module.
+ *
+ * This function will get the clock gate state for ADC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetAdcGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for CMP module.
+ *
+ * This function enables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmpClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Disable the clock for CMP module.
+ *
+ * This function disables the clock for CMP module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmpClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMP module.
+ *
+ * This function will get the clock gate state for CMP module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmpGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmp);
+}
+
+/*!
+ * @brief Enable the clock for DAC module.
+ *
+ * This function enables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableDacClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for DAC module.
+ *
+ * This function disables the clock for DAC module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableDacClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for DAC module.
+ *
+ * This function will get the clock gate state for DAC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetDacGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for VREF module.
+ *
+ * This function enables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableVrefClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Disable the clock for VREF module.
+ *
+ * This function disables the clock for VREF module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableVrefClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Get the the clock gate state for VREF module.
+ *
+ * This function will get the clock gate state for VREF module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetVrefGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateVref0);
+}
+
+/*!
+ * @brief Enable the clock for SAI module.
+ *
+ * This function enables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableSaiClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Disable the clock for SAI module.
+ *
+ * This function disables the clock for SAI module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableSaiClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Get the the clock gate state for SAI module.
+ *
+ * This function will get the clock gate state for SAI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetSaiGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateSai0);
+}
+
+/*!
+ * @brief Enable the clock for PDB module.
+ *
+ * This function enables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePdbClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Disable the clock for PDB module.
+ *
+ * This function disables the clock for PDB module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePdbClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PDB module.
+ *
+ * This function will get the clock gate state for PDB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPdbGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePdb0);
+}
+
+/*!
+ * @brief Enable the clock for FTM module.
+ *
+ * This function enables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for FTM module.
+ *
+ * This function disables the clock for FTM module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableFtmClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for FTM module.
+ *
+ * This function will get the clock gate state for FTM module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetFtmGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for PIT module.
+ *
+ * This function enables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnablePitClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Disable the clock for PIT module.
+ *
+ * This function disables the clock for PIT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisablePitClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Get the the clock gate state for PIT module.
+ *
+ * This function will get the clock gate state for PIT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetPitGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGatePit0);
+}
+
+/*!
+ * @brief Enable the clock for LPTIMER module.
+ *
+ * This function enables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Disable the clock for LPTIMER module.
+ *
+ * This function disables the clock for LPTIMER module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableLptmrClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Get the the clock gate state for LPTIMER module.
+ *
+ * This function will get the clock gate state for LPTIMER module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetLptmrGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateLptmr0);
+}
+
+/*!
+ * @brief Enable the clock for CMT module.
+ *
+ * This function enables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableCmtClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Disable the clock for CMT module.
+ *
+ * This function disables the clock for CMT module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableCmtClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Get the the clock gate state for CMT module.
+ *
+ * This function will get the clock gate state for CMT module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetCmtGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateCmt0);
+}
+
+/*!
+ * @brief Enable the clock for RTC module.
+ *
+ * This function enables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableRtcClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Disable the clock for RTC module.
+ *
+ * This function disables the clock for RTC module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableRtcClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Get the the clock gate state for RTC module.
+ *
+ * This function will get the clock gate state for RTC module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetRtcGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateRtc0);
+}
+
+/*!
+ * @brief Enable the clock for USBFS module.
+ *
+ * This function enables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Disable the clock for USBFS module.
+ *
+ * This function disables the clock for USBFS module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbfsClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USB module.
+ *
+ * This function will get the clock gate state for USB module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbfsGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbfs0);
+}
+
+/*!
+ * @brief Enable the clock for USBDCD module.
+ *
+ * This function enables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_EnableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_EnableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Disable the clock for USBDCD module.
+ *
+ * This function disables the clock for USBDCD module.
+ * @param instance module device instance
+ */
+static inline void CLOCK_SYS_DisableUsbdcdClock(uint32_t instance)
+{
+ SIM_HAL_DisableClock(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Get the the clock gate state for USBDCD module.
+ *
+ * This function will get the clock gate state for USBDCD module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+static inline bool CLOCK_SYS_GetUsbdcdGateCmd(uint32_t instance)
+{
+ return SIM_HAL_GetGateCmd(SIM, kSimClockGateUsbdcd0);
+}
+
+/*!
+ * @brief Enable the clock for SPI module.
+ *
+ * This function enables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for SPI module.
+ *
+ * This function disables the clock for SPI module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableSpiClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for SPI module.
+ *
+ * This function will get the clock gate state for SPI module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetSpiGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for I2C module.
+ *
+ * This function enables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for I2C module.
+ *
+ * This function disables the clock for I2C module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableI2cClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for I2C module.
+ *
+ * This function will get the clock gate state for I2C module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetI2cGateCmd(uint32_t instance);
+
+/*!
+ * @brief Enable the clock for UART module.
+ *
+ * This function enables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_EnableUartClock(uint32_t instance);
+
+/*!
+ * @brief Disable the clock for UART module.
+ *
+ * This function disables the clock for UART module.
+ * @param instance module device instance
+ */
+void CLOCK_SYS_DisableUartClock(uint32_t instance);
+
+/*!
+ * @brief Get the the clock gate state for UART module.
+ *
+ * This function will get the clock gate state for UART module.
+ * @param instance module device instance
+ * @return state true - ungated(Enabled), false - gated (Disabled)
+ */
+bool CLOCK_SYS_GetUartGateCmd(uint32_t instance);
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus*/
+
+/*! @}*/
+
+#endif /* __FSL_CLOCK_KW24DA5_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/fsl_clock_manager.c b/KSDK_1.2.0/platform/system/src/clock/fsl_clock_manager.c
new file mode 100755
index 0000000..e1710e4
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/fsl_clock_manager.c
@@ -0,0 +1,742 @@
+/*
+ * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "fsl_device_registers.h"
+#include "fsl_clock_manager.h"
+#include "fsl_os_abstraction.h"
+#include <assert.h>
+#if defined(RTC_INSTANCE_COUNT)
+extern RTC_Type * const g_rtcBase[RTC_INSTANCE_COUNT];
+#include "fsl_rtc_hal.h"
+#endif
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/* Macro for clock manager critical section. */
+#if (USE_RTOS)
+ mutex_t g_clockLock;
+ #define CLOCK_SYS_LOCK_INIT() OSA_MutexCreate(&g_clockLock)
+ #define CLOCK_SYS_LOCK() OSA_MutexLock(&g_clockLock, OSA_WAIT_FOREVER)
+ #define CLOCK_SYS_UNLOCK() OSA_MutexUnlock(&g_clockLock)
+ #define CLOCK_SYS_LOCK_DEINIT() OSA_MutexDestroy(&g_clockLock)
+#else
+ #define CLOCK_SYS_LOCK_INIT() do {}while(0)
+ #define CLOCK_SYS_LOCK() do {}while(0)
+ #define CLOCK_SYS_UNLOCK() do {}while(0)
+ #define CLOCK_SYS_LOCK_DEINIT() do {}while(0)
+#endif
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+static clock_manager_state_t g_clockState;
+
+#if FSL_FEATURE_SYSTICK_HAS_EXT_REF
+uint32_t CLOCK_SYS_GetSystickFreq(void)
+{
+ /* Use external reference clock. */
+ if (!(SysTick->CTRL & SysTick_CTRL_CLKSOURCE_Msk))
+ {
+#if FSL_FEATURE_SYSTICK_EXT_REF_CORE_DIV
+ return CLOCK_SYS_GetCoreClockFreq() / FSL_FEATURE_SYSTICK_EXT_REF_CORE_DIV;
+#else
+ return 0U;
+#endif
+ }
+ else // Use core clock.
+ {
+ return CLOCK_SYS_GetCoreClockFreq();
+ }
+}
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_Init
+ * Description : Install pre-defined clock configurations.
+ * This function installs the pre-defined clock configuration table to the
+ * clock manager.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_Init(clock_manager_user_config_t const **clockConfigsPtr,
+ uint8_t configsNumber,
+ clock_manager_callback_user_config_t **callbacksPtr,
+ uint8_t callbacksNumber)
+{
+ assert(NULL != clockConfigsPtr);
+ assert(NULL != callbacksPtr);
+
+ CLOCK_SYS_LOCK_INIT();
+
+ g_clockState.configTable = clockConfigsPtr;
+ g_clockState.clockConfigNum = configsNumber;
+ g_clockState.callbackConfig = callbacksPtr;
+ g_clockState.callbackNum = callbacksNumber;
+
+ /*
+ * errorCallbackIndex is the index of the callback which returns error
+ * during clock mode switch. If all callbacks return success, then the
+ * errorCallbackIndex is callbacksnumber.
+ */
+ g_clockState.errorCallbackIndex = callbacksNumber;
+
+ return kClockManagerSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_UpdateConfiguration
+ * Description : Send notification and change system clock configuration.
+ * This function sends the notification to all callback functions, if all
+ * callbacks return OK or forceful policy is used, this function will change
+ * system clock configuration.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_UpdateConfiguration(uint8_t targetConfigIndex,
+ clock_manager_policy_t policy)
+{
+ uint8_t callbackIdx;
+ clock_manager_error_code_t ret = kClockManagerSuccess;
+
+ clock_manager_callback_user_config_t* callbackConfig;
+
+ clock_notify_struct_t notifyStruct;
+ notifyStruct.targetClockConfigIndex = targetConfigIndex;
+ notifyStruct.policy = policy;
+
+ /* Clock configuration index is out of range. */
+ if (targetConfigIndex >= g_clockState.clockConfigNum)
+ {
+ return kClockManagerErrorOutOfRange;
+ }
+
+ OSA_EnterCritical(kCriticalLockSched);
+ /* Set errorcallbackindex as callbackNum, which means no callback error now.*/
+ g_clockState.errorCallbackIndex = g_clockState.callbackNum;
+
+ /* First step: Send "BEFORE" notification. */
+ notifyStruct.notifyType = kClockManagerNotifyBefore;
+
+ /* Send notification to all callback. */
+ for (callbackIdx=0; callbackIdx<g_clockState.callbackNum; callbackIdx++)
+ {
+ callbackConfig = g_clockState.callbackConfig[callbackIdx];
+ if ((NULL != callbackConfig) &&
+ ((uint8_t)callbackConfig->callbackType & (uint8_t)kClockManagerNotifyBefore))
+ {
+ if (kClockManagerSuccess !=
+ (*callbackConfig->callback)(&notifyStruct,
+ callbackConfig->callbackData))
+ {
+ g_clockState.errorCallbackIndex = callbackIdx;
+ /* Save the error callback index. */
+ ret = kClockManagerErrorNotificationBefore;
+
+ if (kClockManagerPolicyAgreement == policy)
+ {
+ break;
+ }
+ }
+ }
+ }
+
+ /* If all callback success or forceful policy is used. */
+ if ((kClockManagerSuccess == ret) ||
+ (policy == kClockManagerPolicyForcible))
+ {
+ /* clock mode switch. */
+ OSA_EnterCritical(kCriticalDisableInt);
+ CLOCK_SYS_SetConfiguration(g_clockState.configTable[targetConfigIndex]);
+
+ g_clockState.curConfigIndex = targetConfigIndex;
+ OSA_ExitCritical(kCriticalDisableInt);
+
+ notifyStruct.notifyType = kClockManagerNotifyAfter;
+
+ for (callbackIdx=0; callbackIdx<g_clockState.callbackNum; callbackIdx++)
+ {
+ callbackConfig = g_clockState.callbackConfig[callbackIdx];
+ if ((NULL != callbackConfig) &&
+ ((uint8_t)callbackConfig->callbackType & (uint8_t)kClockManagerNotifyAfter))
+ {
+ if (kClockManagerSuccess !=
+ (*callbackConfig->callback)(&notifyStruct,
+ callbackConfig->callbackData))
+ {
+ g_clockState.errorCallbackIndex = callbackIdx;
+ /* Save the error callback index. */
+ ret = kClockManagerErrorNotificationAfter;
+
+ if (kClockManagerPolicyAgreement == policy)
+ {
+ break;
+ }
+ }
+ }
+ }
+ }
+ else /* Error occurs, need to send "RECOVER" notification. */
+ {
+ notifyStruct.notifyType = kClockManagerNotifyRecover;
+ while (callbackIdx--)
+ {
+ callbackConfig = g_clockState.callbackConfig[callbackIdx];
+ if (NULL != callbackConfig)
+ {
+ (*callbackConfig->callback)(&notifyStruct,
+ callbackConfig->callbackData);
+ }
+ }
+ }
+
+ OSA_ExitCritical(kCriticalLockSched);
+
+ return ret;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetCurrentConfiguration
+ * Description : Get current clock configuration index.
+ *
+ *END**************************************************************************/
+uint8_t CLOCK_SYS_GetCurrentConfiguration(void)
+{
+ return g_clockState.curConfigIndex;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_GetErrorCallback
+ * Description : Get the callback which returns error in last clock switch.
+ *
+ *END**************************************************************************/
+clock_manager_callback_user_config_t* CLOCK_SYS_GetErrorCallback(void)
+{
+ /* If all callbacks return success. */
+ if (g_clockState.errorCallbackIndex >= g_clockState.clockConfigNum)
+ {
+ return NULL;
+ }
+ else
+ {
+ return g_clockState.callbackConfig[g_clockState.errorCallbackIndex];
+ }
+}
+
+#if (defined(CLOCK_USE_SCG))
+
+#elif (defined(CLOCK_USE_MCG_LITE))
+/*FUNCTION******************************************************************************
+ *
+ * Functon name : CLOCK_SYS_SetMcgliteMode
+ * Description : Set MCG_Lite to some mode.
+ * This function transitions the MCG_lite to some mode according to configuration
+ * parameter.
+ *
+ *END***********************************************************************************/
+mcglite_mode_error_t CLOCK_SYS_SetMcgliteMode(mcglite_config_t const *targetConfig)
+{
+ uint32_t outFreq = 0U;
+ mcglite_mode_error_t ret = kMcgliteModeErrNone;
+
+ assert(targetConfig->mcglite_mode < kMcgliteModeStop);
+
+ /* MCG_LITE mode change. */
+ switch (targetConfig->mcglite_mode)
+ {
+ case kMcgliteModeLirc8M:
+ ret = CLOCK_HAL_SetLircMode(MCG,
+ kMcgliteLircSel8M,
+ targetConfig->fcrdiv,
+ &outFreq);
+ break;
+ case kMcgliteModeLirc2M:
+ ret = CLOCK_HAL_SetLircMode(MCG,
+ kMcgliteLircSel2M,
+ targetConfig->fcrdiv,
+ &outFreq);
+ break;
+ case kMcgliteModeExt:
+ ret = CLOCK_HAL_SetExtMode(MCG, &outFreq);
+ break;
+ default:
+ ret = CLOCK_HAL_SetHircMode(MCG, &outFreq);
+ break;
+ }
+
+ /* Set other registers. */
+ if (kMcgliteModeErrNone == ret)
+ {
+ /* Enable HIRC when MCG_LITE is not in HIRC mode. */
+ CLOCK_HAL_SetHircCmd(MCG, targetConfig->hircEnableInNotHircMode);
+
+ /* Enable IRCLK. */
+ CLOCK_HAL_SetLircCmd(MCG, targetConfig->irclkEnable);
+ CLOCK_HAL_SetLircStopCmd(MCG, targetConfig->irclkEnableInStop);
+
+ /* Set IRCS. */
+ CLOCK_HAL_SetLircSelMode(MCG, targetConfig->ircs);
+
+ /* Set LIRC_DIV2. */
+ CLOCK_HAL_SetLircDiv2(MCG, targetConfig->lircDiv2);
+ }
+
+ return ret;
+}
+#else
+
+/*FUNCTION******************************************************************************
+ *
+ * Functon name : CLOCK_SYS_SetMcgPeeToFbe
+ * Description : This function changes MCG from PEE mode to FBE mode, it is
+ * only used internally.
+ *
+ *END***********************************************************************************/
+#if FSL_FEATURE_MCG_HAS_PLL
+static void CLOCK_SYS_SetMcgPeeToFbe(void)
+{
+ /* Change to use external clock first. */
+ CLOCK_HAL_SetClkOutSrc(MCG, kMcgClkOutSrcExternal);
+ /* Wait for clock status bits to update */
+ while (CLOCK_HAL_GetClkOutStat(MCG) != kMcgClkOutStatExternal) {}
+
+ /* Set PLLS to select FLL. */
+ CLOCK_HAL_SetPllSelectCmd(MCG, false);
+ // wait for PLLST status bit to set
+ while ((CLOCK_HAL_IsPllSelected(MCG) != false)) {}
+}
+#endif
+
+/*FUNCTION******************************************************************************
+ *
+ * Function name : CLOCK_SYS_SetMcgMode
+ * Description : This function sets MCG to some target mode defined by the configure
+ * structure, if can not switch to target mode directly, this function will choose
+ * the proper path. If external clock is used in the target mode, please make sure
+ * it is enabled, for example, if the external oscillator is used, please setup EREFS/HGO
+ * correctly and make sure OSCINIT is set.
+ * This function is used by clock dynamic setting, it only supports some specific
+ * mode transitions, including:
+ * 1. FEI ==> FEE/PEE
+ * 2. BLPI <==> FEE/PEE
+ * 3. Reconfigure PLL in PEE mode.
+ * 4. Reconfigure FLL in FEE mode.
+ *
+ *END***********************************************************************************/
+mcg_mode_error_t CLOCK_SYS_SetMcgMode(mcg_config_t const *targetConfig,
+ void (* fllStableDelay)(void))
+{
+ uint32_t outClkFreq;
+#if FSL_FEATURE_MCG_HAS_PLL
+ /* Current mode is only used for PEE mode transition. */
+ mcg_modes_t curMode; // Current MCG mode.
+#endif
+
+#if FSL_FEATURE_MCG_USE_OSCSEL
+ mcg_oscsel_select_t oscsel = targetConfig->oscsel;
+#else
+ mcg_oscsel_select_t oscsel = kMcgOscselOsc;
+#endif
+
+#if FSL_FEATURE_MCG_HAS_PLL
+#if (FSL_FEATURE_MCG_HAS_PLL1 || FSL_FEATURE_MCG_HAS_EXTERNAL_PLL)
+ mcg_pll_clk_select_t pllcs = targetConfig->pllcs;
+#else
+ mcg_pll_clk_select_t pllcs = kMcgPllClkSelPll0;
+#endif
+#endif
+
+#if FSL_FEATURE_MCG_HAS_PLL
+ curMode = CLOCK_HAL_GetMcgMode(MCG);
+#endif
+
+ if (kMcgModeBLPI == targetConfig->mcg_mode)
+ {
+#if FSL_FEATURE_MCG_HAS_PLL
+ // If current mode is PEE mode, swith to FBE mode first.
+ if (kMcgModePEE == curMode)
+ {
+ CLOCK_SYS_SetMcgPeeToFbe();
+ }
+#endif
+ // Change to FBI mode.
+ CLOCK_HAL_SetFbiMode(MCG,
+ targetConfig->drs,
+ targetConfig->ircs,
+ targetConfig->fcrdiv,
+ fllStableDelay,
+ &outClkFreq);
+
+ // Enable low power mode to enter BLPI.
+ CLOCK_HAL_SetLowPowerModeCmd(MCG, true);
+ }
+ else if (kMcgModeFEE == targetConfig->mcg_mode)
+ {
+#if FSL_FEATURE_MCG_HAS_PLL
+ // If current mode is PEE mode, swith to FBE mode first.
+ if (kMcgModePEE == curMode)
+ {
+ CLOCK_SYS_SetMcgPeeToFbe();
+ }
+#endif
+ // Disalbe low power mode.
+ CLOCK_HAL_SetLowPowerModeCmd(MCG, false);
+ // Configure FLL in FBE mode then switch to FEE mode.
+ CLOCK_HAL_SetFbeMode(MCG,
+ oscsel,
+ targetConfig->frdiv,
+ targetConfig->dmx32,
+ targetConfig->drs,
+ fllStableDelay,
+ &outClkFreq);
+ // Change CLKS to enter FEE mode.
+ CLOCK_HAL_SetClkOutSrc(MCG, kMcgClkOutSrcOut);
+ while (CLOCK_HAL_GetClkOutStat(MCG) != kMcgClkOutStatFll) {}
+ }
+#if FSL_FEATURE_MCG_HAS_PLL
+ else if (kMcgModePEE == targetConfig->mcg_mode)
+ {
+ /*
+ * If current mode is FEI/FEE/BLPI, then switch to FBE mode first.
+ * If current mode is PEE mode, which means need to reconfigure PLL,
+ * fist switch to PBE mode and configure PLL, then switch to PEE.
+ */
+
+ if (kMcgModePEE != curMode)
+ {
+ // Disalbe low power mode.
+ CLOCK_HAL_SetLowPowerModeCmd(MCG, false);
+
+ // Change to FBE mode.
+ CLOCK_HAL_SetFbeMode(MCG,
+ oscsel,
+ targetConfig->frdiv,
+ targetConfig->dmx32,
+ targetConfig->drs,
+ fllStableDelay,
+ &outClkFreq);
+ }
+
+ // Change to PBE mode.
+ CLOCK_HAL_SetPbeMode(MCG,
+ oscsel,
+ pllcs,
+ targetConfig->prdiv0,
+ targetConfig->vdiv0,
+ &outClkFreq);
+
+ // Set CLKS to enter PEE mode.
+ CLOCK_HAL_SetClkOutSrc(MCG, kMcgClkOutSrcOut);
+ while (CLOCK_HAL_GetClkOutStat(MCG) != kMcgClkOutStatPll) {}
+ }
+#endif
+ else
+ {
+ return kMcgModeErrModeUnreachable;
+ }
+
+ /* Enable MCGIRCLK. */
+ CLOCK_HAL_SetInternalRefClkEnableCmd(MCG, targetConfig->irclkEnable);
+ CLOCK_HAL_SetInternalRefClkEnableInStopCmd(MCG, targetConfig->irclkEnableInStop);
+
+ /* Configure MCGIRCLK. */
+ if (targetConfig->irclkEnable)
+ {
+ if (kMcgIrcFast == targetConfig->ircs)
+ {
+ /* Update FCRDIV if necessary. */
+ CLOCK_HAL_UpdateFastClkInternalRefDiv(MCG, targetConfig->fcrdiv);
+ }
+
+ CLOCK_HAL_SetInternalRefClkMode(MCG, targetConfig->ircs);
+ while (targetConfig->ircs != CLOCK_HAL_GetInternalRefClkMode(MCG)) {}
+ }
+
+#if FSL_FEATURE_MCG_HAS_PLL
+ /* Enable PLL0. */
+ if (targetConfig->pll0EnableInFllMode)
+ {
+ CLOCK_HAL_EnablePll0InFllMode(MCG,
+ targetConfig->prdiv0,
+ targetConfig->vdiv0,
+ targetConfig->pll0EnableInStop);
+ }
+ else
+ {
+ CLOCK_HAL_SetPll0EnableCmd(MCG, false);
+ }
+#endif
+
+ return kMcgModeErrNone;
+}
+
+#endif
+
+#if (defined(CLOCK_USE_SCG)) // USE SCG
+
+#else
+
+#if (defined(CLOCK_USE_MCG_LITE)) // USE MCG_LITE
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_OscInit
+ * Description : Initialize OSC.
+ *
+ * This function initializes OSC according to configuration.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_OscInit(uint32_t instance,
+ osc_user_config_t *config)
+{
+ assert(instance < OSC_INSTANCE_COUNT);
+ uint32_t capacitorMask = 0U;
+
+ if (kOscSrcOsc == config->erefs) /* oscillator is used. */
+ {
+ capacitorMask = (config->enableCapacitor2p ? kOscCapacitor2p : 0U) |
+ (config->enableCapacitor4p ? kOscCapacitor4p : 0U) |
+ (config->enableCapacitor8p ? kOscCapacitor8p : 0U) |
+ (config->enableCapacitor16p ? kOscCapacitor16p : 0U);
+ OSC_HAL_SetCapacitor(g_oscBase[instance], capacitorMask);
+ }
+
+#if FSL_FEATURE_MCGLITE_HAS_RANGE0
+ CLOCK_HAL_SetRange0Mode(MCG, config->range);
+#endif
+#if FSL_FEATURE_MCGLITE_HAS_HGO0
+ CLOCK_HAL_SetHighGainOsc0Mode(MCG, config->hgo);
+#endif
+ CLOCK_HAL_SetExtRefSelMode0(MCG, config->erefs);
+
+ CLOCK_SYS_SetOscerConfigration(instance, &(config->oscerConfig));
+
+ /* oscillator is used. */
+ if ((kOscSrcOsc == config->erefs) &&
+ (true == config->oscerConfig.enable))
+ {
+ while(!CLOCK_HAL_IsOscStable(MCG)){}
+ }
+
+ g_xtal0ClkFreq = config->freq;
+
+ return kClockManagerSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_OscDeinit
+ * Description : Deinitialize OSC.
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_OscDeinit(uint32_t instance)
+{
+ assert(instance < OSC_INSTANCE_COUNT);
+
+ OSC_HAL_SetExternalRefClkInStopModeCmd(g_oscBase[instance], false);
+ OSC_HAL_SetExternalRefClkCmd(g_oscBase[instance], false);
+ CLOCK_HAL_SetExtRefSelMode0(MCG, kOscSrcExt);
+#if FSL_FEATURE_MCGLITE_HAS_RANGE0
+ CLOCK_HAL_SetRange0Mode(MCG, kOscRangeLow);
+#endif
+#if FSL_FEATURE_MCGLITE_HAS_HGO0
+ CLOCK_HAL_SetHighGainOsc0Mode(MCG, kOscGainLow);
+#endif
+
+ g_xtal0ClkFreq = 0U;
+}
+
+#else // Use MCG
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_OscInit
+ * Description : Initialize OSC.
+ *
+ * This function initializes OSC according to configuration.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_OscInit(uint32_t instance,
+ osc_user_config_t *config)
+{
+ assert(instance < OSC_INSTANCE_COUNT);
+ uint32_t capacitorMask = 0U;
+
+ if (kOscSrcOsc == config->erefs) /* oscillator is used. */
+ {
+ capacitorMask = (config->enableCapacitor2p ? kOscCapacitor2p : 0U) |
+ (config->enableCapacitor4p ? kOscCapacitor4p : 0U) |
+ (config->enableCapacitor8p ? kOscCapacitor8p : 0U) |
+ (config->enableCapacitor16p ? kOscCapacitor16p : 0U);
+ OSC_HAL_SetCapacitor(g_oscBase[instance], capacitorMask);
+ }
+
+ CLOCK_SYS_SetOscerConfigration(instance, &(config->oscerConfig));
+
+#if (defined(FSL_FEATURE_MCG_HAS_OSC1) && (1U == FSL_FEATURE_MCG_HAS_OSC1))
+ if (0U == instance)
+ {
+#endif
+ CLOCK_HAL_SetOsc0Mode(MCG, config->range, config->hgo, config->erefs);
+
+ /* oscillator is used. */
+ if ((kOscSrcOsc == config->erefs) &&
+ (true == config->oscerConfig.enable))
+ {
+ while(!CLOCK_HAL_IsOsc0Stable(MCG)){}
+ }
+ g_xtal0ClkFreq = config->freq;
+#if (defined(FSL_FEATURE_MCG_HAS_OSC1) && (1U == FSL_FEATURE_MCG_HAS_OSC1))
+ }
+ else
+ {
+ CLOCK_HAL_SetOsc1Mode(MCG, config->range, config->hgo, config->erefs);
+
+ /* oscillator is used. */
+ if ((kOscSrcOsc == config->erefs) &&
+ (true == config->oscerConfig.enable))
+ {
+ while(!CLOCK_HAL_IsOsc1Stable(MCG)){}
+ }
+ g_xtal1ClkFreq = config->freq;
+ }
+#endif
+
+ return kClockManagerSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_OscDeinit
+ * Description : Deinitialize OSC.
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_OscDeinit(uint32_t instance)
+{
+ assert(instance < OSC_INSTANCE_COUNT);
+ OSC_HAL_SetExternalRefClkInStopModeCmd(g_oscBase[instance], false);
+ OSC_HAL_SetExternalRefClkCmd(g_oscBase[instance], false);
+
+#if (defined(FSL_FEATURE_MCG_HAS_OSC1) && (1U == FSL_FEATURE_MCG_HAS_OSC1))
+ if (0U == instance)
+ {
+#endif
+ CLOCK_HAL_SetOsc0Mode(MCG,
+ kOscRangeLow,
+ kOscGainLow,
+ kOscSrcExt);
+ g_xtal0ClkFreq = 0U;
+#if (defined(FSL_FEATURE_MCG_HAS_OSC1) && (1U == FSL_FEATURE_MCG_HAS_OSC1))
+ }
+ else
+ {
+ CLOCK_HAL_SetOsc1Mode(MCG,
+ kOscRangeLow,
+ kOscGainLow,
+ kOscSrcExt);
+ g_xtal1ClkFreq = 0U;
+ }
+#endif
+}
+
+#endif
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_SetOscerConfigration
+ * Description : This funtion sets the OSCERCLK for clock transition.
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_SetOscerConfigration(uint32_t instance, oscer_config_t const *config)
+{
+#if FSL_FEATURE_OSC_HAS_EXT_REF_CLOCK_DIVIDER
+ OSC_HAL_SetExternalRefClkDiv(g_oscBase[instance],
+ config->erclkDiv);
+#endif
+
+ OSC_HAL_SetExternalRefClkCmd(g_oscBase[instance],
+ config->enable);
+
+ OSC_HAL_SetExternalRefClkInStopModeCmd(g_oscBase[instance],
+ config->enableInStop);
+}
+#endif
+
+#if defined(RTC_INSTANCE_COUNT)
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_RtcOscInit
+ * Description : This funtion initializes the RTC OSC.
+ *
+ *END**************************************************************************/
+clock_manager_error_code_t CLOCK_SYS_RtcOscInit(uint32_t instance,
+ rtc_osc_user_config_t *config)
+{
+ assert(instance < RTC_INSTANCE_COUNT);
+ RTC_Type * rtcBase = g_rtcBase[instance];
+
+ CLOCK_SYS_EnableRtcClock(instance);
+ g_xtalRtcClkFreq = config->freq;
+
+ // If the oscillator is not enabled and should be enabled.
+ if ((!RTC_HAL_IsOscillatorEnabled(rtcBase)) && (config->enableOsc))
+ {
+ RTC_HAL_SetOsc2pfLoadCmd(rtcBase, config->enableCapacitor2p);
+ RTC_HAL_SetOsc4pfLoadCmd(rtcBase, config->enableCapacitor4p);
+ RTC_HAL_SetOsc8pfLoadCmd(rtcBase, config->enableCapacitor8p);
+ RTC_HAL_SetOsc16pfLoadCmd(rtcBase, config->enableCapacitor16p);
+ }
+ RTC_HAL_SetOscillatorCmd(rtcBase, config->enableOsc);
+ RTC_HAL_SetClockOutCmd(rtcBase, config->enableClockOutput);
+
+ return kClockManagerSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : CLOCK_SYS_RtcOscDeinit
+ * Description : This funtion de-initializes the RTC OSC.
+ *
+ *END**************************************************************************/
+void CLOCK_SYS_RtcOscDeinit(uint32_t instance)
+{
+ assert(instance < RTC_INSTANCE_COUNT);
+ RTC_Type * rtcBase = g_rtcBase[instance];
+
+ RTC_HAL_SetOscillatorCmd(rtcBase, false);
+}
+#endif
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/clock/fsl_clock_manager_common.c b/KSDK_1.2.0/platform/system/src/clock/fsl_clock_manager_common.c
new file mode 100755
index 0000000..6cbefe9
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/clock/fsl_clock_manager_common.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "fsl_device_registers.h"
+#include "fsl_clock_manager.h"
+
+/*******************************************************************************
+ * Variables
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+/* Table of base addresses for instances. */
+SIM_Type * const g_simBase[] = SIM_BASE_PTRS;
+#if (defined(CLOCK_USE_MCG) || defined(CLOCK_USE_MCG_LITE))
+MCG_Type * const g_mcgBase[] = MCG_BASE_PTRS;
+#endif
+
+#if (defined(CLOCK_USE_SCG))
+const uint32_t g_scgBase[] = SCG_BASE_PTRS;
+#endif
+
+#if (!defined(CLOCK_USE_SCG))
+OSC_Type * const g_oscBase[] = OSC_BASE_PTRS;
+#endif
+
+#if (defined(PCC_INSTANCE_COUNT))
+PCC_Type * const g_pccBase[] = PCC_BASE_PTRS;
+#endif
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer.c b/KSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer.c
new file mode 100755
index 0000000..72daf1a
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer.c
@@ -0,0 +1,417 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "fsl_hwtimer.h"
+
+/*******************************************************************************
+ * Internal type definition
+ ******************************************************************************/
+/*******************************************************************************
+ * Internal Variables
+ ******************************************************************************/
+ /*******************************************************************************
+ * Internal Code
+ ******************************************************************************/
+ /*******************************************************************************
+ * Code
+ ******************************************************************************/
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : HWTIMER_SYS_Init
+ * Description : The device interface pointer determines low layer driver to
+ * be used. Device interface structure is exported by each low layer driver and
+ * is opaque to the applications. Please refer to chapter concerning low layer
+ * driver below for details. Meaning of the numerical identifier varies depending
+ * on low layer driver used. Typically, it identifies particular timer channel to
+ * initialize. The initialization function has to be called prior using any other
+ * API function.
+ *
+ *END**************************************************************************/
+_hwtimer_error_code_t HWTIMER_SYS_Init(hwtimer_t *hwtimer, const hwtimer_devif_t * kDevif, uint32_t id, void *data)
+ {
+ /* Check input parameters */
+ if ((hwtimer == NULL) || (kDevif == NULL))
+ {
+ return kHwtimerInvalidInput;
+ }
+
+ assert(NULL != kDevif->init);
+
+ /* Initialize hwtimer structure */
+ hwtimer->devif = kDevif;
+ hwtimer->ticks = 0U;
+ hwtimer->divider = 0U;
+ hwtimer->modulo = 0U;
+ hwtimer->callbackFunc = NULL;
+ hwtimer->callbackData = NULL;
+ hwtimer->callbackPending = 0U;
+ hwtimer->callbackBlocked = 0U;
+
+ /* Call low level driver init function. */
+ return hwtimer->devif->init(hwtimer, id, data);
+ }
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : HWTIMER_SYS_Deinit
+ * Description : Calls lower layer stop function to stop timer, then calls low
+ * layer de-initialization function and afterwards invalidates hwtimer structure
+ * by clearing it.
+ *
+ *END**************************************************************************/
+_hwtimer_error_code_t HWTIMER_SYS_Deinit(hwtimer_t *hwtimer)
+{
+ _hwtimer_error_code_t result;
+
+ /* Check input parameters */
+ if (NULL == hwtimer)
+ {
+ return kHwtimerInvalidInput;
+ }
+ if (NULL == hwtimer->devif)
+ {
+ return kHwtimerInvalidPointer;
+ }
+ /* Stop timer if runs */
+ assert(NULL != hwtimer->devif->stop);
+ result = hwtimer->devif->stop(hwtimer);
+ if (kHwtimerSuccess != result)
+ {
+ return result;
+ }
+
+ /* De-initialize timer. */
+ assert(NULL != hwtimer->devif->deinit);
+ result = hwtimer->devif->deinit(hwtimer);
+ if (kHwtimerSuccess != result)
+ {
+ return result;
+ }
+
+ hwtimer->devif = NULL;
+ hwtimer->clockFreq = 0U;
+ hwtimer->ticks = 0U;
+ hwtimer->divider = 0U;
+ hwtimer->modulo = 0U;
+ hwtimer->callbackFunc = NULL;
+ hwtimer->callbackData = NULL;
+ hwtimer->callbackPending = 0U;
+ hwtimer->callbackBlocked = 0U;
+
+ return kHwtimerSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : HWTIMER_SYS_SetPeriod
+ * Description : The function provides an alternate way to set up the timer to
+ * desired period specified in microseconds rather than to frequency in Hz.
+ *
+ *END**************************************************************************/
+_hwtimer_error_code_t HWTIMER_SYS_SetPeriod(hwtimer_t *hwtimer, uint32_t period)
+{
+ /* Check input parameters */
+ if ((NULL == hwtimer) || (0U == period))
+ {
+ return kHwtimerInvalidInput;
+ }
+ if (NULL == hwtimer->devif)
+ {
+ return kHwtimerInvalidPointer;
+ }
+
+ assert(NULL != hwtimer->devif->setDiv);
+ return hwtimer->devif->setDiv(hwtimer, period);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : HWTIMER_SYS_GetPeriod
+ * Description : The function returns current period of the timer in
+ * microseconds calculated from the base frequency and actual divider settings
+ * of the timer.
+ *
+ *END**************************************************************************/
+uint32_t HWTIMER_SYS_GetPeriod(hwtimer_t *hwtimer)
+{
+ uint32_t period;
+
+ /* Check input parameters */
+ if (NULL == hwtimer)
+ {
+ return 0U;
+ }
+
+ /* Obtain clock source clock frequency.*/
+ if (hwtimer->clockFreq == 0U)
+ {
+ return 0U;
+ }
+
+ assert(hwtimer->divider <= hwtimer->clockFreq);
+ /* Divider is always less than clockFreq */
+ period = ((uint64_t)1000000U * hwtimer->divider) / hwtimer->clockFreq;
+
+ return period;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : HWTIMER_SYS_Start
+ * Description : Enables the timer and leaves it running. The timer starts
+ * counting a new period generating interrupts every time the timer rolls over.
+ *
+ *END**************************************************************************/
+_hwtimer_error_code_t HWTIMER_SYS_Start(hwtimer_t *hwtimer)
+{
+ /* Check input parameters */
+ if (NULL == hwtimer)
+ {
+ return kHwtimerInvalidInput;
+ }
+ if (NULL == hwtimer->devif)
+ {
+ return kHwtimerInvalidPointer;
+ }
+ /* Start timer */
+ assert(NULL != hwtimer->devif->start);
+ return hwtimer->devif->start(hwtimer);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : HWTIMER_SYS_Stop
+ * Description : The timer stops counting after this function is called.
+ * Pending interrupts and callbacks are cancelled.
+ *
+ *END**************************************************************************/
+_hwtimer_error_code_t HWTIMER_SYS_Stop(hwtimer_t *hwtimer)
+{
+ _hwtimer_error_code_t result;
+
+ /* Check input parameters */
+ if (NULL == hwtimer)
+ {
+ return kHwtimerInvalidInput;
+ }
+ if (NULL == hwtimer->devif)
+ {
+ return kHwtimerInvalidPointer;
+ }
+
+ assert(NULL != hwtimer->devif->stop);
+ result = hwtimer->devif->stop(hwtimer);
+ hwtimer->callbackPending = 0U;
+
+ return result;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : HWTIMER_SYS_GetModulo
+ * Description : The function returns period of the timer in sub-ticks. It is
+ * typically called after HWTIMER_SYS_SetPeriod() to obtain actual resolution
+ * of the timer in the current configuration.
+ *
+ *END**************************************************************************/
+uint32_t HWTIMER_SYS_GetModulo(hwtimer_t *hwtimer)
+{
+ /* Check input parameters */
+ if (NULL == hwtimer)
+ {
+ return 0U;
+ }
+
+ return hwtimer->modulo;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : HWTIMER_SYS_GetTime
+ * Description : The function reads the current value of the hwtimer. Elapsed
+ * periods(ticks) and current value of the timer counter (sub-ticks) are filled
+ * into the Hwtimer_time structure. The sub-ticks number always counts up and is
+ * reset to zero when the timer overflows regardless of the counting direction
+ * of the underlying device.
+ *
+ *END**************************************************************************/
+_hwtimer_error_code_t HWTIMER_SYS_GetTime(hwtimer_t *hwtimer, hwtimer_time_t *time)
+{
+ /* Check input parameters */
+ if ((NULL == hwtimer) || (NULL == time))
+ {
+ return kHwtimerInvalidInput;
+ }
+ if (NULL == hwtimer->devif)
+ {
+ return kHwtimerInvalidPointer;
+ }
+
+ assert(NULL != hwtimer->devif->getTime);
+ return hwtimer->devif->getTime(hwtimer, time);
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : HWTIMER_SYS_GetTicks
+ * Description : The function reads the current value of the hwtimer.
+ * The returned value corresponds with lower 32 bits of elapsed periods (ticks).
+ * The value is guaranteed to be obtained atomically without necessity to mask
+ * timer interrupt. Lower layer driver is not involved at all, thus call to this
+ * function is considerably faster than HWTIMER_SYS_GetTime.
+ *
+ *END**************************************************************************/
+uint32_t HWTIMER_SYS_GetTicks(hwtimer_t *hwtimer)
+{
+ /* Check input parameters */
+ if (NULL == hwtimer)
+ {
+ return 0U;
+ }
+
+ /* return lower 32b of 64 bit value */
+ return (uint32_t)hwtimer->ticks;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : HWTIMER_SYS_RegisterCallback
+ * Description : Registers function to be called when the timer expires.
+ * The callback_data is arbitrary pointer passed as parameter to the callback
+ * function.
+ *
+ *END**************************************************************************/
+_hwtimer_error_code_t HWTIMER_SYS_RegisterCallback(hwtimer_t *hwtimer, hwtimer_callback_t callbackFunc, void *callbackData)
+{
+ hwtimer_t volatile *hwtimerVol;
+
+ /* Check input parameters */
+ if (NULL == hwtimer)
+ {
+ return kHwtimerInvalidInput;
+ }
+
+ hwtimerVol = hwtimer;
+ /* Volatile used to prevent optimization of following lines. Interrupt may happen meanwhile. */
+ hwtimerVol->callbackFunc = NULL; /* Prevent callback execution with old data */
+ hwtimerVol->callbackPending = 0U;
+ hwtimerVol->callbackData = callbackData;
+ hwtimerVol->callbackFunc = callbackFunc;
+
+ return kHwtimerSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : HWTIMER_SYS_BlockCallback
+ * Description : The function is used to block callbacks in circumstances when
+ * execution of the callback function is undesired. If the timer overflows when
+ * callbacks are blocked the callback becomes pending.
+ *
+ *END**************************************************************************/
+_hwtimer_error_code_t HWTIMER_SYS_BlockCallback(hwtimer_t *hwtimer)
+{
+ /* Check input parameters */
+ if (NULL == hwtimer)
+ {
+ return kHwtimerInvalidInput;
+ }
+
+ hwtimer->callbackBlocked = 1U;
+
+ return kHwtimerSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : HWTIMER_SYS_UnblockCallback
+ * Description : The function is used to unblock previously blocked callbacks.
+ * If there is a callback pending, it gets immediately executed. This function
+ * must not be called from a callback routine (it does not make sense to do so
+ * anyway as callback function never gets executed while callbacks are blocked).
+ *
+ *END**************************************************************************/
+_hwtimer_error_code_t HWTIMER_SYS_UnblockCallback(hwtimer_t *hwtimer)
+{
+ hwtimer_callback_t callbackFunc;
+ hwtimer_t volatile *hwtimerVol = hwtimer;
+
+ /* Check input parameters */
+ if (NULL == hwtimer)
+ {
+ return kHwtimerInvalidInput;
+ }
+
+ /* Unblock callbacks in ISR. No more pending request could arrive after this. */
+ hwtimerVol->callbackBlocked = 0U;
+ /* Check for any previously set pending requests during blocked state */
+ if (hwtimerVol->callbackPending)
+ {
+ callbackFunc = hwtimerVol->callbackFunc;
+ if (NULL != callbackFunc)
+ {
+ /* Prevent invocation of callback from ISR (callback may not be re-entrant) */
+ hwtimerVol->callbackFunc = NULL;
+ callbackFunc(hwtimerVol->callbackData);
+ /* Allow invocation of callback from ISR */
+ hwtimerVol->callbackFunc = callbackFunc;
+ }
+ /* Clear pending flag, callback just serviced */
+ hwtimerVol->callbackPending = 0U;
+ }
+
+ return kHwtimerSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : HWTIMER_SYS_CancelCallback
+ * Description : The function cancels pending callback, if any.
+ *
+ *END**************************************************************************/
+_hwtimer_error_code_t HWTIMER_SYS_CancelCallback(hwtimer_t *hwtimer)
+{
+ /* Check input parameters */
+ if (NULL == hwtimer)
+ {
+ return kHwtimerInvalidInput;
+ }
+
+ hwtimer->callbackPending = 0U;
+
+ return kHwtimerSuccess;
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer_pit.c b/KSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer_pit.c
new file mode 100755
index 0000000..fdc149b
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer_pit.c
@@ -0,0 +1,434 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <assert.h>
+#include "fsl_hwtimer.h"
+#include "fsl_hwtimer_pit.h"
+#include "fsl_pit_hal.h"
+#include "fsl_os_abstraction.h"
+#include "fsl_interrupt_manager.h"
+#include "fsl_clock_manager.h"
+
+/*******************************************************************************
+ * Internal type definition
+ ******************************************************************************/
+extern PIT_Type * const g_pitBase[];
+extern const IRQn_Type g_pitIrqId[];
+/*******************************************************************************
+ * Internal Variables
+ ******************************************************************************/
+void HWTIMER_SYS_PitIsrAction(uint8_t pitChannel);
+static _hwtimer_error_code_t HWTIMER_SYS_PitInit(hwtimer_t *hwtimer, uint32_t pitId, void *data);
+static _hwtimer_error_code_t HWTIMER_SYS_PitDeinit(hwtimer_t *hwtimer);
+static _hwtimer_error_code_t HWTIMER_SYS_PitSetDiv(hwtimer_t *hwtimer, uint32_t period);
+static _hwtimer_error_code_t HWTIMER_SYS_PitStart(hwtimer_t *hwtimer);
+static _hwtimer_error_code_t HWTIMER_SYS_PitStop(hwtimer_t *hwtimer);
+static _hwtimer_error_code_t HWTIMER_SYS_PitGetTime(hwtimer_t *hwtimer, hwtimer_time_t *time);
+
+
+const hwtimer_devif_t kPitDevif =
+{
+ HWTIMER_SYS_PitInit,
+ HWTIMER_SYS_PitDeinit,
+ HWTIMER_SYS_PitSetDiv,
+ HWTIMER_SYS_PitStart,
+ HWTIMER_SYS_PitStop,
+ HWTIMER_SYS_PitGetTime,
+};
+
+static hwtimer_t *g_hwtimersPit[FSL_FEATURE_PIT_TIMER_COUNT] = {0U};
+
+
+ /*******************************************************************************
+ * Internal Code
+ ******************************************************************************/
+/*!
+ * @cond DOXYGEN_PRIVATE
+ *
+ * @brief Called from the Interrupt service routine.
+ *
+ * Checks whether callback_func is not NULL,
+ * and unless callback is blocked by callback_blocked being non-zero it calls the callback function with callback_data as parameter,
+ * otherwise callback_pending is set to non-zero value.
+ *
+ * @return void
+ *
+ * @see HWTIMER_SYS_Pitdeinit
+ * @see HWTIMER_SYS_PitsetDiv
+ * @see HWTIMER_SYS_Pitstart
+ * @see HWTIMER_SYS_Pitstop
+ * @see HWTIMER_SYS_PitgetTime
+ */
+void HWTIMER_SYS_PitIsrAction(uint8_t pitChannel)
+{
+ PIT_Type * base = g_pitBase[0];
+ hwtimer_t *hwtimer = g_hwtimersPit[pitChannel];
+
+ /* If hwtimer exist*/
+ if (NULL != hwtimer)
+ {
+ /* Check if interrupt is enabled for this channel. Cancel spurious interrupt */
+ if (!(PIT_BRD_TCTRL_TIE(base, pitChannel)))
+ {
+ return;
+ }
+
+ /* If interrupt occurred for this pit and channel*/
+ if(PIT_HAL_IsIntPending(base, pitChannel))
+ {
+ /* Clear interrupt flag */
+ PIT_HAL_ClearIntFlag(base, pitChannel);
+ /* Following part of function is typically the same for all low level hwtimer drivers */
+ hwtimer->ticks++;
+
+ if (NULL != hwtimer->callbackFunc)
+ {
+ if (hwtimer->callbackBlocked)
+ {
+ hwtimer->callbackPending = 1U;
+ }
+ else
+ {
+ /* Run user function*/
+ hwtimer->callbackFunc(hwtimer->callbackData);
+ }
+ }
+ }
+ }
+}
+
+/*!
+ * @cond DOXYGEN_PRIVATE
+ *
+ * @brief This function initializes caller allocated structure according to given
+ * numerical identifier of the timer.
+ *
+ * Called by hwtimer_init().
+ * Initializes the HWTIMER structure.
+ *
+ * @param hwtimer[in] Returns initialized hwtimer structure handle.
+ * @param pitId[in] Determines PIT module and pit channel.
+ * @param data[in] Specific data. Not used in this timer.
+ *
+ * @return kHwtimerSuccess Success.
+ * @return kHwtimerInvalidInput When channel number does not exist in pit module.
+ * @return kHwtimerRegisterHandlerError When registration of the interrupt service routine failed.
+ *
+ * @see HWTIMER_SYS_PitDeinit
+ * @see HWTIMER_SYS_PitSetDiv
+ * @see HWTIMER_SYS_PitStart
+ * @see HWTIMER_SYS_PitStop
+ * @see HWTIMER_SYS_PitGetTime
+ * @see HWTIMER_SYS_PitIsrAction
+ */
+static _hwtimer_error_code_t HWTIMER_SYS_PitInit(hwtimer_t * hwtimer, uint32_t pitId, void *data)
+{
+ uint32_t pitChannel;
+ PIT_Type * base = g_pitBase[0];
+ if (FSL_FEATURE_PIT_TIMER_COUNT < pitId)
+ {
+ return kHwtimerInvalidInput;
+ }
+
+ assert(NULL != hwtimer);
+
+ /* We need to store pitId of timer in context struct */
+ hwtimer->llContext[0U] = pitId;
+
+ pitChannel = hwtimer->llContext[0U];
+
+ /* Un-gate pit clock */
+ CLOCK_SYS_EnablePitClock(0U);
+
+ /* Enable PIT module clock */
+ PIT_HAL_Enable(base);
+
+ /* Allows the timers to be stopped when the device enters the Debug mode. */
+ PIT_HAL_SetTimerRunInDebugCmd(base, false);
+
+ /* Disable timer and interrupt */
+ PIT_HAL_StopTimer(base, pitChannel);
+ PIT_HAL_SetIntCmd(base, pitChannel, false);
+ /* Clear any pending interrupt */
+ PIT_HAL_ClearIntFlag(base, pitChannel);
+
+ /* Store hwtimer in global array */
+ g_hwtimersPit[pitChannel] = hwtimer;
+
+ PIT_HAL_SetIntCmd(base, pitChannel, true);
+ INT_SYS_EnableIRQ(g_pitIrqId[pitChannel]);
+
+ return kHwtimerSuccess;
+}
+
+/*!
+ * @cond DOXYGEN_PRIVATE
+ *
+ * @brief Initialization of pit timer module
+ *
+ * Called by hwtimer_deinit. Disables the peripheral. Unregisters ISR.
+ *
+ * @param hwtimer[in] Pointer to hwtimer structure.
+ *
+ * @return kHwtimerSuccess Success.
+ * @return kHwtimerRegisterHandlerError When un-registration of the interrupt service routine failed.
+ *
+ * @see HWTIMER_SYS_PitInit
+ * @see HWTIMER_SYS_PitSetDiv
+ * @see HWTIMER_SYS_PitStart
+ * @see HWTIMER_SYS_PitStop
+ * @see HWTIMER_SYS_PitGetTime
+ * @see HWTIMER_SYS_PitIsrAction
+ */
+static _hwtimer_error_code_t HWTIMER_SYS_PitDeinit(hwtimer_t * hwtimer)
+{
+ /* We believe that if isr is shared ,than is shared for every channels */
+ PIT_Type * base = g_pitBase[0];
+ uint32_t pitChannel;
+ int i;
+
+ assert(NULL != hwtimer);
+
+ pitChannel = hwtimer->llContext[0U];
+ assert(pitChannel < FSL_FEATURE_PIT_TIMER_COUNT);
+
+ /* Remove Hwtimer from global array and disable interrupt on this channel */
+ PIT_HAL_StopTimer(base, pitChannel);
+ PIT_HAL_SetIntCmd(base, pitChannel, false);
+ PIT_HAL_ClearIntFlag(base, pitChannel);
+
+ /* Pit can have shared interrupt vectors. We need un-register interrupt only when all hwtimers are de-inited(set to NULL) */
+ g_hwtimersPit[pitChannel] = NULL;
+
+ /* Check if this is last hwtimer in pit_hwtimers_array */
+ for (i = 0U; i < FSL_FEATURE_PIT_TIMER_COUNT; i++)
+ {
+ if (NULL != g_hwtimersPit[i])
+ {
+ break;
+ }
+ }
+
+ return kHwtimerSuccess;
+}
+
+/*!
+ * @cond DOXYGEN_PRIVATE
+ *
+ * @brief Sets up timer with divider settings closest to the requested period in microseconds.
+ *
+ * The function gets the value of the base frequency of the timer via clock manager and calculates required
+ * divider ratio.
+ *
+ * Called by hwtimer_set_freq() and hwtimer_set_period().
+ * Fills in the divider (actual total divider) and modulo (sub-tick resolution) members of the HWTIMER structure.
+ *
+ * @param hwtimer[in] Pointer to hwtimer structure.
+ * @param period[in] Required period of timer in micro seconds.
+ *
+ * @return kHwtimerSuccess Success.
+ *
+ * @see HWTIMER_SYS_PitInit
+ * @see HWTIMER_SYS_PitDeinit
+ * @see HWTIMER_SYS_PitStart
+ * @see HWTIMER_SYS_PitStop
+ * @see HWTIMER_SYS_PitGetTime
+ * @see HWTIMER_SYS_PitIsrAction
+ */
+static _hwtimer_error_code_t HWTIMER_SYS_PitSetDiv(hwtimer_t * hwtimer, uint32_t period)
+{
+ uint32_t pitChannel;
+ PIT_Type * base = g_pitBase[0];
+ uint64_t divider;
+
+ assert(NULL != hwtimer);
+
+ /* Store clock frequency in struct. */
+ hwtimer->clockFreq = CLOCK_SYS_GetPitFreq(0);
+
+ divider = (((uint64_t)hwtimer->clockFreq * period)) / 1000000U ;
+ /* If required frequency is higher than input clock frequency, we set divider 1 (for setting the highest possible frequency) */
+ if (0U == divider)
+ {
+ divider = 1U;
+ }
+ /* if divider is greater than 32b value we set divider to max 32b value */
+ else if (divider & 0xFFFFFFFF00000000U)
+ {
+ return kHwtimerInvalidInput;
+ }
+
+ pitChannel = hwtimer->llContext[0U];
+ assert(pitChannel < FSL_FEATURE_PIT_TIMER_COUNT);
+
+ /* Set divider for pit chanell */
+ PIT_HAL_SetTimerPeriodByCount(base, pitChannel, divider - 1U);
+
+ hwtimer->divider = divider;
+ hwtimer->modulo = divider;
+
+ return kHwtimerSuccess;
+}
+
+
+/*!
+ * @cond DOXYGEN_PRIVATE
+ *
+ * @brief Start pit timer module
+ *
+ * This function enables the timer and leaves it running, timer is
+ * periodically generating interrupts.
+ *
+ * @param hwtimer[in] Pointer to hwtimer structure.
+ *
+ * @return kHwtimerSuccess Success.
+ *
+ * @see HWTIMER_SYS_PitInit
+ * @see HWTIMER_SYS_PitDeinit
+ * @see HWTIMER_SYS_PitSetDiv
+ * @see HWTIMER_SYS_PitStop
+ * @see HWTIMER_SYS_PitGet_time
+ * @see HWTIMER_SYS_PitIsrAction
+ */
+static _hwtimer_error_code_t HWTIMER_SYS_PitStart(hwtimer_t * hwtimer)
+{
+ uint32_t pitChannel;
+ PIT_Type * base = g_pitBase[0];
+ assert(NULL != hwtimer);
+
+ pitChannel = hwtimer->llContext[0U];
+ assert(pitChannel < FSL_FEATURE_PIT_TIMER_COUNT);
+
+ PIT_HAL_StopTimer(base, pitChannel);
+ PIT_HAL_ClearIntFlag(base, pitChannel);
+ PIT_HAL_SetIntCmd(base, pitChannel, true);
+ PIT_HAL_StartTimer(base, pitChannel);
+
+ return kHwtimerSuccess;
+}
+
+/*!
+ * @cond DOXYGEN_PRIVATE
+ *
+ * @brief Stop pit timer module
+ *
+ * Disable timer and interrupt
+ *
+ * @param hwtimer[in] Pointer to hwtimer structure.
+ *
+ * @return kHwtimerSuccess Success.
+ *
+ * @see HWTIMER_SYS_PitInit
+ * @see HWTIMER_SYS_PitDeinit
+ * @see HWTIMER_SYS_PitSetDiv
+ * @see HWTIMER_SYS_PitStart
+ * @see HWTIMER_SYS_PitGetTime
+ * @see HWTIMER_SYS_PitIsrAction
+ */
+static _hwtimer_error_code_t HWTIMER_SYS_PitStop(hwtimer_t * hwtimer)
+{
+ uint32_t pitChannel;
+ PIT_Type * base = g_pitBase[0];
+ assert(NULL != hwtimer);
+
+ pitChannel = hwtimer->llContext[0U];
+ assert(pitChannel < FSL_FEATURE_PIT_TIMER_COUNT);
+
+ /* Disable timer and interrupt */
+ PIT_HAL_StopTimer(base, pitChannel);
+ PIT_HAL_SetIntCmd(base, pitChannel, false);
+ PIT_HAL_ClearIntFlag(base, pitChannel);
+
+ return kHwtimerSuccess;
+}
+
+/*!
+ * @cond DOXYGEN_PRIVATE
+ *
+ * @brief Atomically captures current time into HWTIMER_TIME_STRUCT structure
+ *
+ * Corrects/normalizes the values if necessary (interrupt pending, etc.)
+ *
+ * @param hwtimer[in] Pointer to hwtimer structure.
+ * @param time[out] Pointer to time structure. This value is filled with current value of the timer.
+ *
+ * @return kHwtimerSuccess Success.
+ *
+ * @see HWTIMER_SYS_PitInit
+ * @see HWTIMER_SYS_PitDeinit
+ * @see HWTIMER_SYS_PitSetDiv
+ * @see HWTIMER_SYS_PitStart
+ * @see HWTIMER_SYS_PitStop
+ * @see HWTIMER_SYS_PitIsrAction
+ */
+static _hwtimer_error_code_t HWTIMER_SYS_PitGetTime(hwtimer_t *hwtimer, hwtimer_time_t *time)
+{
+ uint32_t pitChannel;
+ uint32_t tempCval;
+ PIT_Type * base = g_pitBase[0];
+ assert(NULL != hwtimer);
+ assert(NULL != time);
+
+ pitChannel = hwtimer->llContext[0U];
+ assert(pitChannel < FSL_FEATURE_PIT_TIMER_COUNT);
+
+ /* Enter critical section to avoid disabling interrupt from pit for very long time */
+ OSA_EnterCritical(kCriticalDisableInt);
+ PIT_HAL_SetIntCmd(base, pitChannel, false);
+
+ time->ticks = hwtimer->ticks;
+
+ tempCval = PIT_HAL_ReadTimerCount(base, pitChannel);
+ /* Check pending interrupt flag */
+ if (PIT_HAL_IsIntPending(base, pitChannel))
+ {
+ PIT_HAL_SetIntCmd(base, pitChannel, true);
+ OSA_ExitCritical(kCriticalDisableInt);
+ time->subTicks = hwtimer->modulo - 1U;
+ }
+ else
+ {
+ PIT_HAL_SetIntCmd(base, pitChannel, true);
+ OSA_ExitCritical(kCriticalDisableInt);
+ /* todo: following line should be updated when HAL will be updated with this functionality. */
+ time->subTicks = PIT_RD_LDVAL(base, pitChannel) - tempCval;
+ }
+
+ return kHwtimerSuccess;
+}
+ /*******************************************************************************
+ * Code
+ ******************************************************************************/
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer_pit_irq.c b/KSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer_pit_irq.c
new file mode 100755
index 0000000..3278e68
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer_pit_irq.c
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include "fsl_device_registers.h"
+
+/*!
+ * @addtogroup htwint
+ * @{
+ */
+
+/*******************************************************************************
+ * Variables
+ ******************************************************************************/
+extern void HWTIMER_SYS_PitIsrAction(uint8_t pitChannel);
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*!
+ * @brief HW Timers PIT Interrupt service routine.
+ *
+ * This is a shared interrupt handler for all PIT channels.
+ */
+#if FSL_FEATURE_PIT_HAS_SHARED_IRQ_HANDLER
+void PIT_IRQHandler(void)
+{
+ uint32_t i;
+
+ for(i = 0; i < FSL_FEATURE_PIT_TIMER_COUNT; i++)
+ {
+ HWTIMER_SYS_PitIsrAction(i);
+ }
+}
+#else
+
+#if (FSL_FEATURE_PIT_TIMER_COUNT > 0U)
+/*!
+ * @brief HW Timers PIT 0 Interrupt service routine.
+ *
+ */
+void PIT0_IRQHandler(void)
+{
+ HWTIMER_SYS_PitIsrAction(0U);
+}
+#endif
+
+#if (FSL_FEATURE_PIT_TIMER_COUNT > 1U)
+/*!
+ * @brief HW Timers PIT 1 Interrupt service routine.
+ *
+ */
+void PIT1_IRQHandler(void)
+{
+ HWTIMER_SYS_PitIsrAction(1U);
+}
+#endif
+
+#if (FSL_FEATURE_PIT_TIMER_COUNT > 2U)
+/*!
+ * @brief HW Timers PIT 2 Interrupt service routine.
+ *
+ */
+void PIT2_IRQHandler(void)
+{
+ HWTIMER_SYS_PitIsrAction(2U);
+}
+#endif
+
+#if (FSL_FEATURE_PIT_TIMER_COUNT > 3U)
+/*!
+ * @brief HW Timers PIT 3 Interrupt service routine.
+ *
+ */
+void PIT3_IRQHandler(void)
+{
+ HWTIMER_SYS_PitIsrAction(3U);
+}
+#endif
+
+#endif /* FSL_FEATURE_PIT_HAS_SHARED_IRQ_HANDLER */
+
+/*! @} */
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer_systick.c b/KSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer_systick.c
new file mode 100755
index 0000000..fba842c
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer_systick.c
@@ -0,0 +1,399 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "fsl_hwtimer.h"
+#include "fsl_hwtimer_systick.h"
+#include "fsl_os_abstraction.h"
+#include "fsl_interrupt_manager.h"
+#include "fsl_clock_manager.h"
+
+/*******************************************************************************
+ * Internal type definition
+ ******************************************************************************/
+/*******************************************************************************
+ * Internal Variables
+ ******************************************************************************/
+void HWTIMER_SYS_SystickIsrAction(void);
+static _hwtimer_error_code_t HWTIMER_SYS_SystickInit(hwtimer_t *hwtimer, uint32_t systickId, void *data);
+static _hwtimer_error_code_t HWTIMER_SYS_SystickDeinit(hwtimer_t *hwtimer);
+static _hwtimer_error_code_t HWTIMER_SYS_SystickSetDiv(hwtimer_t *hwtimer, uint32_t period);
+static _hwtimer_error_code_t HWTIMER_SYS_SystickStart(hwtimer_t *hwtimer);
+static _hwtimer_error_code_t HWTIMER_SYS_SystickStop(hwtimer_t *hwtimer);
+static _hwtimer_error_code_t HWTIMER_SYS_SystickGetTime(hwtimer_t *hwtimer, hwtimer_time_t *time);
+
+const hwtimer_devif_t kSystickDevif =
+{
+ HWTIMER_SYS_SystickInit,
+ HWTIMER_SYS_SystickDeinit,
+ HWTIMER_SYS_SystickSetDiv,
+ HWTIMER_SYS_SystickStart,
+ HWTIMER_SYS_SystickStop,
+ HWTIMER_SYS_SystickGetTime,
+};
+
+static hwtimer_t *g_hwtimersSystick = NULL;
+
+
+ /*******************************************************************************
+ * Internal Code
+ ******************************************************************************/
+
+/*!
+ * @cond DOXYGEN_PRIVATE
+ *
+ * @brief Called from the Interrupt service routine.
+ *
+ * This ISR is used when SysTick counted to 0.
+ * Checks whether callback_func is not NULL,
+ * and unless callback is blocked by callback_blocked being non-zero it calls the callback function with callback_data as parameter,
+ * otherwise callback_pending is set to non-zero value.
+ *
+ * @return void
+ *
+ * @see HWTIMER_SYS_SystickDeinit
+ * @see HWTIMER_SYS_SystickSet_div
+ * @see HWTIMER_SYS_SystickStart
+ * @see HWTIMER_SYS_SystickStop
+ * @see HWTIMER_SYS_SystickGet_time
+ */
+void HWTIMER_SYS_SystickIsrAction(void)
+{
+ hwtimer_t *hwtimer = g_hwtimersSystick;
+
+ /* Check if interrupt is enabled for this systick. Cancel spurious interrupt */
+ if (!(SysTick_CTRL_TICKINT_Msk & SysTick->CTRL))
+ {
+ return;
+ }
+
+ if (NULL != hwtimer)
+ {
+
+ /* Following part of function is typically the same for all low level hwtimer drivers */
+ hwtimer->ticks++;
+
+ if (NULL != hwtimer->callbackFunc)
+ {
+ if (hwtimer->callbackBlocked)
+ {
+ hwtimer->callbackPending = 1U;
+ }
+ else
+ {
+ /* Run user function*/
+ hwtimer->callbackFunc(hwtimer->callbackData);
+ }
+ }
+ }
+}
+
+
+/*!
+ * @cond DOXYGEN_PRIVATE
+ *
+ * @brief This function initializes caller allocated structure according to given
+ * numerical identifier of the timer.
+ *
+ * Called by hwtimer_init().
+ * Initializes the hwtimer_t structure.
+ *
+ * @param hwtimer[in] Returns initialized hwtimer structure handle.
+ * @param systickId[in] Determines Systick modul( Always 0).
+ * @param isrPrior[in] Interrupt priority for systick
+ * @param data[in] Specific data. Not used in this timer.
+ *
+ * @return kHwtimerSuccess Success.
+ * @return kHwtimerInvalidInput When systick_id does not exist(When systick_id is not zero).
+ * @return kHwtimerRegisterHandlerError When registration of the interrupt service routine failed.
+ *
+ * @see HWTIMER_SYS_SystickDeinit
+ * @see HWTIMER_SYS_SystickSet_div
+ * @see HWTIMER_SYS_SystickStart
+ * @see HWTIMER_SYS_SystickStop
+ * @see HWTIMER_SYS_SystickGet_time
+ * @see HWTIMER_SYS_SystickIsrAction
+ */
+static _hwtimer_error_code_t HWTIMER_SYS_SystickInit(hwtimer_t *hwtimer, uint32_t systickId, void *data)
+{
+
+ assert(NULL != hwtimer);
+ /* We count only with one systick module inside core */
+ if ( 1U <= systickId)
+ {
+ return kHwtimerInvalidInput;
+ }
+
+ /* Disable timer and interrupt. Set clock source to processor clock */
+ /* But mostly The CLKSOURCE bit in SysTick Control and Status register is always set to select the core clock. */
+ SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk;
+
+ /* Reset reload value register. A start value of 0 is possible, but has no effect */
+ SysTick->LOAD = 0U;
+ /* A write of any value to current value register clears the field to 0, and also clears the SYST_CSR COUNTFLAG bit to 0. */
+ SysTick->VAL = 0U;
+
+ /* Store hwtimer in global variable */
+ g_hwtimersSystick = hwtimer;
+
+ return kHwtimerSuccess;
+}
+
+/*!
+ * @cond DOXYGEN_PRIVATE
+ *
+ * @brief Initialization of systick timer module
+ *
+ * Called by hwtimer_deinit. Disables the peripheral. Unregisters ISR.
+ *
+ * @param hwtimer[in] Pointer to hwtimer structure.
+ *
+ * @return kHwtimerSuccess Success.
+ * @return kHwtimerRegisterHandlerError When registration of the interrupt service routine failed.
+ *
+ * @see HWTIMER_SYS_SystickInit
+ * @see HWTIMER_SYS_SystickSet_div
+ * @see HWTIMER_SYS_SystickStart
+ * @see HWTIMER_SYS_SystickStop
+ * @see HWTIMER_SYS_SystickGet_time
+ * @see HWTIMER_SYS_SystickIsrAction
+ */
+static _hwtimer_error_code_t HWTIMER_SYS_SystickDeinit(hwtimer_t *hwtimer)
+{
+ _hwtimer_error_code_t retval = kHwtimerSuccess;
+ assert(NULL != hwtimer);
+
+ /* Disable timer and interrupt */
+ SysTick->CTRL = 0U;
+ /* Reset reload value register. A start value of 0 is possible, but has no effect */
+ SysTick->LOAD = 0U;
+ /* A write of any value to current value register clears the field to 0, and also clears the SYST_CSR COUNTFLAG bit to 0. */
+ SysTick->VAL = 0U;
+
+ g_hwtimersSystick = NULL;
+
+ return retval;
+}
+
+/*!
+ * @cond DOXYGEN_PRIVATE
+ *
+ * @brief Sets up timer with divider settings closest to the requested period in microseconds.
+ *
+ * The function gets the value of the base frequency of the timer via clock manager and calculates required
+ * divider ratio. If the required period is a large value, then the code will try to use a low-frequency
+ * external clock if available.
+ *
+ * Called by hwtimer_set_freq() and hwtimer_set_period().
+ * Fills in the divider (actual total divider) and modulo (sub-tick resolution) members of the hwtimer_t structure.
+ *
+ * @param hwtimer[in] Pointer to hwtimer structure.
+ * @param period[in] Required period of timer in micro seconds.
+ *
+ * @return kHwtimerSuccess Success.
+ * @return kHwtimerInvalidInput Divider is equal too big.
+ *
+ * @see HWTIMER_SYS_SystickInit
+ * @see HWTIMER_SYS_SystickDeinit
+ * @see HWTIMER_SYS_SystickStart
+ * @see HWTIMER_SYS_SystickStop
+ * @see HWTIMER_SYS_SystickGet_time
+ * @see HWTIMER_SYS_SystickIsrAction
+ */
+static _hwtimer_error_code_t HWTIMER_SYS_SystickSetDiv(hwtimer_t *hwtimer, uint32_t period)
+{
+ assert(NULL != hwtimer);
+ uint64_t divider;
+
+#if FSL_FEATURE_SYSTICK_HAS_EXT_REF
+ /* Set the clock source back to core freq */
+ CLOCK_SYS_SetSystickSrc(kClockSystickSrcCore);
+#endif
+ /* Get Core clock frequency */
+ hwtimer->clockFreq = CLOCK_SYS_GetSystickFreq();
+
+ divider = (((uint64_t)hwtimer->clockFreq * period)) / 1000000U ;
+
+ /* if divider is greater than 24b value we return an error */
+ if ((divider - 1U) & ~SysTick_LOAD_RELOAD_Msk)
+ {
+#if FSL_FEATURE_SYSTICK_HAS_EXT_REF
+ /* Check if we can use a slower clock source to get required period */
+ CLOCK_SYS_SetSystickSrc(kClockSystickSrcExtRef);
+ hwtimer->clockFreq = CLOCK_SYS_GetSystickFreq();
+ divider = (((uint64_t)hwtimer->clockFreq * period)) / 1000000U ;
+
+ if ((divider - 1U) & ~SysTick_LOAD_RELOAD_Msk)
+ {
+ return kHwtimerInvalidInput;
+ }
+#else
+ return kHwtimerInvalidInput;
+#endif
+ }
+
+ /*
+ * A start value of 0 (divider == 1) is possible, but has no effect because the
+ * SysTick interrupt and COUNTFLAG are activated when counting from 1 to 0.
+ */
+ if (divider == 1U)
+ {
+ divider = 2U; /* Set smallest possible value for divider. */
+ }
+
+ SysTick->LOAD = divider - 1U;
+
+ /* Store in struct. */
+ hwtimer->divider = divider;
+ hwtimer->modulo = divider;
+
+ return kHwtimerSuccess;
+}
+
+
+/*!
+ * @cond DOXYGEN_PRIVATE
+ *
+ * @brief Start systick timer module
+ *
+ * This function enables the timer and leaves it running, timer is
+ * periodically generating interrupts.
+ *
+ * @param hwtimer[in] Pointer to hwtimer structure.
+ *
+ * @return kHwtimerSuccess Success.
+ *
+ * @see HWTIMER_SYS_SystickInit
+ * @see HWTIMER_SYS_SystickDeinit
+ * @see HWTIMER_SYS_SystickSet_div
+ * @see HWTIMER_SYS_SystickStop
+ * @see HWTIMER_SYS_SystickGet_time
+ * @see HWTIMER_SYS_SystickIsrAction
+ */
+static _hwtimer_error_code_t HWTIMER_SYS_SystickStart(hwtimer_t *hwtimer)
+{
+ assert(NULL != hwtimer);
+
+ /* A write of any value to current value register clears the field to 0, and also clears the SYST_CSR COUNTFLAG bit to 0. */
+ SysTick->VAL = 0U;
+
+ /* Run timer and enable interrupt */
+ SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_TICKINT_Msk;
+
+ return kHwtimerSuccess;
+}
+
+/*!
+ * @cond DOXYGEN_PRIVATE
+ *
+ * @brief Stop systick timer module.
+ *
+ * Disable timer and interrupt.
+ *
+ * @param hwtimer[in] Pointer to hwtimer structure.
+ *
+ * @return kHwtimerSuccess Success.
+ *
+ * @see HWTIMER_SYS_SystickInit
+ * @see HWTIMER_SYS_SystickDeinit
+ * @see HWTIMER_SYS_SystickSet_div
+ * @see HWTIMER_SYS_SystickStart
+ * @see HWTIMER_SYS_SystickGet_time
+ * @see HWTIMER_SYS_SystickIsrAction
+ */
+static _hwtimer_error_code_t HWTIMER_SYS_SystickStop(hwtimer_t *hwtimer)
+{
+ assert(NULL != hwtimer);
+
+ /* Disable timer and interrupt */
+ SysTick->CTRL = 0U;
+
+ return kHwtimerSuccess;
+}
+
+/*!
+ * @cond DOXYGEN_PRIVATE
+ *
+ * @brief Atomically captures current time into Hwtimer_time structure.
+ *
+ * Corrects/normalizes the values if necessary (interrupt pending, etc.)
+ *
+ * @param hwtimer[in] Pointer to hwtimer structure.
+ * @param time[out] Pointer to time structure. This value is filled with current value of the timer.
+ *
+ * @return kHwtimerSuccess Success.
+ *
+ * @warning This function calls _int_enable and _int_disable functions
+ *
+ * @see HWTIMER_SYS_SystickInit
+ * @see HWTIMER_SYS_SystickDeinit
+ * @see HWTIMER_SYS_SystickSet_div
+ * @see HWTIMER_SYS_SystickStart
+ * @see HWTIMER_SYS_SystickStop
+ * @see HWTIMER_SYS_SystickIsrAction
+ */
+static _hwtimer_error_code_t HWTIMER_SYS_SystickGetTime(hwtimer_t *hwtimer, hwtimer_time_t *time)
+{
+ uint32_t tempVal;
+
+ assert(NULL != hwtimer);
+ assert(NULL != time);
+
+ /* Enter critical section to avoid disabling interrupt from pit for very long time */
+ OSA_EnterCritical(kCriticalDisableInt);
+ SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
+
+ time->ticks = hwtimer->ticks;
+ tempVal = SysTick->VAL;
+ /* Check systick pending interrupt flag */
+ if (SCB->ICSR & SCB_ICSR_PENDSTSET_Msk)
+ {
+ SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
+ OSA_ExitCritical(kCriticalDisableInt);
+ time->subTicks = hwtimer->modulo - 1U;
+ }
+ else
+ {
+ SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
+ OSA_ExitCritical(kCriticalDisableInt);
+ /* interrupt flag is set upon 1->0 transition, not upon reload - wrap around */
+ time->subTicks = SysTick->LOAD - tempVal + 1U;
+ }
+
+ return kHwtimerSuccess;
+}
+ /*******************************************************************************
+ * Code
+ ******************************************************************************/
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
diff --git a/KSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer_systick_irq.c b/KSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer_systick_irq.c
new file mode 100755
index 0000000..09c4354
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/hwtimer/fsl_hwtimer_systick_irq.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*!
+ * @addtogroup htwint
+ * @{
+ */
+
+/*******************************************************************************
+ * Variables
+ ******************************************************************************/
+extern void HWTIMER_SYS_SystickIsrAction(void);
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*!
+ * @brief Interrupt service routine.
+ */
+void SysTick_Handler(void)
+{
+ HWTIMER_SYS_SystickIsrAction();
+}
+
+/*! @} */
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/interrupt/fsl_interrupt_manager.c b/KSDK_1.2.0/platform/system/src/interrupt/fsl_interrupt_manager.c
new file mode 100755
index 0000000..1bb3ed3
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/interrupt/fsl_interrupt_manager.c
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <assert.h>
+#include "fsl_interrupt_manager.h"
+
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/*!
+ * @brief Counter to manage the nested callings of global disable/enable interrupt.
+ */
+uint32_t g_interruptDisableCount = 0;
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : INT_SYS_InstallHandler
+ * Description : Install an interrupt handler routine for a given IRQ number
+ * This function will let application to register/replace the interrupt
+ * handler for specified IRQ number. IRQ number is different with Vector
+ * number. IRQ 0 will start from Vector 16 address. Refer to reference
+ * manual for details. Also refer to startup_MKxxxx.s file for each chip
+ * family to find out the default interrut handler for each device. This
+ * function will convert the IRQ number to vector number by adding 16 to
+ * it.
+ *
+ *END**************************************************************************/
+void * INT_SYS_InstallHandler(IRQn_Type irqNumber, void (*handler)(void))
+{
+#if (defined(__CC_ARM))
+ extern uint32_t Image$$VECTOR_RAM$$Base[];
+ #define __VECTOR_RAM Image$$VECTOR_RAM$$Base
+#else
+ extern uint32_t __VECTOR_RAM[];
+#endif
+
+ /* Check IRQ number */
+ assert(FSL_FEATURE_INTERRUPT_IRQ_MIN <= irqNumber);
+ assert(irqNumber <= FSL_FEATURE_INTERRUPT_IRQ_MAX);
+
+ /* Check whether there is vector table in RAM */
+ assert(__VECTOR_RAM != 0U);
+
+ /* Save the former handler pointer */
+ void * retVal = (void *)__VECTOR_RAM[irqNumber + 16];
+
+ /* Set handler into vector table */
+ __VECTOR_RAM[irqNumber + 16] = (uint32_t)handler;
+
+ return retVal;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : INT_SYS_EnableIRQGlobal
+ * Description : Enable system interrupt
+ * This function will enable the global interrupt by calling the core API
+ *
+ *END**************************************************************************/
+void INT_SYS_EnableIRQGlobal(void)
+{
+ /* check and update */
+ if (g_interruptDisableCount > 0)
+ {
+ g_interruptDisableCount--;
+
+ if (g_interruptDisableCount > 0)
+ {
+ return;
+ }
+
+ /* call core API to enable the global interrupt*/
+ __enable_irq();
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : INT_SYS_DisableIRQGlobal
+ * Description : Disnable system interrupt
+ * This function will disable the global interrupt by calling the core API
+ *
+ *END**************************************************************************/
+void INT_SYS_DisableIRQGlobal(void)
+{
+ /* call core API to disable the global interrupt*/
+ __disable_irq();
+
+ /* update counter*/
+ g_interruptDisableCount++;
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/power/fsl_power_manager.c b/KSDK_1.2.0/platform/system/src/power/fsl_power_manager.c
new file mode 100755
index 0000000..c0df8dc
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/power/fsl_power_manager.c
@@ -0,0 +1,953 @@
+/*
+ * Copyright (c) 2014-2015, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "fsl_power_manager_common.h"
+#include "fsl_power_manager.h"
+#include "fsl_smc_hal.h"
+#include "fsl_pmc_hal.h"
+#include "fsl_rcm_hal.h"
+#include "fsl_sim_hal.h"
+#include "fsl_os_abstraction.h"
+#include "fsl_clock_manager.h"
+#include <string.h>
+
+/* Checks mcg version */
+#if defined(FSL_FEATURE_MCGLITE_MCGLITE)
+#if (FSL_FEATURE_MCGLITE_MCGLITE)
+#define POWER_VLPR_MCG_LITE 1
+#endif
+#endif
+
+/* Includes mcg or mcglite hal */
+#if defined(POWER_VLPR_MCG_LITE)
+#include "fsl_mcglite_hal_modes.h"
+#include "fsl_mcglite_hal.h"
+#else
+#include "fsl_mcg_hal_modes.h"
+#include "fsl_mcg_hal.h"
+#endif
+
+/* Maximum allowed clocks for VLPR mode */
+#if defined(POWER_VLPR_MCG_LITE)
+#define POWER_VLPR_MAX_CLK 2000000UL
+#else
+#define POWER_VLPR_MAX_CLK 4000000UL
+#define POWER_VLPR_MCG_LITE 0
+#endif
+
+#define POWER_VLPR_MAX_FLASH_BLPE_CLK 1000000UL
+/*! For BLPI mode the maximum allowed flash clock in VLPR mode is 800 kHz or 1 MHz, see RM for details */
+#define POWER_VLPR_MAX_FLASH_BLPI_CLK 1000000UL
+
+/*******************************************************************************
+ * Internal Variables
+ ******************************************************************************/
+
+/*! @brief Power manager internal structure. */
+static power_manager_state_t gPowerManagerState;
+
+/*! @brief Power manager internal structure lock. */
+mutex_t gPowerManagerStateSync;
+
+/*******************************************************************************
+ * PROTOTYPES
+ ******************************************************************************/
+
+static power_manager_error_code_t POWER_SYS_WaitForRunStatus(void);
+static power_manager_error_code_t POWER_SYS_WaitForVlprStatus(void);
+static power_manager_error_code_t POWER_SYS_CheckClocks(power_manager_modes_t mode);
+
+/*!
+ * @brief Macros for power manager lock mechanism.
+ *
+ * Mutex is used when operating system is present otherwise critical section
+ * (global interrupt disable).
+ *
+ */
+#if (USE_RTOS)
+ #define POWER_SYS_LOCK_INIT() OSA_MutexCreate(&gPowerManagerStateSync)
+ #define POWER_SYS_LOCK() OSA_MutexLock(&gPowerManagerStateSync, OSA_WAIT_FOREVER)
+ #define POWER_SYS_UNLOCK() OSA_MutexUnlock(&gPowerManagerStateSync)
+ #define POWER_SYS_LOCK_DEINIT() OSA_MutexDestroy(&gPowerManagerStateSync)
+#else
+ #define POWER_SYS_LOCK_INIT() do {}while(0)
+ #define POWER_SYS_LOCK() OSA_EnterCritical(kCriticalDisableInt)
+ #define POWER_SYS_UNLOCK() OSA_ExitCritical(kCriticalDisableInt)
+ #define POWER_SYS_LOCK_DEINIT() do {}while(0)
+#endif
+
+/*! Timeout used for waiting to set new mode */
+#define POWER_SET_MODE_TIMEOUT 1000U
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : POWER_SYS_Init
+ * Description : Initializes the Power manager for operation.
+ * This function initializes the Power manager and its run-time state structure.
+ * Reference to an array of Power mode configuration structures has to be passed
+ * as parameter along with parameter specifying its size. At least one power mode
+ * configuration is required. Optionally, reference to array of predefined
+ * call-backs can be passed with its size parameter.
+ * For details about call-backs refer to the power_manager_callback_user_config_t.
+ * As Power manager stores only references to array of these structures they have
+ * to exist while Power manager is used.
+ * It is expected that prior POWER_SYS_Init() call the write-once protection
+ * register was configured appropriately allowing to enter all required low power
+ * modes.
+ * The following is an example of how to set up two power modes and three
+ * call-backs and initialize the Power manager with structures containing their settings.
+ * The example shows two possible ways how where the configuration structures can be stored
+ * (ROM or RAM) although it is expected that they will be placed rather in the read-only
+ * memory to save the RAM space. (Note: In the example it is assumed that the programmed chip
+ * doesn't support any optional power options described in the power_manager_user_config_t)
+ *
+ *END**************************************************************************/
+power_manager_error_code_t POWER_SYS_Init(power_manager_user_config_t const ** powerConfigsPtr,
+ uint8_t configsNumber,
+ power_manager_callback_user_config_t ** callbacksPtr,
+ uint8_t callbacksNumber)
+{
+ /* Check input parameter - at least one power mode configuration is required */
+ if ((powerConfigsPtr == NULL) || (configsNumber == 0U))
+ {
+ return kPowerManagerError;
+ }
+ /* Initialize internal state structure lock */
+ POWER_SYS_LOCK_INIT();
+ /* Initialize internal state structure */
+ memset(&gPowerManagerState, 0, sizeof(power_manager_state_t));
+ /* Store references to user-defined power mode configurations */
+ gPowerManagerState.configs = powerConfigsPtr;
+ gPowerManagerState.configsNumber = configsNumber;
+ /* Store references to user-defined callback configurations and increment call-back handle counter */
+ if (callbacksPtr != NULL)
+ {
+ gPowerManagerState.staticCallbacks = callbacksPtr;
+ gPowerManagerState.staticCallbacksNumber = callbacksNumber;
+ /* Default value of handle of last call-back that returned error */
+ gPowerManagerState.errorCallbackIndex = callbacksNumber;
+ }
+ /* Enables clock gate for LLWU */
+#if FSL_FEATURE_SIM_HAS_SCGC_LLWU
+ SIM_HAL_EnableClock(SIM,kSimClockGateLlwu0);
+#endif
+ return kPowerManagerSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : POWER_SYS_Deinit
+ * Description : Deinitializes the Power manager.
+ *
+ *END**************************************************************************/
+power_manager_error_code_t POWER_SYS_Deinit(void)
+{
+ /* Deinitialize internal state structure lock */
+ POWER_SYS_LOCK_DEINIT();
+ return kPowerManagerSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : POWER_SYS_SetMode
+ * Description : Configures the power mode.
+ *
+ * This function switches to one of the defined power modes. Requested mode number is passed
+ * as an input parameter. This function notifies all registered callback functions before
+ * the mode change (using kPowerManagerCallbackBefore set as callback type parameter),
+ * sets specific power options defined in the power mode configuration and enters the specified
+ * mode. In case of run modes (for example, Run, Very low power run, or High speed run), this function
+ * also invokes all registered callbacks after the mode change (using kPowerManagerCallbackAfter).
+ * In case of sleep or deep sleep modes, if the requested mode is not exited through
+ * a reset, these notifications are sent after the core wakes up.
+ * Callbacks are invoked in the following order: All registered callbacks are notified
+ * ordered by index in the callbacks array (see callbacksPtr parameter of POWER_SYS_Init()).
+ * The same order is used for before and after switch notifications.
+ * The notifications before the power mode switch can be used to obtain confirmation about
+ * the change from registered callbacks. If any registered callback denies the power
+ * mode change, further execution of this function depends on mode change policy: the mode
+ * change is either forced (kPowerManagerPolicyForcible) or exited (kPowerManagerPolicyAgreement).
+ * When mode change is forced, the result of the before switch notifications are ignored. If
+ * agreement is required, if any callback returns an error code then further notifications
+ * before switch notifications are cancelled and all already notified callbacks are re-invoked
+ * with kPowerManagerCallbackAfter set as callback type parameter. The index of the callback
+ * which returned error code during pre-switch notifications is stored (any error codes during
+ * callbacks re-invocation are ignored) and POWER_SYS_GetErrorCallback() can be used to get it.
+ * Regardless of the policies, if any callback returned an error code, an error code denoting in which phase
+ * the error occurred is returned when POWER_SYS_SetMode() exits.
+ * It is possible to enter any mode supported by the processor. Refer to the chip reference manual
+ * for list of available power modes. If it is necessary to switch into intermediate power mode prior to
+ * entering requested mode (for example, when switching from Run into Very low power wait through Very low
+ * power run mode), then the intermediate mode is entered without invoking the callback mechanism.
+ *
+ *END**************************************************************************/
+power_manager_error_code_t POWER_SYS_SetMode(uint8_t powerModeIndex, power_manager_policy_t policy)
+{
+ power_manager_user_config_t const * configPtr; /* Local pointer to the requested user-defined power mode configuration */
+ power_manager_modes_t mode; /* Local variable with requested power mode */
+ smc_power_mode_config_t halModeConfig; /* SMC HAL layer configuration structure */
+ uint8_t currentStaticCallback = 0U; /* Index to array of statically registered call-backs */
+ power_manager_error_code_t returnCode = kPowerManagerSuccess; /* Function return */
+ power_manager_error_code_t clockCheckRetCode; /* Return code from clock checks */
+ power_manager_notify_struct_t notifyStruct; /* Callback notification structure */
+ power_manager_callback_user_config_t * callbackConfig; /* Pointer to callback configuration */
+
+ /* Default value of handle of last call-back that returned error */
+ gPowerManagerState.errorCallbackIndex = gPowerManagerState.staticCallbacksNumber;
+
+ POWER_SYS_LOCK();
+ /* Requested power mode configuration availability check */
+ if (powerModeIndex >= gPowerManagerState.configsNumber)
+ {
+ POWER_SYS_UNLOCK();
+ return kPowerManagerErrorOutOfRange;
+ }
+
+ /* Initialization of local variables from the Power manager state structure */
+ configPtr = gPowerManagerState.configs[powerModeIndex];
+ mode = configPtr->mode;
+ notifyStruct.policy = policy;
+ notifyStruct.targetPowerConfigIndex = powerModeIndex;
+ notifyStruct.targetPowerConfigPtr = configPtr;
+
+ /* Check that requested power mode is not protected */
+ if ((mode == kPowerManagerVlpr) || (mode == kPowerManagerVlpw) || (mode == kPowerManagerVlps))
+ {
+ if (!SMC_HAL_GetProtection(SMC, kAllowPowerModeVlp))
+ {
+ POWER_SYS_UNLOCK();
+ return kPowerManagerError;
+ }
+ }
+#if FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE
+#if FSL_FEATURE_SMC_HAS_STOP_SUBMODE0
+ else if ((mode >= kPowerManagerLls) && (mode < kPowerManagerVlls0))
+#else
+ else if ((mode >= kPowerManagerLls) && (mode < kPowerManagerVlls1))
+#endif
+ {
+ if (!SMC_HAL_GetProtection(SMC, kAllowPowerModeLls))
+ {
+ POWER_SYS_UNLOCK();
+ return kPowerManagerError;
+ }
+ }
+#endif
+#if FSL_FEATURE_SMC_HAS_STOP_SUBMODE0
+ else if (mode >= kPowerManagerVlls0)
+#else
+ else if (mode >= kPowerManagerVlls1)
+#endif
+ {
+ if (!SMC_HAL_GetProtection(SMC, kAllowPowerModeVlls))
+ {
+ POWER_SYS_UNLOCK();
+ return kPowerManagerError;
+ }
+ }
+
+ notifyStruct.notifyType = kPowerManagerNotifyBefore;
+ /* From all statically registered call-backs... */
+ for (currentStaticCallback = 0U; currentStaticCallback < gPowerManagerState.staticCallbacksNumber; currentStaticCallback++)
+ {
+ callbackConfig = (gPowerManagerState.staticCallbacks[currentStaticCallback]);
+ /* Check pointer to static callback configuration */
+ if ( callbackConfig != NULL ){
+ /* ...notify only those which asked to be called before the power mode change */
+ if (((uint32_t)callbackConfig->callbackType) & kPowerManagerCallbackBefore)
+ {
+ /* In case that call-back returned error code mark it, store the call-back handle and eventually cancel the mode switch */
+ if (callbackConfig->callback(&notifyStruct, callbackConfig->callbackData) != kPowerManagerSuccess)
+ {
+ returnCode = kPowerManagerErrorNotificationBefore;
+ gPowerManagerState.errorCallbackIndex = currentStaticCallback;
+ /* If not forcing power mode switch, call all already notified call-backs to revert their state as the mode change is canceled */
+ if (policy != kPowerManagerPolicyForcible)
+ {
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ POWER_SYS_UNLOCK();
+
+ /* Clocks should be in desired range. Some registered callback can change the clock so checks clock after callbacks */
+ clockCheckRetCode = POWER_SYS_CheckClocks(mode);
+
+ /* Power mode switch */
+
+ /* In case that any call-back returned error code and policy doesn't force the mode switch go to after switch call-backs */
+ if ( ((policy == kPowerManagerPolicyForcible) || (returnCode == kPowerManagerSuccess)) && (clockCheckRetCode == kPowerManagerSuccess))
+ {
+#if FSL_FEATURE_SMC_HAS_LPWUI
+ halModeConfig.lpwuiOptionValue = configPtr->lowPowerWakeUpOnInterruptValue;
+#endif
+
+ /* Configure the HAL layer */
+ switch (mode) {
+#if FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE
+ /* High speed run mode */
+ case kPowerManagerHsrun:
+ halModeConfig.powerModeName = kPowerModeHsrun;
+ break;
+#endif
+ /* Run mode */
+ case kPowerManagerRun:
+ halModeConfig.powerModeName = kPowerModeRun;
+ break;
+ /* Very low power run mode */
+ case kPowerManagerVlpr:
+ halModeConfig.powerModeName = kPowerModeVlpr;
+ break;
+ /* Wait mode */
+ case kPowerManagerWait:
+ halModeConfig.powerModeName = kPowerModeWait;
+ break;
+ /* Very low power wait mode */
+ case kPowerManagerVlpw:
+ halModeConfig.powerModeName = kPowerModeVlpw;
+ break;
+#if FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE
+ /* Low leakage stop modes */
+ case kPowerManagerLls:
+ halModeConfig.powerModeName = kPowerModeLls;
+ break;
+#if FSL_FEATURE_SMC_HAS_LLS_SUBMODE
+ case kPowerManagerLls2:
+ halModeConfig.powerModeName = kPowerModeLls;
+ halModeConfig.stopSubMode = kSmcStopSub2;
+ break;
+ case kPowerManagerLls3:
+ halModeConfig.powerModeName = kPowerModeLls;
+ halModeConfig.stopSubMode = kSmcStopSub3;
+ break;
+#endif
+#endif
+ /* Very low leakage stop modes */
+#if FSL_FEATURE_SMC_HAS_STOP_SUBMODE0
+ case kPowerManagerVlls0:
+ halModeConfig.powerModeName = kPowerModeVlls;
+ halModeConfig.stopSubMode = kSmcStopSub0;
+#if FSL_FEATURE_SMC_HAS_PORPO
+ /* Optionally setup the power-on-reset detect circuit in VLLS0 */
+ halModeConfig.porOptionValue = configPtr->powerOnResetDetectionValue;
+#endif
+ break;
+#endif
+ case kPowerManagerVlls1:
+ halModeConfig.powerModeName = kPowerModeVlls;
+ halModeConfig.stopSubMode = kSmcStopSub1;
+ break;
+#if FSL_FEATURE_SMC_HAS_STOP_SUBMODE2
+ case kPowerManagerVlls2:
+ halModeConfig.powerModeName = kPowerModeVlls;
+ halModeConfig.stopSubMode = kSmcStopSub2;
+#if FSL_FEATURE_SMC_HAS_RAM2_POWER_OPTION
+ /* Optionally setup the RAM2 partition retention in VLLS2 */
+ halModeConfig.ram2OptionValue = configPtr->RAM2PartitionValue;
+#endif
+ break;
+#endif
+ case kPowerManagerVlls3:
+ halModeConfig.powerModeName = kPowerModeVlls;
+ halModeConfig.stopSubMode = kSmcStopSub3;
+ break;
+#if FSL_FEATURE_SMC_HAS_PSTOPO
+ /* Partial stop modes */
+ case kPowerManagerPstop1:
+ halModeConfig.powerModeName = kPowerModeStop;
+ halModeConfig.pstopOptionValue = kSmcPstopStop1;
+ break;
+ case kPowerManagerPstop2:
+ halModeConfig.powerModeName = kPowerModeStop;
+ halModeConfig.pstopOptionValue = kSmcPstopStop2;
+ break;
+#endif
+ /* Stop mode */
+ case kPowerManagerStop:
+ halModeConfig.powerModeName = kPowerModeStop;
+#if FSL_FEATURE_SMC_HAS_PSTOPO
+ halModeConfig.pstopOptionValue = kSmcPstopStop;
+#endif
+ break;
+ /* Very low power stop mode */
+ case kPowerManagerVlps:
+ halModeConfig.powerModeName = kPowerModeVlps;
+ break;
+ default:
+ return kPowerManagerErrorSwitch;
+ }
+
+#if FSL_FEATURE_SMC_HAS_LPOPO
+#if FSL_FEATURE_SMC_HAS_LOW_LEAKAGE_STOP_MODE
+ if ((mode >= kPowerManagerLls) && (mode <= kPowerManagerVlls3))
+#else
+#if FSL_FEATURE_SMC_HAS_STOP_SUBMODE0
+ if ((mode >= kPowerManagerVlls0) && (mode <= kPowerManagerVlls3))
+#else
+ if ((mode >= kPowerManagerVlls1) && (mode <= kPowerManagerVlls3))
+#endif
+#endif
+ {
+ /* Optionally setup the LPO operation in LLSx/VLLSx */
+ halModeConfig.lpoOptionValue = configPtr->lowPowerOscillatorValue;
+ }
+#endif
+
+ /* Configure ARM core what to do after interrupt invoked in (deep) sleep state */
+ if (mode >= kPowerManagerWait)
+ {
+ if (configPtr->sleepOnExitValue)
+ {
+ /* Go back to (deep) sleep state on ISR exit */
+ SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;
+ }
+ else
+ {
+ /* Do not re-enter (deep) sleep state on ISR exit */
+ SCB->SCR &= ~(SCB_SCR_SLEEPONEXIT_Msk);
+ }
+ }
+
+ /* Switch the mode */
+ if (SMC_HAL_SetMode(SMC, &halModeConfig) != kSmcHalSuccess)
+ {
+ returnCode = kPowerManagerErrorSwitch;
+ }
+
+ /* Wait until new run mode is entered */
+ if (mode == kPowerManagerRun)
+ {
+ returnCode = POWER_SYS_WaitForRunStatus();
+
+ if(returnCode != kPowerManagerSuccess)
+ {
+ return returnCode;
+ }
+ }
+ else if (mode == kPowerManagerVlpr)
+ {
+ returnCode = POWER_SYS_WaitForVlprStatus();
+
+ if(returnCode != kPowerManagerSuccess)
+ {
+ return returnCode;
+ }
+ }
+
+ /* End of successful switch */
+
+ POWER_SYS_LOCK();
+ /* Update current configuration index */
+ gPowerManagerState.currentConfig = powerModeIndex;
+ notifyStruct.notifyType = kPowerManagerNotifyAfter;
+ /* From all statically registered call-backs... */
+ for (currentStaticCallback = 0U; currentStaticCallback < gPowerManagerState.staticCallbacksNumber; currentStaticCallback++)
+ {
+ callbackConfig = (gPowerManagerState.staticCallbacks[currentStaticCallback]);
+ /* Check pointer to static callback configuration */
+ if ( callbackConfig != NULL ){
+ /* ...notify only those which asked to be called after the power mode change */
+ if (((uint32_t)callbackConfig->callbackType) & kPowerManagerCallbackAfter)
+ {
+ /* In case that call-back returned error code mark it and store the call-back handle */
+ if (callbackConfig->callback(&notifyStruct, callbackConfig->callbackData) != kPowerManagerSuccess)
+ {
+ returnCode = kPowerManagerErrorNotificationAfter;
+ gPowerManagerState.errorCallbackIndex = currentStaticCallback;
+
+ }
+ }
+ }
+ }
+ POWER_SYS_UNLOCK();
+ }
+ else
+ {
+ /* End of unsuccessful switch */
+
+ /* Checks if we can't switch due to clock */
+ if((policy == kPowerManagerPolicyForcible) || (returnCode == kPowerManagerSuccess))
+ {
+ returnCode = clockCheckRetCode;
+ }
+
+ POWER_SYS_LOCK();
+
+ notifyStruct.notifyType = kPowerManagerNotifyRecover;
+ while(currentStaticCallback--)
+ {
+ callbackConfig = (gPowerManagerState.staticCallbacks[currentStaticCallback]);
+ /* Check pointer to static callback configuration */
+ if ( callbackConfig != NULL ){
+ if (((uint32_t)callbackConfig->callbackType) & kPowerManagerCallbackBefore)
+ {
+ callbackConfig->callback(&notifyStruct, callbackConfig->callbackData);
+ }
+ }
+ }
+ POWER_SYS_UNLOCK();
+
+ }
+
+ return returnCode;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : POWER_SYS_GetLastModeIndex
+ * Description : This function returns power mode set as the last one.
+ *
+ * This function returns index of power mode which was set using POWER_SYS_SetMode() as the last one.
+ * If the power mode was entered although some of the registered call-back denied the mode change
+ * or if any of the call-backs invoked after the entering/restoring run mode failed then the return
+ * code of this function has kPowerManagerError value.
+ * value.
+ *
+ *END**************************************************************************/
+power_manager_error_code_t POWER_SYS_GetLastMode(uint8_t *powerModeIndexPtr)
+{
+ POWER_SYS_LOCK();
+ /* Pass index of user-defined configuration structure of currently running power mode */
+ *powerModeIndexPtr = gPowerManagerState.currentConfig;
+ /* Return whether all call-backs executed without error */
+ if (gPowerManagerState.errorCallbackIndex == gPowerManagerState.staticCallbacksNumber)
+ {
+ POWER_SYS_UNLOCK();
+ return kPowerManagerSuccess;
+ }
+ else
+ {
+ POWER_SYS_UNLOCK();
+ return kPowerManagerError;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : POWER_SYS_GetLastModeConfig
+ * Description : This function returns user configuration structure of power mode set as the last one.
+ *
+ * This function returns reference to configuration structure which was set using POWER_SYS_SetMode()
+ * as the last one. If the current power mode was entered although some of the registered call-back denied
+ * the mode change or if any of the call-backs invoked after the entering/restoring run mode failed then
+ * the return code of this function has kPowerManagerError value.
+ *
+ *END**************************************************************************/
+power_manager_error_code_t POWER_SYS_GetLastModeConfig(power_manager_user_config_t const ** powerModePtr)
+{
+ POWER_SYS_LOCK();
+ /* Pass reference to user-defined configuration structure of currently running power mode */
+ *powerModePtr = gPowerManagerState.configs[gPowerManagerState.currentConfig];
+ /* Return whether all call-backs executed without error */
+ if (gPowerManagerState.errorCallbackIndex == gPowerManagerState.staticCallbacksNumber)
+ {
+ POWER_SYS_UNLOCK();
+ return kPowerManagerSuccess;
+ }
+ else
+ {
+ POWER_SYS_UNLOCK();
+ return kPowerManagerError;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : POWER_SYS_GetCurrentMode
+ * Description : Returns currently running power mode.
+ *
+ *END**************************************************************************/
+power_manager_modes_t POWER_SYS_GetCurrentMode(void)
+{
+ power_manager_modes_t retVal;
+ switch (SMC_HAL_GetStat(SMC))
+ {
+#if FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE
+ /* High speed run mode */
+ case kStatHsrun:
+ retVal = kPowerManagerHsrun;
+ break;
+#endif
+ /* Run mode */
+ case kStatRun:
+ retVal = kPowerManagerRun;
+ break;
+ /* Very low power run mode */
+ case kStatVlpr:
+ retVal = kPowerManagerVlpr;
+ break;
+ /* This should never happen - core has to be in some run mode to execute code */
+ default:
+ retVal = kPowerManagerMax;
+ break;
+ }
+ return retVal;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : POWER_SYS_GetErrorCallbackIndex
+ * Description : Returns the last failed notification callback.
+ *
+ * This function returns index of the last call-back that failed during the power mode switch while
+ * the last POWER_SYS_SetMode() was called. If the last POWER_SYS_SetMode() call ended successfully
+ * value equal to callbacks number is returned. Returned value represents index in the array of
+ * static call-backs.
+ *
+ *END**************************************************************************/
+uint8_t POWER_SYS_GetErrorCallbackIndex (void)
+{
+ return gPowerManagerState.errorCallbackIndex;
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : POWER_SYS_GetErrorCallback
+ * Description : Get the callback which returns error in last mode switch.
+ *
+ *END**************************************************************************/
+power_manager_callback_user_config_t* POWER_SYS_GetErrorCallback(void)
+{
+ /* If all callbacks return success. */
+ if (gPowerManagerState.errorCallbackIndex >= gPowerManagerState.staticCallbacksNumber)
+ {
+ return NULL;
+ }
+ else
+ {
+ return gPowerManagerState.staticCallbacks[gPowerManagerState.errorCallbackIndex];
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : POWER_SYS_GetVeryLowPowerModeStatus
+ * Description : Returns whether very low power mode is running.
+ *
+ *END**************************************************************************/
+bool POWER_SYS_GetVeryLowPowerModeStatus(void)
+{
+ /* Get current power mode and return true if it is very low power mode */
+ uint8_t status = SMC_HAL_GetStat(SMC);
+ if (status == kStatVlpr)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : POWER_SYS_GetLowLeakageWakeupResetStatus
+ * Description : Returns whether reset was caused by low leakage wake up.
+ *
+ *END**************************************************************************/
+bool POWER_SYS_GetLowLeakageWakeupResetStatus(void)
+{
+ return RCM_HAL_GetSrcStatus(RCM, kRcmWakeup);
+}
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : POWER_SYS_GetAckIsolation
+ * Description : Returns true if ACK isolation is set.
+ *
+ *END**************************************************************************/
+bool POWER_SYS_GetAckIsolation(void)
+{
+ return PMC_HAL_GetAckIsolation(PMC)?true:false;
+}
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : POWER_SYS_ClearAckIsolation
+ * Description : Clears the acknowledge isolation flag.
+ *
+ *END**************************************************************************/
+void POWER_SYS_ClearAckIsolation(void)
+{
+ if( PMC_HAL_GetAckIsolation(PMC) )
+ {
+ PMC_HAL_ClearAckIsolation(PMC);
+ }
+}
+
+#if FSL_FEATURE_SOC_LLWU_COUNT
+#if FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : POWER_SYS_SetWakeupModule
+ * Description : This function allows to set wake up module in low leakage wake up unit (LLWU).
+ *
+ *END**************************************************************************/
+void POWER_SYS_SetWakeupModule(power_wakeup_module_t module,bool enable)
+{
+ /* Checks module range which is defined by enumeration type */
+ assert( module < kPowerManagerWakeupMax);
+ /* Set module */
+ LLWU_HAL_SetInternalModuleCmd(LLWU, (llwu_wakeup_module_t)module, enable);
+
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : POWER_SYS_GetWakeupModuleFlag
+ * Description : This function allows to get wake up module flag in LLWU.
+ *
+ *END**************************************************************************/
+bool POWER_SYS_GetWakeupModuleFlag(power_wakeup_module_t module)
+{
+ /* Checks module range which is defined by enumeration type */
+ assert( module < kPowerManagerWakeupMax);
+ return LLWU_HAL_GetInternalModuleWakeupFlag(LLWU, (llwu_wakeup_module_t)module);
+}
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : POWER_SYS_SetWakeupPin
+ * Description : This function allows to set wake up pin in low leakage wake up unit (LLWU).
+ * Each of the available wake-up sources can be individually enabled or disabled.
+ *
+ *END**************************************************************************/
+void POWER_SYS_SetWakeupPin(power_wakeup_pin_t pin, llwu_external_pin_modes_t pinMode, const gpio_input_pin_t * config)
+{
+ llwu_wakeup_pin_t llwuPin = POWER_EXTRACT_LLWU_PIN(pin);
+ uint32_t gpioPin = POWER_EXTRACT_GPIO_PINNAME(pin);
+
+ assert( (uint32_t)llwuPin < FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN);
+ LLWU_HAL_SetExternalInputPinMode(LLWU,pinMode, llwuPin);
+
+ /* Configures gpio pin if config is passed */
+ if( (gpioPin != POWER_GPIO_RESERVED) && (config != NULL) )
+ {
+ /* Configures pin as input pin and configures electrical parameters */
+ gpio_input_pin_user_config_t pinConfig;
+
+ pinConfig.pinName = gpioPin;
+ pinConfig.config = *config;
+ GPIO_DRV_InputPinInit(&pinConfig);
+ }
+}
+
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : POWER_SYS_GetWakeupPinFlag
+ * Description : This function allows to get wake up pin flag in low leakage wake up unit (LLWU).
+ *
+ *END**************************************************************************/
+bool POWER_SYS_GetWakeupPinFlag(power_wakeup_pin_t pin)
+{
+ llwu_wakeup_pin_t llwuPin = POWER_EXTRACT_LLWU_PIN(pin);
+
+ assert( (uint32_t)llwuPin < FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN);
+ return LLWU_HAL_GetExternalPinWakeupFlag(LLWU, llwuPin);
+}
+/*FUNCTION**********************************************************************
+ *
+ * Function Name : POWER_SYS_ClearWakeupPinFlag
+ * Description : This function allows to clear wake up pin flag in low leakage wake up unit (LLWU).
+ *
+ *END**************************************************************************/
+void POWER_SYS_ClearWakeupPinFlag(power_wakeup_pin_t pin)
+{
+ llwu_wakeup_pin_t llwuPin = POWER_EXTRACT_LLWU_PIN(pin);
+
+ assert( (uint32_t)llwuPin < FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN);
+ LLWU_HAL_ClearExternalPinWakeupFlag(LLWU, llwuPin);
+}
+#endif
+#endif
+/*FUNCTION**********************************************************************
+ * Function Name : POWER_SYS_WaitForRunStatus
+ * Description :Internal function used by POWER_SYS_SetMode function
+ *END**************************************************************************/
+static power_manager_error_code_t POWER_SYS_WaitForRunStatus(void)
+{
+ uint32_t i;
+
+ for (i=0; !PMC_HAL_GetRegulatorStatus(PMC); i++)
+ {
+ if(i > POWER_SET_MODE_TIMEOUT)
+ {
+ return kPowerManagerErrorSwitch;
+ }
+ }
+
+ for (i=0; SMC_HAL_GetStat(SMC) != kStatRun; i++)
+ {
+ if(i > POWER_SET_MODE_TIMEOUT)
+ {
+ return kPowerManagerErrorSwitch;
+ }
+ }
+
+ return kPowerManagerSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ * Function Name : POWER_SYS_WaitForVlprStatus
+ * Description :Internal function used by POWER_SYS_SetMode function
+ *END**************************************************************************/
+static power_manager_error_code_t POWER_SYS_WaitForVlprStatus(void)
+{
+ uint32_t i;
+
+ for (i=0; SMC_HAL_GetStat(SMC) != kStatVlpr; i++)
+ {
+ if(i > POWER_SET_MODE_TIMEOUT)
+ {
+ return kPowerManagerErrorSwitch;
+ }
+ }
+
+ return kPowerManagerSuccess;
+}
+
+/*FUNCTION**********************************************************************
+ * Function Name : POWER_SYS_CheckClocks
+ * Description :Internal function used by POWER_SYS_SetMode function
+ *END**************************************************************************/
+static power_manager_error_code_t POWER_SYS_CheckClocks(power_manager_modes_t mode)
+{
+#if POWER_VLPR_MCG_LITE
+ mcglite_mode_t mcgMode = CLOCK_HAL_GetMode(MCG);
+#else
+ mcg_modes_t mcgMode = CLOCK_HAL_GetMcgMode(MCG);
+
+ /* Check clock monitors */
+ switch(mode)
+ {
+#if FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE
+ case kPowerManagerHsrun:
+#endif
+ case kPowerManagerRun:
+ case kPowerManagerWait:
+ /* Clock monitors can be enabled */
+ break;
+ default:
+ /* For other modes clock monitors should be disabled */
+#if FSL_FEATURE_MCG_HAS_EXTERNAL_CLOCK_MONITOR
+ if( CLOCK_HAL_IsOsc0MonitorEnabled(MCG) )
+ {
+ return kPowerManagerErrorClock;
+ }
+#endif
+#if FSL_FEATURE_MCG_HAS_RTC_32K
+ if( CLOCK_HAL_IsRtcOscMonitorEnabled(MCG) )
+ {
+ return kPowerManagerErrorClock;
+ }
+#endif
+#if FSL_FEATURE_MCG_USE_PLLREFSEL
+ if( CLOCK_HAL_IsOsc1MonitorEnabled(MCG) )
+ {
+ return kPowerManagerErrorClock;
+ }
+#endif
+ break;
+ }
+#endif
+
+ /* We need check clocks if goes into VLPR or VLPW over VLPR */
+ if( (mode!=kPowerManagerVlpr) && (mode!=kPowerManagerVlpw) )
+ {
+ return kPowerManagerSuccess;
+ }
+
+#if POWER_VLPR_MCG_LITE
+ switch(mcgMode)
+ {
+ case kMcgliteModeLirc8M:
+ case kMcgliteModeLirc2M:
+ case kMcgliteModeExt:
+ /* allowed modes */
+ break;
+ default:
+ return kPowerManagerErrorClock;
+ }
+
+ if(CLOCK_SYS_GetFlashClockFreq() > POWER_VLPR_MAX_FLASH_BLPE_CLK)
+ {
+ return kPowerManagerErrorClock;
+ }
+#else
+ switch(mcgMode)
+ {
+ case kMcgModeBLPI:
+ /* fast IRC must be selected */
+ if(CLOCK_HAL_GetInternalRefClkMode(MCG) != kMcgIrcFast)
+ {
+ return kPowerManagerErrorClock;
+ }
+ if(CLOCK_SYS_GetFlashClockFreq() > POWER_VLPR_MAX_FLASH_BLPI_CLK)
+ {
+ return kPowerManagerErrorClock;
+ }
+ break;
+ case kMcgModeBLPE:
+ if(CLOCK_SYS_GetFlashClockFreq() > POWER_VLPR_MAX_FLASH_BLPE_CLK)
+ {
+ return kPowerManagerErrorClock;
+ }
+ break;
+ default:
+ return kPowerManagerErrorClock;
+ }
+#endif
+ if(CLOCK_SYS_GetCoreClockFreq() > POWER_VLPR_MAX_CLK)
+ {
+ return kPowerManagerErrorClock;
+ }
+
+ if(CLOCK_SYS_GetBusClockFreq() > POWER_VLPR_MAX_CLK)
+ {
+ return kPowerManagerErrorClock;
+ }
+
+ if(CLOCK_SYS_GetSystemClockFreq() > POWER_VLPR_MAX_CLK)
+ {
+ return kPowerManagerErrorClock;
+ }
+
+ return kPowerManagerSuccess;
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
diff --git a/KSDK_1.2.0/platform/system/src/power/fsl_power_manager_common.h b/KSDK_1.2.0/platform/system/src/power/fsl_power_manager_common.h
new file mode 100755
index 0000000..0ff4350
--- /dev/null
+++ b/KSDK_1.2.0/platform/system/src/power/fsl_power_manager_common.h
@@ -0,0 +1,209 @@
+/*
+ * Copyright (c) 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ * of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ * list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __FSL_POWER_MANAGER_COMMON_H__
+#define __FSL_POWER_MANAGER_COMMON_H__
+
+#include "fsl_device_registers.h"
+
+#if FSL_FEATURE_SOC_LLWU_COUNT
+#include "fsl_llwu_hal.h"
+#endif
+#include "fsl_gpio_driver.h"
+
+/*!
+ * @addtogroup power_manager
+ * @{
+ */
+
+#if FSL_FEATURE_SOC_LLWU_COUNT
+/*******************************************************************************
+ * Definitions
+ ******************************************************************************/
+#define POWER_MAKE_WAKEUP_PIN(llwuPin,port,pin) ( llwuPin | ( GPIO_MAKE_PIN(port,pin)<<16U) )
+#define POWER_GPIO_RESERVED 0xFFFFU
+#define POWER_EXTRACT_LLWU_PIN(pin) (llwu_wakeup_pin_t)( ((uint32_t)pin)&0xFFU)
+#define POWER_EXTRACT_GPIO_PINNAME(pin) ((((uint32_t)pin)>>16)&0xFFFFU)
+#define POWER_LLWU_GPIO_PIN(num) \
+ POWER_MAKE_WAKEUP_PIN(kLlwuWakeupPin##num, \
+ FSL_FEATURE_LLWU_PIN##num##_GPIO_IDX, \
+ FSL_FEATURE_LLWU_PIN##num##_GPIO_PIN)
+/*
+ * Include the cpu specific API.
+ */
+/*!
+ * @brief Power manager internal wake up modules.
+ */
+#if FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE
+typedef enum _power_wakeup_module
+{
+#if FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE0
+ kPowerManagerWakeupLptmr = kLlwuWakeupModule0,
+#endif
+#if FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE1
+ kPowerManagerWakeupCmp0 = kLlwuWakeupModule1,
+#endif
+#if FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE2
+ kPowerManagerWakeupCmp1 = kLlwuWakeupModule2,
+#endif
+#if FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE3
+ kPowerManagerWakeupCmp2 = kLlwuWakeupModule3,
+#endif
+#if FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE4
+ kPowerManagerWakeupTsi = kLlwuWakeupModule4,
+#endif
+#if FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE5
+ kPowerManagerWakeupRtcAlarm = kLlwuWakeupModule5,
+#endif
+#if FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE6
+ kPowerManagerWakeupDryIce = kLlwuWakeupModule6,
+#endif
+#if FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE7
+ kPowerManagerWakeupRtcSeconds = kLlwuWakeupModule7,
+#endif
+ kPowerManagerWakeupMax = FSL_FEATURE_LLWU_HAS_INTERNAL_MODULE
+} power_wakeup_module_t;
+
+#endif
+
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN
+/*!
+ * @brief Power manager external wake up pins.
+ */
+typedef enum _power_wakeup_pin
+{
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN0
+ kPowerManagerWakeupPin0 = POWER_LLWU_GPIO_PIN(0),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN1
+ kPowerManagerWakeupPin1 = POWER_LLWU_GPIO_PIN(1),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN2
+ kPowerManagerWakeupPin2 = POWER_LLWU_GPIO_PIN(2),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN3
+ kPowerManagerWakeupPin3 = POWER_LLWU_GPIO_PIN(3),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN4
+ kPowerManagerWakeupPin4 = POWER_LLWU_GPIO_PIN(4),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN5
+ kPowerManagerWakeupPin5 = POWER_LLWU_GPIO_PIN(5),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN6
+ kPowerManagerWakeupPin6 = POWER_LLWU_GPIO_PIN(6),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN7
+ kPowerManagerWakeupPin7 = POWER_LLWU_GPIO_PIN(7),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN8
+ kPowerManagerWakeupPin8 = POWER_LLWU_GPIO_PIN(8),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN9
+ kPowerManagerWakeupPin9 = POWER_LLWU_GPIO_PIN(9),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN10
+ kPowerManagerWakeupPin10 = POWER_LLWU_GPIO_PIN(10),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN11
+ kPowerManagerWakeupPin11 = POWER_LLWU_GPIO_PIN(11),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN12
+ kPowerManagerWakeupPin12 = POWER_LLWU_GPIO_PIN(12),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN13
+ kPowerManagerWakeupPin13 = POWER_LLWU_GPIO_PIN(13),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN14
+ kPowerManagerWakeupPin14 = POWER_LLWU_GPIO_PIN(14),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN15
+ kPowerManagerWakeupPin15 = POWER_LLWU_GPIO_PIN(15),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN16
+ kPowerManagerWakeupPin16 = POWER_LLWU_GPIO_PIN(16),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN17
+ kPowerManagerWakeupPin17 = POWER_LLWU_GPIO_PIN(17),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN18
+ kPowerManagerWakeupPin18 = POWER_LLWU_GPIO_PIN(18),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN19
+ kPowerManagerWakeupPin19 = POWER_LLWU_GPIO_PIN(19),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN20
+ kPowerManagerWakeupPin20 = POWER_LLWU_GPIO_PIN(20),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN21
+ kPowerManagerWakeupPin21 = POWER_LLWU_GPIO_PIN(21),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN22
+ kPowerManagerWakeupPin22 = POWER_LLWU_GPIO_PIN(22),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN23
+ kPowerManagerWakeupPin23 = POWER_LLWU_GPIO_PIN(23),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN24
+ kPowerManagerWakeupPin24 = POWER_LLWU_GPIO_PIN(24),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN25
+ kPowerManagerWakeupPin25 = POWER_LLWU_GPIO_PIN(25),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN26
+ kPowerManagerWakeupPin26 = POWER_LLWU_GPIO_PIN(26),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN27
+ kPowerManagerWakeupPin27 = POWER_LLWU_GPIO_PIN(27),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN28
+ kPowerManagerWakeupPin28 = POWER_LLWU_GPIO_PIN(28),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN29
+ kPowerManagerWakeupPin29 = POWER_LLWU_GPIO_PIN(29),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN30
+ kPowerManagerWakeupPin30 = POWER_LLWU_GPIO_PIN(30),
+#endif
+#if FSL_FEATURE_LLWU_HAS_EXTERNAL_PIN31
+ kPowerManagerWakeupPin31 = POWER_LLWU_GPIO_PIN(31),
+#endif
+}power_wakeup_pin_t;
+
+#endif
+
+#endif
+/*! @}*/
+
+#endif /* __FSL_POWER_MANAGER_COMMON_H__ */
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+