LUFA Library  151115
Clock Management Driver - LUFA/Platform/UC3/ClockManagement.h

Module Clock Driver for the AVR32 UC3 microcontrollers. More...

Enumerations

enum  UC3_Extern_OSC_ClockStartup_t {
  EXOSC_START_0CLK = AVR32_PM_OSCCTRL0_STARTUP_0_RCOSC,
  EXOSC_START_64CLK = AVR32_PM_OSCCTRL0_STARTUP_64_RCOSC,
  EXOSC_START_128CLK = AVR32_PM_OSCCTRL0_STARTUP_128_RCOSC,
  EXOSC_START_2048CLK = AVR32_PM_OSCCTRL0_STARTUP_2048_RCOSC,
  EXOSC_START_4096CLK = AVR32_PM_OSCCTRL0_STARTUP_4096_RCOSC,
  EXOSC_START_8192CLK = AVR32_PM_OSCCTRL0_STARTUP_8192_RCOSC,
  EXOSC_START_16384CLK = AVR32_PM_OSCCTRL0_STARTUP_16384_RCOSC
}
 
enum  UC3_Extern_OSC_ClockTypes_t {
  EXOSC_MODE_CLOCK = AVR32_PM_OSCCTRL0_MODE_EXT_CLOCK,
  EXOSC_MODE_900KHZ_MAX = AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G0,
  EXOSC_MODE_3MHZ_MAX = AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G1,
  EXOSC_MODE_8MHZ_MAX = AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G2,
  EXOSC_MODE_8MHZ_OR_MORE = AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G3
}
 
enum  UC3_System_ClockSource_t {
  CLOCK_SRC_SLOW_CLK = 0,
  CLOCK_SRC_OSC0 = 1,
  CLOCK_SRC_OSC1 = 2,
  CLOCK_SRC_PLL0 = 3,
  CLOCK_SRC_PLL1 = 4
}
 

Functions

static bool UC3CLK_SetCPUClockSource (const uint8_t Source, const uint32_t SourceFreq) ATTR_ALWAYS_INLINE
 
static bool UC3CLK_StartExternalOscillator (const uint8_t Channel, const uint8_t Type, const uint8_t Startup) ATTR_ALWAYS_INLINE
 
static bool UC3CLK_StartGenericClock (const uint8_t Channel, const uint8_t Source, const uint32_t SourceFreq, const uint32_t Frequency) ATTR_ALWAYS_INLINE
 
static bool UC3CLK_StartPLL (const uint8_t Channel, const uint8_t Source, const uint32_t SourceFreq, const uint32_t Frequency) ATTR_ALWAYS_INLINE
 
static void UC3CLK_StopExternalOscillator (const uint8_t Channel) ATTR_ALWAYS_INLINE
 
static bool UC3CLK_StopGenericClock (const uint8_t Channel) ATTR_ALWAYS_INLINE
 
static void UC3CLK_StopPLL (const uint8_t Channel) 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 AVR32 UC3 microcontrollers. This driver allows for the configuration of the various clocks within the device to clock the various peripherals.

Usage Example:

void main(void)
{
// Start the master external oscillator which will be used as the main clock reference
// Start the PLL for the CPU clock, switch CPU to it
UC3CLK_StartPLL(0, CLOCK_SRC_OSC0, 12000000, F_CPU);
// Start the PLL for the USB Generic Clock module
UC3CLK_StartPLL(1, CLOCK_SRC_OSC0, 12000000, 48000000);
}

Enumeration Type Documentation

Enum for the possible external oscillator startup times.

Enumerator
EXOSC_START_0CLK 

Immediate startup, no delay.

EXOSC_START_64CLK 

Wait 64 clock cycles before startup for stability.

EXOSC_START_128CLK 

Wait 128 clock cycles before startup for stability.

EXOSC_START_2048CLK 

Wait 2048 clock cycles before startup for stability.

EXOSC_START_4096CLK 

Wait 4096 clock cycles before startup for stability.

EXOSC_START_8192CLK 

