Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
SAM System Clock Management (SYSTEM CLOCK) Driver

This driver for Atmel® | SMART ARM®-based microcontrollers provides an interface for the configuration and management of the device's clocking related functions.

This includes the various clock sources, bus clocks, and generic clocks within the device, with functions to manage the enabling, disabling, source selection, and prescaling of clocks to various internal peripherals.

The following peripherals are used by this module:

The following devices can use this module:

The outline of this documentation is as follows:

Prerequisites

There are no prerequisites for this module.

Module Overview

The SAM devices contain a sophisticated clocking system, which is designed to give the maximum flexibility to the user application. This system allows a system designer to tune the performance and power consumption of the device in a dynamic manner, to achieve the best trade-off between the two for a particular application.

This driver provides a set of functions for the configuration and management of the various clock related functionality within the device.

Clock Sources

The SAM devices have a number of master clock source modules, each of which being capable of producing a stabilized output frequency, which can then be fed into the various peripherals and modules within the device.

Possible clock source modules include internal R/C oscillators as well as external crystal oscillators and/or clock inputs.

CPU / Bus Clocks

The CPU and AHB/APBx buses are clocked by the same physical clock source (referred in this module as the Main Clock), however the APBx buses may have additional prescaler division ratios set to give each peripheral bus a different clock speed.

The general main clock tree for the CPU and associated buses is shown in the figure below.

Clock Masking

To save power, the input clock to one or more peripherals on the AHB and APBx buses can be masked away - when masked, no clock is passed into the module. Disabling of clocks of unused modules will prevent all access to the masked module, and will reduce the overall device power consumption.

Generic Clocks

Within the SAM devices there are a number of Generic Clocks; these are used to provide clocks to the various peripheral clock domains in the device in a standardized manner. One or more master source clocks can be selected as the input clock to a Generic Clock Generator, which can prescale down the input frequency to a slower rate for use in a peripheral.

Additionally, a number of individually selectable Generic Clock Channels are provided, which multiplex and gate the various generator outputs for one or more peripherals within the device. This setup allows for a single common generator to feed one or more channels, which can then be enabled or disabled individually as required.

Clock Chain Example

An example setup of a complete clock chain within the device is shown in the figure below.

Generic Clock Generators

Each Generic Clock generator within the device can source its input clock from one of the provided Source Clocks, and prescale the output for one or more Generic Clock Channels in a one-to-many relationship. The generators thus allow for several clocks to be generated of different frequencies, power usages, and accuracies, which can be turned on and off individually to disable the clocks to multiple peripherals as a group.

Generic Clock Channels

To connect a Generic Clock Generator to a peripheral within the device, a Generic Clock Channel is used. Each peripheral or peripheral group has an associated Generic Clock Channel, which serves as the clock input for the peripheral(s). To supply a clock to the peripheral module(s), the associated channel must be connected to a running Generic Clock Generator and the channel enabled.

Special Considerations

There are no special considerations for this module.

Extra Information

For extra information, see Extra Information for SYSTEM CLOCK Driver. This includes:

Examples

For a list of examples related to this driver, see Examples for System Clock Driver.

API Overview

Data Structures

struct  system_clock_source_dpll_config
 Configuration structure for DPLL. More...
 
struct  system_clock_source_osc32k_config
 Configuration structure for OSCULP32K. More...
 
struct  system_clock_source_osc48m_config
 Configuration structure for OSC48M. More...
 
struct  system_clock_source_osculp32k_config
 Configuration structure for OSCULP32K. More...
 
struct  system_clock_source_xosc32k_config
 Configuration structure for XOSC32K. More...
 
struct  system_clock_source_xosc_config
 Configuration structure for XOSC. More...
 
struct  system_gclk_chan_config
 Generic Clock configuration structure. More...
 
struct  system_gclk_gen_config
 Generic Clock Generator configuration structure. More...
 

Enumerations

enum  gclk_generator {
  GCLK_GENERATOR_0,
  GCLK_GENERATOR_1,
  GCLK_GENERATOR_2,
  GCLK_GENERATOR_3,
  GCLK_GENERATOR_4,
  GCLK_GENERATOR_5,
  GCLK_GENERATOR_6,
  GCLK_GENERATOR_7,
  GCLK_GENERATOR_8,
  GCLK_GENERATOR_9,
  GCLK_GENERATOR_10,
  GCLK_GENERATOR_11,
  GCLK_GENERATOR_12,
  GCLK_GENERATOR_13,
  GCLK_GENERATOR_14,
  GCLK_GENERATOR_15,
  GCLK_GENERATOR_16
}
 List of available GCLK generators. More...
 
enum  system_clock_apb_bus {
  SYSTEM_CLOCK_APB_APBA,
  SYSTEM_CLOCK_APB_APBB,
  SYSTEM_CLOCK_APB_APBC
}
 List of APB peripheral buses. More...
 
enum  system_clock_external {
  SYSTEM_CLOCK_EXTERNAL_CRYSTAL,
  SYSTEM_CLOCK_EXTERNAL_CLOCK
}
 External clock source types. More...
 
enum  system_clock_source {
  SYSTEM_CLOCK_SOURCE_OSC48M = GCLK_SOURCE_OSC48M,
  SYSTEM_CLOCK_SOURCE_OSC32K = GCLK_SOURCE_OSC32K,
  SYSTEM_CLOCK_SOURCE_XOSC = GCLK_SOURCE_XOSC,
  SYSTEM_CLOCK_SOURCE_XOSC32K = GCLK_SOURCE_XOSC32K,
  SYSTEM_CLOCK_SOURCE_ULP32K = GCLK_SOURCE_OSCULP32K,
  SYSTEM_CLOCK_SOURCE_GCLKIN = GCLK_SOURCE_GCLKIN,
  SYSTEM_CLOCK_SOURCE_GCLKGEN1 = GCLK_SOURCE_GCLKGEN1,
  SYSTEM_CLOCK_SOURCE_DPLL = GCLK_SOURCE_FDPLL
}
 Available clock sources in the system. More...
 
enum  system_clock_source_dpll_filter {
  SYSTEM_CLOCK_SOURCE_DPLL_FILTER_DEFAULT,
  SYSTEM_CLOCK_SOURCE_DPLL_FILTER_LOW_BANDWIDTH_FILTER,
  SYSTEM_CLOCK_SOURCE_DPLL_FILTER_HIGH_BANDWIDTH_FILTER,
  SYSTEM_CLOCK_SOURCE_DPLL_FILTER_HIGH_DAMPING_FILTER
}
 Filter type of the DPLL module. More...
 
enum  system_clock_source_dpll_lock_time {
  SYSTEM_CLOCK_SOURCE_DPLL_LOCK_TIME_DEFAULT,
  SYSTEM_CLOCK_SOURCE_DPLL_LOCK_TIME_8MS = 0x04,
  SYSTEM_CLOCK_SOURCE_DPLL_LOCK_TIME_9MS,
  SYSTEM_CLOCK_SOURCE_DPLL_LOCK_TIME_10MS,
  SYSTEM_CLOCK_SOURCE_DPLL_LOCK_TIME_11MS
}
 Lock time-out value of the DPLL module. More...
 
enum  system_clock_source_dpll_prescaler {
  SYSTEM_CLOCK_SOURCE_DPLL_DIV_1,
  SYSTEM_CLOCK_SOURCE_DPLL_DIV_2,
  SYSTEM_CLOCK_SOURCE_DPLL_DIV_4
}
 DPLL Output Clock Prescaler. More...
 
enum  system_clock_source_dpll_reference_clock {
  SYSTEM_CLOCK_SOURCE_DPLL_REFERENCE_CLOCK_XOSC32K,
  SYSTEM_CLOCK_SOURCE_DPLL_REFERENCE_CLOCK_XOSC,
  SYSTEM_CLOCK_SOURCE_DPLL_REFERENCE_CLOCK_GCLK
}
 Reference clock source of the DPLL module. More...
 
