LUFA Library  120219
Clock Management Driver - LUFA/Platform/XMEGA/ClockManagement.h

Module Clock Driver for the AVR USB XMEGA microcontrollers. More...

Enumerations

enum  XMEGA_Extern_OSC_ClockFrequency_t {
  EXOSC_FREQ_2MHZ_MAX = OSC_FRQRANGE_04TO2_gc,
  EXOSC_FREQ_9MHZ_MAX = OSC_FRQRANGE_2TO9_gc,
  EXOSC_FREQ_12MHZ_MAX = OSC_FRQRANGE_9TO12_gc,
  EXOSC_FREQ_16MHZ_MAX = OSC_FRQRANGE_12TO16_gc
}
enum  XMEGA_Extern_OSC_ClockStartup_t {
  EXOSC_START_6CLK = OSC_XOSCSEL_EXTCLK_gc,
  EXOSC_START_32KCLK = OSC_XOSCSEL_32KHz_gc,
  EXOSC_START_256CLK = OSC_XOSCSEL_XTAL_256CLK_gc,
  EXOSC_START_1KCLK = OSC_XOSCSEL_XTAL_1KCLK_gc,
  EXOSC_START_16KCLK = OSC_XOSCSEL_XTAL_16KCLK_gc
}
enum  XMEGA_System_ClockSource_t {
  CLOCK_SRC_INT_RC2MHZ = 0,
  CLOCK_SRC_INT_RC32MHZ = 1,
  CLOCK_SRC_INT_RC32KHZ = 2,
  CLOCK_SRC_XOSC = 3,
  CLOCK_SRC_PLL = 4
}
enum  XMEGA_System_DFLLReference_t {
  DFLL_REF_INT_RC32KHZ = 0,
  DFLL_REF_EXT_RC32KHZ = 1,
  DFLL_REF_INT_USBSOF = 2
}

Functions

static bool XMEGACLK_StartExternalOscillator (const uint8_t FreqRange, const uint8_t Startup) ATTR_ALWAYS_INLINE
static void XMEGACLK_StopExternalOscillator (void) ATTR_ALWAYS_INLINE
static uint8_t XMEGACLK_StartInternalOscillator (const uint8_t Source) ATTR_ALWAYS_INLINE
static bool XMEGACLK_StopInternalOscillator (const uint8_t Source) ATTR_ALWAYS_INLINE
static bool XMEGACLK_StartPLL (const uint8_t Source, const uint32_t SourceFreq, const uint32_t Frequency) ATTR_ALWAYS_INLINE
static void XMEGACLK_StopPLL (void) ATTR_ALWAYS_INLINE
static bool XMEGACLK_StartDFLL (const uint8_t Source, const uint8_t Reference, const uint32_t Frequency) ATTR_ALWAYS_INLINE
static bool XMEGACLK_StopDFLL (const uint8_t Source) ATTR_ALWAYS_INLINE
static bool XMEGACLK_SetCPUClockSource (const uint8_t Source) ATTR_ALWAYS_INLINE

Detailed Description

Module Source Dependencies

The following files must be built with any user project that uses this module:

Module Description

Clock management driver for the AVR USB XMEGA microcontrollers. This driver allows for the configuration of the various clocks within the device to clock the various peripherals.

Usage Example:

    #include <LUFA/Platform/XMEGA/ClockManagement.h>

    void main(void)
    {
        // Start the PLL to multiply the 2MHz RC oscillator to 32MHz and switch the CPU core to run from it
        XMEGACLK_StartPLL(CLOCK_SRC_INT_RC2MHZ, 2000000, 32000000);
        XMEGACLK_SetCPUClockSource(CLOCK_SRC_PLL, F_CPU);

        // Start the 32MHz internal RC oscillator and start the DFLL to increase it to 48MHz using the USB SOF as a reference
        XMEGACLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ);
        XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, 48000000);
    }

Enumeration Type Documentation

Enum for the possible external oscillator frequency ranges.

Enumerator:
EXOSC_FREQ_2MHZ_MAX 

External crystal oscillator equal to or slower than 2MHz.

EXOSC_FREQ_9MHZ_MAX 

External crystal oscillator equal to or slower than 9MHz.

EXOSC_FREQ_12MHZ_MAX 

External crystal oscillator equal to or slower than 12MHz.

EXOSC_FREQ_16MHZ_MAX 

External crystal oscillator equal to or slower than 16MHz.

Enum for the possible external oscillator statup times.

Enumerator:
EXOSC_START_6CLK 

Wait 6 clock cycles before startup (external clock).

EXOSC_START_32KCLK 

Wait 32K clock cycles before startup (32.768KHz crystal).

EXOSC_START_256CLK 

Wait 256 clock cycles before startup.

EXOSC_START_1KCLK 

Wait 1K clock cycles before startup.

