Microchip® Advanced Software Framework

clock.c File Reference

SAM L21 Clock Driver.

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

#include <clock.h>
#include <conf_clocks.h>
#include <system.h>
#include "clock_config_check.h"

Data Structures

struct  _system_clock_dfll_config
 DFLL-specific data container. More...
 
struct  _system_clock_dpll_config
 DPLL-specific data container. More...
 
struct  _system_clock_module
 System clock module data container. More...
 
struct  _system_clock_xosc_config
 XOSC-specific data container. More...
 

Macros

#define NVM_DFLL_COARSE_POS   26 /* DFLL48M Coarse calibration value bit position.*/
 
#define NVM_DFLL_COARSE_SIZE   6 /* DFLL48M Coarse calibration value bit size.*/
 

Functions

static void _system_clock_source_dfll_set_config_errata_9905 (void)
 
static void _system_clock_source_osc16m_freq_sel (void)
 OSC16M frequency selection. Frequency selection can be done only when OSC16M is disabled,thus, OSCULP32K is temporarily used as a new clocksource for mainclock . More...
 
static void _system_dfll_wait_for_sync (void)
 Wait for sync to the DFLL control registers. More...
 
static void _system_osc32k_wait_for_sync (void)
 Wait for sync to the OSC32K control registers. More...
 
void system_clock_init (void)
 Initialize clock system based on the configuration in conf_clocks.h. More...
 
void system_clock_source_dfll_set_config (struct system_clock_source_dfll_config *const config)
 Configure the DFLL clock source. More...
 
enum status_code system_clock_source_disable (const enum system_clock_source clock_source)
 Disables a clock source. More...
 
void system_clock_source_dpll_set_config (struct system_clock_source_dpll_config *const config)
 Configure the DPLL clock source. More...
 
enum status_code system_clock_source_enable (const enum system_clock_source clock_source)
 Enables a clock source. More...
 
uint32_t system_clock_source_get_hz (const enum system_clock_source clock_source)
 Retrieve the frequency of a clock source. More...
 
bool system_clock_source_is_ready (const enum system_clock_source clock_source)
 Checks if a clock source is ready. More...
 
void system_clock_source_osc16m_set_config (struct system_clock_source_osc16m_config *const config)
 Configure the internal OSC16M oscillator clock source. More...
 
void system_clock_source_osc32k_set_config (struct system_clock_source_osc32k_config *const config)
 Configure the internal OSC32K oscillator clock source. More...
 
void system_clock_source_osculp32k_set_config (struct system_clock_source_osculp32k_config *const config)
 Configure the internal OSCULP32K oscillator clock source. More...
 
enum status_code system_clock_source_write_calibration (const enum system_clock_source clock_source, const uint16_t calibration_value, const uint8_t freq_select)
 Writes the calibration values for a given oscillator clock source. 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...
 
void system_clock_source_xosc_set_config (struct system_clock_source_xosc_config *const config)
 Configure the external oscillator clock source. More...
 

Variables

static struct _system_clock_module _system_clock_inst
 Internal module instance to cache configuration values. More...
 

#define NVM_DFLL_COARSE_POS   26 /* DFLL48M Coarse calibration value bit position.*/

Referenced by system_clock_init().

#define NVM_DFLL_COARSE_SIZE   6 /* DFLL48M Coarse calibration value bit size.*/

Referenced by system_clock_init().

static void _system_clock_source_dfll_set_config_errata_9905 ( void  )
inlinestatic
static void _system_dfll_wait_for_sync ( void  )
inlinestatic

Wait for sync to the DFLL control registers.

Referenced by _system_clock_source_dfll_set_config_errata_9905(), and system_clock_source_get_hz().

static void _system_osc32k_wait_for_sync ( void  )
inlinestatic

Wait for sync to the OSC32K control registers.

Referenced by system_clock_source_write_calibration().

enum status_code system_clock_source_enable ( const enum system_clock_source  clock_source)
enum status_code system_clock_source_write_calibration ( const enum system_clock_source  clock_source,
const uint16_t  calibration_value,
const uint8_t  freq_select 
)

Writes the calibration values for a given oscillator clock source.

Writes an oscillator calibration value to the given oscillator control registers. The acceptable ranges are:

For OSC32K:

  • 7 bits (max. value 128) For OSC16MHZ:
  • 8 bits (max. value 255) For OSCULP:
  • 5 bits (max. value 32)
Note
The frequency range parameter applies only when configuring the 8MHz oscillator and will be ignored for the other oscillators.
Parameters
[in]clock_sourceClock source to calibrate
[in]calibration_valueCalibration value to write
[in]freq_rangeFrequency range (8MHz oscillator only)
Return values
STATUS_OKThe calibration value was written successfully
STATUS_ERR_INVALID_ARGThe setting is not valid for selected clock source

References _system_osc32k_wait_for_sync(), Assert, STATUS_ERR_INVALID_ARG, STATUS_OK, SYSTEM_CLOCK_SOURCE_OSC16M, SYSTEM_CLOCK_SOURCE_OSC32K, and SYSTEM_CLOCK_SOURCE_ULP32K.

struct _system_clock_module _system_clock_inst
static
Initial value:
= {
.dfll = {
.control = 0,
.val = 0,
.mul = 0,
},
.dpll = {
.frequency = 0,
},
.xosc = {
.frequency = 0,
},
.xosc32k = {
.frequency = 0,
},
}

Internal module instance to cache configuration values.