enum  system_clock_xosc32k_failure_detector_prescaler {
  SYSTEM_CLOCK_XOSC32K_FAILURE_DETECTOR_PRESCALER_1,
  SYSTEM_CLOCK_XOSC32K_FAILURE_DETECTOR_PRESCALER_2
}
 XOSC32K failure detector prescaler from OSCULP32K. More...
 
enum  system_clock_xosc_failure_detector_prescaler {
  SYSTEM_CLOCK_XOSC_FAILURE_DETECTOR_PRESCALER_1,
  SYSTEM_CLOCK_XOSC_FAILURE_DETECTOR_PRESCALER_2,
  SYSTEM_CLOCK_XOSC_FAILURE_DETECTOR_PRESCALER_4,
  SYSTEM_CLOCK_XOSC_FAILURE_DETECTOR_PRESCALER_8,
  SYSTEM_CLOCK_XOSC_FAILURE_DETECTOR_PRESCALER_16,
  SYSTEM_CLOCK_XOSC_FAILURE_DETECTOR_PRESCALER_32,
  SYSTEM_CLOCK_XOSC_FAILURE_DETECTOR_PRESCALER_64,
  SYSTEM_CLOCK_XOSC_FAILURE_DETECTOR_PRESCALER_128
}
 XOSC failure detector prescaler from OSC48M . More...
 
enum  system_main_clock_div {
  SYSTEM_MAIN_CLOCK_DIV_1,
  SYSTEM_MAIN_CLOCK_DIV_2,
  SYSTEM_MAIN_CLOCK_DIV_4,
  SYSTEM_MAIN_CLOCK_DIV_8,
  SYSTEM_MAIN_CLOCK_DIV_16,
  SYSTEM_MAIN_CLOCK_DIV_32,
  SYSTEM_MAIN_CLOCK_DIV_64,
  SYSTEM_MAIN_CLOCK_DIV_128
}
 Main CPU division. More...
 
enum  system_osc32k_startup {
  SYSTEM_OSC32K_STARTUP_3,
  SYSTEM_OSC32K_STARTUP_4,
  SYSTEM_OSC32K_STARTUP_6,
  SYSTEM_OSC32K_STARTUP_10,
  SYSTEM_OSC32K_STARTUP_18,
  SYSTEM_OSC32K_STARTUP_34,
  SYSTEM_OSC32K_STARTUP_66,
  SYSTEM_OSC32K_STARTUP_130
}
 Available startup times for the OSC32K. More...
 
enum  system_osc48m_div {
  SYSTEM_OSC48M_DIV_1,
  SYSTEM_OSC48M_DIV_2,
  SYSTEM_OSC48M_DIV_3,
  SYSTEM_OSC48M_DIV_4,
  SYSTEM_OSC48M_DIV_5,
  SYSTEM_OSC48M_DIV_6,
  SYSTEM_OSC48M_DIV_7,
  SYSTEM_OSC48M_DIV_8,
  SYSTEM_OSC48M_DIV_9,
  SYSTEM_OSC48M_DIV_10,
  SYSTEM_OSC48M_DIV_11,
  SYSTEM_OSC48M_DIV_12,
  SYSTEM_OSC48M_DIV_13,
  SYSTEM_OSC48M_DIV_14,
  SYSTEM_OSC48M_DIV_15,
  SYSTEM_OSC48M_DIV_16
}
 Division prescalers for the internal 48MHz system clock. More...
 
enum  system_osc48m_startup {
  SYSTEM_OSC48M_STARTUP_8,
  SYSTEM_OSC48M_STARTUP_16,
  SYSTEM_OSC48M_STARTUP_32,
  SYSTEM_OSC48M_STARTUP_64,
  SYSTEM_OSC48M_STARTUP_128,
  SYSTEM_OSC48M_STARTUP_256,
  SYSTEM_OSC48M_STARTUP_512,
  SYSTEM_OSC48M_STARTUP_1024
}
 Available startup times for the OSC48M. More...
 
enum  system_xosc32k_startup {
  SYSTEM_XOSC32K_STARTUP_2048,
  SYSTEM_XOSC32K_STARTUP_4096,
  SYSTEM_XOSC32K_STARTUP_16384,
  SYSTEM_XOSC32K_STARTUP_32768,
  SYSTEM_XOSC32K_STARTUP_65536,
  SYSTEM_XOSC32K_STARTUP_131072,
  SYSTEM_XOSC32K_STARTUP_262144
}
 Available startup times for the XOSC32K. More...
 
enum  system_xosc_startup {
  SYSTEM_XOSC_STARTUP_1,
  SYSTEM_XOSC_STARTUP_2,
  SYSTEM_XOSC_STARTUP_4,
  SYSTEM_XOSC_STARTUP_8,
  SYSTEM_XOSC_STARTUP_16,
  SYSTEM_XOSC_STARTUP_32,
  SYSTEM_XOSC_STARTUP_64,
  SYSTEM_XOSC_STARTUP_128,
  SYSTEM_XOSC_STARTUP_256,
  SYSTEM_XOSC_STARTUP_512,
  SYSTEM_XOSC_STARTUP_1024,
  SYSTEM_XOSC_STARTUP_2048,
  SYSTEM_XOSC_STARTUP_4096,
  SYSTEM_XOSC_STARTUP_8192,
  SYSTEM_XOSC_STARTUP_16384,
  SYSTEM_XOSC_STARTUP_32768
}
 Available startup times for the XOSC. More...
 

Generic Clock Management

void system_gclk_init (void)
 Initializes the GCLK driver. More...
 

Generic Clock Management (Generators)

static void system_gclk_gen_get_config_defaults (struct system_gclk_gen_config *const config)
 Initializes a Generic Clock Generator configuration structure to defaults. More...
 
void system_gclk_gen_set_config (const uint8_t generator, struct system_gclk_gen_config *const config)
 Writes a Generic Clock Generator configuration to the hardware module. More...
 
void system_gclk_gen_enable (const uint8_t generator)
 Enables a Generic Clock Generator that was previously configured. More...
 
void system_gclk_gen_disable (const uint8_t generator)
 Disables a Generic Clock Generator that was previously enabled. More...
 
bool system_gclk_gen_is_enabled (const uint8_t generator)
 Determins if the specified Generic Clock Generator is enabled. More...
 

Generic Clock Management (Channels)

static void system_gclk_chan_get_config_defaults (struct system_gclk_chan_config *const config)
 Initializes a Generic Clock configuration structure to defaults. More...
 
void system_gclk_chan_set_config (const uint8_t channel, struct system_gclk_chan_config *const config)
 Writes a Generic Clock configuration to the hardware module. More...
 
void system_gclk_chan_enable (const uint8_t channel)
 Enables a Generic Clock that was previously configured. More...
 
void system_gclk_chan_disable (const uint8_t channel)
 Disables a Generic Clock that was previously enabled. More...
 
bool system_gclk_chan_is_enabled (const uint8_t channel)
 Determins if the specified Generic Clock channel is enabled. More...
 
void system_gclk_chan_lock (const uint8_t channel)
 Locks a Generic Clock channel from further configuration writes. More...
 
bool system_gclk_chan_is_locked (const uint8_t channel)
 Determins if the specified Generic Clock channel is locked. More...
 

Generic Clock Frequency Retrieval

uint32_t system_gclk_gen_get_hz (const uint8_t generator)
 Retrieves the clock frequency of a Generic Clock generator. More...
 
uint32_t system_gclk_chan_get_hz (const uint8_t channel)
 Retrieves the clock frequency of a Generic Clock channel. More...
 

External Oscillator Management

static void system_clock_source_xosc_get_config_defaults (struct system_clock_source_xosc_config *const config)
 Retrieve the default configuration for XOSC. More...
 
void system_clock_source_xosc_set_config (struct system_clock_source_xosc_config *const config)
 Configure the external oscillator clock source. More...
 
