| NUC029FAE_BSP V3.02.000 The Board Support Package for NUC029FAE MCU

Functions
CLK Exported Functions
NUC029FAE Device Driver » CLK Driver » CLK Exported Constants
Collaboration diagram for CLK Exported Functions:

## Functions
void | CLK_DisableCKO (void)
| This function disable frequency output function. More...
void | CLK_EnableCKO (uint32_t u32ClkSrc, uint32_t u32ClkDiv, uint32_t u32ClkDivBy1En)
| This function enable frequency divider module clock, enable frequency divider clock function and configure frequency divider. More...
void | CLK_PowerDown (void)
| This function let system enter to Power-down mode. More...
void | CLK_Idle (void)
| This function let system enter to Idle mode. More...
uint32_t | CLK_GetHXTFreq (void)
| This function get external high frequency crystal frequency. The frequency unit is Hz. More...
uint32_t | CLK_GetLXTFreq (void)
| This function get external low frequency crystal frequency. The frequency unit is Hz. More...
uint32_t | CLK_GetHCLKFreq (void)
| This function get HCLK frequency. The frequency unit is Hz. More...
uint32_t | CLK_GetPCLKFreq (void)
uint32_t | CLK_GetCPUFreq (void)
| This function get CPU frequency. The frequency unit is Hz. More...
uint32_t | CLK_SetCoreClock (uint32_t u32Hclk)
void | CLK_SetHCLK (uint32_t u32ClkSrc, uint32_t u32ClkDiv)
| This function set HCLK clock source and HCLK clock divider. More...
void | CLK_SetModuleClock (uint32_t u32ModuleIdx, uint32_t u32ClkSrc, uint32_t u32ClkDiv)
| This function set selected module clock source and module clock divider. More...
void | CLK_SetSysTickClockSrc (uint32_t u32ClkSrc)
| This function set SysTick clock source. More...
void | CLK_EnableXtalRC (uint32_t u32ClkMask)
| This function enable clock source. More...
void | CLK_DisableXtalRC (uint32_t u32ClkMask)
| This function disable clock source. More...
void | CLK_EnableModuleClock (uint32_t u32ModuleIdx)
| This function enable module clock. More...
void | CLK_DisableModuleClock (uint32_t u32ModuleIdx)
| This function disable module clock. More...
int32_t | CLK_SysTickDelay (uint32_t us)
| This function execute delay function. More...
uint32_t | CLK_WaitClockReady (uint32_t u32ClkMask)
| This function check selected clock source status. More...

## Detailed Description

## Function Documentation

## ◆ CLK_DisableCKO()

void CLK_DisableCKO | ( | void |  | ) |

This function disable frequency output function.

Returns
  None

Definition at line 30 of file clk.c.

## ◆ CLK_DisableModuleClock()

void CLK_DisableModuleClock | ( | uint32_t | u32ModuleIdx | ) |

This function disable module clock.

Parameters

  u32ModuleIdx | is module index WDT_MODULE TMR0_MODULE TMR1_MODULE FDIV_MODULE I2C_MODULE SPI_MODULE UART_MODULE PWM01_MODULE PWM23_MODULE PWM45_MODULE ADC_MODULE ACMP_MODULE

Returns
  None

Definition at line 285 of file clk.c.

## ◆ CLK_DisableXtalRC()

void CLK_DisableXtalRC | ( | uint32_t | u32ClkMask | ) |

This function disable clock source.

Parameters

  u32ClkMask | is clock source mask. Including : CLK_PWRCON_XTLCLK_EN_Msk, CLK_PWRCON_LIRC_EN_Msk, CLK_PWRCON_HIRC_EN_Msk,

Returns
  None

Definition at line 241 of file clk.c.

## ◆ CLK_EnableCKO()

void CLK_EnableCKO | ( | uint32_t | u32ClkSrc,
|  | uint32_t | u32ClkDiv,
|  | uint32_t | u32ClkDivBy1En
| ) |  |

This function enable frequency divider module clock, enable frequency divider clock function and configure frequency divider.

Parameters

  u32ClkSrc | is frequency divider function clock source CLK_CLKSEL2_FRQDIV_XTAL CLK_CLKSEL2_FRQDIV_HCLK CLK_CLKSEL2_FRQDIV_HIRC
  u32ClkDiv | Set the clock divider to CKO. 0 <= u32ClkDiv <= 15
  u32ClkDivBy1En | is frequency divided by one enable.