EXOSC_START_16KCLK 

Wait 16K clock cycles before startup.

Enum for the possible module clock sources.

Enumerator:
CLOCK_SRC_INT_RC2MHZ 

Clock sourced from the Internal 2MHz RC Oscillator clock.

CLOCK_SRC_INT_RC32MHZ 

Clock sourced from the Internal 32MHz RC Oscillator clock.

CLOCK_SRC_INT_RC32KHZ 

Clock sourced from the Internal 32KHz RC Oscillator clock.

CLOCK_SRC_XOSC 

Clock sourced from the External Oscillator clock.

CLOCK_SRC_PLL 

Clock sourced from the Internal PLL clock.

Enum for the possible DFLL clock reference sources.

Enumerator:
DFLL_REF_INT_RC32KHZ 

Reference clock sourced from the Internal 32KHz RC Oscillator clock.

DFLL_REF_EXT_RC32KHZ 

Reference clock sourced from the External 32KHz RC Oscillator clock connected to TOSC pins.

DFLL_REF_INT_USBSOF 

Reference clock sourced from the USB Start Of Frame packets.


Function Documentation

static bool XMEGACLK_SetCPUClockSource ( const uint8_t  Source) [inline, static]

Sets the clock source for the main microcontroller core. The given clock source should be configured and ready for use before this function is called.

Parameters:
[in]SourceClock source for the CPU core, a value from XMEGA_System_ClockSource_t.
Returns:
Boolean true if the CPU core clock was sucessfully altered, false if invalid parameters specified.
static bool XMEGACLK_StartDFLL ( const uint8_t  Source,
const uint8_t  Reference,
const uint32_t  Frequency 
) [inline, static]

Starts the DFLL of the XMEGA microcontroller, with the given options.

Parameters:
[in]SourceRC Clock source for the DFLL, a value from XMEGA_System_ClockSource_t.
[in]ReferenceReference clock source for the DFLL, an value from XMEGA_System_DFLLReference_t
[in]FrequencyTarget frequency of the DFLL's output.
Returns:
Boolean true if the DFLL was successfully started, false if invalid parameters specified.
static bool XMEGACLK_StartExternalOscillator ( const uint8_t  FreqRange,
const uint8_t  Startup 
) [inline, static]

Starts the external oscillator of the XMEGA microcontroller, with the given options. This routine blocks until the oscillator is ready for use.

Parameters:
[in]FreqRangeFrequency range of the external oscillator, a value from XMEGA_Extern_OSC_ClockFrequency_t.
[in]StartupStatup time of the external oscillator, a value from XMEGA_Extern_OSC_ClockStartup_t.
Returns:
Boolean true if the external oscillator was successfully started, false if invalid parameters specified.
static uint8_t XMEGACLK_StartInternalOscillator ( const uint8_t  Source) [inline, static]

Starts the given internal oscillator of the XMEGA microcontroller, with the given options. This routine blocks until the oscillator is ready for use.

Parameters:
[in]SourceInternal oscillator to start, a value from XMEGA_System_ClockSource_t.
Returns:
Boolean true if the internal oscillator was successfully started, false if invalid parameters specified.
static bool XMEGACLK_StartPLL ( const uint8_t  Source,
const uint32_t  SourceFreq,
const uint32_t  Frequency 
) [inline, static]

Starts the PLL of the XMEGA microcontroller, with the given options. This routine blocks until the PLL is ready for use.

Note:
The output frequency must be equal to or greater than the source frequency.
Parameters:
[in]SourceClock source for the PLL, a value from XMEGA_System_ClockSource_t.
[in]SourceFreqFrequency of the PLL's clock source, in Hz.
[in]FrequencyTarget frequency of the PLL's output.
Returns:
Boolean true if the PLL was successfully started, false if invalid parameters specified.
static bool XMEGACLK_StopDFLL ( const uint8_t  Source) [inline, static]

Stops the given DFLL of the XMEGA microcontroller.

Parameters:
[in]SourceRC Clock source for the DFLL to be stopped, a value from XMEGA_System_ClockSource_t.
Returns:
Boolean true if the DFLL was successfully stopped, false if invalid parameters specified.
static void XMEGACLK_StopExternalOscillator ( void  ) [inline, static]

Stops the external oscillator of the XMEGA microcontroller.

static bool XMEGACLK_StopInternalOscillator ( const uint8_t  Source) [inline, static]

Stops the given internal oscillator of the XMEGA microcontroller.

Parameters:
[in]SourceInternal oscillator to stop, a value from XMEGA_System_ClockSource_t.
Returns:
Boolean true if the internal oscillator was successfully stopped, false if invalid parameters specified.
static void XMEGACLK_StopPLL ( void  ) [inline, static]

Stops the PLL of the XMEGA microcontroller.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines