Macros | Functions
System Clock Management
Collaboration diagram for System Clock Management:

Macros

#define CONFIG_USBCLK_DIV   1
 Configuration symbol for the USB generic clock divider setting. More...
 
#define CONFIG_USBCLK_SOURCE   USBCLK_SRC_UPLL
 Configuration symbol for the USB generic clock source. More...
 

Functions

void sysclk_disable_usb (void)
 
void sysclk_enable_usb (void)
 

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_UPLLCK   9
 Use UPLLCK 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...
 

Master Clock Division (MCK)

#define SYSCLK_DIV_1   PMC_MCKR_MDIV_EQ_PCK
 Set master clock division to 1. More...
 
#define SYSCLK_DIV_2   PMC_MCKR_MDIV_PCK_DIV2
 Set master clock division to 2. More...
 
#define SYSCLK_DIV_4   PMC_MCKR_MDIV_PCK_DIV4
 Set master clock division to 4. More...
 
#define SYSCLK_DIV_3   PMC_MCKR_MDIV_PCK_DIV3
 Set master clock division to 3. More...
 

USB Clock Sources

#define USBCLK_SRC_PLL0   0
 Use PLLA. More...
 
#define USBCLK_SRC_UPLL   1
 Use UPLL. 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...
 

Detailed Description

See Quick Start Guide for the System Clock Management.

The sysclk API covers the system clock and all clocks derived from it. The system clock is a chip-internal clock on which all synchronous clocks, i.e. CPU and bus/peripheral clocks, are based. The system clock is typically generated from one of a variety of sources, which may include crystal and RC oscillators as well as PLLs. The clocks derived from the system clock are sometimes also known as synchronous clocks, since they always run synchronously with respect to each other, as opposed to generic clocks which may run from different oscillators or PLLs.

Most applications should simply call sysclk_init() to initialize everything related to the system clock and its source (oscillator, PLL or DFLL), and leave it at that. More advanced applications, and platform-specific drivers, may require additional services from the clock system, some of which may be platform-specific.

Platform Dependencies

The sysclk API is partially chip- or platform-specific. While all platforms provide mostly the same functionality, there are some variations around how different bus types and clock tree structures are handled.

The following functions are available on all platforms with the same parameters and functionality. These functions may be called freely by portable applications, drivers and services:

The following functions are available on all platforms, but there may be variations in the function signature (i.e. parameters) and behavior. These functions are typically called by platform-specific parts of drivers, and applications that aren't intended to be portable:

All other functions should be considered platform-specific. Enabling/disabling clocks to specific peripherals as well as determining the speed of these clocks should be done by calling functions provided by the driver for that peripheral.

Macro Definition Documentation

◆ CONFIG_SYSCLK_PRES

#define CONFIG_SYSCLK_PRES   0

Initial CPU clock divider (mck)

The MCK will run at

\[ f_{MCK} = \frac{f_{sys}}{\mathrm{CONFIG\_SYSCLK\_PRES}}\,\mbox{Hz} \]

after initialization.

Definition at line 228 of file same70/sysclk.h.

◆ CONFIG_SYSCLK_SOURCE

#define CONFIG_SYSCLK_SOURCE   SYSCLK_SRC_MAINCK_4M_RC

Initial/static main system clock source.

The main system clock will be configured to use this clock during initialization.

Definition at line 215 of file same70/sysclk.h.

◆ CONFIG_USBCLK_DIV

#define CONFIG_USBCLK_DIV   1

Configuration symbol for the USB generic clock divider setting.

Sets the clock division for the USB generic clock. If a USB clock source is selected with CONFIG_USBCLK_SOURCE, this configuration symbol must also be defined.

Definition at line 87 of file conf_clock.h.

◆ CONFIG_USBCLK_SOURCE

#define CONFIG_USBCLK_SOURCE   USBCLK_SRC_UPLL

Configuration symbol for the USB generic clock source.

Sets the clock source to use for the USB. The source must also be properly configured.

Define this to one of the USBCLK_SRC_xxx settings. Leave it undefined if USB is not required.

Definition at line 86 of file conf_clock.h.

◆ SYSCLK_DIV_1

#define SYSCLK_DIV_1   PMC_MCKR_MDIV_EQ_PCK

Set master clock division to 1.

Definition at line 261 of file same70/sysclk.h.

◆ SYSCLK_DIV_2