Returns
  None

Output selected clock to CKO. The output clock frequency is divided by u32ClkDiv. The formula is: CKO frequency = (Clock source frequency) / 2^(u32ClkDiv + 1) This function is just used to set CKO clock. User must enable I/O for CKO clock output pin by themselves.

Definition at line 53 of file clk.c.

## ◆ CLK_EnableModuleClock()

void CLK_EnableModuleClock | ( | uint32_t | u32ModuleIdx | ) |

This function enable module clock.

Parameters

  u32ModuleIdx | is module index. Including : WDT_MODULE TMR0_MODULE TMR1_MODULE FDIV_MODULE I2C_MODULE SPI_MODULE UART_MODULE PWM01_MODULE PWM23_MODULE PWM45_MODULE ADC_MODULE ACMP_MODULE

Returns
  None

Definition at line 263 of file clk.c.

## ◆ CLK_EnableXtalRC()

void CLK_EnableXtalRC | ( | uint32_t | u32ClkMask | ) |

This function enable clock source.

Parameters

  u32ClkMask | is clock source mask. Including : CLK_PWRCON_HXT or CLK_PWRCON_LXT, CLK_PWRCON_LIRC_EN_Msk CLK_PWRCON_HIRC_EN_Msk

Returns
  None

Definition at line 228 of file clk.c.

## ◆ CLK_GetCPUFreq()

uint32_t CLK_GetCPUFreq | ( | void |  | ) |

This function get CPU frequency. The frequency unit is Hz.

Returns
  CPU frequency

Definition at line 125 of file clk.c.

Here is the call graph for this function:

## ◆ CLK_GetHCLKFreq()

uint32_t CLK_GetHCLKFreq | ( | void |  | ) |

This function get HCLK frequency. The frequency unit is Hz.

Returns
  HCLK frequency

Definition at line 114 of file clk.c.

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ CLK_GetHXTFreq()

uint32_t CLK_GetHXTFreq | ( | void |  | ) |

This function get external high frequency crystal frequency. The frequency unit is Hz.

Returns
  None

Definition at line 90 of file clk.c.

Here is the caller graph for this function:

## ◆ CLK_GetLXTFreq()

uint32_t CLK_GetLXTFreq | ( | void |  | ) |

This function get external low frequency crystal frequency. The frequency unit is Hz.

Returns
  LXT frequency

Definition at line 102 of file clk.c.

Here is the caller graph for this function:

## ◆ CLK_GetPCLKFreq()

uint32_t CLK_GetPCLKFreq | ( | void |  | ) |

## ◆ CLK_Idle()

void CLK_Idle | ( | void |  | ) |

This function let system enter to Idle mode.

Returns
  None

Definition at line 80 of file clk.c.

## ◆ CLK_PowerDown()

void CLK_PowerDown | ( | void |  | ) |

This function let system enter to Power-down mode.

Returns
  None

Definition at line 69 of file clk.c.

## ◆ CLK_SetCoreClock()

uint32_t CLK_SetCoreClock | ( | uint32_t | u32Hclk | ) |

## ◆ CLK_SetHCLK()

void CLK_SetHCLK | ( | uint32_t | u32ClkSrc,
|  | uint32_t | u32ClkDiv
| ) |  |

This function set HCLK clock source and HCLK clock divider.

Parameters

  u32ClkSrc | is HCLK clock source. Including : CLK_CLKSEL0_HCLK_S_XTAL CLK_CLKSEL0_HCLK_S_LIRC CLK_CLKSEL0_HCLK_S_HIRC
  u32ClkDiv | is HCLK clock divider. Including : CLK_CLKDIV_HCLK(x)

Returns
  None

Definition at line 141 of file clk.c.

## ◆ CLK_SetModuleClock()

void CLK_SetModuleClock | ( | uint32_t | u32ModuleIdx,
|  | uint32_t | u32ClkSrc,
|  | uint32_t | u32ClkDiv
| ) |  |

This function set selected module clock source and module clock divider.

Parameters

  u32ModuleIdx | is module index.
  u32ClkSrc | is module clock source.
  u32ClkDiv | is module clock divider.

Returns
  None

