Microchip® Advanced Software Framework

clock_feature.h File Reference

SAM C2x Clock Driver.

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

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

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

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

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