Microchip® Advanced Software Framework

pmc.h File Reference

Power Management Controller (PMC) driver for SAM.

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

#include "compiler.h"

Macros

#define CKGR_MOR_KEY_PASSWD   CKGR_MOR_KEY(0x37U)
 Key to unlock CKGR_MOR register. More...
 
#define PMC_FAST_STARTUP_Msk   (0x7FFFFu)
 Mask to access fast startup input. More...
 
#define PMC_MASK_STATUS0   (0xFFFFFFFC)
 Bit mask for peripheral clocks (PCER0) More...
 
#define PMC_MASK_STATUS1   (0xFFFFFFFF)
 Bit mask for peripheral clocks (PCER1) More...
 
#define PMC_OSC_BYPASS   1
 Oscillator in bypass mode. More...
 
#define PMC_OSC_XTAL   0
 Using external oscillator. More...
 
#define PMC_PCK_0   0 /* PCK0 ID */
 
#define PMC_PCK_1   1 /* PCK1 ID */
 
#define PMC_PCK_2   2 /* PCK2 ID */
 
#define PMC_TIMEOUT   (2048)
 Loop counter timeout value. More...
 
#define pmc_us_to_moscxtst(startup_us, slowck_freq)
 Convert startup time from us to MOSCXTST. More...
 
#define PMC_WPMR_WPKEY_PASSWD   PMC_WPMR_WPKEY((uint32_t) 0x504D43)
 PMC_WPMR Write Protect KEY, unlock it. More...
 
#define SUPC_CR_KEY_PASSWD   SUPC_CR_KEY(0xA5U)
 Key used to write SUPC registers. More...
 
#define SUPC_MR_KEY_PASSWD   SUPC_MR_KEY(0xA5U)
 

Functions

Master clock (MCK) Source and Prescaler configuration
Note
The following functions may be used to select the clock source and prescaler for the master clock.
void pmc_mck_set_prescaler (uint32_t ul_pres)
 Set the prescaler of the MCK. More...
 
void pmc_mck_set_source (uint32_t ul_source)
 Set the source of the MCK. More...
 
uint32_t pmc_switch_mck_to_sclk (uint32_t ul_pres)
 Switch master clock source selection to slow clock. More...
 
uint32_t pmc_switch_mck_to_mainck (uint32_t ul_pres)
 Switch master clock source selection to main clock. More...
 
uint32_t pmc_switch_mck_to_pllack (uint32_t ul_pres)
 Switch master clock source selection to PLLA clock. More...
 
Slow clock (SLCK) oscillator and configuration
void pmc_switch_sclk_to_32kxtal (uint32_t ul_bypass)
 Switch slow clock source selection to external 32k (Xtal or Bypass). More...
 
uint32_t pmc_osc_is_ready_32kxtal (void)
 Check if the external 32k Xtal is ready. More...
 
Main Clock (MAINCK) oscillator and configuration
void pmc_switch_mainck_to_fastrc (uint32_t ul_moscrcf)
 Switch main clock source selection to internal fast RC. More...
 
void pmc_osc_enable_fastrc (uint32_t ul_rc)
 Enable fast RC oscillator. More...
 
void pmc_osc_disable_fastrc (void)
 Disable the internal fast RC. More...
 
uint32_t pmc_osc_is_ready_fastrc (void)
 Check if the main fastrc is ready. More...
 
void pmc_osc_enable_main_xtal (uint32_t ul_xtal_startup_time)
 Enable main XTAL oscillator. More...
 
void pmc_osc_bypass_main_xtal (void)
 Bypass main XTAL. More...
 
void pmc_osc_disable_main_xtal (void)
 Disable the main Xtal. More...
 
uint32_t pmc_osc_is_bypassed_main_xtal (void)
 Check if the main crystal is bypassed. More...
 
uint32_t pmc_osc_is_ready_main_xtal (void)
 Check if the main crystal is ready. More...
 
void pmc_switch_mainck_to_xtal (uint32_t ul_bypass, uint32_t ul_xtal_startup_time)
 Switch main clock source selection to external Xtal/Bypass. More...
 
void pmc_osc_disable_xtal (uint32_t ul_bypass)
 Disable the external Xtal. More...
 
uint32_t pmc_osc_is_ready_mainck (void)
 Check if the MAINCK is ready. More...
 
void pmc_mainck_osc_select (uint32_t ul_xtal_rc)
 Select Main Crystal or internal RC as main clock source. More...
 
PLL oscillator and configuration
void pmc_enable_pllack (uint32_t mula, uint32_t pllacount, uint32_t diva)
 Enable PLLA clock. More...
 
void pmc_disable_pllack (void)
 Disable PLLA clock. More...
 
uint32_t pmc_is_locked_pllack (void)
 Is PLLA locked? More...
 
Peripherals clock configuration
uint32_t pmc_enable_periph_clk (uint32_t ul_id)
 Enable the specified peripheral clock. More...
 
uint32_t pmc_disable_periph_clk (uint32_t ul_id)
 Disable the specified peripheral clock. More...
 
void pmc_enable_all_periph_clk (void)
 Enable all peripheral clocks. More...
 