#define SYSCLK_DIV_2   PMC_MCKR_MDIV_PCK_DIV2

Set master clock division to 2.

Definition at line 262 of file same70/sysclk.h.

◆ SYSCLK_DIV_3

#define SYSCLK_DIV_3   PMC_MCKR_MDIV_PCK_DIV3

Set master clock division to 3.

Definition at line 264 of file same70/sysclk.h.

◆ SYSCLK_DIV_4

#define SYSCLK_DIV_4   PMC_MCKR_MDIV_PCK_DIV4

Set master clock division to 4.

Definition at line 263 of file same70/sysclk.h.

◆ SYSCLK_PRES_1

#define SYSCLK_PRES_1   PMC_MCKR_PRES_CLK_1

Set master clock prescaler to 1.

Definition at line 249 of file same70/sysclk.h.

◆ SYSCLK_PRES_16

#define SYSCLK_PRES_16   PMC_MCKR_PRES_CLK_16

Set master clock prescaler to 16.

Definition at line 253 of file same70/sysclk.h.

◆ SYSCLK_PRES_2

#define SYSCLK_PRES_2   PMC_MCKR_PRES_CLK_2

Set master clock prescaler to 2.

Definition at line 250 of file same70/sysclk.h.

◆ SYSCLK_PRES_3

#define SYSCLK_PRES_3   PMC_MCKR_PRES_CLK_3

Set master clock prescaler to 3.

Definition at line 256 of file same70/sysclk.h.

◆ SYSCLK_PRES_32

#define SYSCLK_PRES_32   PMC_MCKR_PRES_CLK_32

Set master clock prescaler to 32.

Definition at line 254 of file same70/sysclk.h.

◆ SYSCLK_PRES_4

#define SYSCLK_PRES_4   PMC_MCKR_PRES_CLK_4

Set master clock prescaler to 4.

Definition at line 251 of file same70/sysclk.h.

◆ SYSCLK_PRES_64

#define SYSCLK_PRES_64   PMC_MCKR_PRES_CLK_64

Set master clock prescaler to 64.

Definition at line 255 of file same70/sysclk.h.

◆ SYSCLK_PRES_8

#define SYSCLK_PRES_8   PMC_MCKR_PRES_CLK_8

Set master clock prescaler to 8.

Definition at line 252 of file same70/sysclk.h.

◆ SYSCLK_SRC_MAINCK_12M_RC

#define SYSCLK_SRC_MAINCK_12M_RC   5

Internal 12MHz RC oscillator as master source clock.

Definition at line 240 of file same70/sysclk.h.

◆ SYSCLK_SRC_MAINCK_4M_RC

#define SYSCLK_SRC_MAINCK_4M_RC   3

Internal 4MHz RC oscillator as master source clock.

Definition at line 238 of file same70/sysclk.h.

◆ SYSCLK_SRC_MAINCK_8M_RC

#define SYSCLK_SRC_MAINCK_8M_RC   4

Internal 8MHz RC oscillator as master source clock.

Definition at line 239 of file same70/sysclk.h.

◆ SYSCLK_SRC_MAINCK_BYPASS

#define SYSCLK_SRC_MAINCK_BYPASS   7

External bypass oscillator as master source clock.

Definition at line 242 of file same70/sysclk.h.

◆ SYSCLK_SRC_MAINCK_XTAL

#define SYSCLK_SRC_MAINCK_XTAL   6

External crystal oscillator as master source clock.

Definition at line 241 of file same70/sysclk.h.

◆ SYSCLK_SRC_PLLACK

#define SYSCLK_SRC_PLLACK   8

Use PLLACK as master source clock.

Definition at line 243 of file same70/sysclk.h.

◆ SYSCLK_SRC_SLCK_BYPASS

#define SYSCLK_SRC_SLCK_BYPASS   2

External 32kHz bypass oscillator as master source clock.

Definition at line 237 of file same70/sysclk.h.

◆ SYSCLK_SRC_SLCK_RC

#define SYSCLK_SRC_SLCK_RC   0

Internal 32kHz RC oscillator as master source clock.

Definition at line 235 of file same70/sysclk.h.

◆ SYSCLK_SRC_SLCK_XTAL

#define SYSCLK_SRC_SLCK_XTAL   1

External 32kHz crystal oscillator as master source clock.

Definition at line 236 of file same70/sysclk.h.

