host-aprom/NUC123/system_NUC123.c

58 lines
2.0 KiB
C
Raw Normal View History

2024-06-29 20:17:34 +00:00
/**************************************************************************//**
* @file system_NUC123.c
* @version V3.0
* $Revision: 5 $
* $Date: 15/07/02 11:21a $
* @brief NUC123 Series CMSIS System File
*
* @note
* SPDX-License-Identifier: Apache-2.0
* Copyright (C) 2014~2015 Nuvoton Technology Corp. All rights reserved.
*
******************************************************************************/
#include <stdint.h>
2024-07-12 16:18:18 +00:00
#include "NUC123.h"
2024-06-29 20:17:34 +00:00
/*----------------------------------------------------------------------------
Clock Variable definitions
*----------------------------------------------------------------------------*/
2024-07-12 16:18:18 +00:00
uint32_t SystemCoreClock = __HSI; /*!< System Clock Frequency (Core Clock) */
uint32_t CyclesPerUs = (__HSI / 1000000); /* Cycles per micro second */
uint32_t PllClock = __HSI; /*!< PLL Output Clock Frequency */
uint32_t gau32ClkSrcTbl[] = { __HXT, NULL, __HSI, __LIRC, NULL, NULL, NULL, __HIRC };
2024-06-29 20:17:34 +00:00
/*----------------------------------------------------------------------------
Clock functions
This function is used to update the variable SystemCoreClock
and must be called whenever the core clock is changed.
*----------------------------------------------------------------------------*/
2024-07-12 16:18:18 +00:00
void SystemCoreClockUpdate(void) /* Get Core Clock Frequency */
2024-06-29 20:17:34 +00:00
{
uint32_t u32Freq, u32ClkSrc;
uint32_t u32HclkDiv;
/* Update PLL Clock */
PllClock = CLK_GetPLLClockFreq();
u32ClkSrc = CLK->CLKSEL0 & CLK_CLKSEL0_HCLK_S_Msk;
2024-07-12 16:18:18 +00:00
if (u32ClkSrc == CLK_CLKSEL0_HCLK_S_PLL) {
2024-06-29 20:17:34 +00:00
/* Use PLL clock */
u32Freq = PllClock;
2024-07-12 16:18:18 +00:00
} else if (u32ClkSrc == CLK_CLKSEL0_HCLK_S_PLL_DIV2) {
2024-06-29 20:17:34 +00:00
/* Use PLL/2 clock */
u32Freq = PllClock >> 1;
2024-07-12 16:18:18 +00:00
} else {
2024-06-29 20:17:34 +00:00
/* Use the clock sources directly */
u32Freq = gau32ClkSrcTbl[u32ClkSrc];
}
u32HclkDiv = (CLK->CLKDIV & CLK_CLKDIV_HCLK_N_Msk) + 1;
/* Update System Core Clock */
SystemCoreClock = u32Freq / u32HclkDiv;
CyclesPerUs = (SystemCoreClock + 500000) / 1000000;
}