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:
There are no prerequisites for this module.
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 functionalities within the device.
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, internal DFLL modules, as well as external crystal oscillators and/or clock inputs.
The CPU and AHB/APBx buses are clocked by the same physical clock source (referred in this module as the Main Clock). The CPU and bus clocks are divided into a number of clock domains. Each clock domain can run at different frequencies.
There are three clock domains:
Each clock domain (CPU, LP, BUP) can be changed on the fly. To ensure correct operation, frequencies must be selected so that BUPDIV ≥ LPDIV ≥ HSDIV. Also, frequencies must never exceed the specified maximum frequency for each clock domain. A module may be connected to several clock domains (for instance, AHB and APB).
The general main clock tree for the CPU and associated buses is shown in the figure below.
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, but will reduce the overall device power consumption.
Within the SAM devices 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.
An example setup of a complete clock chain within the device is shown in the figure below.
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.
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.
There are no special considerations for this module.
For extra information, see Extra Information for SYSTEM CLOCK Driver. This includes:
For a list of examples related to this driver, see Examples for System Clock Driver.
Data Structures | |
struct | system_clock_source_dfll_config |
Configuration structure for DFLL. More... | |
struct | system_clock_source_dpll_config |
Configuration structure for DPLL. More... | |
struct | system_clock_source_osc16m_config |
Configuration structure for OSC16M. More... | |
struct | system_clock_source_osc32k_config |
Configuration structure for OSCULP32K. 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... | |
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... | |
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... | |
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 16MHz Oscillator Management | |
static void | system_clock_source_osc16m_get_config_defaults (struct system_clock_source_osc16m_config *const config) |
Retrieve the default configuration for OSC16M. More... | |
void | system_clock_source_osc16m_set_config (struct system_clock_source_osc16m_config *const config) |
Configure the internal OSC16M oscillator clock source. More... | |
Internal DFLL Management | |
static void | system_clock_source_dfll_get_config_defaults (struct system_clock_source_dfll_config *const config) |
Retrieve the default configuration for DFLL. More... | |
void | system_clock_source_dfll_set_config (struct system_clock_source_dfll_config *const config) |
Configure the DFLL 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_main_clock_set_failure_detect (const bool enable) |
Enable or disable the main clock failure detection. More... | |
static void | system_cpu_clock_set_divider (const enum system_main_clock_div divider) |
Set main CPU clock divider. More... | |
static void | system_low_power_clock_set_divider (const enum system_main_clock_div divider) |
Set Low-Power Clock divider. More... | |
static void | system_backup_clock_set_divider (const enum system_main_clock_div divider) |
Set Backup Clock divider. More... | |
static uint32_t | system_cpu_clock_get_hz (void) |
Retrieves the current frequency of the CPU core. More... | |
static uint32_t | system_low_power_clock_get_hz (void) |
Retrieves the current frequency of Low-Power clock. More... | |
static uint32_t | system_backup_clock_get_hz (void) |
Retrieves the current frequency of backup clock. 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... | |
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... | |
enum gclk_generator |
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.
enum system_clock_apb_bus |
List of APB peripheral buses.
Available bus clock domains on the APB bus.
Chill cycle behavior of the DFLL module.
DFLL chill cycle behavior modes of the DFLL module. A chill cycle is a period of time when the DFLL output frequency is not measured by the unit, to allow the output to stabilize after a change in the input clock source.
Operating modes of the DFLL clock source.
Available operating modes of the DFLL clock source module.
QuickLock settings for the DFLL module.
DFLL QuickLock settings for the DFLL module, to allow for a faster lock of the DFLL output frequency at the expense of accuracy.
Fine tracking behavior for the DFLL once a lock has been acquired.
DFLL fine tracking behavior modes after a lock has been acquired.
enum system_clock_source |
Available clock sources in the system.
Clock sources available to the GCLK generators.
Filter type of the DPLL module.
Lock time-out value of the DPLL module.
Main CPU, Lowpower and Backup clock division.
Available division ratios for the CPU and Lowpower and Backup clocks.
enum system_osc16m_fsel |
Frequency selection for the internal 16MHz system clock.
Available frequency selection for the internal 16MHz (nominal) system clock.
Enumerator | |
---|---|
SYSTEM_OSC16M_4M |
Frequency Selection 4MHz. |
SYSTEM_OSC16M_8M |
Frequency Selection 8MHz. |
SYSTEM_OSC16M_12M |
Frequency Selection 12MHz. |
SYSTEM_OSC16M_16M |
Frequency Selection 16MHz. |
Available start-up times for the OSC32K.
Available internal 32KHz oscillator start-up times, as a number of internal OSC32K clock cycles.
Available start-up times for the XOSC32K.
Available external 32KHz oscillator start-up times, as a number of external clock cycles.
enum system_xosc_startup |
Available start-up times for the XOSC.
Available external oscillator start-up times, as a number of external clock cycles.
|
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.
[in] | ahb_mask | AHB clock 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, 0 bits in the mask will be ignored
[in] | ahb_mask | AHB clock mask |
Referenced by dma_allocate().
|
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.
[in] | mask | APBx clock mask, a SYSTEM_CLOCK_APB_APBx constant from the device header files |
[in] | bus | Bus to clear clock mask bits |
STATUS_ERR_INVALID_ARG | Invalid bus ID was given |
STATUS_OK | The clock mask was changed successfully |
References Assert, STATUS_ERR_INVALID_ARG, STATUS_OK, SYSTEM_CLOCK_APB_APBA, SYSTEM_CLOCK_APB_APBB, SYSTEM_CLOCK_APB_APBC, SYSTEM_CLOCK_APB_APBD, and SYSTEM_CLOCK_APB_APBE.
|
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.
[in] | mask | APBx clock mask, a SYSTEM_CLOCK_APB_APBx constant from the device header files |
[in] | bus | Bus to set clock mask bits for, a mask of PM_APBxMASK_* constants from the device header files |
STATUS_ERR_INVALID_ARG | Invalid bus given |
STATUS_OK | The clock mask was set successfully |
References Assert, STATUS_ERR_INVALID_ARG, STATUS_OK, SYSTEM_CLOCK_APB_APBA, SYSTEM_CLOCK_APB_APBB, SYSTEM_CLOCK_APB_APBC, SYSTEM_CLOCK_APB_APBD, and SYSTEM_CLOCK_APB_APBE.
Referenced by _system_events_init(), _system_extint_init(), ac_init(), adc_init(), aes_init(), ccl_init(), dac_init(), dma_allocate(), i2c_master_init(), i2c_slave_init(), nvm_set_config(), opamp_module_init(), rtc_calendar_init(), rtc_count_init(), spi_init(), system_gclk_init(), tc_init(), tcc_init(), trng_init(), usart_init(), usb_init(), and wdt_set_config().
|
inlinestatic |
Retrieves the current frequency of backup clock.
Retrieves the operating frequency of backup clock, obtained from backup clock and the set backup clock divider.
References GCLK_GENERATOR_0, and system_gclk_gen_get_hz().
|
inlinestatic |
Set Backup Clock divider.
Sets the clock divider used on the main clock to provide the CPU clock.
[in] | divider | CPU clock divider |
Referenced by system_clock_init().
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.
References _system_clock_source_osc16m_freq_sel(), Assert, system_clock_source_dfll_config::chill_cycle, system_clock_source_dfll_config::coarse_max_step, system_clock_source_dfll_config::coarse_value, 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_xosc32k_config::external_clock, system_clock_source_xosc_config::external_clock, system_clock_source_dpll_config::filter, system_clock_source_dfll_config::fine_max_step, system_clock_source_dfll_config::fine_value, system_clock_source_xosc_config::frequency, system_clock_source_xosc32k_config::frequency, system_clock_source_dpll_config::lock_bypass, system_clock_source_dpll_config::lock_time, system_clock_source_dfll_config::loop_mode, system_clock_source_dpll_config::low_power_enable, MREPEAT, system_clock_source_dfll_config::multiply_factor, system_clock_source_xosc32k_config::on_demand, system_clock_source_osc32k_config::on_demand, system_clock_source_dfll_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_dfll_config::quick_lock, system_clock_source_dpll_config::reference_clock, system_clock_source_dpll_config::reference_divider, system_clock_source_dpll_config::reference_frequency, system_clock_source_dfll_config::run_in_stanby, 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_dfll_config::stable_tracking, system_clock_source_xosc32k_config::startup_time, system_clock_source_osc32k_config::startup_time, system_clock_source_xosc_config::startup_time, system_backup_clock_set_divider(), SYSTEM_CLOCK_DFLL_CHILL_CYCLE_DISABLE, SYSTEM_CLOCK_DFLL_CHILL_CYCLE_ENABLE, SYSTEM_CLOCK_DFLL_LOOP_MODE_CLOSED, SYSTEM_CLOCK_DFLL_LOOP_MODE_OPEN, SYSTEM_CLOCK_DFLL_QUICK_LOCK_DISABLE, SYSTEM_CLOCK_DFLL_QUICK_LOCK_ENABLE, SYSTEM_CLOCK_DFLL_STABLE_TRACKING_FIX_AFTER_LOCK, SYSTEM_CLOCK_DFLL_STABLE_TRACKING_TRACK_AFTER_LOCK, SYSTEM_CLOCK_DFLL_WAKEUP_LOCK_KEEP, SYSTEM_CLOCK_DFLL_WAKEUP_LOCK_LOSE, SYSTEM_CLOCK_SOURCE_DFLL, system_clock_source_dfll_get_config_defaults(), system_clock_source_dfll_set_config(), SYSTEM_CLOCK_SOURCE_DPLL, system_clock_source_dpll_get_config_defaults(), SYSTEM_CLOCK_SOURCE_DPLL_LOCK_TIME_DEFAULT, 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_get_hz(), 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_low_power_clock_set_divider(), SYSTEM_MAIN_CLOCK_DIV_1, SYSTEM_MAIN_CLOCK_DIV_8, system_main_clock_set_failure_detect(), SYSTEM_OSC16M_4M, SYSTEM_PERFORMANCE_LEVEL_0, SYSTEM_PERFORMANCE_LEVEL_2, system_switch_performance_level(), system_clock_source_dpll_config::wake_up_fast, and system_clock_source_dfll_config::wakeup_lock.
Referenced by system_init().
|
inlinestatic |
Retrieve the default configuration for DFLL.
Fills a configuration structure with the default configuration for a DFLL oscillator module:
[out] | config | Configuration structure to fill with default values |
References Assert, system_clock_source_dfll_config::chill_cycle, system_clock_source_dfll_config::coarse_max_step, system_clock_source_dfll_config::coarse_value, system_clock_source_dfll_config::fine_max_step, system_clock_source_dfll_config::fine_value, system_clock_source_dfll_config::loop_mode, system_clock_source_dfll_config::multiply_factor, system_clock_source_dfll_config::on_demand, system_clock_source_dfll_config::quick_lock, system_clock_source_dfll_config::run_in_stanby, system_clock_source_dfll_config::stable_tracking, SYSTEM_CLOCK_DFLL_CHILL_CYCLE_ENABLE, SYSTEM_CLOCK_DFLL_LOOP_MODE_OPEN, SYSTEM_CLOCK_DFLL_QUICK_LOCK_ENABLE, SYSTEM_CLOCK_DFLL_STABLE_TRACKING_TRACK_AFTER_LOCK, SYSTEM_CLOCK_DFLL_WAKEUP_LOCK_KEEP, and system_clock_source_dfll_config::wakeup_lock.
Referenced by system_clock_init().
void system_clock_source_dfll_set_config | ( | struct system_clock_source_dfll_config *const | config | ) |
Configure the DFLL clock source.
Configures the Digital Frequency Locked Loop clock source with the given configuration settings.
[in] | config | DFLL configuration structure containing the new config |
References system_clock_source_dfll_config::chill_cycle, system_clock_source_dfll_config::coarse_max_step, system_clock_source_dfll_config::coarse_value, _system_clock_dfll_config::control, _system_clock_module::dfll, system_clock_source_dfll_config::fine_max_step, system_clock_source_dfll_config::fine_value, system_clock_source_dfll_config::loop_mode, _system_clock_dfll_config::mul, system_clock_source_dfll_config::multiply_factor, system_clock_source_dfll_config::on_demand, system_clock_source_dfll_config::quick_lock, system_clock_source_dfll_config::run_in_stanby, system_clock_source_dfll_config::stable_tracking, SYSTEM_CLOCK_DFLL_LOOP_MODE_CLOSED, _system_clock_dfll_config::val, and system_clock_source_dfll_config::wakeup_lock.
Referenced by system_clock_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.
[in] | clock_source | Clock source to disable |
STATUS_OK | Clock source was disabled successfully |
STATUS_ERR_INVALID_ARG | An invalid or unavailable clock source was given |
References Assert, _system_clock_dfll_config::control, _system_clock_module::dfll, STATUS_ERR_INVALID_ARG, STATUS_OK, SYSTEM_CLOCK_SOURCE_DFLL, SYSTEM_CLOCK_SOURCE_DPLL, SYSTEM_CLOCK_SOURCE_OSC16M, SYSTEM_CLOCK_SOURCE_OSC32K, SYSTEM_CLOCK_SOURCE_ULP32K, SYSTEM_CLOCK_SOURCE_XOSC, and SYSTEM_CLOCK_SOURCE_XOSC32K.
Referenced by _system_clock_source_osc16m_freq_sel().
|
inlinestatic |
Retrieve the default configuration for DPLL.
Fills a configuration structure with the default configuration for a DPLL oscillator module:
[out] | config | Configuration 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 | ) |
Configure the DPLL clock source.
Configures the Digital Phase-Locked Loop clock source with the given configuration settings.
[in] | config | DPLL configuration structure containing the new config |
References _system_clock_module::dpll, system_clock_source_dpll_config::filter, _system_clock_dpll_config::frequency, 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_REFERENCE_CLOCK_XOSC, and system_clock_source_dpll_config::wake_up_fast.
Referenced by system_clock_init().
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.
[in] | clock_source | Clock source |
References _system_dfll_wait_for_sync(), _system_clock_dfll_config::control, _system_clock_module::dfll, _system_clock_module::dpll, _system_clock_dpll_config::frequency, _system_clock_xosc_config::frequency, _system_clock_dfll_config::mul, SYSTEM_CLOCK_SOURCE_DFLL, SYSTEM_CLOCK_SOURCE_DPLL, SYSTEM_CLOCK_SOURCE_OSC16M, SYSTEM_CLOCK_SOURCE_OSC32K, SYSTEM_CLOCK_SOURCE_ULP32K, SYSTEM_CLOCK_SOURCE_XOSC, SYSTEM_CLOCK_SOURCE_XOSC32K, system_gclk_chan_get_hz(), _system_clock_module::xosc, and _system_clock_module::xosc32k.
Referenced by system_gclk_gen_get_hz().
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.
[in] | clock_source | Clock source to check if ready |
true | Clock source is enabled and ready |
false | Clock source is disabled or not yet ready |
References SYSTEM_CLOCK_DFLL_LOOP_MODE_CLOSED, SYSTEM_CLOCK_SOURCE_DFLL, SYSTEM_CLOCK_SOURCE_DPLL, SYSTEM_CLOCK_SOURCE_OSC16M, SYSTEM_CLOCK_SOURCE_OSC32K, SYSTEM_CLOCK_SOURCE_ULP32K, SYSTEM_CLOCK_SOURCE_XOSC, and SYSTEM_CLOCK_SOURCE_XOSC32K.
Referenced by _system_clock_source_osc16m_freq_sel(), and system_clock_init().
|
inlinestatic |
Retrieve the default configuration for OSC16M.
Fills a configuration structure with the default configuration for an internal 16MHz (nominal) oscillator module:
[out] | config | Configuration structure to fill with default values |
References Assert, system_clock_source_osc16m_config::fsel, system_clock_source_osc16m_config::on_demand, system_clock_source_osc16m_config::run_in_standby, and SYSTEM_OSC16M_4M.
Referenced by _system_clock_source_osc16m_freq_sel().
void system_clock_source_osc16m_set_config | ( | struct system_clock_source_osc16m_config *const | config | ) |
Configure the internal OSC16M oscillator clock source.
Configures the 16MHz (nominal) internal RC oscillator with the given configuration settings.
[in] | config | OSC16M configuration structure containing the new config |
References system_clock_source_osc16m_config::fsel, system_clock_source_osc16m_config::on_demand, and system_clock_source_osc16m_config::run_in_standby.
Referenced by _system_clock_source_osc16m_freq_sel().
|
inlinestatic |
Retrieve the default configuration for OSC32K.
Fills a configuration structure with the default configuration for an internal 32KHz oscillator module:
[out] | config | Configuration 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.
[in] | config | OSC32K 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().
|
inlinestatic |
Retrieve the default configuration for OSCULP32K.
Fills a configuration structure with the default configuration for an internal Ultra Low Power 32KHz oscillator module:
[out] | config | Configuration structure to fill with default values |
References Assert, and system_clock_source_osculp32k_config::write_once.
Referenced by opamp_module_init(), and opamp_voltage_doubler_enable().
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.
[in] | config | OSCULP32K configuration structure containing the new config |
References system_clock_source_osculp32k_config::write_once.
Referenced by opamp_module_init(), and opamp_voltage_doubler_enable().
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 | ||
) |
|
inlinestatic |
Retrieve the default configuration for XOSC32K.
Fills a configuration structure with the default configuration for an external 32KHz oscillator module:
[out] | config | Configuration structure to fill with default values |
References Assert, system_clock_source_xosc32k_config::enable_1khz_output, system_clock_source_xosc32k_config::enable_32khz_output, 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_XOSC32K_STARTUP_16384, and system_clock_source_xosc32k_config::write_once.
Referenced by system_clock_init().
void system_clock_source_xosc32k_set_config | ( | struct system_clock_source_xosc32k_config *const | config | ) |
Configure the XOSC32K external 32KHz oscillator clock source.
Configures the external 32KHz oscillator clock source with the given configuration settings.
[in] | config | XOSC32K configuration structure containing the new config |
References system_clock_source_xosc32k_config::enable_1khz_output, system_clock_source_xosc32k_config::enable_32khz_output, system_clock_source_xosc32k_config::external_clock, _system_clock_xosc_config::frequency, 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_source_xosc32k_config::write_once, and _system_clock_module::xosc32k.
Referenced by system_clock_init().
|
inlinestatic |
Retrieve the default configuration for XOSC.
Fills a configuration structure with the default configuration for an external oscillator module:
[out] | config | Configuration structure to fill with default values |
References Assert, system_clock_source_xosc_config::auto_gain_control, 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, and SYSTEM_XOSC_STARTUP_16384.
Referenced by system_clock_init().
void system_clock_source_xosc_set_config | ( | struct system_clock_source_xosc_config *const | config | ) |
Configure the external oscillator clock source.
Configures the external oscillator clock source with the given configuration settings.
[in] | config | External oscillator configuration structure containing the new config |
References system_clock_source_xosc_config::auto_gain_control, system_clock_source_xosc_config::external_clock, _system_clock_xosc_config::frequency, 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, and _system_clock_module::xosc.
Referenced by system_clock_init().
|
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.
References GCLK_GENERATOR_0, and system_gclk_gen_get_hz().
Referenced by system_clock_init().
|
inlinestatic |
Set main CPU clock divider.
Sets the clock divider used on the main clock to provide the CPU clock.
[in] | divider | CPU clock divider |
Referenced by system_clock_init().
|
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.
[in] | wait_states | Number of wait states to use for internal flash |
References Assert.
Referenced by 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().
[in] | channel | Generic 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().
void system_gclk_chan_enable | ( | const uint8_t | channel | ) |
Enables a Generic Clock that was previously configured.
Starts the clock generation of a Generic Clock that was previously configured via a call to system_gclk_chan_set_config().
[in] | channel | Generic Clock channel to enable |
References system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().
Referenced by _ac_set_config(), _adc_set_config(), _system_extint_init(), ccl_init(), dac_init(), events_allocate(), extint_nmi_set_config(), i2c_master_init(), i2c_slave_init(), rtc_calendar_init(), rtc_count_init(), sercom_set_gclk_generator(), spi_init(), system_clock_init(), tc_init(), tcc_init(), usart_init(), usb_init(), and wdt_set_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:
[out] | config | Configuration 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(), _system_extint_init(), ccl_init(), dac_init(), events_allocate(), i2c_master_init(), i2c_slave_init(), rtc_calendar_init(), rtc_count_init(), sercom_set_gclk_generator(), spi_init(), system_clock_init(), tc_init(), tcc_init(), usart_init(), and usb_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.
[in] | channel | Generic Clock Channel index |
References system_gclk_gen_get_hz(), system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().
Referenced by _spi_set_config(), _usart_set_config(), spi_set_baudrate(), and system_clock_source_get_hz().
bool system_gclk_chan_is_enabled | ( | const uint8_t | channel | ) |
Determins if the specified Generic Clock channel is enabled.
[in] | channel | Generic Clock Channel index |
true | The Generic Clock channel is enabled |
false | The 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.
[in] | channel | Generic Clock Channel index |
true | The Generic Clock channel is locked |
false | The 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.
[in] | channel | Generic 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.
[in] | channel | Generic Clock channel to configure |
[in] | config | Configuration 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(), _system_extint_init(), ccl_init(), dac_init(), events_allocate(), i2c_master_init(), i2c_slave_init(), rtc_calendar_init(), rtc_count_init(), sercom_set_gclk_generator(), spi_init(), system_clock_init(), tc_init(), tcc_init(), usart_init(), usb_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().
[in] | generator | Generic 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().
[in] | generator | Generic Clock Generator index to enable |
References system_gclk_is_syncing(), system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().
|
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:
[out] | config | Configuration 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 _system_clock_source_osc16m_freq_sel().
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.
[in] | generator | Generic Clock Generator index |
References system_clock_source_get_hz(), system_gclk_is_syncing(), system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().
Referenced by system_backup_clock_get_hz(), system_cpu_clock_get_hz(), system_gclk_chan_get_hz(), and system_low_power_clock_get_hz().
bool system_gclk_gen_is_enabled | ( | const uint8_t | generator | ) |
Determins if the specified Generic Clock Generator is enabled.
[in] | generator | Generic Clock Generator index to check |
true | The Generic Clock Generator is enabled |
false | The 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.
[in] | generator | Generic Clock Generator index to configure |
[in] | config | Configuration 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 _system_clock_source_osc16m_freq_sel().
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().
|
inlinestatic |
Retrieves the current frequency of Low-Power clock.
Retrieves the operating frequency of Low-Power, obtained from Low-Power clock and the set Low-Power clock divider.
References GCLK_GENERATOR_0, and system_gclk_gen_get_hz().
|
inlinestatic |
Set Low-Power Clock divider.
Sets the clock divider used on the main clock to provide the CPU clock.
[in] | divider | CPU clock divider to set |
Referenced by system_clock_init().
|
inlinestatic |
Enable or disable the main clock failure detection.
This mechanism allows switching automatically the main clock to the safe RCSYS clock, when the main clock source is considered off.
This may happen for instance when an external crystal is selected as the clock source of the main clock and the crystal dies. The mechanism is to detect, during a RCSYS period, at least one rising edge of the main clock. If no rising edge is seen the clock is considered failed. As soon as the detector is enabled, the clock failure detector (CFD) will monitor the divided main clock. When a clock failure is detected, the main clock automatically switches to the RCSYS clock and the CFD interrupt is generated if enabled.
[in] | enable | Boolean true to enable, false to disable detection |
Referenced by system_clock_init().