Hardware Abstraction Layer (HAL)

General Description

Implementation specific interface for using the Clock driver.

These items, while usable within the HAL, are not necessarily portable between devices. The diagram below shows how the clocks relate to each other. This is a superset of what is available. See the device specific Data Sheet for the exact set of clocks that are available on a specific device.

m0s8_clock_tree.png

Code snippets

Note
Error handling code has been intentionally left out of snippets to highlight API usage.

Snippet: System initialization

The following snippet shows the clock driver can be used to initialize all clocks in the system.

Note
This example is device specific.
cy_rslt_t rslt;
cyhal_clock_t clock_hf;
const cyhal_clock_t* clock_hf_src;
#if defined(CYHAL_CLOCK_PLL)
cyhal_clock_t clock_path, clock_pll;
// Initialize the PLL Mux to source from the IMO
rslt = cyhal_clock_reserve(&clock_path, &CYHAL_CLOCK_PLLSEL);
rslt = cyhal_clock_set_source(&clock_path, &CYHAL_CLOCK_IMO);
rslt = cyhal_clock_set_enabled(&clock_path, true, true);
// Initialize the PLL to source from the PLL Mux, and run at 48MHz
rslt = cyhal_clock_reserve(&clock_pll, &CYHAL_CLOCK_PLL);
rslt = cyhal_clock_set_source(&clock_pll, &clock_path);
rslt = cyhal_clock_set_frequency(&clock_pll, 48000000, NULL);
rslt = cyhal_clock_set_enabled(&clock_pll, true, true);
clock_hf_src = &clock_pll;
#else // if defined(CYHAL_CLOCK_PLL)
clock_hf_src = &CYHAL_CLOCK_IMO;
#endif // if defined(CYHAL_CLOCK_PLL)
// Initialize the HF clock to source from the PLL, and run at 48MHz
rslt = cyhal_clock_reserve(&clock_hf, &CYHAL_CLOCK_HF);
rslt = cyhal_clock_set_source(&clock_hf, clock_hf_src);
rslt = cyhal_clock_set_divider(&clock_hf, 1);
// Initialize peripherals based on the system clock settings

Variables

const cyhal_clock_t CYHAL_CLOCK_IMO
 Internal Main Oscillator: This is a fixed-frequency clock that is commonly used as a general purpose source for clocks that do not require specific frequencies or very high accuracy. More...
 
const cyhal_resource_inst_t CYHAL_CLOCK_RSC_IMO
 Internal Main Oscillator: This is a fixed-frequency clock that is commonly used as a general purpose source for clocks that do not require specific frequencies or very high accuracy. More...
 
const cyhal_clock_t CYHAL_CLOCK_EXT
 External Clock: This is an off-chip clock (not an oscillator). More...
 
const cyhal_resource_inst_t CYHAL_CLOCK_RSC_EXT
 External Clock: This is an off-chip clock (not an oscillator). More...
 
const cyhal_clock_t CYHAL_CLOCK_ILO
 Internal Low Speed Oscillator: This is a low accuracy fixed-frequency clock in the kilohertz range that is available in sleep, deep sleep and hibernate power modes. More...
 
const cyhal_resource_inst_t CYHAL_CLOCK_RSC_ILO
 Internal Low Speed Oscillator: This is a low accuracy fixed-frequency clock in the kilohertz range that is available in sleep, deep sleep and hibernate power modes. More...
 
const cyhal_clock_t CYHAL_CLOCK_WCO
 Watch Crystal Oscillator: This source is driven from an off-chip watch crystal that provides an extremely accurate source. More...
 
const cyhal_resource_inst_t CYHAL_CLOCK_RSC_WCO
 Watch Crystal Oscillator: This source is driven from an off-chip watch crystal that provides an extremely accurate source. More...
 
const cyhal_clock_t CYHAL_CLOCK_LF
 Low Frequency Clock: This clock is the source for the multi-counter watchdog timers (MCWDT), and can also be a source for the RTC. More...
 
const cyhal_resource_inst_t CYHAL_CLOCK_RSC_LF
 Low Frequency Clock: This clock is the source for the multi-counter watchdog timers (MCWDT), and can also be a source for the RTC. More...
 
const cyhal_clock_t CYHAL_CLOCK_HF
 High Frequency Clock: A high-frequency clock output driving specific peripherals. More...
 
const cyhal_resource_inst_t CYHAL_CLOCK_RSC_HF
 High Frequency Clock: A high-frequency clock output driving specific peripherals. More...
 