Valid parameter combinations listed in following table:

Module index | Clock source | Divider
--- | --- | ---
WDT_MODULE | CLK_CLKSEL1_WDT_S_XTAL | x
WDT_MODULE | CLK_CLKSEL1_WDT_S_HCLK_DIV2048 | x
WDT_MODULE | CLK_CLKSEL1_WDT_S_LIRC | x
TMR0_MODULE | CLK_CLKSEL1_TMR0_S_XTAL | x
TMR0_MODULE | CLK_CLKSEL1_TMR0_S_LIRC | x
TMR0_MODULE | CLK_CLKSEL1_TMR0_S_HCLK | x
TMR0_MODULE | CLK_CLKSEL1_TMR0_S_HIRC | x
TMR1_MODULE | CLK_CLKSEL1_TMR1_S_XTAL | x
TMR1_MODULE | CLK_CLKSEL1_TMR1_S_LIRC | x
TMR1_MODULE | CLK_CLKSEL1_TMR1_S_HCLK | x
TMR1_MODULE | CLK_CLKSEL1_TMR1_S_HIRC | x
FDIV_MODULE | CLK_CLKSEL2_FRQDIV_XTAL | x
FDIV_MODULE | CLK_CLKSEL2_FRQDIV_HCLK | x
FDIV_MODULE | CLK_CLKSEL2_FRQDIV_HIRC | x
I2C_MODULE | x | x
SPI_MODULE | CLK_CLKSEL1_SPI_S_HXTorLXT | x
SPI_MODULE | CLK_CLKSEL1_SPI_S_HCLK | x
UART_MODULE | CLK_CLKSEL1_UART_S_XTAL | CLK_CLKDIV_UART(x)
UART_MODULE | CLK_CLKSEL1_UART_S_HIRC | CLK_CLKDIV_UART(x)
PWM01_MODULE | CLK_CLKSEL1_PWM01_S_HCLK | x
PWM23_MODULE | CLK_CLKSEL1_PWM23_S_HCLK | x
PWM45_MODULE | CLK_CLKSEL2_PWM45_S_HCLK | x
ADC_MODULE | CLK_CLKSEL1_ADC_S_XTAL | CLK_CLKDIV_ADC(x)
ADC_MODULE | CLK_CLKSEL1_ADC_S_HCLK | CLK_CLKDIV_ADC(x)
ADC_MODULE | CLK_CLKSEL1_ADC_S_HIRC | CLK_CLKDIV_ADC(x)
ACMP_MODULE | x | x

Definition at line 185 of file clk.c.

## ◆ CLK_SetSysTickClockSrc()

void CLK_SetSysTickClockSrc | ( | uint32_t | u32ClkSrc | ) |

This function set SysTick clock source.

Parameters

  u32ClkSrc | is module clock source. Including CLK_CLKSEL0_STCLK_S_XTAL CLK_CLKSEL0_STCLK_S_XTAL_DIV2 CLK_CLKSEL0_STCLK_S_HCLK_DIV2 CLK_CLKSEL0_STCLK_S_HIRC_DIV2

Returns
  None

Definition at line 215 of file clk.c.

## ◆ CLK_SysTickDelay()

int32_t CLK_SysTickDelay | ( | uint32_t | us | ) |

This function execute delay function.

Parameters

  us | Delay time. The Max value is 2^24 / CPU Clock(MHz). Ex: 50MHz => 335544us, 48MHz => 349525us, 28MHz => 699050us ...

Returns
  None

Use the SysTick to generate the delay time and the UNIT is in us. The SysTick clock source is from HCLK, i.e the same as system core clock.

Definition at line 298 of file clk.c.

## ◆ CLK_WaitClockReady()

uint32_t CLK_WaitClockReady | ( | uint32_t | u32ClkMask | ) |

This function check selected clock source status.

Parameters

  u32ClkMask | is selected clock source. Including CLK_CLKSTATUS_CLK_SW_FAIL_Msk CLK_CLKSTATUS_HIRC_STB_Msk CLK_CLKSTATUS_LIRC_STB_Msk CLK_CLKSTATUS_XTL_STB_Msk

Returns
  0 clock is not stable 1 clock is stable

To wait for clock ready by specified CLKSTATUS bit or timeout (~5ms)

Definition at line 328 of file clk.c.