static bool system_clock_xosc_clock_failure_detected (void)
 Checks if XOSC clock failure detected. More...
 
static bool system_clock_xosc_is_switched (void)
 Checks if XOSC is switched and provides the safe clock. More...
 

External 32KHz Oscillator Management

static void system_clock_source_xosc32k_get_config_defaults (struct system_clock_source_xosc32k_config *const config)
 Retrieve the default configuration for XOSC32K. More...
 
void system_clock_source_xosc32k_set_config (struct system_clock_source_xosc32k_config *const config)
 Configure the XOSC32K external 32KHz oscillator clock source. More...
 
static bool system_clock_xosc32k_clock_failure_detected (void)
 Checks if XOSC32K clock failure detected. More...
 
static bool system_clock_xosc32k_is_switched (void)
 Checks if XOSC32K is switched and provides the safe clock. More...
 

Internal 32KHz Oscillator Management

static void system_clock_source_osc32k_get_config_defaults (struct system_clock_source_osc32k_config *const config)
 Retrieve the default configuration for OSC32K. More...
 
void system_clock_source_osc32k_set_config (struct system_clock_source_osc32k_config *const config)
 Configure the internal OSC32K oscillator clock source. More...
 

Internal Ultra Low Power 32KHz Oscillator management

static void system_clock_source_osculp32k_get_config_defaults (struct system_clock_source_osculp32k_config *const config)
 Retrieve the default configuration for OSCULP32K. More...
 
void system_clock_source_osculp32k_set_config (struct system_clock_source_osculp32k_config *const config)
 Configure the internal OSCULP32K oscillator clock source. More...
 

Internal 48MHz Oscillator Management

static void system_clock_source_osc48m_get_config_defaults (struct system_clock_source_osc48m_config *const config)
 Retrieve the default configuration for OSC48M. More...
 
void system_clock_source_osc48m_set_config (struct system_clock_source_osc48m_config *const config)
 Configure the internal OSC48M oscillator clock source. More...
 

Clock Source Management

enum status_code system_clock_source_write_calibration (const enum system_clock_source system_clock_source, const uint16_t calibration_value, const uint8_t freq_range)
 
enum status_code system_clock_source_enable (const enum system_clock_source system_clock_source)
 
enum status_code system_clock_source_disable (const enum system_clock_source clk_source)
 Disables a clock source. More...
 
bool system_clock_source_is_ready (const enum system_clock_source clk_source)
 Checks if a clock source is ready. More...
 
uint32_t system_clock_source_get_hz (const enum system_clock_source clk_source)
 Retrieve the frequency of a clock source. More...
 

Main Clock Management

static void system_cpu_clock_set_divider (const enum system_main_clock_div divider)
 Set main CPU clock divider. More...
 
static uint32_t system_cpu_clock_get_hz (void)
 Retrieves the current frequency of the CPU core. More...
 

Bus Clock Masking

static void system_ahb_clock_set_mask (const uint32_t ahb_mask)
 Set bits in the clock mask for the AHB bus. More...
 
static void system_ahb_clock_clear_mask (const uint32_t ahb_mask)
 Clear bits in the clock mask for the AHB bus. More...
 
static enum status_code system_apb_clock_set_mask (const enum system_clock_apb_bus bus, const uint32_t mask)
 Set bits in the clock mask for an APBx bus. More...
 
static enum status_code system_apb_clock_clear_mask (const enum system_clock_apb_bus bus, const uint32_t mask)
 Clear bits in the clock mask for an APBx bus. More...
 

Internal DPLL Management

static void system_clock_source_dpll_get_config_defaults (struct system_clock_source_dpll_config *const config)
 Retrieve the default configuration for DPLL. More...
 
void system_clock_source_dpll_set_config (struct system_clock_source_dpll_config *const config)
 Configure the DPLL clock source. More...
 

System Clock Initialization

void system_clock_init (void)
 Initialize clock system based on the configuration in conf_clocks.h. More...
 

System Flash Wait States

static void system_flash_set_waitstates (uint8_t wait_states)
 Set flash controller wait states. More...
 

List of available GCLK generators.

List of Available GCLK generators. This enum is used in the peripheral device drivers to select the GCLK generator to be used for its operation.

The number of GCLK generators available is device dependent.

Enumerator
GCLK_GENERATOR_0 

GCLK generator channel 0.

GCLK_GENERATOR_1 

GCLK generator channel 1.

GCLK_GENERATOR_2 

GCLK generator channel 2.

GCLK_GENERATOR_3 

GCLK generator channel 3.

GCLK_GENERATOR_4 

GCLK generator channel 4.

GCLK_GENERATOR_5 

GCLK generator channel 5.

GCLK_GENERATOR_6 

GCLK generator channel 6.

GCLK_GENERATOR_7 

GCLK generator channel 7.

GCLK_GENERATOR_8 

GCLK generator channel 8.

GCLK_GENERATOR_9 

GCLK generator channel 9.

GCLK_GENERATOR_10 

GCLK generator channel 10.

GCLK_GENERATOR_11 

GCLK generator channel 11.

GCLK_GENERATOR_12 

GCLK generator channel 12.

GCLK_GENERATOR_13 

GCLK generator channel 13.

GCLK_GENERATOR_14 

GCLK generator channel 14.

GCLK_GENERATOR_15 

GCLK generator channel 15.

GCLK_GENERATOR_16 

GCLK generator channel 16.

List of APB peripheral buses.

Available bus clock domains on the APB bus.

Enumerator
SYSTEM_CLOCK_APB_APBA 

Peripheral bus A on the APB bus.

SYSTEM_CLOCK_APB_APBB 

Peripheral bus B on the APB bus.

SYSTEM_CLOCK_APB_APBC 

Peripheral bus C on the APB bus.

External clock source types.

Available external clock source types.

Enumerator
SYSTEM_CLOCK_EXTERNAL_CRYSTAL 

The external clock source is a crystal oscillator.

SYSTEM_CLOCK_EXTERNAL_CLOCK 

The connected clock source is an external logic level clock signal.

Available clock sources in the system.

Clock sources available to the GCLK generators

Enumerator
SYSTEM_CLOCK_SOURCE_OSC48M 

Internal 48MHz RC oscillator.

SYSTEM_CLOCK_SOURCE_OSC32K 

Internal 32KHz RC oscillator.

SYSTEM_CLOCK_SOURCE_XOSC 

External oscillator.

SYSTEM_CLOCK_SOURCE_XOSC32K 

External 32KHz oscillator.

SYSTEM_CLOCK_SOURCE_ULP32K 

Internal Ultra Low Power 32KHz oscillator.

SYSTEM_CLOCK_SOURCE_GCLKIN 

Generator input pad.

SYSTEM_CLOCK_SOURCE_GCLKGEN1 

Generic clock generator one output.

SYSTEM_CLOCK_SOURCE_DPLL 

Digital Phase Locked Loop (DPLL)

Filter type of the DPLL module.

Enumerator
SYSTEM_CLOCK_SOURCE_DPLL_FILTER_DEFAULT 

Default filter mode.

SYSTEM_CLOCK_SOURCE_DPLL_FILTER_LOW_BANDWIDTH_FILTER 

Low bandwidth filter.

SYSTEM_CLOCK_SOURCE_DPLL_FILTER_HIGH_BANDWIDTH_FILTER 

High bandwidth filter.

SYSTEM_CLOCK_SOURCE_DPLL_FILTER_HIGH_DAMPING_FILTER 

High damping filter.

Lock time-out value of the DPLL module.

Enumerator
SYSTEM_CLOCK_SOURCE_DPLL_LOCK_TIME_DEFAULT 

Set no time-out as default.

SYSTEM_CLOCK_SOURCE_DPLL_LOCK_TIME_8MS 

Set time-out if no lock within 8ms.

SYSTEM_CLOCK_SOURCE_DPLL_LOCK_TIME_9MS 

