Add software FIFOs to the UC3B pipe control interfaces, to match the endpoint control...
[pub/lufa.git] / LUFA / Drivers / USB / Core / UC3B / Pipe_UC3B.h
index 033dd01..183975a 100644 (file)
                        {\r
                                AVR32_USBB.uprst |=  (AVR32_USBB_PRST0_MASK << PipeNumber);\r
                                AVR32_USBB.uprst &= ~(AVR32_USBB_PRST0_MASK << PipeNumber);\r
+                               USB_PipeFIFOPos[Pipe_SelectedPipe] = &AVR32_USBB_SLAVE[Pipe_SelectedPipe * 0x10000];\r
                        }\r
 \r
                        /** Enables the currently selected pipe so that data can be sent and received through it to and from\r
                        static inline void Pipe_ClearSETUP(void)\r
                        {\r
                                (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].txstpic = true;\r
+                               USB_PipeFIFOPos[Pipe_SelectedPipe] = &AVR32_USBB_SLAVE[Pipe_SelectedPipe * 0x10000];\r
                        }\r
 \r
                        /** Acknowledges the reception of a setup IN request from the attached device on the currently selected\r
                        {\r
                                (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].rxinic   = true;\r
                                (&AVR32_USBB.UPCON0CLR)[USB_SelectedPipe].fifoconc = true;\r
+                               USB_PipeFIFOPos[Pipe_SelectedPipe] = &AVR32_USBB_SLAVE[Pipe_SelectedPipe * 0x10000];\r
                        }\r
 \r
                        /** Sends the currently selected pipe's contents to the device as an OUT packet on the selected pipe, freeing\r
                        {\r
                                (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].txoutic  = true;\r
                                (&AVR32_USBB.UPCON0CLR)[USB_SelectedPipe].fifoconc = true;\r
+                               USB_PipeFIFOPos[Pipe_SelectedPipe] = &AVR32_USBB_SLAVE[Pipe_SelectedPipe * 0x10000];\r
                        }\r
 \r
                        /** Determines if the device sent a NAK (Negative Acknowledge) in response to the last sent packet on\r
                        static inline void Pipe_ClearStall(void)\r
                        {\r
                                (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].rxstalldic = true;\r
+                               USB_PipeFIFOPos[Pipe_SelectedPipe] = &AVR32_USBB_SLAVE[Pipe_SelectedPipe * 0x10000];\r
                        }\r
 \r
                        /** Reads one byte from the currently selected pipe's bank, for OUT direction pipes.\r
                        static inline uint8_t Pipe_Read_Byte(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
                        static inline uint8_t Pipe_Read_Byte(void)\r
                        {\r
-                               return *((uint8_t*)AVR32_USBB_EP_DATA);\r
+                               return *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
                        }\r
 \r
                        /** Writes one byte from the currently selected pipe's bank, for IN direction pipes.\r
                        static inline void Pipe_Write_Byte(const uint8_t Byte) ATTR_ALWAYS_INLINE;\r
                        static inline void Pipe_Write_Byte(const uint8_t Byte)\r
                        {\r
-                               *((uint8_t*)AVR32_USBB_EP_DATA) = Byte;\r
+                               *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++) = Byte;\r
                        }\r
 \r
                        /** Discards one byte from the currently selected pipe's bank, for OUT direction pipes.\r
                        {\r
                                uint8_t Dummy;\r
 \r
-                               Dummy = *((uint8_t*)AVR32_USBB_EP_DATA);\r
+                               Dummy = *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
                        }\r
 \r
                        /** Reads two bytes from the currently selected pipe's bank in little endian format, for OUT\r
                        static inline uint16_t Pipe_Read_Word_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
                        static inline uint16_t Pipe_Read_Word_LE(void)\r
                        {\r
-                               union\r
-                               {\r
-                                       uint16_t Word;\r
-                                       uint8_t  Bytes[2];\r
-                               } Data;\r
-\r
-                               Data.Bytes[0] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
-                               Data.Bytes[1] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
+                               uint16_t Byte1 = *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
+                               uint16_t Byte0 = *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
 \r
-                               return Data.Word;\r
+                               return ((Byte0 << 8) | Byte1);\r
                        }\r
 \r
                        /** Reads two bytes from the currently selected pipe's bank in big endian format, for OUT\r
                        static inline uint16_t Pipe_Read_Word_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
                        static inline uint16_t Pipe_Read_Word_BE(void)\r
                        {\r
-                               union\r
-                               {\r
-                                       uint16_t Word;\r
-                                       uint8_t  Bytes[2];\r
-                               } Data;\r
-\r
-                               Data.Bytes[1] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
-                               Data.Bytes[0] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
+                               uint16_t Byte0 = *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
+                               uint16_t Byte1 = *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
 \r
-                               return Data.Word;\r
+                               return ((Byte0 << 8) | Byte1);\r
                        }\r
 \r
                        /** Writes two bytes to the currently selected pipe's bank in little endian format, for IN\r
                        static inline void Pipe_Write_Word_LE(const uint16_t Word) ATTR_ALWAYS_INLINE;\r
                        static inline void Pipe_Write_Word_LE(const uint16_t Word)\r
                        {\r
-                               *((uint8_t*)AVR32_USBB_EP_DATA) = (Word & 0xFF);\r
-                               *((uint8_t*)AVR32_USBB_EP_DATA) = (Word >> 8);\r
+                               *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++) = (Word >> 8);\r
+                               *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++) = (Word & 0xFF);\r
                        }\r
 \r
                        /** Writes two bytes to the currently selected pipe's bank in big endian format, for IN\r
                        static inline void Pipe_Write_Word_BE(const uint16_t Word) ATTR_ALWAYS_INLINE;\r
                        static inline void Pipe_Write_Word_BE(const uint16_t Word)\r
                        {\r
-                               *((uint8_t*)AVR32_USBB_EP_DATA) = (Word >> 8);\r
-                               *((uint8_t*)AVR32_USBB_EP_DATA) = (Word & 0xFF);\r
+                               *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++) = (Word & 0xFF);\r
+                               *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++) = (Word >> 8);\r
                        }\r
 \r
                        /** Discards two bytes from the currently selected pipe's bank, for OUT direction pipes.\r
                        {\r
                                uint8_t Dummy;\r
 \r
-                               Dummy = *((uint8_t*)AVR32_USBB_EP_DATA);\r
-                               Dummy = *((uint8_t*)AVR32_USBB_EP_DATA);\r
+                               Dummy = *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
+                               Dummy = *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
                        }\r
 \r
                        /** Reads four bytes from the currently selected pipe's bank in little endian format, for OUT\r
                        static inline uint32_t Pipe_Read_DWord_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
                        static inline uint32_t Pipe_Read_DWord_LE(void)\r
                        {\r
-                               union\r
-                               {\r
-                                       uint32_t DWord;\r
-                                       uint8_t  Bytes[4];\r
-                               } Data;\r
-\r
-                               Data.Bytes[0] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
-                               Data.Bytes[1] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
-                               Data.Bytes[2] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
-                               Data.Bytes[3] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
+                               uint32_t Byte3 = *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
+                               uint32_t Byte2 = *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
+                               uint32_t Byte1 = *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
+                               uint32_t Byte0 = *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
 \r
-                               return Data.DWord;\r
+                               return ((Byte0 << 24) | (Byte1 << 16) | (Byte2 << 8) | Byte3);\r
                        }\r
 \r
                        /** Reads four bytes from the currently selected pipe's bank in big endian format, for OUT\r
                        static inline uint32_t Pipe_Read_DWord_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
                        static inline uint32_t Pipe_Read_DWord_BE(void)\r
                        {\r
-                               union\r
-                               {\r
-                                       uint32_t DWord;\r
-                                       uint8_t  Bytes[4];\r
-                               } Data;\r
-\r
-                               Data.Bytes[3] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
-                               Data.Bytes[2] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
-                               Data.Bytes[1] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
-                               Data.Bytes[0] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
+                               uint32_t Byte0 = *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
+                               uint32_t Byte1 = *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
+                               uint32_t Byte2 = *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
+                               uint32_t Byte3 = *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
 \r
-                               return Data.DWord;\r
+                               return ((Byte0 << 24) | (Byte1 << 16) | (Byte2 << 8) | Byte3);\r
                        }\r
 \r
                        /** Writes four bytes to the currently selected pipe's bank in little endian format, for IN\r
                        static inline void Pipe_Write_DWord_LE(const uint32_t DWord) ATTR_ALWAYS_INLINE;\r
                        static inline void Pipe_Write_DWord_LE(const uint32_t DWord)\r
                        {\r
-                               *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord &  0xFF);\r
-                               *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord >> 8);\r
-                               *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord >> 16);\r
-                               *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord >> 24);\r
+                               *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++) = (DWord >> 24);\r
+                               *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++) = (DWord >> 16);\r
+                               *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++) = (DWord >> 8);\r
+                               *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++) = (DWord &  0xFF);\r
                        }\r
 \r
                        /** Writes four bytes to the currently selected pipe's bank in big endian format, for IN\r
                        static inline void Pipe_Write_DWord_BE(const uint32_t DWord) ATTR_ALWAYS_INLINE;\r
                        static inline void Pipe_Write_DWord_BE(const uint32_t DWord)\r
                        {\r
-                               *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord >> 24);\r
-                               *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord >> 16);\r
-                               *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord >> 8);\r
-                               *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord &  0xFF);\r
+                               *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++) = (DWord &  0xFF);\r
+                               *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++) = (DWord >> 8);\r
+                               *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++) = (DWord >> 16);\r
+                               *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++) = (DWord >> 24);\r
                        }\r
 \r
                        /** Discards four bytes from the currently selected pipe's bank, for OUT direction pipes.\r
                        {\r
                                uint8_t Dummy;\r
 \r
-                               Dummy = *((uint8_t*)AVR32_USBB_EP_DATA);\r
-                               Dummy = *((uint8_t*)AVR32_USBB_EP_DATA);\r
-                               Dummy = *((uint8_t*)AVR32_USBB_EP_DATA);\r
-                               Dummy = *((uint8_t*)AVR32_USBB_EP_DATA);\r
+                               Dummy = *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
+                               Dummy = *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
+                               Dummy = *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
+                               Dummy = *(((volatile uint8_t** volatile)USB_PipeFIFOPos)[USB_SelectedPipe]++);\r
                        }\r
 \r
                /* External Variables: */\r