获得系统时钟(HCLK)频率值
uint32_t Clk_GetHClkFreq(void)
{
uint32_t u32Val = 0;
uint16_t u16TrimVal22_12 = 0;
const uint8_t u8hcr_tbl[] = { 4, 8, 16, 24 };
const uint32_t u32lcr_tbl[] = { 32768, 38400 };
en_clk_source_t enSrc;
//1. get current input source
enSrc = (en_clk_source_t)M0P_CLOCK->SYSCTRL0_f.CLK_SW4_SEL;
switch (enSrc)
{
case ClkRCH:
u32Val = u8hcr_tbl[(M0P_CLOCK->RCH_CR_f.TRIM&0x600U)>>9u];
u32Val *= 1000u * 1000u;
if(24000000u == u32Val)
{
u16TrimVal22_12 = RCH_CR_TRIM_22_12M_VAL;
if(u16TrimVal22_12 == M0P_CLOCK->RCH_CR_f.TRIM)
{
u32Val = 22120000u;
}
}
break;
case ClkRCL:
u32Val = u32lcr_tbl[(M0P_CLOCK->RCL_CR_f.TRIM&0x200U)>>9u];
break;
case ClkXTH:
u32Val = CLK_XTH_VAL;
break;
default:
u32Val = 0u;
break;
}
u32Val = u32Val >> M0P_CLOCK->SYSCTRL0_f.HCLK_PRS;
return u32Val;
}
|