◆ SYSCLK_SRC_UPLLCK

#define SYSCLK_SRC_UPLLCK   9

Use UPLLCK as master source clock.

Definition at line 244 of file same70/sysclk.h.

◆ USBCLK_SRC_PLL0

#define USBCLK_SRC_PLL0   0

Use PLLA.

Definition at line 269 of file same70/sysclk.h.

◆ USBCLK_SRC_UPLL

#define USBCLK_SRC_UPLL   1

Use UPLL.

Definition at line 270 of file same70/sysclk.h.

Function Documentation

◆ sysclk_disable_peripheral_clock()

static void sysclk_disable_peripheral_clock ( uint32_t  ul_id)
inlinestatic

Disable a peripheral's clock.

Parameters
ul_idId (number) of the peripheral clock.

Definition at line 433 of file same70/sysclk.h.

◆ sysclk_disable_usb()

void sysclk_disable_usb ( void  )

◆ sysclk_enable_peripheral_clock()

static void sysclk_enable_peripheral_clock ( uint32_t  ul_id)
inlinestatic

Enable a peripheral's clock.

Parameters
ul_idId (number) of the peripheral clock.

Definition at line 423 of file same70/sysclk.h.

◆ sysclk_enable_usb()

void sysclk_enable_usb ( void  )

◆ sysclk_get_cpu_hz()

static uint32_t sysclk_get_cpu_hz ( void  )
inlinestatic

Return the current rate in Hz of the CPU clock.

Todo:
This function assumes that the CPU always runs at the system clock frequency. We want to support at least two more scenarios: Fixed CPU/bus clock dividers (config symbols) and dynamic CPU/bus clock dividers (which may change at run time). Ditto for all the bus clocks.
Returns
Frequency of the CPU clock, in Hz.

Definition at line 378 of file same70/sysclk.h.

◆ sysclk_get_main_hz()

static uint32_t sysclk_get_main_hz ( void  )
inlinestatic

Return the current rate in Hz of the main system clock.

Todo:
This function assumes that the main clock source never changes once it's been set up, and that PLL0 always runs at the compile-time configured default rate. While this is probably the most common configuration, which we want to support as a special case for performance reasons, we will at some point need to support more dynamic setups as well.

Definition at line 324 of file same70/sysclk.h.

◆ sysclk_get_peripheral_bus_hz()

static uint32_t sysclk_get_peripheral_bus_hz ( const volatile void *  module)
inlinestatic

Retrieves the current rate in Hz of the Peripheral Bus clock attached to the specified peripheral.

Parameters
modulePointer to the module's base address.
Returns
Frequency of the bus attached to the specified peripheral, in Hz.

Definition at line 408 of file same70/sysclk.h.

◆ sysclk_get_peripheral_hz()

static uint32_t sysclk_get_peripheral_hz ( void  )
inlinestatic

Retrieves the current rate in Hz of the peripheral clocks.

Returns
Frequency of the peripheral clocks, in Hz.

Definition at line 392 of file same70/sysclk.h.

◆ sysclk_init()

void sysclk_init ( void  )

Initialize the synchronous clock system.

This function will initialize the system clock and its source. This includes:

  • Mask all synchronous clocks except for any clocks which are essential for normal operation (for example internal memory clocks).
  • Set up the system clock prescalers as specified by the application's configuration file.
  • Enable the clock source specified by the application's configuration file (oscillator or PLL) and wait for it to become stable.
  • Set the main system clock source to the clock specified by the application's configuration file.

Since all non-essential peripheral clocks are initially disabled, it is the responsibility of the peripheral driver to re-enable any clocks that are needed for normal operation.

Definition at line 158 of file sysclk.c.

◆ sysclk_set_prescalers()

void sysclk_set_prescalers ( uint32_t  ul_pres)

Set system clock prescaler configuration.

This function will change the system clock prescaler configuration to match the parameters.

Note
The parameters to this function are device-specific.
Parameters
ul_presThe CPU clock will be divided by $2^{mck\_pres}$

Definition at line 69 of file sysclk.c.

◆ sysclk_set_source()

void sysclk_set_source ( uint32_t  ul_src)

Change the source of the main system clock.

Parameters
ul_srcThe new system clock source. Must be one of the constants from the System Clock Sources section.

Definition at line 81 of file sysclk.c.



inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:18:00