Wait 8192 clock cycles before startup for stability.

EXOSC_START_16384CLK 

Wait 16384 clock cycles before startup for stability.

Enum for the possible external oscillator types.

Enumerator
EXOSC_MODE_CLOCK 

External clock (non-crystal) mode.

EXOSC_MODE_900KHZ_MAX 

External crystal oscillator equal to or slower than 900KHz.

EXOSC_MODE_3MHZ_MAX 

External crystal oscillator equal to or slower than 3MHz.

EXOSC_MODE_8MHZ_MAX 

External crystal oscillator equal to or slower than 8MHz.

EXOSC_MODE_8MHZ_OR_MORE 

External crystal oscillator equal to or faster than 8MHz.

Enum for the possible module clock sources.

Enumerator
CLOCK_SRC_SLOW_CLK 

Clock sourced from the internal slow clock.

CLOCK_SRC_OSC0 

Clock sourced from the Oscillator 0 clock.

CLOCK_SRC_OSC1 

Clock sourced from the Oscillator 1 clock.

CLOCK_SRC_PLL0 

Clock sourced from the PLL 0 clock.

CLOCK_SRC_PLL1 

Clock sourced from the PLL 1 clock.

Function Documentation

static bool UC3CLK_SetCPUClockSource ( const uint8_t  Source,
const uint32_t  SourceFreq 
)
inlinestatic

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.

This function will configure the FLASH controller's wait states automatically to suit the given clock source.

Parameters
[in]SourceClock source for the CPU core, a value from UC3_System_ClockSource_t.
[in]SourceFreqFrequency of the CPU core's clock source, in Hz.
Returns
Boolean true if the CPU core clock was successfully altered, false if invalid parameters specified.
static bool UC3CLK_StartExternalOscillator ( const uint8_t  Channel,
const uint8_t  Type,
const uint8_t  Startup 
)
inlinestatic

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

Parameters
[in]ChannelIndex of the external oscillator to start.
[in]TypeType of clock attached to the given oscillator channel, a value from UC3_Extern_OSC_ClockTypes_t.
[in]StartupStartup time of the external oscillator, a value from UC3_Extern_OSC_ClockStartup_t.
Returns
Boolean true if the external oscillator was successfully started, false if invalid parameters specified.
static bool UC3CLK_StartGenericClock ( const uint8_t  Channel,
const uint8_t  Source,
const uint32_t  SourceFreq,
const uint32_t  Frequency 
)
inlinestatic

Starts the given Generic Clock of the UC3 microcontroller, with the given options.

Parameters
[in]ChannelIndex of the Generic Clock to start.
[in]SourceClock source for the Generic Clock, a value from UC3_System_ClockSource_t.
[in]SourceFreqFrequency of the Generic Clock's clock source, in Hz.
[in]FrequencyTarget frequency of the Generic Clock's output.
Returns
Boolean true if the Generic Clock was successfully started, false if invalid parameters specified.
static bool UC3CLK_StartPLL ( const uint8_t  Channel,
const uint8_t  Source,
const uint32_t  SourceFreq,
const uint32_t  Frequency 
)
inlinestatic

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

Attention
The output frequency must be equal to or greater than the source frequency.
Parameters
[in]ChannelIndex of the PLL to start.
[in]SourceClock source for the PLL, a value from UC3_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 void UC3CLK_StopExternalOscillator ( const uint8_t  Channel)
inlinestatic

Stops the given external oscillator of the UC3 microcontroller.

Parameters
[in]ChannelIndex of the external oscillator to stop.
static bool UC3CLK_StopGenericClock ( const uint8_t  Channel)
inlinestatic

Stops the given generic clock of the UC3 microcontroller.

Parameters
[in]ChannelIndex of the generic clock to stop.
Returns
Boolean true if the generic clock was successfully stopped, false if invalid parameters specified.
static void UC3CLK_StopPLL ( const uint8_t  Channel)
inlinestatic

Stops the given PLL of the UC3 microcontroller.

Parameters
[in]ChannelIndex of the PLL to stop.