const cyhal_clock_t CYHAL_CLOCK_PUMP
 Analog Pump Clock: This clock ensures precision analog performance in low voltage applications. More...
 
const cyhal_resource_inst_t CYHAL_CLOCK_RSC_PUMP
 Analog Pump Clock: This clock ensures precision analog performance in low voltage applications. More...
 
const cyhal_clock_t CYHAL_CLOCK_SYS
 System Clock: This is the source clock for any divided clock in the design. More...
 
const cyhal_resource_inst_t CYHAL_CLOCK_RSC_SYS
 System Clock: This is the source clock for any divided clock in the design. More...
 

Variable Documentation

◆ CYHAL_CLOCK_IMO

const cyhal_clock_t CYHAL_CLOCK_IMO

Internal Main Oscillator: This is a fixed-frequency clock that is commonly used as a general purpose source for clocks that do not require specific frequencies or very high accuracy.

This clock is stopped in the deep sleep and hibernate power modes.

◆ CYHAL_CLOCK_RSC_IMO

const cyhal_resource_inst_t CYHAL_CLOCK_RSC_IMO

Internal Main Oscillator: This is a fixed-frequency clock that is commonly used as a general purpose source for clocks that do not require specific frequencies or very high accuracy.

This clock is stopped in the deep sleep and hibernate power modes.

◆ CYHAL_CLOCK_EXT

const cyhal_clock_t CYHAL_CLOCK_EXT

External Clock: This is an off-chip clock (not an oscillator).

This clock is stopped in the deep sleep and hibernate power modes.

◆ CYHAL_CLOCK_RSC_EXT

const cyhal_resource_inst_t CYHAL_CLOCK_RSC_EXT

External Clock: This is an off-chip clock (not an oscillator).

This clock is stopped in the deep sleep and hibernate power modes.

◆ CYHAL_CLOCK_ILO

const cyhal_clock_t CYHAL_CLOCK_ILO

Internal Low Speed Oscillator: This is a low accuracy fixed-frequency clock in the kilohertz range that is available in sleep, deep sleep and hibernate power modes.

◆ CYHAL_CLOCK_RSC_ILO

const cyhal_resource_inst_t CYHAL_CLOCK_RSC_ILO

Internal Low Speed Oscillator: This is a low accuracy fixed-frequency clock in the kilohertz range that is available in sleep, deep sleep and hibernate power modes.

◆ CYHAL_CLOCK_WCO

const cyhal_clock_t CYHAL_CLOCK_WCO

Watch Crystal Oscillator: This source is driven from an off-chip watch crystal that provides an extremely accurate source.

This clock is stopped in the hibernate power mode.

◆ CYHAL_CLOCK_RSC_WCO

const cyhal_resource_inst_t CYHAL_CLOCK_RSC_WCO

Watch Crystal Oscillator: This source is driven from an off-chip watch crystal that provides an extremely accurate source.

This clock is stopped in the hibernate power mode.

◆ CYHAL_CLOCK_LF

const cyhal_clock_t CYHAL_CLOCK_LF

Low Frequency Clock: This clock is the source for the multi-counter watchdog timers (MCWDT), and can also be a source for the RTC.

◆ CYHAL_CLOCK_RSC_LF

const cyhal_resource_inst_t CYHAL_CLOCK_RSC_LF

Low Frequency Clock: This clock is the source for the multi-counter watchdog timers (MCWDT), and can also be a source for the RTC.

◆ CYHAL_CLOCK_HF

const cyhal_clock_t CYHAL_CLOCK_HF

High Frequency Clock: A high-frequency clock output driving specific peripherals.

◆ CYHAL_CLOCK_RSC_HF

const cyhal_resource_inst_t CYHAL_CLOCK_RSC_HF

High Frequency Clock: A high-frequency clock output driving specific peripherals.

◆ CYHAL_CLOCK_PUMP

const cyhal_clock_t CYHAL_CLOCK_PUMP

Analog Pump Clock: This clock ensures precision analog performance in low voltage applications.

◆ CYHAL_CLOCK_RSC_PUMP

const cyhal_resource_inst_t CYHAL_CLOCK_RSC_PUMP

Analog Pump Clock: This clock ensures precision analog performance in low voltage applications.

◆ CYHAL_CLOCK_SYS

const cyhal_clock_t CYHAL_CLOCK_SYS

System Clock: This is the source clock for any divided clock in the design.

◆ CYHAL_CLOCK_RSC_SYS

const cyhal_resource_inst_t CYHAL_CLOCK_RSC_SYS

System Clock: This is the source clock for any divided clock in the design.