Microchip® Advanced Software Framework

sam4s/sysclk.h File Reference

Chip-specific system clock management functions.

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

#include <osc.h>
#include <pll.h>

Macros

#define CONFIG_USBCLK_DIV
 Configuration symbol for the USB generic clock divider setting. More...
 
#define CONFIG_USBCLK_SOURCE
 Configuration symbol for the USB generic clock source. More...
 
Configuration Symbols
#define CONFIG_SYSCLK_SOURCE   SYSCLK_SRC_MAINCK_4M_RC
 Initial/static main system clock source. More...
 
#define CONFIG_SYSCLK_PRES   0
 Initial CPU clock divider (mck) More...
 
Master Clock Sources (MCK)
#define SYSCLK_SRC_SLCK_RC   0
 Internal 32kHz RC oscillator as master source clock. More...
 
#define SYSCLK_SRC_SLCK_XTAL   1
 External 32kHz crystal oscillator as master source clock. More...
 
#define SYSCLK_SRC_SLCK_BYPASS   2
 External 32kHz bypass oscillator as master source clock. More...
 
#define SYSCLK_SRC_MAINCK_4M_RC   3
 Internal 4MHz RC oscillator as master source clock. More...
 
#define SYSCLK_SRC_MAINCK_8M_RC   4
 Internal 8MHz RC oscillator as master source clock. More...
 
#define SYSCLK_SRC_MAINCK_12M_RC   5
 Internal 12MHz RC oscillator as master source clock. More...
 
#define SYSCLK_SRC_MAINCK_XTAL   6
 External crystal oscillator as master source clock. More...
 
#define SYSCLK_SRC_MAINCK_BYPASS   7
 External bypass oscillator as master source clock. More...
 
#define SYSCLK_SRC_PLLACK   8
 Use PLLACK as master source clock. More...
 
#define SYSCLK_SRC_PLLBCK   9
 Use PLLBCK as master source clock. More...
 
Master Clock Prescalers (MCK)
#define SYSCLK_PRES_1   PMC_MCKR_PRES_CLK_1
 Set master clock prescaler to 1. More...
 
#define SYSCLK_PRES_2   PMC_MCKR_PRES_CLK_2
 Set master clock prescaler to 2. More...
 
#define SYSCLK_PRES_4   PMC_MCKR_PRES_CLK_4
 Set master clock prescaler to 4. More...
 
#define SYSCLK_PRES_8   PMC_MCKR_PRES_CLK_8
 Set master clock prescaler to 8. More...
 
#define SYSCLK_PRES_16   PMC_MCKR_PRES_CLK_16
 Set master clock prescaler to 16. More...
 
#define SYSCLK_PRES_32   PMC_MCKR_PRES_CLK_32
 Set master clock prescaler to 32. More...
 
#define SYSCLK_PRES_64   PMC_MCKR_PRES_CLK_64
 Set master clock prescaler to 64. More...
 
#define SYSCLK_PRES_3   PMC_MCKR_PRES_CLK_3
 Set master clock prescaler to 3. More...
 
USB Clock Sources
#define USBCLK_SRC_PLL0   0
 Use PLLA. More...
 
#define USBCLK_SRC_PLL1   1
 Use PLLB. More...
 

Functions

void sysclk_disable_usb (void)
 Disable the USB clock. More...
 
void sysclk_enable_usb (void)
 Enable USB clock. More...
 
Querying the system clock

The following functions may be used to query the current frequency of the system clock and the CPU and bus clocks derived from it.

sysclk_get_main_hz() and sysclk_get_cpu_hz() can be assumed to be available on all platforms, although some platforms may define additional accessors for various chip-internal bus clocks. These are usually not intended to be queried directly by generic code.

static uint32_t sysclk_get_main_hz (void)
 Return the current rate in Hz of the main system clock. More...
 
static uint32_t sysclk_get_cpu_hz (void)
 Return the current rate in Hz of the CPU clock. More...
 
static uint32_t sysclk_get_peripheral_hz (void)
 Retrieves the current rate in Hz of the peripheral clocks. More...
 
static uint32_t sysclk_get_peripheral_bus_hz (const volatile void *module)
 Retrieves the current rate in Hz of the Peripheral Bus clock attached to the specified peripheral. More...
 
Enabling and disabling synchronous clocks
static void sysclk_enable_peripheral_clock (uint32_t ul_id)
 Enable a peripheral's clock. More...
 
static void sysclk_disable_peripheral_clock (uint32_t ul_id)
 Disable a peripheral's clock. More...
 
System Clock Source and Prescaler configuration
void sysclk_set_prescalers (uint32_t ul_pres)
 Set system clock prescaler configuration. More...
 
void sysclk_set_source (uint32_t ul_src)
 Change the source of the main system clock. More...
 
System Clock Initialization
void sysclk_init (void)
 Initialize the synchronous clock system. More...