More AVR32 achitecture ports.

pull/1469/head
Dean Camera 15 years ago
parent 3702ba1fb3
commit a7aaa45ec4

@ -72,6 +72,12 @@
/** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 32. */ /** SPI prescaler mask for SPI_Init(). Divides the system clock by a factor of 32. */
#define SPI_SPEED_FCPU_DIV_32 AVR32_SPI_MR_FDIV_MASK #define SPI_SPEED_FCPU_DIV_32 AVR32_SPI_MR_FDIV_MASK
/** SPI chip selection mode for direct peripheral-to-CS pin connections. */
#define SPI_CS_4BITDECODER AVR32_SPI_MR_PSDEC_MASK
/** SPI chip selection mode for peripheral CS pin connections through a 4-bit decoder. */
#define SPI_CS_DIRECT 0
/** SPI mode mask for SPI_Init(). Indicates that the SPI interface should be initialized into slave mode. */ /** SPI mode mask for SPI_Init(). Indicates that the SPI interface should be initialized into slave mode. */
#define SPI_MODE_SLAVE 0 #define SPI_MODE_SLAVE 0
@ -89,12 +95,15 @@
* configure these seperately to connect the SPI module to the desired GPIO pins via the * configure these seperately to connect the SPI module to the desired GPIO pins via the
* GPIO MUX registers. * GPIO MUX registers.
* *
* \param[in] SPIOptions SPI Options, a mask consisting of one of each of the SPI_SPEED_* * \param[in] SPIOptions SPI Options, a mask consisting of one of each of the SPI_SPEED_*,
* and SPI_MODE_* masks * SPI_CS_* and SPI_MODE_* masks
*/ */
static inline void SPI_Init(const uintN_t SPIOptions) static inline void SPI_Init(const uintN_t SPIOptions)
{ {
AVR32_SPI.cr = (AVR32_SPI_CR_SPIEN_MASK | AVR32_SPI_CR_SWRST_MASK); AVR32_PM.pbamask = (1 << 5);
AVR32_SPI.CR.swrst = true;
AVR32_SPI.CR.spien = true;
AVR32_SPI.mr = SPIOptions; AVR32_SPI.mr = SPIOptions;
} }
@ -102,6 +111,8 @@
static inline void SPI_ShutDown(void) static inline void SPI_ShutDown(void)
{ {
AVR32_SPI.cr = AVR32_SPI_CR_SPIDIS_MASK; AVR32_SPI.cr = AVR32_SPI_CR_SPIDIS_MASK;
AVR32_PM.pbamask &= ~(1 << 5);
} }
/** Sends and receives a transfer through the SPI interface, blocking until the transfer is complete. /** Sends and receives a transfer through the SPI interface, blocking until the transfer is complete.
@ -115,9 +126,12 @@
static inline uint16_t SPI_Transfer(const uint16_t Data) ATTR_ALWAYS_INLINE; static inline uint16_t SPI_Transfer(const uint16_t Data) ATTR_ALWAYS_INLINE;
static inline uint16_t SPI_Transfer(const uint16_t Data) static inline uint16_t SPI_Transfer(const uint16_t Data)
{ {
AVR32_SPI.TDR.td = Data;
while (!(AVR32_SPI.SR.tdre)); while (!(AVR32_SPI.SR.tdre));
return AVR32_SPI.rdr; AVR32_SPI.TDR.td = Data;
while ((AVR32_SPI.sr & (AVR32_SPI_SR_RDRF_MASK | AVR32_SPI_SR_TXEMPTY_MASK)) !=
(AVR32_SPI_SR_RDRF_MASK | AVR32_SPI_SR_TXEMPTY_MASK));
return AVR32_SPI.RDR.rd;
} }
/** Sends a transfer through the SPI interface, blocking until the transfer is complete. The response /** Sends a transfer through the SPI interface, blocking until the transfer is complete. The response
@ -129,8 +143,8 @@
static inline void SPI_Send(const uint16_t Data) ATTR_ALWAYS_INLINE; static inline void SPI_Send(const uint16_t Data) ATTR_ALWAYS_INLINE;
static inline void SPI_Send(const uint16_t Data) static inline void SPI_Send(const uint16_t Data)
{ {
AVR32_SPI.TDR.td = Data;
while (!(AVR32_SPI.SR.tdre)); while (!(AVR32_SPI.SR.tdre));
AVR32_SPI.TDR.td = Data;
} }
/** Sends a dummy transfer through the SPI interface, blocking until the transfer is complete. The response /** Sends a dummy transfer through the SPI interface, blocking until the transfer is complete. The response
@ -142,8 +156,11 @@
static inline uint16_t SPI_Receive(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT; static inline uint16_t SPI_Receive(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
static inline uint16_t SPI_Receive(void) static inline uint16_t SPI_Receive(void)
{ {
AVR32_SPI.TDR.td = 0x0000;
while (!(AVR32_SPI.SR.tdre)); while (!(AVR32_SPI.SR.tdre));
AVR32_SPI.TDR.td = 0x0000;
while ((AVR32_SPI.sr & (AVR32_SPI_SR_RDRF_MASK | AVR32_SPI_SR_TXEMPTY_MASK)) !=
(AVR32_SPI_SR_RDRF_MASK | AVR32_SPI_SR_TXEMPTY_MASK));
return AVR32_SPI.RDR.rd; return AVR32_SPI.RDR.rd;
} }

@ -345,7 +345,11 @@ static bool RNDIS_Device_ProcessNDISQuery(USB_ClassInfo_RNDIS_Device_t* const RN
case OID_GEN_SUPPORTED_LIST: case OID_GEN_SUPPORTED_LIST:
*ResponseSize = sizeof(AdapterSupportedOIDList); *ResponseSize = sizeof(AdapterSupportedOIDList);
#if defined(__AVR32__)
memcpy(ResponseData, AdapterSupportedOIDList, sizeof(AdapterSupportedOIDList));
#elif defined(__AVR__)
memcpy_P(ResponseData, AdapterSupportedOIDList, sizeof(AdapterSupportedOIDList)); memcpy_P(ResponseData, AdapterSupportedOIDList, sizeof(AdapterSupportedOIDList));
#endif
return true; return true;
case OID_GEN_PHYSICAL_MEDIUM: case OID_GEN_PHYSICAL_MEDIUM:

@ -51,6 +51,12 @@ void USB_INT_DisableAllInterrupts(void)
void USB_INT_ClearAllInterrupts(void) void USB_INT_ClearAllInterrupts(void)
{ {
#if defined(__AVR32__)
AVR32_USBB.USBSTACLR = 0xFFFFFF;
AVR32_USBB.UHINTCLR = 0xFFFFFF;
AVR32_USBB.UECONX =
AVR32_USBB.UDINTCLR = 0xFFFFFF;
#elif defined(__AVR__)
#if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
USBINT = 0; USBINT = 0;
#endif #endif
@ -63,6 +69,7 @@ void USB_INT_ClearAllInterrupts(void)
#if defined(USB_CAN_BE_DEVICE) #if defined(USB_CAN_BE_DEVICE)
UDINT = 0; UDINT = 0;
#endif #endif
#endif
} }
ISR(USB_GEN_vect, ISR_BLOCK) ISR(USB_GEN_vect, ISR_BLOCK)

@ -62,7 +62,7 @@
#if defined(__AVR32__) #if defined(__AVR32__)
#define USB_INT_Enable(int) MACROS{ USB_INT_GET_EN_REG(int) |= USB_INT_GET_EN_MASK(int); }MACROE #define USB_INT_Enable(int) MACROS{ USB_INT_GET_EN_REG(int) |= USB_INT_GET_EN_MASK(int); }MACROE
#define USB_INT_Disable(int) MACROS{ USB_INT_GET_EN_REG(int) &= ~(USB_INT_GET_EN_MASK(int)); }MACROE #define USB_INT_Disable(int) MACROS{ USB_INT_GET_EN_REG(int) &= ~(USB_INT_GET_EN_MASK(int)); }MACROE
#define USB_INT_Clear(int) MACROS{ USB_INT_GET_INT_REG(int) ## CLR |= USB_INT_GET_INT_MASK(int) ## C; }MACROE #define USB_INT_Clear(int) MACROS{ USB_INT_GET_INTC_REG(int) |= USB_INT_GET_INTC_MASK(int); }MACROE
#define USB_INT_IsEnabled(int) ((USB_INT_GET_EN_REG(int) & USB_INT_GET_EN_MASK(int)) ? true : false) #define USB_INT_IsEnabled(int) ((USB_INT_GET_EN_REG(int) & USB_INT_GET_EN_MASK(int)) ? true : false)
#define USB_INT_HasOccurred(int) ((USB_INT_GET_INT_REG(int) & USB_INT_GET_INT_MASK(int)) ? true : false) #define USB_INT_HasOccurred(int) ((USB_INT_GET_INT_REG(int) & USB_INT_GET_INT_MASK(int)) ? true : false)
@ -70,9 +70,11 @@
#define USB_INT_GET_EN_MASK(a, b, c, d) AVR32_USBB_ ## b #define USB_INT_GET_EN_MASK(a, b, c, d) AVR32_USBB_ ## b
#define USB_INT_GET_INT_REG(a, b, c, d) *( (volatile uint32_t*)AVR32_USBB_ ## c ) #define USB_INT_GET_INT_REG(a, b, c, d) *( (volatile uint32_t*)AVR32_USBB_ ## c )
#define USB_INT_GET_INT_MASK(a, b, c, d) AVR32_USBB_ ## d #define USB_INT_GET_INT_MASK(a, b, c, d) AVR32_USBB_ ## d
#define USB_INT_GET_INTC_REG(a, b, c, d) *( (volatile uint32_t*)AVR32_USBB_ ## c ## CLR )
#define USB_INT_GET_INTC_MASK(a, b, c, d) AVR32_USBB_ ## d ## C
#define USB_INT_VBUS USBCON, USBCON_VBUSTE_MASK, USBSTA, USBSTA_VBUSTI_MASK #define USB_INT_VBUS USBCON, USBCON_VBUSTE_MASK, USBSTA, USBSTA_VBUSTI_MASK
#define USB_INT_IDTI USBCON, USBCON_IDTE_MASK , USBINT, USBCON_IDTI_MASK #define USB_INT_IDTI USBCON, USBCON_IDTE_MASK , USBSTA, USBCON_IDTI_MASK
#define USB_INT_WAKEUP UDIEN , UDIEN_WAKEUPE_MASK, UDINT , UDIEN_WAKEUPI_MASK #define USB_INT_WAKEUP UDIEN , UDIEN_WAKEUPE_MASK, UDINT , UDIEN_WAKEUPI_MASK
#define USB_INT_SUSPEND UDIEN , UDIEN_SUSPE_MASK , UDINT , UDIEN_SUSPI_MASK #define USB_INT_SUSPEND UDIEN , UDIEN_SUSPE_MASK , UDINT , UDIEN_SUSPI_MASK
#define USB_INT_EORSTI UDIEN , UDIEN_EORSTE_MASK , UDINT , UDIEN_EORSTI_MASK #define USB_INT_EORSTI UDIEN , UDIEN_EORSTE_MASK , UDINT , UDIEN_EORSTI_MASK
@ -81,10 +83,10 @@
#define USB_INT_DDISCI UHIEN , UDIEN_DDISCE_MASK , UHINT , UHIEN_DDISCI_MASK #define USB_INT_DDISCI UHIEN , UDIEN_DDISCE_MASK , UHINT , UHIEN_DDISCI_MASK
#define USB_INT_HSOFI UHIEN, UHIEN_HSOFE_MASK , UHINT , UHIEN_HSOFI_MASK #define USB_INT_HSOFI UHIEN, UHIEN_HSOFE_MASK , UHINT , UHIEN_HSOFI_MASK
#define USB_INT_RSTI UHIEN , UHIEN_RSTE_MASK , UHINT , UHIEN_RSTI_MASK #define USB_INT_RSTI UHIEN , UHIEN_RSTE_MASK , UHINT , UHIEN_RSTI_MASK
#define USB_INT_RXSTPI UEIENX, UEIENX_RXSTPE_MASK, UEINTX, UEIENX_RXSTPI_MASK #define USB_INT_RXSTPI UECONX, UECONX_RXSTPE_MASK, UESTAX, UESTAX_RXSTPI_MASK
#define USB_INT_BCERRI OTGIEN, OTGIEN_BCERRE_MASK, OTGINT, OTGIEN_BCERRI_MASK #define USB_INT_BCERRI USBCON, USBCON_BCERRE_MASK, USBSTA, USBSTA_BCERRI_MASK
#define USB_INT_VBERRI OTGIEN, OTGIEN_VBERRE_MASK, OTGINT, OTGIEN_VBERRI_MASK #define USB_INT_VBERRI USBCON, USBCON_VBERRE_MASK, USBSTA, USBSTA_VBERRI_MASK
#define USB_INT_SRPI OTGIEN, OTGIEN_SRPE_MASK , OTGINT, OTGIEN_SRPI_MASK #define USB_INT_SRPI USBCON, USBCON_SRPE_MASK , USBSTA, USBSTA_SRPI_MASK
#elif defined(__AVR__) #elif defined(__AVR__)
#define USB_INT_Enable(int) MACROS{ USB_INT_GET_EN_REG(int) |= USB_INT_GET_EN_MASK(int); }MACROE #define USB_INT_Enable(int) MACROS{ USB_INT_GET_EN_REG(int) |= USB_INT_GET_EN_MASK(int); }MACROE
#define USB_INT_Disable(int) MACROS{ USB_INT_GET_EN_REG(int) &= ~(USB_INT_GET_EN_MASK(int)); }MACROE #define USB_INT_Disable(int) MACROS{ USB_INT_GET_EN_REG(int) &= ~(USB_INT_GET_EN_MASK(int)); }MACROE

@ -87,7 +87,7 @@
extern USB_Request_Header_t USB_ControlRequest; extern USB_Request_Header_t USB_ControlRequest;
#if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__) #if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__)
#if (!defined(__AVR32__) && !defined(HOST_STATE_AS_GPIOR)) || defined(__DOXYGEN__) #if (!defined(__AVR32__) || !defined(HOST_STATE_AS_GPIOR)) || defined(__DOXYGEN__)
/** Indicates the current host state machine state. When in host mode, this indicates the state /** Indicates the current host state machine state. When in host mode, this indicates the state
* via one of the values of the \ref USB_Host_States_t enum values. * via one of the values of the \ref USB_Host_States_t enum values.
* *
@ -116,7 +116,7 @@
#endif #endif
#if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__) #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)
#if (!defined(__AVR32__) && !defined(DEVICE_STATE_AS_GPIOR)) || defined(__DOXYGEN__) #if (defined(__AVR32__) || !defined(DEVICE_STATE_AS_GPIOR)) || defined(__DOXYGEN__)
/** Indicates the current device state machine state. When in device mode, this indicates the state /** Indicates the current device state machine state. When in device mode, this indicates the state
* via one of the values of the \ref USB_Device_States_t enum values. * via one of the values of the \ref USB_Device_States_t enum values.
* *

@ -223,7 +223,7 @@
#define USB_Device_SetLowSpeed() MACROS{ AVR32_USBB.UDCON.ls = true; }MACROE #define USB_Device_SetLowSpeed() MACROS{ AVR32_USBB.UDCON.ls = true; }MACROE
#define USB_Device_SetFullSpeed() MACROS{ AVR32_USBB.UDCON.ls = false; }MACROE #define USB_Device_SetFullSpeed() MACROS{ AVR32_USBB.UDCON.ls = false; }MACROE
#define USB_Device_SetDeviceAddress(addr) MACROS{ AVR32_USBB.UDADDR = (AVR32_USBB_UDCON_ADDEN_MASK | DeviceAddress); }MACROE #define USB_Device_SetDeviceAddress(addr) MACROS{ AVR32_USBB.UDCON.uadd = DeviceAddress; AVR32_USBB.UDCON.adden = true; }MACROE
#elif defined(__AVR__) #elif defined(__AVR__)
#define USB_Device_SetLowSpeed() MACROS{ UDCON |= (1 << LSM); }MACROE #define USB_Device_SetLowSpeed() MACROS{ UDCON |= (1 << LSM); }MACROE
#define USB_Device_SetFullSpeed() MACROS{ UDCON &= ~(1 << LSM); }MACROE #define USB_Device_SetFullSpeed() MACROS{ UDCON &= ~(1 << LSM); }MACROE

@ -95,6 +95,10 @@
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif #endif
#if defined(__AVR32__) && !defined(__AVR32_EPREG_X)
#define __AVR32_EPREG_X(x) ((volatile uint32_t*)AVR32_USBB_ ## x)[USB_SelectedEPNumber]
#endif
/* Public Interface - May be used in end-application: */ /* Public Interface - May be used in end-application: */
/* Macros: */ /* Macros: */
#if defined(__AVR32__) || defined(__DOXYGEN__) #if defined(__AVR32__) || defined(__DOXYGEN__)
@ -377,17 +381,17 @@
#if !defined(CONTROL_ONLY_DEVICE) #if !defined(CONTROL_ONLY_DEVICE)
#define Endpoint_GetCurrentEndpoint() USB_SelectedEPNumber #define Endpoint_GetCurrentEndpoint() USB_SelectedEPNumber
#define Endpoint_SelectEndpoint(epnum) MACROS{ USB_SelectedEPNumber = (epnum); }MACROE #define Endpoint_SelectEndpoint(epnum) MACROS{ USB_SelectedEPNumber = (epnum); }MACROE
#define Endpoint_IsReadWriteAllowed() (__AVR32_EPREG_X(UESTA0) & AVR32_USBB_RWAL_MASK) #define Endpoint_IsReadWriteAllowed() (__AVR32_EPREG_X(UESTA0) & AVR32_USBB_RWALL_MASK)
#else #else
#define Endpoint_GetCurrentEndpoint() ENDPOINT_CONTROLEP #define Endpoint_GetCurrentEndpoint() ENDPOINT_CONTROLEP
#define Endpoint_SelectEndpoint(epnum) (void)(epnum) #define Endpoint_SelectEndpoint(epnum) (void)(epnum)
#endif #endif
#define Endpoint_ResetFIFO(epnum) MACROS{ AVR32_USBB.UERST |= (AVR32_USBB_EPRST0_MASK << (epnum)); \ #define Endpoint_ResetFIFO(epnum) MACROS{ AVR32_USBB.uerst |= (AVR32_USBB_EPRST0_MASK << (epnum)); \
AVR32_USBB.UERST &= ~(AVR32_USBB_EPRST0_MASK << (epnum)); }MACROE AVR32_USBB.uerst &= ~(AVR32_USBB_EPRST0_MASK << (epnum)); }MACROE
#define Endpoint_EnableEndpoint() MACROS{ AVR32_USBB.UERST |= (AVR32_USBB_UERST_EPEN0_MASK << (epen)); }MACROE #define Endpoint_EnableEndpoint() MACROS{ AVR32_USBB.uerst |= (AVR32_USBB_UERST_EPEN0_MASK << USB_SelectedEPNumber); }MACROE
#define Endpoint_DisableEndpoint() MACROS{ AVR32_USBB.UERST &= ~(AVR32_USBB_UERST_EPEN0_MASK << (epen)); }MACROE #define Endpoint_DisableEndpoint() MACROS{ AVR32_USBB.uerst &= ~(AVR32_USBB_UERST_EPEN0_MASK << USB_SelectedEPNumber); }MACROE
#define Endpoint_IsEnabled() ((AVR32_USBB.UERST & (AVR32_USBB_UERST_EPEN0_MASK << (epen))) ? true : false) #define Endpoint_IsEnabled() ((AVR32_USBB.uerst & (AVR32_USBB_UERST_EPEN0_MASK << USB_SelectedEPNumber)) ? true : false)
#define Endpoint_IsConfigured() ((__AVR32_EPREG_X(UESTA0) & AVR32_USBB_UESTA0_CFGOK_MASK) ? true : false) #define Endpoint_IsConfigured() ((__AVR32_EPREG_X(UESTA0) & AVR32_USBB_UESTA0_CFGOK_MASK) ? true : false)
#define Endpoint_GetEndpointInterrupts() (AVR32_USBB.UDINT >> AVR32_USBB_EP0INT) #define Endpoint_GetEndpointInterrupts() (AVR32_USBB.UDINT >> AVR32_USBB_EP0INT)

