Microchip® Advanced Software Framework

clock_feature.h File Reference

SAM L21 Clock Driver.

Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.

#include <compiler.h>
#include <gclk.h>

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...
 

Enumerations

enum  system_clock_apb_bus {
  SYSTEM_CLOCK_APB_APBA,
  SYSTEM_CLOCK_APB_APBB,
  SYSTEM_CLOCK_APB_APBC,
  SYSTEM_CLOCK_APB_APBD,
  SYSTEM_CLOCK_APB_APBE
}
 List of APB peripheral buses. More...
 
enum  system_clock_dfll_chill_cycle {
  SYSTEM_CLOCK_DFLL_CHILL_CYCLE_ENABLE,
  SYSTEM_CLOCK_DFLL_CHILL_CYCLE_DISABLE = OSCCTRL_DFLLCTRL_CCDIS
}
 Chill cycle behavior of the DFLL module. More...
 
enum  system_clock_dfll_loop_mode {
  SYSTEM_CLOCK_DFLL_LOOP_MODE_OPEN,
  SYSTEM_CLOCK_DFLL_LOOP_MODE_CLOSED = OSCCTRL_DFLLCTRL_MODE
}
 Operating modes of the DFLL clock source. More...
 
enum  system_clock_dfll_quick_lock {
  SYSTEM_CLOCK_DFLL_QUICK_LOCK_ENABLE,
  SYSTEM_CLOCK_DFLL_QUICK_LOCK_DISABLE = OSCCTRL_DFLLCTRL_QLDIS
}
 QuickLock settings for the DFLL module. More...
 
enum  system_clock_dfll_stable_tracking {
  SYSTEM_CLOCK_DFLL_STABLE_TRACKING_TRACK_AFTER_LOCK,
  SYSTEM_CLOCK_DFLL_STABLE_TRACKING_FIX_AFTER_LOCK = OSCCTRL_DFLLCTRL_STABLE
}
 Fine tracking behavior for the DFLL once a lock has been acquired. More...
 
enum  system_clock_dfll_wakeup_lock {
  SYSTEM_CLOCK_DFLL_WAKEUP_LOCK_KEEP,
  SYSTEM_CLOCK_DFLL_WAKEUP_LOCK_LOSE = OSCCTRL_DFLLCTRL_LLAW
}
 Locking behavior for the DFLL during device wake-up. 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_OSC16M = GCLK_SOURCE_OSC16M,
  SYSTEM_CLOCK_SOURCE_OSC32K = GCLK_SOURCE_OSC32K,
  SYSTEM_CLOCK_SOURCE_XOSC = GCLK_SOURCE_XOSC,
  SYSTEM_CLOCK_SOURCE_XOSC32K = GCLK_SOURCE_XOSC32K,
  SYSTEM_CLOCK_SOURCE_DFLL = GCLK_SOURCE_DFLL48M,
  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_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, Lowpower and Backup clock division. More...
 
enum  system_osc16m_fsel {
  SYSTEM_OSC16M_4M,
  SYSTEM_OSC16M_8M,
  SYSTEM_OSC16M_12M,
  SYSTEM_OSC16M_16M
}
 Frequency selection for the internal 16MHz system clock. 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 start-up times for the OSC32K. 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 start-up 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 start-up times for the XOSC. More...
 

Functions

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...