|
|
@ -28,8 +28,48 @@ |
|
|
|
this software. |
|
|
|
this software. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#ifndef _CLOCK_MANAGEMENT_H_ |
|
|
|
/** \file
|
|
|
|
#define _CLOCK_MANAGEMENT_H_ |
|
|
|
* \brief Module Clock Driver for the AVR32 UC3 microcontrollers. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* 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. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** \ingroup Group_PlatformDrivers
|
|
|
|
|
|
|
|
* \defgroup Group_PlatformDrivers_UC3Clocks UC3 Clock Management Driver - LUFA/Platform/UC3/ClockManagement.h |
|
|
|
|
|
|
|
* \brief Module Clock Driver for the AVR32 UC3 microcontrollers. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* \section Sec_Dependencies Module Source Dependencies |
|
|
|
|
|
|
|
* The following files must be built with any user project that uses this module: |
|
|
|
|
|
|
|
* - None |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* \section Sec_ModDescription 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: |
|
|
|
|
|
|
|
* \code |
|
|
|
|
|
|
|
* #include <LUFA/Platform/UC3/ClockManagement.h> |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* void main(void) |
|
|
|
|
|
|
|
* { |
|
|
|
|
|
|
|
* // Start the master external oscillator which will be used as the main clock reference
|
|
|
|
|
|
|
|
* AVR32CLK_StartExternalOscillator(0, EXOSC_MODE_8MHZ_OR_MORE, EXOSC_START_0CLK); |
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* // Start the PLL for the CPU clock, switch CPU to it
|
|
|
|
|
|
|
|
* AVR32CLK_StartPLL(0, CLOCK_SRC_OSC0, 12000000, F_CPU); |
|
|
|
|
|
|
|
* AVR32CLK_SetCPUClockSource(CLOCK_SRC_PLL0, F_CPU); |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* // Start the PLL for the USB Generic Clock module
|
|
|
|
|
|
|
|
* AVR32CLK_StartPLL(1, CLOCK_SRC_OSC0, 12000000, 48000000); |
|
|
|
|
|
|
|
* } |
|
|
|
|
|
|
|
* \endcode |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @{ |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _UC3_CLOCK_MANAGEMENT_H_ |
|
|
|
|
|
|
|
#define _UC3_CLOCK_MANAGEMENT_H_ |
|
|
|
|
|
|
|
|
|
|
|
/* Includes: */ |
|
|
|
/* Includes: */ |
|
|
|
#include <avr32/io.h> |
|
|
|
#include <avr32/io.h> |
|
|
@ -38,144 +78,240 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include <LUFA/Common/Common.h> |
|
|
|
#include <LUFA/Common/Common.h> |
|
|
|
|
|
|
|
|
|
|
|
/* Macros: */ |
|
|
|
/* Enable C linkage for C++ Compilers: */ |
|
|
|
enum Extern_OSC_ClockStartup_t |
|
|
|
#if defined(__cplusplus) |
|
|
|
{ |
|
|
|
extern "C" { |
|
|
|
EXOSC_START_0CLK = 0, |
|
|
|
#endif |
|
|
|
EXOSC_START_64CLK = 1, |
|
|
|
|
|
|
|
EXOSC_START_128CLK = 2, |
|
|
|
/* Public Interface - May be used in end-application: */ |
|
|
|
EXOSC_START_2048CLK = 3, |
|
|
|
/* Macros: */ |
|
|
|
EXOSC_START_4096CLK = 4, |
|
|
|
/** Enum for the possible external oscillator types. */ |
|
|
|
EXOSC_START_8192CLK = 5, |
|
|
|
enum Extern_OSC_ClockTypes_t |
|
|
|
EXOSC_START_16384CLK = 6, |
|
|
|
{ |
|
|
|
}; |
|
|
|
EXOSC_MODE_CLOCK = 0, /**< External clock (non-crystal) mode. */ |
|
|
|
|
|
|
|
EXOSC_MODE_900KHZ_MAX = 1, /**< External crystal oscillator equal to or slower than 900KHz. */ |
|
|
|
enum Extern_OSC_ClockMode_t |
|
|
|
EXOSC_MODE_3MHZ_MAX = 2, /**< External crystal oscillator equal to or slower than 3MHz. */ |
|
|
|
{ |
|
|
|
EXOSC_MODE_8MHZ_MAX = 3, /**< External crystal oscillator equal to or slower than 8MHz. */ |
|
|
|
EXOSC_MODE_CLOCK = 0, |
|
|
|
EXOSC_MODE_8MHZ_OR_MORE = 4, /**< External crystal oscillator equal to or faster than 8MHz. */
|
|
|
|
EXOSC_MODE_900KHZ_MAX = 1, |
|
|
|
}; |
|
|
|
EXOSC_MODE_3MHZ_MAX = 2, |
|
|
|
|
|
|
|
EXOSC_MODE_8MHZ_MAX = 3, |
|
|
|
/** Enum for the possible external oscillator statup times. */ |
|
|
|
EXOSC_MODE_8MHZ_OR_MORE = 4,
|
|
|
|
enum Extern_OSC_ClockStartup_t |
|
|
|
}; |
|
|
|
{ |
|
|
|
|
|
|
|
EXOSC_START_0CLK = 0, /**< Immediate startup, no delay. */ |
|
|
|
enum |
|
|
|
EXOSC_START_64CLK = 1, /**< Wait 64 clock cyles before startup for stability. */ |
|
|
|
{ |
|
|
|
EXOSC_START_128CLK = 2, /**< Wait 128 clock cyles before startup for stability. */ |
|
|
|
CLOCK_SRC_SLOW_CLK = 0, |
|
|
|
EXOSC_START_2048CLK = 3, /**< Wait 2048 clock cyles before startup for stability. */ |
|
|
|
CLOCK_SRC_OSC0 = 1, |
|
|
|
EXOSC_START_4096CLK = 4, /**< Wait 4096 clock cyles before startup for stability. */ |
|
|
|
CLOCK_SRC_OSC1 = 2, |
|
|
|
EXOSC_START_8192CLK = 5, /**< Wait 8192 clock cyles before startup for stability. */ |
|
|
|
CLOCK_SRC_PLL0 = 3, |
|
|
|
EXOSC_START_16384CLK = 6, /**< Wait 16384 clock cyles before startup for stability. */ |
|
|
|
CLOCK_SRC_PLL1 = 4, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** Enum for the possible module clock sources. */ |
|
|
|
/* Inline Functions: */ |
|
|
|
enum System_ClockSource_t |
|
|
|
static inline bool AVR32CLK_StartExternalOscillator(const uint8_t Channel, |
|
|
|
{ |
|
|
|
const uint8_t Type, |
|
|
|
CLOCK_SRC_SLOW_CLK = 0, /**< Clock sourced from the internal slow clock. */ |
|
|
|
const uint8_t Startup) |
|
|
|
CLOCK_SRC_OSC0 = 1, /**< Clock sourced from the Oscillator 0 clock. */ |
|
|
|
{ |
|
|
|
CLOCK_SRC_OSC1 = 2, /**< Clock sourced from the Oscillator 1 clock. */ |
|
|
|
AVR32_PM.OSCCTRL0.startup = Startup; |
|
|
|
CLOCK_SRC_PLL0 = 3, /**< Clock sourced from the PLL 0 clock. */ |
|
|
|
AVR32_PM.OSCCTRL0.mode = Type; |
|
|
|
CLOCK_SRC_PLL1 = 4, /**< Clock sourced from the PLL 1 clock. */ |
|
|
|
AVR32_PM.mcctrl |= (1 << (AVR32_PM_MCCTRL_OSC0EN_OFFSET + Channel)); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
while (!(AVR32_PM.poscsr & (1 << (AVR32_PM_POSCSR_OSC0RDY_OFFSET + Channel)))); |
|
|
|
/* Inline Functions: */ |
|
|
|
return true; |
|
|
|
/** Starts the given external oscillator of the UC3 microcontroller, with the given options. This routine blocks until
|
|
|
|
} |
|
|
|
* the oscillator is ready for use. |
|
|
|
|
|
|
|
* |
|
|
|
static inline void AVR32CLK_StopExternalOscillator(const uint8_t Channel) |
|
|
|
* \param[in] Channel Index of the external oscillator to start. |
|
|
|
{ |
|
|
|
* \param[in] Type Type of clock attached to the given oscillator channel, a value from \ref Extern_OSC_ClockTypes_t. |
|
|
|
AVR32_PM.mcctrl &= ~(1 << (AVR32_PM_MCCTRL_OSC0EN_OFFSET + Channel)); |
|
|
|
* \param[in] Startup Statup time of the external oscillator, a value from \ref Extern_OSC_ClockStartup_t. |
|
|
|
} |
|
|
|
* |
|
|
|
|
|
|
|
* \return Boolean \c true if the external oscillator was successfully started, \c false if invalid parameters specified. |
|
|
|
static inline bool AVR32CLK_StartPLL(const uint8_t Channel, |
|
|
|
*/ |
|
|
|
const uint8_t Source, |
|
|
|
static inline void AVR32CLK_StartExternalOscillator(const uint8_t Channel, |
|
|
|
const uint32_t SourceFreq, |
|
|
|
const uint8_t Type, |
|
|
|
const uint32_t Frequency) |
|
|
|
const uint8_t Startup) ATTR_ALWAYS_INLINE; |
|
|
|
{ |
|
|
|
static inline void AVR32CLK_StartExternalOscillator(const uint8_t Channel, |
|
|
|
switch (Source) |
|
|
|
const uint8_t Type, |
|
|
|
|
|
|
|
const uint8_t Startup) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
switch (Channel) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
case 0: |
|
|
|
|
|
|
|
AVR32_PM.OSCCTRL0.startup = Startup; |
|
|
|
|
|
|
|
AVR32_PM.OSCCTRL0.mode = Type; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 1: |
|
|
|
|
|
|
|
AVR32_PM.OSCCTRL1.startup = Startup; |
|
|
|
|
|
|
|
AVR32_PM.OSCCTRL1.mode = Type; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AVR32_PM.mcctrl |= (1 << (AVR32_PM_MCCTRL_OSC0EN_OFFSET + Channel)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (!(AVR32_PM.poscsr & (1 << (AVR32_PM_POSCSR_OSC0RDY_OFFSET + Channel)))); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Stops the given external oscillator of the UC3 microcontroller.
|
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* \param[in] Channel Index of the external oscillator to stop. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static inline void AVR32CLK_StopExternalOscillator(const uint8_t Channel) ATTR_ALWAYS_INLINE; |
|
|
|
|
|
|
|
static inline void AVR32CLK_StopExternalOscillator(const uint8_t Channel) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case CLOCK_SRC_OSC0: |
|
|
|
AVR32_PM.mcctrl &= ~(1 << (AVR32_PM_MCCTRL_OSC0EN_OFFSET + Channel)); |
|
|
|
AVR32_PM.PLL[Channel].pllosc = 0; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case CLOCK_SRC_OSC1: |
|
|
|
|
|
|
|
AVR32_PM.PLL[Channel].pllosc = 1; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
AVR32_PM.PLL[Channel].pllmul = (Frequency / SourceFreq) ? (((Frequency / SourceFreq) - 1) / 2) : 0; |
|
|
|
/** Starts the given PLL of the UC3 microcontroller, with the given options. This routine blocks until the PLL is ready for use.
|
|
|
|
AVR32_PM.PLL[Channel].plldiv = 0; |
|
|
|
* |
|
|
|
AVR32_PM.PLL[Channel].pllen = true; |
|
|
|
* \param[in] Channel Index of the PLL to start. |
|
|
|
|
|
|
|
* \param[in] Source Clock source for the PLL, a value from \ref System_ClockSource_t. |
|
|
|
while (!(AVR32_PM.poscsr & (1 << (AVR32_PM_POSCSR_LOCK0_OFFSET + Channel)))); |
|
|
|
* \param[in] SourceFreq Frequency of the PLL's clock source, in Hz. |
|
|
|
return true; |
|
|
|
* \param[in] Frequency Target frequency of the PLL's output. |
|
|
|
} |
|
|
|
* |
|
|
|
|
|
|
|
* \return Boolean \c true if the PLL was successfully started, \c false if invalid parameters specified. |
|
|
|
static inline void AVR32CLK_StopPLL(const uint8_t Channel) |
|
|
|
*/ |
|
|
|
{ |
|
|
|
static inline bool AVR32CLK_StartPLL(const uint8_t Channel, |
|
|
|
AVR32_PM.PLL[Channel].pllen = false; |
|
|
|
const uint8_t Source, |
|
|
|
} |
|
|
|
const uint32_t SourceFreq, |
|
|
|
|
|
|
|
const uint32_t Frequency) ATTR_ALWAYS_INLINE; |
|
|
|
static inline bool AVR32CLK_StartGenericClock(const uint8_t Channel, |
|
|
|
static inline bool AVR32CLK_StartPLL(const uint8_t Channel, |
|
|
|
const uint8_t Source, |
|
|
|
const uint8_t Source, |
|
|
|
const uint32_t SourceFreq, |
|
|
|
const uint32_t SourceFreq, |
|
|
|
const uint32_t Frequency) |
|
|
|
const uint32_t Frequency) |
|
|
|
{ |
|
|
|
|
|
|
|
switch (Source) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
case CLOCK_SRC_OSC0: |
|
|
|
switch (Source) |
|
|
|
AVR32_PM.GCCTRL[Channel].pllsel = 0; |
|
|
|
{ |
|
|
|
AVR32_PM.GCCTRL[Channel].oscsel = 0; |
|
|
|
case CLOCK_SRC_OSC0: |
|
|
|
break; |
|
|
|
AVR32_PM.PLL[Channel].pllosc = 0; |
|
|
|
case CLOCK_SRC_OSC1: |
|
|
|
break; |
|
|
|
AVR32_PM.GCCTRL[Channel].pllsel = 0; |
|
|
|
case CLOCK_SRC_OSC1: |
|
|
|
AVR32_PM.GCCTRL[Channel].oscsel = 1; |
|
|
|
AVR32_PM.PLL[Channel].pllosc = 1; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case CLOCK_SRC_PLL0: |
|
|
|
default: |
|
|
|
AVR32_PM.GCCTRL[Channel].pllsel = 1; |
|
|
|
return false; |
|
|
|
AVR32_PM.GCCTRL[Channel].oscsel = 0; |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
case CLOCK_SRC_PLL1: |
|
|
|
AVR32_PM.PLL[Channel].pllmul = (Frequency / SourceFreq) ? (((Frequency / SourceFreq) - 1) / 2) : 0; |
|
|
|
AVR32_PM.GCCTRL[Channel].pllsel = 1; |
|
|
|
AVR32_PM.PLL[Channel].plldiv = 0; |
|
|
|
AVR32_PM.GCCTRL[Channel].oscsel = 1; |
|
|
|
AVR32_PM.PLL[Channel].pllen = true; |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
while (!(AVR32_PM.poscsr & (1 << (AVR32_PM_POSCSR_LOCK0_OFFSET + Channel)))); |
|
|
|
return false; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
AVR32_PM.GCCTRL[Channel].diven = (SourceFreq > Frequency) ? true : false; |
|
|
|
/** Stops the given PLL of the UC3 microcontroller.
|
|
|
|
AVR32_PM.GCCTRL[Channel].div = (((SourceFreq / Frequency) - 1) / 2); |
|
|
|
* |
|
|
|
AVR32_PM.GCCTRL[Channel].cen = true; |
|
|
|
* \param[in] Channel Index of the PLL to stop. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static inline void AVR32CLK_StopPLL(const uint8_t Channel) ATTR_ALWAYS_INLINE; |
|
|
|
|
|
|
|
static inline void AVR32CLK_StopPLL(const uint8_t Channel) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
AVR32_PM.PLL[Channel].pllen = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Starts the given Generic Clock of the UC3 microcontroller, with the given options.
|
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* \param[in] Channel Index of the Generic Clock to start. |
|
|
|
|
|
|
|
* \param[in] Source Clock source for the Generic Clock, a value from \ref System_ClockSource_t. |
|
|
|
|
|
|
|
* \param[in] SourceFreq Frequency of the Generic Clock's clock source, in Hz. |
|
|
|
|
|
|
|
* \param[in] Frequency Target frequency of the Generic Clock's output. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* \return Boolean \c true if the Generic Clock was successfully started, \c false if invalid parameters specified. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static inline bool AVR32CLK_StartGenericClock(const uint8_t Channel, |
|
|
|
|
|
|
|
const uint8_t Source, |
|
|
|
|
|
|
|
const uint32_t SourceFreq, |
|
|
|
|
|
|
|
const uint32_t Frequency) ATTR_ALWAYS_INLINE; |
|
|
|
|
|
|
|
static inline bool AVR32CLK_StartGenericClock(const uint8_t Channel, |
|
|
|
|
|
|
|
const uint8_t Source, |
|
|
|
|
|
|
|
const uint32_t SourceFreq, |
|
|
|
|
|
|
|
const uint32_t Frequency) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
switch (Source) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
case CLOCK_SRC_OSC0: |
|
|
|
|
|
|
|
AVR32_PM.GCCTRL[Channel].pllsel = 0; |
|
|
|
|
|
|
|
AVR32_PM.GCCTRL[Channel].oscsel = 0; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case CLOCK_SRC_OSC1: |
|
|
|
|
|
|
|
AVR32_PM.GCCTRL[Channel].pllsel = 0; |
|
|
|
|
|
|
|
AVR32_PM.GCCTRL[Channel].oscsel = 1; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case CLOCK_SRC_PLL0: |
|
|
|
|
|
|
|
AVR32_PM.GCCTRL[Channel].pllsel = 1; |
|
|
|
|
|
|
|
AVR32_PM.GCCTRL[Channel].oscsel = 0; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case CLOCK_SRC_PLL1: |
|
|
|
|
|
|
|
AVR32_PM.GCCTRL[Channel].pllsel = 1; |
|
|
|
|
|
|
|
AVR32_PM.GCCTRL[Channel].oscsel = 1; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (SourceFreq < Frequency) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AVR32_PM.GCCTRL[Channel].diven = (SourceFreq > Frequency) ? true : false; |
|
|
|
|
|
|
|
AVR32_PM.GCCTRL[Channel].div = (((SourceFreq / Frequency) - 1) / 2); |
|
|
|
|
|
|
|
AVR32_PM.GCCTRL[Channel].cen = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
/** Stops the given generic clock of the UC3 microcontroller.
|
|
|
|
} |
|
|
|
* |
|
|
|
|
|
|
|
* \param[in] Channel Index of the generic clock to stop. |
|
|
|
static inline void AVR32CLK_StopGenericClock(const uint8_t Channel) |
|
|
|
*/ |
|
|
|
{ |
|
|
|
static inline void AVR32CLK_StopGenericClock(const uint8_t Channel) ATTR_ALWAYS_INLINE; |
|
|
|
AVR32_PM.GCCTRL[Channel].cen = false; |
|
|
|
static inline void AVR32CLK_StopGenericClock(const uint8_t Channel) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static inline bool AVR32CLK_SetCPUClockSource(const uint8_t Source, |
|
|
|
|
|
|
|
const uint32_t SourceFreq) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
AVR32_FLASHC.FCR.fws = (SourceFreq > 30000000) ? true : false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (Source) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
case CLOCK_SRC_SLOW_CLK: |
|
|
|
AVR32_PM.GCCTRL[Channel].cen = false; |
|
|
|
AVR32_PM.MCCTRL.mcsel = 0; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case CLOCK_SRC_OSC0: |
|
|
|
|
|
|
|
AVR32_PM.MCCTRL.mcsel = 1; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case CLOCK_SRC_PLL0: |
|
|
|
|
|
|
|
AVR32_PM.MCCTRL.mcsel = 2; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
/** 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. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* \param[in] Source Clock source for the CPU core, a value from \ref System_ClockSource_t. |
|
|
|
|
|
|
|
* \param[in] SourceFreq Frequency of the CPU core's clock source, in Hz. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* \return Boolean \c true if the CPU core clock was sucessfully altered, \c false if invalid parameters specified. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static inline bool AVR32CLK_SetCPUClockSource(const uint8_t Source, |
|
|
|
|
|
|
|
const uint32_t SourceFreq) ATTR_ALWAYS_INLINE; |
|
|
|
|
|
|
|
static inline bool AVR32CLK_SetCPUClockSource(const uint8_t Source, |
|
|
|
|
|
|
|
const uint32_t SourceFreq) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
AVR32_FLASHC.FCR.fws = (SourceFreq > 30000000) ? true : false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (Source) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
case CLOCK_SRC_SLOW_CLK: |
|
|
|
|
|
|
|
AVR32_PM.MCCTRL.mcsel = 0; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case CLOCK_SRC_OSC0: |
|
|
|
|
|
|
|
AVR32_PM.MCCTRL.mcsel = 1; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case CLOCK_SRC_PLL0: |
|
|
|
|
|
|
|
AVR32_PM.MCCTRL.mcsel = 2; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Disable C linkage for C++ Compilers: */ |
|
|
|
|
|
|
|
#if defined(__cplusplus) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @} */ |
|
|
|