Set time-out if no lock within 9ms.

SYSTEM_CLOCK_SOURCE_DPLL_LOCK_TIME_10MS 

Set time-out if no lock within 10ms.

SYSTEM_CLOCK_SOURCE_DPLL_LOCK_TIME_11MS 

Set time-out if no lock within 11ms.

DPLL Output Clock Prescaler.

Enumerator
SYSTEM_CLOCK_SOURCE_DPLL_DIV_1 

DPLL output is divided by 1.

SYSTEM_CLOCK_SOURCE_DPLL_DIV_2 

DPLL output is divided by 2.

SYSTEM_CLOCK_SOURCE_DPLL_DIV_4 

DPLL output is divided by 4.

Reference clock source of the DPLL module.

Enumerator
SYSTEM_CLOCK_SOURCE_DPLL_REFERENCE_CLOCK_XOSC32K 

Select XOSC32K as clock reference.

SYSTEM_CLOCK_SOURCE_DPLL_REFERENCE_CLOCK_XOSC 

Select XOSC as clock reference.

SYSTEM_CLOCK_SOURCE_DPLL_REFERENCE_CLOCK_GCLK 

Select GCLK as clock reference.

XOSC32K failure detector prescaler from OSCULP32K.

Available clock failure detector prescaler.

Enumerator
SYSTEM_CLOCK_XOSC32K_FAILURE_DETECTOR_PRESCALER_1 

Divide OSCULP32K frequency by 1 for clock failure detector clock.

SYSTEM_CLOCK_XOSC32K_FAILURE_DETECTOR_PRESCALER_2 

Divide OSCULP32K frequency by 2 for clock failure detector clock.

XOSC failure detector prescaler from OSC48M .

Available clock failure detector prescaler.

Enumerator
SYSTEM_CLOCK_XOSC_FAILURE_DETECTOR_PRESCALER_1 

Divide OSC48M frequency by 1 for clock failure detector clock.

SYSTEM_CLOCK_XOSC_FAILURE_DETECTOR_PRESCALER_2 

Divide OSC48M frequency by 2 for clock failure detector clock.

SYSTEM_CLOCK_XOSC_FAILURE_DETECTOR_PRESCALER_4 

Divide OSC48M frequency by 4 for clock failure detector clock.

SYSTEM_CLOCK_XOSC_FAILURE_DETECTOR_PRESCALER_8 

Divide OSC48M frequency by 8 for clock failure detector clock.

SYSTEM_CLOCK_XOSC_FAILURE_DETECTOR_PRESCALER_16 

Divide OSC48M frequency by 16 for clock failure detector clock.

SYSTEM_CLOCK_XOSC_FAILURE_DETECTOR_PRESCALER_32 

Divide OSC48M frequency by 32 for clock failure detector clock.

SYSTEM_CLOCK_XOSC_FAILURE_DETECTOR_PRESCALER_64 

Divide OSC48M frequency by 64 for clock failure detector clock.

SYSTEM_CLOCK_XOSC_FAILURE_DETECTOR_PRESCALER_128 

Divide OSC48M frequency by 128 for clock failure detector clock.

Main CPU division.

Available division ratios for the CPU clocks.

Enumerator
SYSTEM_MAIN_CLOCK_DIV_1 

Divide Main clock by one.

SYSTEM_MAIN_CLOCK_DIV_2 

Divide Main clock by two.

SYSTEM_MAIN_CLOCK_DIV_4 

Divide Main clock by four.

SYSTEM_MAIN_CLOCK_DIV_8 

Divide Main clock by eight.

SYSTEM_MAIN_CLOCK_DIV_16 

Divide Main clock by 16.

SYSTEM_MAIN_CLOCK_DIV_32 

Divide Main clock by 32.

SYSTEM_MAIN_CLOCK_DIV_64 

Divide Main clock by 64.

SYSTEM_MAIN_CLOCK_DIV_128 

Divide Main clock by 128.

Available startup times for the OSC32K.

Available internal 32KHz oscillator startup times, as a number of internal OSC32K clock cycles.

Enumerator
SYSTEM_OSC32K_STARTUP_3 

Wait three clock cycles until the clock source is considered stable.

SYSTEM_OSC32K_STARTUP_4 

Wait four clock cycles until the clock source is considered stable.

SYSTEM_OSC32K_STARTUP_6 

Wait six clock cycles until the clock source is considered stable.

SYSTEM_OSC32K_STARTUP_10 

Wait ten clock cycles until the clock source is considered stable.

SYSTEM_OSC32K_STARTUP_18 

Wait 18 clock cycles until the clock source is considered stable.

SYSTEM_OSC32K_STARTUP_34 

Wait 34 clock cycles until the clock source is considered stable.

SYSTEM_OSC32K_STARTUP_66 

Wait 66 clock cycles until the clock source is considered stable.

SYSTEM_OSC32K_STARTUP_130 

Wait 130 clock cycles until the clock source is considered stable.

Division prescalers for the internal 48MHz system clock.

Available prescalers for the internal 48MHz (nominal) system clock.

Enumerator
SYSTEM_OSC48M_DIV_1 

Divide the 48MHz RC oscillator output by one.

SYSTEM_OSC48M_DIV_2 

Divide the 48MHz RC oscillator output by two.

SYSTEM_OSC48M_DIV_3 

Divide the 48MHz RC oscillator output by three.

SYSTEM_OSC48M_DIV_4 

Divide the 48MHz RC oscillator output by four.

SYSTEM_OSC48M_DIV_5 

Divide the 48MHz RC oscillator output by five.

SYSTEM_OSC48M_DIV_6 

Divide the 48MHz RC oscillator output by six.

SYSTEM_OSC48M_DIV_7 

Divide the 48MHz RC oscillator output by seven.

SYSTEM_OSC48M_DIV_8 

Divide the 48MHz RC oscillator output by eight.

SYSTEM_OSC48M_DIV_9 

Divide the 48MHz RC oscillator output by nine.

SYSTEM_OSC48M_DIV_10 

Divide the 48MHz RC oscillator output by ten.

SYSTEM_OSC48M_DIV_11 

Divide the 48MHz RC oscillator output by eleven.

SYSTEM_OSC48M_DIV_12 

Divide the 48MHz RC oscillator output by twelve.

SYSTEM_OSC48M_DIV_13 

Divide the 48MHz RC oscillator output by thirteen.

SYSTEM_OSC48M_DIV_14 

Divide the 48MHz RC oscillator output by fourteen.

SYSTEM_OSC48M_DIV_15 

Divide the 48MHz RC oscillator output by fifteen.

SYSTEM_OSC48M_DIV_16 

Divide the 48MHz RC oscillator output by sixteen.

Available startup times for the OSC48M.

Available internal 48MHz oscillator startup times, as a number of internal clock cycles.

Enumerator
SYSTEM_OSC48M_STARTUP_8 

Wait 8 clock cycles until the clock source is considered stable.

SYSTEM_OSC48M_STARTUP_16 

Wait 16 clock cycles until the clock source is considered stable.

SYSTEM_OSC48M_STARTUP_32 

Wait 32 clock cycles until the clock source is considered stable.

SYSTEM_OSC48M_STARTUP_64 

Wait 64 clock cycles until the clock source is considered stable.

SYSTEM_OSC48M_STARTUP_128 

Wait 128 clock cycles until the clock source is considered stable.

SYSTEM_OSC48M_STARTUP_256 

Wait 256 clock cycles until the clock source is considered stable.

SYSTEM_OSC48M_STARTUP_512 

Wait 512 clock cycles until the clock source is considered stable.

SYSTEM_OSC48M_STARTUP_1024 

Wait 1024 clock cycles until the clock source is considered stable.

Available startup times for the XOSC32K.

Available external 32KHz oscillator startup times, as a number of external clock cycles.

Enumerator
SYSTEM_XOSC32K_STARTUP_2048 

