]>
git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_MCU_K64F/MK64F12/fsl_clock_K64F12.c
2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * o Redistributions of source code must retain the above copyright notice, this list
9 * of conditions and the following disclaimer.
11 * o Redistributions in binary form must reproduce the above copyright notice, this
12 * list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "fsl_device_registers.h"
35 #include "fsl_sim_hal.h"
36 #include "fsl_clock_manager.h"
38 /*******************************************************************************
40 ******************************************************************************/
42 /* Table of base addresses for instances. */
43 extern const uint32_t g_simBaseAddr
[];
44 extern const uint32_t g_mcgBaseAddr
[];
46 /*******************************************************************************
48 ******************************************************************************/
50 /*FUNCTION**********************************************************************
52 * Function Name : CLOCK_SYS_GetDmaFreq
53 * Description : Gets the clock frequency for DMA module
54 * This function gets the clock frequency for DMA moudle.
56 *END**************************************************************************/
57 uint32_t CLOCK_SYS_GetDmaFreq(uint32_t instance
)
60 CLOCK_SYS_GetFreq(kSystemClock
, &freq
);
64 /*FUNCTION**********************************************************************
66 * Function Name : CLOCK_SYS_GetDmamuxFreq
67 * Description : Gets the clock frequency for DMAMUX module
68 * This function gets the clock frequency for DMAMUX moudle.
70 *END**************************************************************************/
71 uint32_t CLOCK_SYS_GetDmamuxFreq(uint32_t instance
)
74 CLOCK_SYS_GetFreq(kBusClock
, &freq
);
78 /*FUNCTION**********************************************************************
80 * Function Name : CLOCK_SYS_GetPortFreq
81 * Description : Gets the clock frequency for PORT module
82 * This function gets the clock frequency for PORT moudle.
84 *END**************************************************************************/
85 uint32_t CLOCK_SYS_GetPortFreq(uint32_t instance
)
88 CLOCK_SYS_GetFreq(kLpoClock
, &freq
);
92 /*FUNCTION**********************************************************************
94 * Function Name : CLOCK_SYS_GetMpuFreq
95 * Description : Gets the clock frequency for MPU module
96 * This function gets the clock frequency for MPU moudle.
98 *END**************************************************************************/
99 uint32_t CLOCK_SYS_GetMpuFreq(uint32_t instance
)
102 CLOCK_SYS_GetFreq(kSystemClock
, &freq
);
106 /*FUNCTION**********************************************************************
108 * Function Name : CLOCK_SYS_GetEwmFreq
109 * Description : Gets the clock frequency for Ewm module
110 * This function gets the clock frequency for Ewm moudle.
112 *END**************************************************************************/
113 uint32_t CLOCK_SYS_GetEwmFreq(uint32_t instance
)
116 CLOCK_SYS_GetFreq(kLpoClock
, &freq
);
120 /*FUNCTION**********************************************************************
122 * Function Name : CLOCK_SYS_GetFlexbusFreq
123 * Description : Gets the clock frequency for FLEXBUS module
124 * This function gets the clock frequency for FLEXBUS moudle.
126 *END**************************************************************************/
127 uint32_t CLOCK_SYS_GetFlexbusFreq(uint32_t instance
)
130 CLOCK_SYS_GetFreq(kSystemClock
, &freq
);
134 /*FUNCTION**********************************************************************
136 * Function Name : CLOCK_SYS_GetFtfFreq
137 * Description : Gets the clock frequency for FTF module. (Flash Memory)
138 * This function gets the clock frequency for FTF moudle.
140 *END**************************************************************************/
141 uint32_t CLOCK_SYS_GetFtfFreq(uint32_t instance
)
144 CLOCK_SYS_GetFreq(kFlashClock
, &freq
);
148 /*FUNCTION**********************************************************************
150 * Function Name : CLOCK_SYS_GetCrcFreq
151 * Description : Gets the clock frequency for CRC module
152 * This function gets the clock frequency for CRC moudle.
154 *END**************************************************************************/
155 uint32_t CLOCK_SYS_GetCrcFreq(uint32_t instance
)
158 CLOCK_SYS_GetFreq(kBusClock
, &freq
);
162 /*FUNCTION**********************************************************************
164 * Function Name : CLOCK_SYS_GetRngaFreq
165 * Description : Gets the clock frequency for RNGA module
166 * This function gets the clock frequency for RNGA moudle.
168 *END**************************************************************************/
169 uint32_t CLOCK_SYS_GetRngaFreq(uint32_t instance
)
172 CLOCK_SYS_GetFreq(kBusClock
, &freq
);
176 /*FUNCTION**********************************************************************
178 * Function Name : CLOCK_SYS_GetAdcFreq
179 * Description : Gets the clock frequency for ADC module
180 * This function gets the clock frequency for ADC moudle.
182 *END**************************************************************************/
183 uint32_t CLOCK_SYS_GetAdcFreq(uint32_t instance
)
186 CLOCK_SYS_GetFreq(kOsc0ErClock
, &freq
);
190 /*FUNCTION**********************************************************************
192 * Function Name : CLOCK_SYS_GetCmpFreq
193 * Description : Gets the clock frequency for CMP module
194 * This function gets the clock frequency for CMP moudle.
196 *END**************************************************************************/
197 uint32_t CLOCK_SYS_GetCmpFreq(uint32_t instance
)
200 CLOCK_SYS_GetFreq(kBusClock
, &freq
);
204 /*FUNCTION**********************************************************************
206 * Function Name : CLOCK_SYS_GetVrefFreq
207 * Description : Gets the clock frequency for VREF module
208 * This function gets the clock frequency for VREF moudle.
210 *END**************************************************************************/
211 uint32_t CLOCK_SYS_GetVrefFreq(uint32_t instance
)
214 CLOCK_SYS_GetFreq(kBusClock
, &freq
);
218 /*FUNCTION**********************************************************************
220 * Function Name : CLOCK_SYS_GetPdbFreq
221 * Description : Gets the clock frequency for PDB module
222 * This function gets the clock frequency for PDB moudle.
224 *END**************************************************************************/
225 uint32_t CLOCK_SYS_GetPdbFreq(uint32_t instance
)
228 CLOCK_SYS_GetFreq(kBusClock
, &freq
);
232 /*FUNCTION**********************************************************************
234 * Function Name : CLOCK_SYS_GetFtmFreq
235 * Description : Gets the clock frequency for FTM module. (FlexTimers)
236 * This function gets the clock frequency for FTM moudle.
238 *END**************************************************************************/
239 uint32_t CLOCK_SYS_GetFtmFreq(uint32_t instance
)
242 CLOCK_SYS_GetFreq(kMcgFfClock
, &freq
);
246 /*FUNCTION**********************************************************************
248 * Function Name : CLOCK_SYS_GetPitFreq
249 * Description : Gets the clock frequency for Pit module.
250 * This function gets the clock frequency for Pit moudle.
252 *END**************************************************************************/
253 uint32_t CLOCK_SYS_GetPitFreq(uint32_t instance
)
256 CLOCK_SYS_GetFreq(kBusClock
, &freq
);
260 /*FUNCTION**********************************************************************
262 * Function Name : CLOCK_SYS_GetCmtFreq
263 * Description : Gets the clock frequency for CMT module.
264 * This function gets the clock frequency for CMT moudle.
266 *END**************************************************************************/
267 uint32_t CLOCK_SYS_GetCmtFreq(uint32_t instance
)
270 CLOCK_SYS_GetFreq(kBusClock
, &freq
);
274 /*FUNCTION**********************************************************************
276 * Function Name : CLOCK_SYS_GetEnetRmiiFreq
277 * Description : Gets the clock frequency for ENET module RMII clock.
278 * This function gets the clock frequency for ENET moudle RMII clock.
280 *END**************************************************************************/
281 uint32_t CLOCK_SYS_GetEnetRmiiFreq(uint32_t instance
)
285 clock_names_t clockName
;
286 /* get the sim clock source setting*/
287 if (CLOCK_HAL_GetSource(g_simBaseAddr
[0], kClockRmiiSrc
, &setting
) != kSimHalSuccess
)
292 if ((sim_rmii_clock_source_t
)setting
== kSimRmiiSrcExtalClk
)
294 clockName
= kEXTAL_Clock
;
298 clockName
= kENET_1588_CLKIN
;
301 CLOCK_SYS_GetFreq(clockName
, &freq
);
305 /*FUNCTION**********************************************************************
307 * Function Name : CLOCK_SYS_GetEnetTimeStampFreq
308 * Description : Gets the clock frequency for ENET module TIME clock.
309 * This function gets the clock frequency for ENET moudle TIME clock.
311 *END**************************************************************************/
312 uint32_t CLOCK_SYS_GetEnetTimeStampFreq(uint32_t instance
)
316 clock_names_t clockName
;
318 /* get the sim clock source setting*/
319 if (CLOCK_HAL_GetSource(g_simBaseAddr
[0], kClockTimeSrc
, &setting
) != kSimHalSuccess
)
324 switch ((sim_time_clock_source_t
)setting
)
326 case kSimTimeSrcCoreSysClk
: /* Core/system clock */
327 clockName
= kCoreClock
;
329 case kSimTimeSrcPllFllSel
: /* clock as selected by SOPT2[PLLFLLSEL]. */
330 /* get the sim clock source setting*/
331 if (CLOCK_HAL_GetSource(g_simBaseAddr
[0], kClockPllfllSel
, &setting
) != kSimHalSuccess
)
336 switch ((sim_pllfll_clock_sel_t
)setting
)
338 case kSimPllFllSelFll
: /* Fll clock */
339 clockName
= kMcgFllClock
;
341 case kSimPllFllSelPll
: /* Pll0 clock */
342 clockName
= kMcgPll0Clock
;
345 clockName
= kReserved
;
349 case kSimTimeSrcOscerclk
: /* OSCERCLK clock */
350 clockName
= kOsc0ErClock
;
352 case kSimTimeSrcExt
: /* Enet 1588 clock */
353 clockName
= kENET_1588_CLKIN
;
356 clockName
= kReserved
;
360 /* Get ref clock freq */
361 CLOCK_SYS_GetFreq(clockName
, &freq
);
365 /*FUNCTION**********************************************************************
367 * Function Name : CLOCK_SYS_GetUsbFreq
368 * Description : Gets the clock frequency for USB FS OTG module.
369 * This function gets the clock frequency for USB FS OTG moudle.
371 *END**************************************************************************/
372 uint32_t CLOCK_SYS_GetUsbFreq(uint32_t instance
)
376 clock_names_t clockName
;
378 uint32_t divider
= 0;
380 /* get the sim clock source setting*/
381 if (CLOCK_HAL_GetSource(g_simBaseAddr
[0], kClockUsbSrc
, &setting
) != kSimHalSuccess
)
386 switch ((sim_usb_clock_source_t
)setting
)
388 case kSimUsbSrcClkIn
: /* Core/system clock */
389 clockName
= kUSB_CLKIN
;
391 case kSimUsbSrcPllFllSel
: /* clock as selected by SOPT2[PLLFLLSEL]. */
392 /* get the sim clock source setting*/
393 if (CLOCK_HAL_GetSource(g_simBaseAddr
[0], kClockPllfllSel
, &setting
) != kSimHalSuccess
)
398 switch ((sim_pllfll_clock_sel_t
)setting
)
400 case kSimPllFllSelFll
: /* Fll clock */
401 clockName
= kMcgFllClock
;
403 case kSimPllFllSelPll
: /* Pll0 clock */
404 clockName
= kMcgPll0Clock
;
407 clockName
= kReserved
;
412 clockName
= kReserved
;
416 /* Get ref clock freq */
417 CLOCK_SYS_GetFreq(clockName
, &freq
);
419 /* Get divider and frac */
420 CLOCK_HAL_GetDivider(g_simBaseAddr
[0], kClockDividerUsbDiv
, ÷r
);
421 CLOCK_HAL_GetDivider(g_simBaseAddr
[0], kClockDividerUsbFrac
, &frac
);
423 /* Divider output clock = Divider input clock × [ (FRAC+1) / (DIV+1) ]*/
424 freq
= (freq
) * (frac
+ 1) / (divider
+ 1);
429 /*FUNCTION**********************************************************************
431 * Function Name : CLOCK_SYS_GetUsbdcdFreq
432 * Description : Gets the clock frequency for USB DCD module.
433 * This function gets the clock frequency for USB DCD moudle.
435 *END**************************************************************************/
436 uint32_t CLOCK_SYS_GetUsbdcdFreq(uint32_t instance
)
439 CLOCK_SYS_GetFreq(kBusClock
, &freq
);
443 /*FUNCTION**********************************************************************
445 * Function Name : CLOCK_SYS_GetSpiFreq
446 * Description : Gets the clock frequency for SPI module.
447 * This function gets the clock frequency for SPI moudle.
449 *END**************************************************************************/
450 uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance
)
453 CLOCK_SYS_GetFreq(kBusClock
, &freq
);
457 /*FUNCTION**********************************************************************
459 * Function Name : CLOCK_SYS_GetI2cFreq
460 * Description : Gets the clock frequency for I2C module.
461 * This function gets the clock frequency for I2C moudle.
463 *END**************************************************************************/
464 uint32_t CLOCK_SYS_GetI2cFreq(uint32_t instance
)
467 CLOCK_SYS_GetFreq(kBusClock
, &freq
);
471 /*FUNCTION**********************************************************************
473 * Function Name : CLOCK_SYS_GetUartFreq
474 * Description : Gets the clock frequency for UART module.
475 * This function gets the clock frequency for UART moudle.
477 *END**************************************************************************/
478 uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance
)
486 CLOCK_SYS_GetFreq(kSystemClock
, &freq
);
492 CLOCK_SYS_GetFreq(kBusClock
, &freq
);
501 /*FUNCTION**********************************************************************
503 * Function Name : CLOCK_SYS_GetSdhcFreq
504 * Description : Gets the clock frequency for SDHC module
505 * This function gets the clock frequency for SDHC moudle
507 *END**************************************************************************/
508 uint32_t CLOCK_SYS_GetSdhcFreq(uint32_t instance
)
512 clock_names_t clockName
;
514 /* get the sim clock source setting*/
515 if (CLOCK_HAL_GetSource(g_simBaseAddr
[0], kClockSdhcSrc
, &setting
) != kSimHalSuccess
)
520 switch ((sim_sdhc_clock_source_t
)setting
)
522 case kSimSdhcSrcCoreSysClk
: /* Core/system clock */
523 clockName
= kCoreClock
;
525 case kSimSdhcSrcPllFllSel
: /* clock as selected by SOPT2[PLLFLLSEL]. */
526 /* get the sim clock source setting*/
527 if (CLOCK_HAL_GetSource(g_simBaseAddr
[0], kClockPllfllSel
, &setting
) != kSimHalSuccess
)
532 switch ((sim_pllfll_clock_sel_t
)setting
)
534 case kSimPllFllSelFll
: /* Fll clock */
535 clockName
= kMcgFllClock
;
537 case kSimPllFllSelPll
: /* Pll0 clock */
538 clockName
= kMcgPll0Clock
;
541 clockName
= kReserved
;
545 case kSimSdhcSrcOscerclk
: /* OSCERCLK clock */
546 clockName
= kOsc0ErClock
;
548 case kSimSdhcSrcExt
: /* SDHC CLKIN clock */
549 clockName
= kSDHC0_CLKIN
;
552 clockName
= kReserved
;
556 /* Get ref clock freq */
557 CLOCK_SYS_GetFreq(clockName
, &freq
);
561 /*FUNCTION**********************************************************************
563 * Function Name : CLOCK_SYS_GetSaiFreq
564 * Description : Gets the clock frequency for I2S module
565 * This function gets the clock frequency for I2S moudle.
567 *END**************************************************************************/
568 uint32_t CLOCK_SYS_GetSaiFreq(uint32_t instance
)
571 CLOCK_SYS_GetFreq(kBusClock
, &freq
);
575 /*FUNCTION**********************************************************************
577 * Function Name : CLOCK_SYS_GetGpioFreq
578 * Description : Gets the clock frequency for GPIO module.
579 * This function gets the clock frequency for GPIO moudle.
581 *END**************************************************************************/
582 uint32_t CLOCK_SYS_GetGpioFreq(uint32_t instance
)
586 CLOCK_SYS_GetFreq(kSystemClock
, &freq
);
590 /*******************************************************************************
592 ******************************************************************************/