diff options
Diffstat (limited to 'LUFA/Platform')
| -rw-r--r-- | LUFA/Platform/Platform.h | 80 | ||||
| -rw-r--r-- | LUFA/Platform/UC3/ClockManagement.h | 41 | ||||
| -rw-r--r-- | LUFA/Platform/UC3/InterruptManagement.h | 16 | ||||
| -rw-r--r-- | LUFA/Platform/XMEGA/ClockManagement.h | 8 |
4 files changed, 118 insertions, 27 deletions
diff --git a/LUFA/Platform/Platform.h b/LUFA/Platform/Platform.h new file mode 100644 index 00000000..25243632 --- /dev/null +++ b/LUFA/Platform/Platform.h @@ -0,0 +1,80 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2012. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +*/ + +/* + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * \brief Architecture Specific Hardware Platform Drivers. + * + * This file is the master dispatch header file for the device-specific hardware platform drivers, for low level + * hardware configuration and management. The platform drivers are a set of drivers which are designed to provide + * a high level management layer for the various low level system functions such as clock control and interrupt + * management. + * + * User code may choose to either include this master dispatch header file to include all available platform + * driver header files for the current architecture, or may choose to only include the specific platform driver + * modules required for a particular application. + */ + +/** \defgroup Group_PlatformDrivers System Platform Drivers - LUFA/Platform/Platform.h + * \brief Hardware platform drivers. + * + * \section Sec_Dependencies Module Source Dependencies + * The following files must be built with any user project that uses this module: + * - <b>UC3 Architecture Only:</b> LUFA/Platform/UC3/InterruptManagement.c <i>(Makefile source module name: LUFA_SRC_PLATFORM)</i> + * - <b>UC3 Architecture Only:</b> LUFA/Platform/UC3/Exception.S <i>(Makefile source module name: LUFA_SRC_PLATFORM)</i> + * + * \section Sec_ModDescription Module Description + * Device-specific hardware platform drivers, for low level hardware configuration and management. The platform + * drivers are a set of drivers which are designed to provide a high level management layer for the various low level + * system functions such as clock control and interrupt management. + * + * User code may choose to either include this master dispatch header file to include all available platform + * driver header files for the current architecture, or may choose to only include the specific platform driver + * modules required for a particular application. + * + * \note The exact APIs and availability of sub-modules within the platform driver group may vary depending on the + * target used - see individual target module documentation for the API specific to your target processor. + */ + +#ifndef __LUFA_PLATFORM_H__ +#define __LUFA_PLATFORM_H__ + + /* Includes: */ + #include "../Common/Common.h" + + /* Includes: */ + #if (ARCH == ARCH_UC3) + #include "UC3/ClockManagement.h" + #include "UC3/InterruptManagement.h" + #elif (ARCH == ARCH_XMEGA) + #include "XMEGA/ClockManagement.h" + #endif + +#endif + 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 diff --git a/LUFA/Platform/XMEGA/ClockManagement.h b/LUFA/Platform/XMEGA/ClockManagement.h index feef8898..c824c89f 100644 --- a/LUFA/Platform/XMEGA/ClockManagement.h +++ b/LUFA/Platform/XMEGA/ClockManagement.h @@ -70,7 +70,7 @@ #define _XMEGA_CLOCK_MANAGEMENT_H_ /* Includes: */ - #include <LUFA/Common/Common.h> + #include "../../Common/Common.h" /* Enable C linkage for C++ Compilers: */ #if defined(__cplusplus) @@ -88,7 +88,7 @@ EXOSC_FREQ_16MHZ_MAX = OSC_FRQRANGE_12TO16_gc, /**< External crystal oscillator equal to or slower than 16MHz. */ }; - /** Enum for the possible external oscillator statup times. */ + /** Enum for the possible external oscillator startup times. */ enum XMEGA_Extern_OSC_ClockStartup_t { EXOSC_START_6CLK = OSC_XOSCSEL_EXTCLK_gc, /**< Wait 6 clock cycles before startup (external clock). */ @@ -141,7 +141,7 @@ * the oscillator is ready for use. * * \param[in] FreqRange Frequency range of the external oscillator, a value from \ref XMEGA_Extern_OSC_ClockFrequency_t. - * \param[in] Startup Statup time of the external oscillator, a value from \ref XMEGA_Extern_OSC_ClockStartup_t. + * \param[in] Startup Startup time of the external oscillator, a value from \ref XMEGA_Extern_OSC_ClockStartup_t. * * \return Boolean \c true if the external oscillator was successfully started, \c false if invalid parameters specified. */ @@ -347,7 +347,7 @@ * * \param[in] Source Clock source for the CPU core, a value from \ref XMEGA_System_ClockSource_t. * - * \return Boolean \c true if the CPU core clock was sucessfully altered, \c false if invalid parameters specified. + * \return Boolean \c true if the CPU core clock was successfully altered, \c false if invalid parameters specified. */ static inline bool XMEGACLK_SetCPUClockSource(const uint8_t Source) ATTR_ALWAYS_INLINE; static inline bool XMEGACLK_SetCPUClockSource(const uint8_t Source) |