@ -89,6 +89,9 @@
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif #endif
#if defined(__AVR32__)
#define USB_PLL_PSC 0
#elif defined(__AVR__)
#if !defined(F_CLOCK) #if !defined(F_CLOCK)
#error F_CLOCK is not defined. You must define F_CLOCK to the frequency of the unprescaled input clock in your project makefile. #error F_CLOCK is not defined. You must define F_CLOCK to the frequency of the unprescaled input clock in your project makefile.
#endif #endif
@ -120,7 +123,8 @@
#endif #endif
#if !defined(USB_PLL_PSC) #if !defined(USB_PLL_PSC)
#error No PLL prescale value available for chosen F_CPU value and AVR model. #error No PLL prescale value available for chosen F_CLOCK value and AVR model.
#endif
#endif #endif
/* Public Interface - May be used in end-application: */ /* Public Interface - May be used in end-application: */

@ -103,6 +103,10 @@
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif #endif
#if defined(__AVR32__) && !defined(__AVR32_EPREG_X)
#define __AVR32_EPREG_X(x) ((volatile uint32_t*)AVR32_USBB_ ## x)[USB_SelectedEPNumber]
#endif
/* Public Interface - May be used in end-application: */ /* Public Interface - May be used in end-application: */
/* Macros: */ /* Macros: */
/** Mask for \ref Pipe_GetErrorFlags(), indicating that an overflow error occurred in the pipe on the received data. */ /** Mask for \ref Pipe_GetErrorFlags(), indicating that an overflow error occurred in the pipe on the received data. */

@ -355,10 +355,6 @@
#define __INCLUDE_FROM_USB_DRIVER #define __INCLUDE_FROM_USB_DRIVER
#endif #endif
#if defined(__AVR32__)
#define __AVR32_EPREG_X(x) ((volatile uint32_t*)AVR32_USBB_ ## x)[USB_SelectedEPNumber]
#endif
/* Includes: */ /* Includes: */
#include "HighLevel/USBMode.h" #include "HighLevel/USBMode.h"

@ -277,7 +277,7 @@
* 0x2064 * 0x2064
* </td> * </td>
* <td> * <td>
* <i>Currently Unallocated</i> * Interfaceless Control-Only LUFA Devices
* </td> * </td>
* </tr> * </tr>
* *

Loading…
Cancel
Save