aboutsummaryrefslogtreecommitdiff
path: root/LUFA/Platform/UC3
diff options
context:
space:
mode:
Diffstat (limited to 'LUFA/Platform/UC3')
-rw-r--r--LUFA/Platform/UC3/ClockManagement.h41
-rw-r--r--LUFA/Platform/UC3/InterruptManagement.h16
2 files changed, 34 insertions, 23 deletions
diff --git a/LUFA/Platform/UC3/ClockManagement.h b/LUFA/Platform/UC3/ClockManagement.h
index 2cd96d2e..b6b6ece2 100644
--- a/LUFA/Platform/UC3/ClockManagement.h
+++ b/LUFA/Platform/UC3/ClockManagement.h
@@ -72,7 +72,7 @@
#define _UC3_CLOCK_MANAGEMENT_H_
/* Includes: */
- #include <LUFA/Common/Common.h>
+ #include "../../Common/Common.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
@@ -91,16 +91,16 @@
EXOSC_MODE_8MHZ_OR_MORE = AVR32_PM_OSCCTRL0_MODE_CRYSTAL_G3, /**< External crystal oscillator equal to or faster than 8MHz. */
};
- /** Enum for the possible external oscillator statup times. */
+ /** Enum for the possible external oscillator startup times. */
enum UC3_Extern_OSC_ClockStartup_t
{
EXOSC_START_0CLK = AVR32_PM_OSCCTRL0_STARTUP_0_RCOSC, /**< Immediate startup, no delay. */
- EXOSC_START_64CLK = AVR32_PM_OSCCTRL0_STARTUP_64_RCOSC, /**< Wait 64 clock cyles before startup for stability. */
- EXOSC_START_128CLK = AVR32_PM_OSCCTRL0_STARTUP_128_RCOSC, /**< Wait 128 clock cyles before startup for stability. */
- EXOSC_START_2048CLK = AVR32_PM_OSCCTRL0_STARTUP_2048_RCOSC, /**< Wait 2048 clock cyles before startup for stability. */
- EXOSC_START_4096CLK = AVR32_PM_OSCCTRL0_STARTUP_4096_RCOSC, /**< Wait 4096 clock cyles before startup for stability. */
- EXOSC_START_8192CLK = AVR32_PM_OSCCTRL0_STARTUP_8192_RCOSC, /**< Wait 8192 clock cyles before startup for stability. */
- EXOSC_START_16384CLK = AVR32_PM_OSCCTRL0_STARTUP_16384_RCOSC, /**< Wait 16384 clock cyles before startup for stability. */
+ EXOSC_START_64CLK = AVR32_PM_OSCCTRL0_STARTUP_64_RCOSC, /**< Wait 64 clock cycles before startup for stability. */
+ EXOSC_START_128CLK = AVR32_PM_OSCCTRL0_STARTUP_128_RCOSC, /**< Wait 128 clock cycles before startup for stability. */
+ EXOSC_START_2048CLK = AVR32_PM_OSCCTRL0_STARTUP_2048_RCOSC, /**< Wait 2048 clock cycles before startup for stability. */
+ EXOSC_START_4096CLK = AVR32_PM_OSCCTRL0_STARTUP_4096_RCOSC, /**< Wait 4096 clock cycles before startup for stability. */
+ EXOSC_START_8192CLK = AVR32_PM_OSCCTRL0_STARTUP_8192_RCOSC, /**< Wait 8192 clock cycles before startup for stability. */
+ EXOSC_START_16384CLK = AVR32_PM_OSCCTRL0_STARTUP_16384_RCOSC, /**< Wait 16384 clock cycles before startup for stability. */
};
/** Enum for the possible module clock sources. */
@@ -231,6 +231,12 @@
const uint32_t SourceFreq,
const uint32_t Frequency)
{
+ if (Channel >= AVR32_PM_GCLK_NUM)
+ return false;
+
+ if (SourceFreq < Frequency)
+ return false;
+
switch (Source)
{
case CLOCK_SRC_OSC0:
@@ -253,9 +259,6 @@
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;
@@ -266,11 +269,18 @@
/** Stops the given generic clock of the UC3 microcontroller.
*
* \param[in] Channel Index of the generic clock to stop.
+ *
+ * \return Boolean \c true if the generic clock was sucessfully stopped, \c false if invalid parameters specified.
*/
- static inline void AVR32CLK_StopGenericClock(const uint8_t Channel) ATTR_ALWAYS_INLINE;
- static inline void AVR32CLK_StopGenericClock(const uint8_t Channel)
+ static inline bool AVR32CLK_StopGenericClock(const uint8_t Channel) ATTR_ALWAYS_INLINE;
+ static inline bool AVR32CLK_StopGenericClock(const uint8_t Channel)
{
+ if (Channel >= AVR32_PM_GCLK_NUM)
+ return false;
+
AVR32_PM.GCCTRL[Channel].cen = false;
+
+ return true;
}
/** Sets the clock source for the main microcontroller core. The given clock source should be configured
@@ -288,8 +298,11 @@
static inline bool AVR32CLK_SetCPUClockSource(const uint8_t Source,
const uint32_t SourceFreq)
{
- AVR32_FLASHC.FCR.fws = (SourceFreq > 30000000) ? true : false;
+ if (SourceFreq > AVR32_PM_CPU_MAX_FREQ)
+ return false;
+ AVR32_FLASHC.FCR.fws = (SourceFreq > AVR32_FLASHC_FWS_0_MAX_FREQ) ? true : false;
+
switch (Source)
{
#if defined(AVR32_PM_MCCTRL_MCSEL_SLOW)
diff --git a/LUFA/Platform/UC3/InterruptManagement.h b/LUFA/Platform/UC3/InterruptManagement.h
index af99f087..384d6d77 100644
--- a/LUFA/Platform/UC3/InterruptManagement.h
+++ b/LUFA/Platform/UC3/InterruptManagement.h
@@ -41,8 +41,8 @@
*
* \section Sec_Dependencies Module Source Dependencies
* The following files must be built with any user project that uses this module:
- * - LUFA/Platform/UC3/InterruptManagement.c
- * - LUFA/Platform/UC3/Exception.S
+ * - LUFA/Platform/UC3/InterruptManagement.c <i>(Makefile source module name: LUFA_SRC_PLATFORM)</i>
+ * - LUFA/Platform/UC3/Exception.S <i>(Makefile source module name: LUFA_SRC_PLATFORM)</i>
*
* \section Sec_ModDescription Module Description
* Interrupt controller driver for the AVR32 UC3 microcontrollers, for the configuration of interrupt
@@ -71,7 +71,7 @@
#define _UC3_INTERRUPT_MANAGEMENT_H_
/* Includes: */
- #include <LUFA/Common/Common.h>
+ #include "../../Common/Common.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
@@ -93,7 +93,7 @@
/* Public Interface - May be used in end-application: */
/* Macros: */
- /** Converts a given interrupt index into its assocated interrupt group.
+ /** Converts a given interrupt index into its associated interrupt group.
*
* \param[in] IRQIndex Index of the interrupt request to convert.
*
@@ -101,7 +101,7 @@
*/
#define INTC_IRQ_GROUP(IRQIndex) (IRQIndex / 32)
- /** Converts a given interrupt index into its assocated interrupt line.
+ /** Converts a given interrupt index into its associated interrupt line.
*
* \param[in] IRQIndex Index of the interrupt request to convert.
*
@@ -110,10 +110,8 @@
#define INTC_IRQ_LINE(IRQIndex) (IRQIndex % 32)
/* Function Prototypes: */
- /** Initializes the interrupt controller, nulling out all interrupt handlers ready for new registration. This
- * function should be called once on startup to ensure the interrupt controller is ready for use.
- */
- void INTC_Init(void);
+ void INTC_Init(void);
+ InterruptHandlerPtr_t INTC_GetInterruptHandler(const uint_reg_t InterruptLevel);
/* Inline Functions: */
/** Registers a handler for a given interrupt group. On the AVR32 UC3 devices, interrupts are grouped by