Wait 2048 clock cycles until the clock source is considered stable.

SYSTEM_XOSC32K_STARTUP_4096 

Wait 4096 clock cycles until the clock source is considered stable.

SYSTEM_XOSC32K_STARTUP_16384 

Wait 16384 clock cycles until the clock source is considered stable.

SYSTEM_XOSC32K_STARTUP_32768 

Wait 32768 clock cycles until the clock source is considered stable.

SYSTEM_XOSC32K_STARTUP_65536 

Wait 65536 clock cycles until the clock source is considered stable.

SYSTEM_XOSC32K_STARTUP_131072 

Wait 131072 clock cycles until the clock source is considered stable.

SYSTEM_XOSC32K_STARTUP_262144 

Wait 262144 clock cycles until the clock source is considered stable.

Available startup times for the XOSC.

Available external oscillator startup times, as a number of external clock cycles.

Enumerator
SYSTEM_XOSC_STARTUP_1 

Wait one clock cycles until the clock source is considered stable.

SYSTEM_XOSC_STARTUP_2 

Wait two clock cycles until the clock source is considered stable.

SYSTEM_XOSC_STARTUP_4 

Wait four clock cycles until the clock source is considered stable.

SYSTEM_XOSC_STARTUP_8 

Wait eight clock cycles until the clock source is considered stable.

SYSTEM_XOSC_STARTUP_16 

Wait 16 clock cycles until the clock source is considered stable.

SYSTEM_XOSC_STARTUP_32 

Wait 32 clock cycles until the clock source is considered stable.

SYSTEM_XOSC_STARTUP_64 

Wait 64 clock cycles until the clock source is considered stable.

SYSTEM_XOSC_STARTUP_128 

Wait 128 clock cycles until the clock source is considered stable.

SYSTEM_XOSC_STARTUP_256 

Wait 256 clock cycles until the clock source is considered stable.

SYSTEM_XOSC_STARTUP_512 

Wait 512 clock cycles until the clock source is considered stable.

SYSTEM_XOSC_STARTUP_1024 

Wait 1024 clock cycles until the clock source is considered stable.

SYSTEM_XOSC_STARTUP_2048 

Wait 2048 clock cycles until the clock source is considered stable.

SYSTEM_XOSC_STARTUP_4096 

Wait 4096 clock cycles until the clock source is considered stable.

SYSTEM_XOSC_STARTUP_8192 

Wait 8192 clock cycles until the clock source is considered stable.

SYSTEM_XOSC_STARTUP_16384 

Wait 16384 clock cycles until the clock source is considered stable.

SYSTEM_XOSC_STARTUP_32768 

Wait 32768 clock cycles until the clock source is considered stable.

static void system_ahb_clock_clear_mask ( const uint32_t  ahb_mask)
inlinestatic

Clear bits in the clock mask for the AHB bus.

This function will clear bits in the clock mask for the AHB bus. Any bits set to 1 will disable that clock, zero bits in the mask will be ignored.

Parameters
[in]ahb_maskAHB clock mask to disable
static void system_ahb_clock_set_mask ( const uint32_t  ahb_mask)
inlinestatic

Set bits in the clock mask for the AHB bus.

This function will set bits in the clock mask for the AHB bus. Any bits set to 1 will enable that clock, zero bits in the mask will be ignored

Parameters
[in]ahb_maskAHB clock mask to enable

Referenced by _can_enable_peripheral_clock(), _system_divas_init(), and dma_allocate().

static enum status_code system_apb_clock_clear_mask ( const enum system_clock_apb_bus  bus,
const uint32_t  mask 
)
inlinestatic

Clear bits in the clock mask for an APBx bus.

This function will clear bits in the clock mask for an APBx bus. Any bits set to 1 will disable the corresponding module clock, zero bits in the mask will be ignored.

Parameters
[in]maskAPBx clock mask, a SYSTEM_CLOCK_APB_APBx constant from the device header files
[in]busBus to clear clock mask bits
Returns
Status indicating the result of the clock mask change operation.
Return values
STATUS_ERR_INVALID_ARGInvalid bus ID was given
STATUS_OKThe clock mask was changed successfully

References Assert, STATUS_ERR_INVALID_ARG, STATUS_OK, SYSTEM_CLOCK_APB_APBA, SYSTEM_CLOCK_APB_APBB, and SYSTEM_CLOCK_APB_APBC.

static enum status_code system_apb_clock_set_mask ( const enum system_clock_apb_bus  bus,
const uint32_t  mask 
)
inlinestatic

Set bits in the clock mask for an APBx bus.

This function will set bits in the clock mask for an APBx bus. Any bits set to 1 will enable the corresponding module clock, zero bits in the mask will be ignored.

Parameters
[in]maskAPBx clock mask, a SYSTEM_CLOCK_APB_APBx constant from the device header files
[in]busBus to set clock mask bits for, a mask of PM_APBxMASK_* constants from the device header files
Returns
Status indicating the result of the clock mask change operation.
Return values
STATUS_ERR_INVALID_ARGInvalid bus given
STATUS_OKThe clock mask was set successfully

References Assert, STATUS_ERR_INVALID_ARG, STATUS_OK, SYSTEM_CLOCK_APB_APBA, SYSTEM_CLOCK_APB_APBB, and SYSTEM_CLOCK_APB_APBC.

Referenced by _system_events_init(), _system_extint_init(), ac_init(), adc_init(), ccl_init(), dac_init(), dma_allocate(), dsu_crc32_init(), freqm_init(), i2c_master_init(), i2c_slave_init(), nvm_set_config(), rtc_calendar_init(), rtc_count_init(), sdadc_init(), spi_init(), spi_master_vec_init(), system_gclk_init(), tc_init(), tcc_init(), tsens_init(), usart_init(), and wdt_set_config().

void system_clock_init ( void  )

Initialize clock system based on the configuration in conf_clocks.h.

This function will apply the settings in conf_clocks.h when run from the user application. All clock sources and GCLK generators are running when this function returns.

Note
OSC48M is always enabled and if the user selects other clocks for GCLK generators, the OSC48M default enable can be disabled after system_clock_init. Make sure the clock switches successfully before disabling OSC48M.

References Assert, system_clock_source_xosc_config::clock_failure_detector_prescaler, system_clock_source_xosc32k_config::clock_failure_detector_prescaler, system_clock_source_xosc32k_config::enable_1khz_output, system_clock_source_osc32k_config::enable_1khz_output, system_clock_source_xosc32k_config::enable_32khz_output, system_clock_source_osc32k_config::enable_32khz_output, system_clock_source_xosc_config::enable_clock_failure_detector, system_clock_source_xosc32k_config::enable_clock_failure_detector, system_clock_source_xosc_config::enable_clock_failure_detector_event_outut, system_clock_source_xosc32k_config::enable_clock_failure_detector_event_outut, system_clock_source_xosc_config::enable_clock_switch_back, system_clock_source_xosc32k_config::enable_clock_switch_back, system_clock_source_xosc32k_config::external_clock, system_clock_source_xosc_config::external_clock, system_clock_source_dpll_config::filter, system_clock_source_xosc_config::frequency, system_clock_source_xosc32k_config::frequency, system_clock_source_dpll_config::lock_bypass, system_clock_source_dpll_config::low_power_enable, MREPEAT, system_clock_source_xosc32k_config::on_demand, system_clock_source_osc32k_config::on_demand, system_clock_source_dpll_config::on_demand, system_clock_source_dpll_config::output_frequency, system_clock_source_dpll_config::prescaler, system_clock_source_dpll_config::reference_clock, system_clock_source_dpll_config::reference_divider, system_clock_source_dpll_config::reference_frequency, system_clock_source_xosc_config::run_in_standby, system_clock_source_xosc32k_config::run_in_standby, system_clock_source_osc32k_config::run_in_standby, system_clock_source_dpll_config::run_in_standby, system_gclk_chan_config::source_generator, system_clock_source_xosc32k_config::startup_time, system_clock_source_osc32k_config::startup_time, system_clock_source_xosc_config::startup_time, SYSTEM_CLOCK_SOURCE_DPLL, system_clock_source_dpll_get_config_defaults(), SYSTEM_CLOCK_SOURCE_DPLL_REFERENCE_CLOCK_GCLK, SYSTEM_CLOCK_SOURCE_DPLL_REFERENCE_CLOCK_XOSC, SYSTEM_CLOCK_SOURCE_DPLL_REFERENCE_CLOCK_XOSC32K, system_clock_source_dpll_set_config(), system_clock_source_enable(), system_clock_source_is_ready(), SYSTEM_CLOCK_SOURCE_OSC32K, system_clock_source_osc32k_get_config_defaults(), system_clock_source_osc32k_set_config(), SYSTEM_CLOCK_SOURCE_XOSC, SYSTEM_CLOCK_SOURCE_XOSC32K, system_clock_source_xosc32k_get_config_defaults(), system_clock_source_xosc32k_set_config(), system_clock_source_xosc_get_config_defaults(), system_clock_source_xosc_set_config(), system_cpu_clock_set_divider(), system_flash_set_waitstates(), system_gclk_chan_enable(), system_gclk_chan_get_config_defaults(), system_gclk_chan_set_config(), system_gclk_init(), SYSTEM_OSC48M_DIV_12, and system_clock_source_dpll_config::wake_up_fast.

Referenced by system_init().

enum status_code system_clock_source_disable ( const enum system_clock_source  clock_source)

Disables a clock source.

Disables a clock source that was previously enabled.

Parameters
[in]clock_sourceClock source to disable
Return values
STATUS_OKClock source was disabled successfully
STATUS_ERR_INVALID_ARGAn invalid or unavailable clock source was given

References Assert, STATUS_ERR_INVALID_ARG, STATUS_OK, SYSTEM_CLOCK_SOURCE_DPLL, SYSTEM_CLOCK_SOURCE_OSC32K, SYSTEM_CLOCK_SOURCE_OSC48M, SYSTEM_CLOCK_SOURCE_ULP32K, SYSTEM_CLOCK_SOURCE_XOSC, and SYSTEM_CLOCK_SOURCE_XOSC32K.

static void system_clock_source_dpll_get_config_defaults ( struct system_clock_source_dpll_config *const  config)
inlinestatic

Retrieve the default configuration for DPLL.

Fills a configuration structure with the default configuration for a DPLL oscillator module:

  • Run only when requested by peripheral (on demand)
  • Don't run in STANDBY sleep mode
  • Lock bypass disabled
  • Fast wake up disabled
  • Low power mode disabled
  • Output frequency is 48MHz
  • Reference clock frequency is 32768Hz
  • Not divide reference clock
  • Select REF0 as reference clock
  • Set lock time to default mode
  • Use default filter
Parameters
[out]configConfiguration structure to fill with default values

References system_clock_source_dpll_config::filter, system_clock_source_dpll_config::lock_bypass, system_clock_source_dpll_config::lock_time, system_clock_source_dpll_config::low_power_enable, system_clock_source_dpll_config::on_demand, system_clock_source_dpll_config::output_frequency, system_clock_source_dpll_config::prescaler, system_clock_source_dpll_config::reference_clock, system_clock_source_dpll_config::reference_divider, system_clock_source_dpll_config::reference_frequency, system_clock_source_dpll_config::run_in_standby, SYSTEM_CLOCK_SOURCE_DPLL_DIV_1, SYSTEM_CLOCK_SOURCE_DPLL_FILTER_DEFAULT, SYSTEM_CLOCK_SOURCE_DPLL_LOCK_TIME_DEFAULT, SYSTEM_CLOCK_SOURCE_DPLL_REFERENCE_CLOCK_GCLK, and system_clock_source_dpll_config::wake_up_fast.

Referenced by system_clock_init().

void system_clock_source_dpll_set_config ( struct system_clock_source_dpll_config *const  config)
enum status_code system_clock_source_enable ( const enum system_clock_source  system_clock_source)
uint32_t system_clock_source_get_hz ( const enum system_clock_source  clock_source)

Retrieve the frequency of a clock source.

Determines the current operating frequency of a given clock source.

Parameters
[in]clock_sourceClock source to get the frequency of
Returns
Frequency of the given clock source, in Hz.

References _system_clock_module::dpll, _system_clock_dpll_config::frequency, _system_clock_xosc_config::frequency, SYSTEM_CLOCK_SOURCE_DPLL, SYSTEM_CLOCK_SOURCE_OSC32K, SYSTEM_CLOCK_SOURCE_OSC48M, SYSTEM_CLOCK_SOURCE_ULP32K, SYSTEM_CLOCK_SOURCE_XOSC, SYSTEM_CLOCK_SOURCE_XOSC32K, _system_clock_module::xosc, and _system_clock_module::xosc32k.

Referenced by run_16bit_capture_and_compare_test(), run_capture_and_compare_test(), system_gclk_gen_get_hz(), and usart_getdata_xmd().

bool system_clock_source_is_ready ( const enum system_clock_source  clock_source)

Checks if a clock source is ready.

Checks if a given clock source is ready to be used.

Parameters
[in]clock_sourceClock source to check if ready
Returns
Ready state of the given clock source.
Return values
trueClock source is enabled and ready
falseClock source is disabled or not yet ready

References SYSTEM_CLOCK_SOURCE_DPLL, SYSTEM_CLOCK_SOURCE_OSC32K, SYSTEM_CLOCK_SOURCE_OSC48M, SYSTEM_CLOCK_SOURCE_ULP32K, SYSTEM_CLOCK_SOURCE_XOSC, and SYSTEM_CLOCK_SOURCE_XOSC32K.

Referenced by init_xosc32k(), sim_xosc32k_failure(), and system_clock_init().

static void system_clock_source_osc32k_get_config_defaults ( struct system_clock_source_osc32k_config *const  config)
inlinestatic

Retrieve the default configuration for OSC32K.

Fills a configuration structure with the default configuration for an internal 32KHz oscillator module:

  • 1KHz clock output enabled
  • 32KHz clock output enabled
  • Don't run in STANDBY sleep mode
  • Run only when requested by peripheral (on demand)
  • Set startup time to 130 cycles
  • Don't lock registers after configuration has been written
Parameters
[out]configConfiguration structure to fill with default values

References Assert, system_clock_source_osc32k_config::enable_1khz_output, system_clock_source_osc32k_config::enable_32khz_output, system_clock_source_osc32k_config::on_demand, system_clock_source_osc32k_config::run_in_standby, system_clock_source_osc32k_config::startup_time, SYSTEM_OSC32K_STARTUP_130, and system_clock_source_osc32k_config::write_once.

Referenced by system_clock_init().

void system_clock_source_osc32k_set_config ( struct system_clock_source_osc32k_config *const  config)

Configure the internal OSC32K oscillator clock source.

Configures the 32KHz (nominal) internal RC oscillator with the given configuration settings.

Parameters
[in]configOSC32K configuration structure containing the new config

References system_clock_source_osc32k_config::enable_1khz_output, system_clock_source_osc32k_config::enable_32khz_output, system_clock_source_osc32k_config::on_demand, system_clock_source_osc32k_config::run_in_standby, system_clock_source_osc32k_config::startup_time, and system_clock_source_osc32k_config::write_once.

Referenced by system_clock_init().

static void system_clock_source_osc48m_get_config_defaults ( struct system_clock_source_osc48m_config *const  config)
inlinestatic

Retrieve the default configuration for OSC48M.

Fills a configuration structure with the default configuration for an internal 48MHz (nominal) oscillator module:

  • Clock divider by 12 and output frequency 4MHz
  • Don't run in STANDBY sleep mode
  • Run only when requested by peripheral (on demand)
  • Startup time of eight clock cycles