void pmc_disable_all_periph_clk (void)
 Disable all peripheral clocks. More...
 
uint32_t pmc_is_periph_clk_enabled (uint32_t ul_id)
 Check if the specified peripheral clock is enabled. More...
 
Programmable clock Source and Prescaler configuration

The following functions may be used to select the clock source and prescaler for the specified programmable clock.

void pmc_pck_set_prescaler (uint32_t ul_id, uint32_t ul_pres)
 Set the prescaler for the specified programmable clock. More...
 
void pmc_pck_set_source (uint32_t ul_id, uint32_t ul_source)
 Set the source oscillator for the specified programmable clock. More...
 
uint32_t pmc_switch_pck_to_sclk (uint32_t ul_id, uint32_t ul_pres)
 Switch programmable clock source selection to slow clock. More...
 
uint32_t pmc_switch_pck_to_mainck (uint32_t ul_id, uint32_t ul_pres)
 Switch programmable clock source selection to main clock. More...
 
uint32_t pmc_switch_pck_to_pllack (uint32_t ul_id, uint32_t ul_pres)
 Switch programmable clock source selection to PLLA clock. More...
 
uint32_t pmc_switch_pck_to_mck (uint32_t ul_id, uint32_t ul_pres)
 Switch programmable clock source selection to mck. More...
 
void pmc_enable_pck (uint32_t ul_id)
 Enable the specified programmable clock. More...
 
void pmc_disable_pck (uint32_t ul_id)
 Disable the specified programmable clock. More...
 
void pmc_enable_all_pck (void)
 Enable all programmable clocks. More...
 
void pmc_disable_all_pck (void)
 Disable all programmable clocks. More...
 
uint32_t pmc_is_pck_enabled (uint32_t ul_id)
 Check if the specified programmable clock is enabled. More...
 
Interrupt and status management
void pmc_enable_interrupt (uint32_t ul_sources)
 Enable PMC interrupts. More...
 
void pmc_disable_interrupt (uint32_t ul_sources)
 Disable PMC interrupts. More...
 
uint32_t pmc_get_interrupt_mask (void)
 Get PMC interrupt mask. More...
 
uint32_t pmc_get_status (void)
 Get current status. More...
 
Power management

The following functions are used to configure sleep mode and additional wake up inputs.

void pmc_set_fast_startup_input (uint32_t ul_inputs)
 Set the wake-up inputs for fast startup mode registers (event generation). More...
 
void pmc_clr_fast_startup_input (uint32_t ul_inputs)
 Clear the wake-up inputs for fast startup mode registers (remove event generation). More...
 
void pmc_enable_sleepmode (uint8_t uc_type)
 Enable Sleep Mode. More...
 
void pmc_enable_waitmode (void)
 Enable Wait Mode. More...
 
void pmc_enable_backupmode (void)
 Enable Backup Mode. More...
 
Failure detector
void pmc_enable_clock_failure_detector (void)
 Enable Clock Failure Detector. More...
 
void pmc_disable_clock_failure_detector (void)
 Disable Clock Failure Detector. More...
 
Write protection
void pmc_set_writeprotect (uint32_t ul_enable)
 Enable or disable write protect of PMC registers. More...
 
uint32_t pmc_get_writeprotect_status (void)
 Return write protect status. More...
 

#define PMC_FAST_STARTUP_Msk   (0x7FFFFu)

Mask to access fast startup input.

Referenced by pmc_clr_fast_startup_input(), and pmc_set_fast_startup_input().

#define PMC_MASK_STATUS0   (0xFFFFFFFC)

Bit mask for peripheral clocks (PCER0)

Referenced by pmc_disable_all_periph_clk(), and pmc_enable_all_periph_clk().

#define PMC_MASK_STATUS1   (0xFFFFFFFF)

Bit mask for peripheral clocks (PCER1)

Referenced by pmc_disable_all_periph_clk(), and pmc_enable_all_periph_clk().

#define PMC_OSC_BYPASS   1

Oscillator in bypass mode.

Referenced by osc_disable(), and osc_enable().

#define PMC_OSC_XTAL   0

Using external oscillator.

Referenced by main(), osc_disable(), and osc_enable().

#define PMC_PCK_0   0 /* PCK0 ID */
#define PMC_PCK_1   1 /* PCK1 ID */
#define PMC_PCK_2   2 /* PCK2 ID */
#define pmc_us_to_moscxtst (   startup_us,
  slowck_freq 
)
Value:
((startup_us * slowck_freq / 8 / 1000000) < 0x100 ? \
(startup_us * slowck_freq / 8 / 1000000) : 0xFF)

Convert startup time from us to MOSCXTST.

Referenced by osc_enable(), and run_switch_mainck_as_mck_test().

#define PMC_WPMR_WPKEY_PASSWD   PMC_WPMR_WPKEY((uint32_t) 0x504D43)

PMC_WPMR Write Protect KEY, unlock it.

Referenced by pmc_set_writeprotect().

#define SUPC_CR_KEY_PASSWD   SUPC_CR_KEY(0xA5U)