Microchip® Advanced Software Framework

clock_feature.h File Reference

SAM Clock Driver.

Copyright (c) 2012-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_osc32k_config
 Configuration structure for OSC32K. More...
 
struct  system_clock_source_osc8m_config
 Configuration structure for OSC8M. 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
}
 List of APB peripheral buses. More...
 
enum  system_clock_dfll_chill_cycle {
  SYSTEM_CLOCK_DFLL_CHILL_CYCLE_ENABLE,
  SYSTEM_CLOCK_DFLL_CHILL_CYCLE_DISABLE = SYSCTRL_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 = SYSCTRL_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 = SYSCTRL_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 = SYSCTRL_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 = SYSCTRL_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_OSC8M = GCLK_SOURCE_OSC8M,
  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
}
 Available clock sources in the system. 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 and APB/AHB bus clock source prescaler values. 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_osc8m_div {
  SYSTEM_OSC8M_DIV_1,
  SYSTEM_OSC8M_DIV_2,
  SYSTEM_OSC8M_DIV_4,
  SYSTEM_OSC8M_DIV_8
}
 Division prescalers for the internal 8MHz system clock. More...
 
enum  system_osc8m_frequency_range {
  SYSTEM_OSC8M_FREQUENCY_RANGE_4_TO_6,
  SYSTEM_OSC8M_FREQUENCY_RANGE_6_TO_8,
  SYSTEM_OSC8M_FREQUENCY_RANGE_8_TO_11,
  SYSTEM_OSC8M_FREQUENCY_RANGE_11_TO_15
}
 Frequency range for the internal 8MHz RC oscillator. More...
 
enum  system_xosc32k_startup {
  SYSTEM_XOSC32K_STARTUP_0,
  SYSTEM_XOSC32K_STARTUP_32,
  SYSTEM_XOSC32K_STARTUP_2048,
  SYSTEM_XOSC32K_STARTUP_4096,
  SYSTEM_XOSC32K_STARTUP_16384,
  SYSTEM_XOSC32K_STARTUP_32768,
  SYSTEM_XOSC32K_STARTUP_65536,
  SYSTEM_XOSC32K_STARTUP_131072
}
 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 8MHz Oscillator Management
static void system_clock_source_osc8m_get_config_defaults (struct system_clock_source_osc8m_config *const config)
 Retrieve the default configuration for OSC8M. More...
 
void system_clock_source_osc8m_set_config (struct system_clock_source_osc8m_config *const config)
 Configure the internal OSC8M 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_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...
 
static enum status_code system_apb_clock_set_divider (const enum system_clock_apb_bus bus, const enum system_main_clock_div divider)
 Set APBx clock divider. More...
 
static uint32_t system_apb_clock_get_hz (const enum system_clock_apb_bus bus)
 Retrieves the current frequency of a ABPx. 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...
 
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...