Parameters
[out]configConfiguration structure to fill with default values

References Assert, system_clock_source_osc48m_config::div, system_clock_source_osc48m_config::on_demand, system_clock_source_osc48m_config::run_in_standby, system_clock_source_osc48m_config::startup_time, SYSTEM_OSC48M_DIV_12, and SYSTEM_OSC48M_STARTUP_8.

void system_clock_source_osc48m_set_config ( struct system_clock_source_osc48m_config *const  config)

Configure the internal OSC48M oscillator clock source.

Configures the 48MHz (nominal) internal RC oscillator with the given configuration settings.

Note
Frequency selection can be done only when OSC48M is disabled.
Parameters
[in]configOSC48M configuration structure containing the new config

References Assert, system_clock_source_osc48m_config::div, system_clock_source_osc48m_config::on_demand, system_clock_source_osc48m_config::run_in_standby, and system_clock_source_osc48m_config::startup_time.

static void system_clock_source_osculp32k_get_config_defaults ( struct system_clock_source_osculp32k_config *const  config)
inlinestatic

Retrieve the default configuration for OSCULP32K.

Fills a configuration structure with the default configuration for an internal Ultra Low Power 32KHz oscillator module:

  • 1KHz clock output enabled
  • 32KHz clock output enabled
Parameters
[out]configConfiguration structure to fill with default values

References Assert, and system_clock_source_osculp32k_config::write_once.

Referenced by init_osculp32k().

void system_clock_source_osculp32k_set_config ( struct system_clock_source_osculp32k_config *const  config)

Configure the internal OSCULP32K oscillator clock source.

Configures the Ultra Low Power 32KHz internal RC oscillator with the given configuration settings.

Parameters
[in]configOSCULP32K configuration structure containing the new config

References system_clock_source_osculp32k_config::write_once.

Referenced by init_osculp32k().

enum status_code system_clock_source_write_calibration ( const enum system_clock_source  system_clock_source,
const uint16_t  calibration_value,
const uint8_t  freq_range 
)
static void system_clock_source_xosc32k_get_config_defaults ( struct system_clock_source_xosc32k_config *const  config)
inlinestatic

Retrieve the default configuration for XOSC32K.

Fills a configuration structure with the default configuration for an external 32KHz oscillator module:

  • External Crystal
  • Startup time of 16384 external clock cycles
  • Automatic crystal gain control mode disabled
  • Frequency of 32.768KHz
  • 1KHz clock output disabled
  • 32KHz clock output enabled
  • Don't run in STANDBY sleep mode
  • Run only when requested by peripheral (on demand)
  • Don't lock registers after configuration has been written
  • Clock failure detector prescaler is 1
  • Clock failure detector event outut is disabled
  • Clock failure detector is disabled
  • Clock switch back is disabled
Parameters
[out]configConfiguration structure to fill with default values

References Assert, system_clock_source_xosc32k_config::clock_failure_detector_prescaler, system_clock_source_xosc32k_config::enable_1khz_output, system_clock_source_xosc32k_config::enable_32khz_output, system_clock_source_xosc32k_config::enable_clock_failure_detector, system_clock_source_xosc32k_config::enable_clock_failure_detector_event_outut, system_clock_source_xosc32k_config::enable_clock_switch_back, system_clock_source_xosc32k_config::external_clock, system_clock_source_xosc32k_config::frequency, system_clock_source_xosc32k_config::on_demand, system_clock_source_xosc32k_config::run_in_standby, system_clock_source_xosc32k_config::startup_time, SYSTEM_CLOCK_EXTERNAL_CRYSTAL, SYSTEM_CLOCK_XOSC32K_FAILURE_DETECTOR_PRESCALER_1, SYSTEM_XOSC32K_STARTUP_16384, and system_clock_source_xosc32k_config::write_once.

Referenced by configure_extosc32k(), configure_osc32k(), init_xosc32k(), and system_clock_init().

static void system_clock_source_xosc_get_config_defaults ( struct system_clock_source_xosc_config *const  config)
inlinestatic

Retrieve the default configuration for XOSC.

Fills a configuration structure with the default configuration for an external oscillator module:

  • External Crystal
  • Startup time of 16384 external clock cycles
  • Automatic crystal gain control mode disabled
  • Frequency of 12MHz
  • Don't run in STANDBY sleep mode
  • Run when it's enabled (not on demand)
  • Clock failure detector prescaler is 1
  • Clock failure detector event outut is disabled
  • Clock failure detector is disabled
  • Clock switch back is disabled
Parameters
[out]configConfiguration structure to fill with default values

References Assert, system_clock_source_xosc_config::auto_gain_control, system_clock_source_xosc_config::clock_failure_detector_prescaler, system_clock_source_xosc_config::enable_clock_failure_detector, system_clock_source_xosc_config::enable_clock_failure_detector_event_outut, system_clock_source_xosc_config::enable_clock_switch_back, system_clock_source_xosc_config::external_clock, system_clock_source_xosc_config::frequency, system_clock_source_xosc_config::on_demand, system_clock_source_xosc_config::run_in_standby, system_clock_source_xosc_config::startup_time, SYSTEM_CLOCK_EXTERNAL_CRYSTAL, SYSTEM_CLOCK_XOSC_FAILURE_DETECTOR_PRESCALER_1, and SYSTEM_XOSC_STARTUP_16384.

Referenced by system_clock_init().

static bool system_clock_xosc32k_clock_failure_detected ( void  )
inlinestatic

Checks if XOSC32K clock failure detected.

Checks if XOSC32K clock detected.

Returns
XOSC32K clock failure detected state.
Return values
trueXOSC32K clock failure detected
falseXOSC32K clock failure is not detected
static bool system_clock_xosc32k_is_switched ( void  )
inlinestatic

Checks if XOSC32K is switched and provides the safe clock.

Checks if XOSC32K is switched and provides the safe clock.

Returns
XOSC32K clock switch state.
Return values
trueXOSC32K clock is switched and provides the safe clock
falseXOSC32K clock is not switched and provides the external clock or crystal oscillator clock
static bool system_clock_xosc_clock_failure_detected ( void  )
inlinestatic

Checks if XOSC clock failure detected.

Checks if XOSC clock detected.

Returns
XOSC clock failure detected state.
Return values
trueXOSC clock failure detected
falseXOSC clock failure is not detected
static bool system_clock_xosc_is_switched ( void  )
inlinestatic

Checks if XOSC is switched and provides the safe clock.

Checks if XOSC is switched and provides the safe clock.

Returns
XOSC clock switch state.
Return values
trueXOSC clock is switched and provides the safe clock
falseXOSC clock is not switched and provides the external clock or crystal oscillator clock
static uint32_t system_cpu_clock_get_hz ( void  )
inlinestatic

Retrieves the current frequency of the CPU core.

Retrieves the operating frequency of the CPU core, obtained from the main generic clock and the set CPU bus divider.

Returns
Current CPU frequency in Hz.

References GCLK_GENERATOR_0, and system_gclk_gen_get_hz().

static void system_cpu_clock_set_divider ( const enum system_main_clock_div  divider)
inlinestatic

Set main CPU clock divider.

Sets the clock divider used on the main clock to provide the CPU clock.

Parameters
[in]dividerCPU clock divider to set

Referenced by system_clock_init().

static void system_flash_set_waitstates ( uint8_t  wait_states)
inlinestatic

Set flash controller wait states.

Will set the number of wait states that are used by the onboard flash memory. The number of wait states depend on both device supply voltage and CPU speed. The required number of wait states can be found in the electrical characteristics of the device.

Parameters
[in]wait_statesNumber of wait states to use for internal flash

References Assert.

Referenced by main(), and system_clock_init().

void system_gclk_chan_disable ( const uint8_t  channel)

Disables a Generic Clock that was previously enabled.

Stops the clock generation of a Generic Clock that was previously started via a call to system_gclk_chan_enable().

Parameters
[in]channelGeneric Clock channel to disable

References Assert, system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().

Referenced by extint_nmi_set_config(), and system_gclk_chan_set_config().

static void system_gclk_chan_get_config_defaults ( struct system_gclk_chan_config *const  config)
inlinestatic

Initializes a Generic Clock configuration structure to defaults.

Initializes a given Generic Clock configuration structure to a set of known default values. This function should be called on all new instances of these configuration structures before being modified by the user application.

The default configuration is as follows:

  • The clock is sourced from the Generic Clock Generator channel 0
  • The clock configuration will not be write-locked when set
Parameters
[out]configConfiguration structure to initialize to default values

References Assert, GCLK_GENERATOR_0, and system_gclk_chan_config::source_generator.

Referenced by _ac_set_config(), _adc_set_config(), _sdadc_set_config(), _system_extint_init(), _tsens_set_config(), can_init(), ccl_init(), configure_gclock_channel(), dac_init(), events_allocate(), freqm_init(), i2c_master_init(), i2c_slave_init(), rtc_calendar_init(), rtc_count_init(), sercom_set_gclk_generator(), spi_init(), spi_master_vec_init(), system_clock_init(), tc_init(), tcc_init(), and usart_init().

uint32_t system_gclk_chan_get_hz ( const uint8_t  channel)

Retrieves the clock frequency of a Generic Clock channel.

Determines the clock frequency (in Hz) of a specified Generic Clock channel, used as a source to a device peripheral module.

Parameters
[in]channelGeneric Clock Channel index
Returns
The frequency of the generic clock channel, in Hz.

References system_gclk_gen_get_hz(), system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().

Referenced by _spi_check_config(), _spi_set_config(), _usart_set_config(), can_fd_set_baudrate(), can_set_baudrate(), spi_master_vec_init(), and spi_set_baudrate().

bool system_gclk_chan_is_enabled ( const uint8_t  channel)

Determins if the specified Generic Clock channel is enabled.

Parameters
[in]channelGeneric Clock Channel index
Returns
The enabled status.
Return values
trueThe Generic Clock channel is enabled
falseThe Generic Clock channel is disabled

References system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().

bool system_gclk_chan_is_locked ( const uint8_t  channel)

Determins if the specified Generic Clock channel is locked.

Parameters
[in]channelGeneric Clock Channel index
Returns
The lock status.
Return values
trueThe Generic Clock channel is locked
falseThe Generic Clock channel is not locked

References system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().

void system_gclk_chan_lock ( const uint8_t  channel)

Locks a Generic Clock channel from further configuration writes.

Locks a generic clock channel from further configuration writes. It is only possible to unlock the channel configuration through a power on reset.

Parameters
[in]channelGeneric Clock channel to enable

References system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().

Referenced by wdt_set_config().

void system_gclk_chan_set_config ( const uint8_t  channel,
struct system_gclk_chan_config *const  config 
)

Writes a Generic Clock configuration to the hardware module.

Writes out a given configuration of a Generic Clock configuration to the hardware module. If the clock is currently running, it will be stopped.

Note
Once called the clock will not be running. To start the clock, call system_gclk_chan_enable() after configuring a clock channel.
Parameters
[in]channelGeneric Clock channel to configure
[in]configConfiguration settings for the clock

References Assert, system_gclk_chan_config::source_generator, and system_gclk_chan_disable().

Referenced by _ac_set_config(), _adc_set_config(), _sdadc_set_config(), _system_extint_init(), _tsens_set_config(), can_disable_sleep_mode(), can_init(), ccl_init(), configure_gclock_channel(), dac_init(), events_allocate(), freqm_init(), i2c_master_init(), i2c_slave_init(), rtc_calendar_init(), rtc_count_init(), sercom_set_gclk_generator(), spi_init(), spi_master_vec_init(), system_clock_init(), tc_init(), tcc_init(), usart_init(), and wdt_set_config().

void system_gclk_gen_disable ( const uint8_t  generator)

Disables a Generic Clock Generator that was previously enabled.

Stops the clock generation of a Generic Clock Generator that was previously started via a call to system_gclk_gen_enable().

Parameters
[in]generatorGeneric Clock Generator index to disable

References system_gclk_is_syncing(), system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().

void system_gclk_gen_enable ( const uint8_t  generator)

Enables a Generic Clock Generator that was previously configured.

Starts the clock generation of a Generic Clock Generator that was previously configured via a call to system_gclk_gen_set_config().

Parameters
[in]generatorGeneric Clock Generator index to enable

References system_gclk_is_syncing(), system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().

Referenced by configure_gclock_generator().

static void system_gclk_gen_get_config_defaults ( struct system_gclk_gen_config *const  config)
inlinestatic

Initializes a Generic Clock Generator configuration structure to defaults.

Initializes a given Generic Clock Generator configuration structure to a set of known default values. This function should be called on all new instances of these configuration structures before being modified by the user application.

The default configuration is:

  • The clock is generated undivided from the source frequency
  • The clock generator output is low when the generator is disabled
  • The input clock is sourced from input clock channel 0
  • The clock will be disabled during sleep
  • The clock output will not be routed to a physical GPIO pin
Parameters
[out]configConfiguration structure to initialize to default values

References Assert, system_gclk_gen_config::division_factor, system_gclk_gen_config::high_when_disabled, system_gclk_gen_config::output_enable, system_gclk_gen_config::run_in_standby, and system_gclk_gen_config::source_clock.

Referenced by configure_gclock_generator(), and main().

uint32_t system_gclk_gen_get_hz ( const uint8_t  generator)

Retrieves the clock frequency of a Generic Clock generator.

Determines the clock frequency (in Hz) of a specified Generic Clock generator, used as a source to a Generic Clock Channel module.

Parameters
[in]generatorGeneric Clock Generator index
Returns
The frequency of the generic clock generator, in Hz.

References system_clock_source_get_hz(), system_gclk_is_syncing(), system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().

Referenced by delay_init(), freqm_init(), main(), ssd1306_hard_reset(), system_cpu_clock_get_hz(), and system_gclk_chan_get_hz().

bool system_gclk_gen_is_enabled ( const uint8_t  generator)

Determins if the specified Generic Clock Generator is enabled.

Parameters
[in]generatorGeneric Clock Generator index to check
Returns
The enabled status.
Return values
trueThe Generic Clock Generator is enabled
falseThe Generic Clock Generator is disabled

References system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().

Referenced by extint_chan_set_config(), and extint_nmi_set_config().

void system_gclk_gen_set_config ( const uint8_t  generator,
struct system_gclk_gen_config *const  config 
)

Writes a Generic Clock Generator configuration to the hardware module.

Writes out a given configuration of a Generic Clock Generator configuration to the hardware module.

Note
Changing the clock source on the fly (on a running generator) can take additional time if the clock source is configured to only run on-demand (ONDEMAND bit is set) and it is not currently running (no peripheral is requesting the clock source). In this case the GCLK will request the new clock while still keeping a request to the old clock source until the new clock source is ready.
This function will not start a generator that is not already running; to start the generator, call system_gclk_gen_enable() after configuring a generator.
Parameters
[in]generatorGeneric Clock Generator index to configure
[in]configConfiguration settings for the generator

References Assert, system_gclk_gen_config::division_factor, system_gclk_gen_config::high_when_disabled, system_gclk_gen_config::output_enable, system_gclk_gen_config::run_in_standby, system_gclk_gen_config::source_clock, system_gclk_is_syncing(), system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().

Referenced by configure_gclock_generator(), and main().

void system_gclk_init ( void  )

Initializes the GCLK driver.

Initializes the Generic Clock module, disabling and resetting all active Generic Clock Generators and Channels to their power-on default values.

References system_apb_clock_set_mask(), and SYSTEM_CLOCK_APB_APBA.

Referenced by system_clock_init().