-/*\r
- LUFA Library\r
- Copyright (C) Dean Camera, 2011.\r
-\r
- dean [at] fourwalledcubicle [dot] com\r
- www.lufa-lib.org\r
-*/\r
-\r
-/*\r
- Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
- Permission to use, copy, modify, distribute, and sell this\r
- software and its documentation for any purpose is hereby granted\r
- without fee, provided that the above copyright notice appear in\r
- all copies and that both that the copyright notice and this\r
- permission notice and warranty disclaimer appear in supporting\r
- documentation, and that the name of the author not be used in\r
- advertising or publicity pertaining to distribution of the\r
- software without specific, written prior permission.\r
-\r
- The author disclaim all warranties with regard to this\r
- software, including all implied warranties of merchantability\r
- and fitness. In no event shall the author be liable for any\r
- special, indirect or consequential damages or any damages\r
- whatsoever resulting from loss of use, data or profits, whether\r
- in an action of contract, negligence or other tortious action,\r
- arising out of or in connection with the use or performance of\r
- this software.\r
-*/\r
-\r
-/** \file\r
- * \brief USB Pipe definitions for the AVR32 UC3B microcontrollers.\r
- * \copydetails Group_PipeManagement_UC3B\r
- *\r
- * \note This file should not be included directly. It is automatically included as needed by the USB driver\r
- * dispatch header located in LUFA/Drivers/USB/USB.h.\r
- */\r
-\r
-/** \ingroup Group_PipeRW\r
- * \defgroup Group_PipeRW_UC3B Pipe Data Reading and Writing (UC3B)\r
- * \brief Pipe data read/write definitions for the Atmel AVR32 UC3B architecture.\r
- *\r
- * Functions, macros, variables, enums and types related to data reading and writing from and to pipes.\r
- */\r
-\r
-/** \ingroup Group_PipePrimitiveRW\r
- * \defgroup Group_PipePrimitiveRW_UC3B Read/Write of Primitive Data Types (UC3B)\r
- * \brief Pipe primative data read/write definitions for the Atmel AVR32 UC3B architecture.\r
- *\r
- * Functions, macros, variables, enums and types related to data reading and writing of primitive data types\r
- * from and to pipes.\r
- */\r
-\r
-/** \ingroup Group_PipePacketManagement\r
- * \defgroup Group_PipePacketManagement_UC3B Pipe Packet Management (UC3B)\r
- * \brief Pipe packet management definitions for the Atmel AVR32 UC3B architecture.\r
- *\r
- * Functions, macros, variables, enums and types related to packet management of pipes.\r
- */\r
-\r
-/** \ingroup Group_PipeControlReq\r
- * \defgroup Group_PipeControlReq_UC3B Pipe Control Request Management (UC3B)\r
- * \brief Pipe control request management definitions for the Atmel AVR32 UC3B architecture.\r
- *\r
- * Module for host mode request processing. This module allows for the transmission of standard, class and\r
- * vendor control requests to the default control endpoint of an attached device while in host mode.\r
- *\r
- * \see Chapter 9 of the USB 2.0 specification.\r
- */\r
-\r
-/** \ingroup Group_PipeManagement\r
- * \defgroup Group_PipeManagement_UC3B Pipe Management (UC3B)\r
- * \brief Pipe management definitions for the Atmel AVR32 UC3B architecture.\r
- *\r
- * This module contains functions, macros and enums related to pipe management when in USB Host mode. This\r
- * module contains the pipe management macros, as well as pipe interrupt and data send/receive functions\r
- * for various data types.\r
- *\r
- * @{\r
- */\r
-\r
-#ifndef __PIPE_UC3B_H__\r
-#define __PIPE_UC3B_H__\r
-\r
- /* Includes: */\r
- #include "../../../../Common/Common.h"\r
- #include "../USBTask.h"\r
-\r
- /* Enable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- extern "C" {\r
- #endif\r
-\r
- /* Preprocessor Checks: */\r
- #if !defined(__INCLUDE_FROM_USB_DRIVER)\r
- #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.\r
- #endif\r
-\r
- /* Private Interface - For use in library only: */\r
- #if !defined(__DOXYGEN__)\r
- /* External Variables: */\r
- extern volatile uint8_t USB_SelectedPipe;\r
- extern volatile uint8_t* USB_PipeFIFOPos[];\r
- #endif\r
-\r
- /* Public Interface - May be used in end-application: */\r
- /* Macros: */\r
- /** \name Pipe Error Flag Masks */\r
- //@{\r
- /** Mask for \ref Pipe_GetErrorFlags(), indicating that an overflow error occurred in the pipe on the received data. */\r
- #define PIPE_ERRORFLAG_OVERFLOW (AVR32_USBB_UPSTA0_OVERFI_MASK << 8)\r
-\r
- /** Mask for \ref Pipe_GetErrorFlags(), indicating that a CRC error occurred in the pipe on the received data. */\r
- #define PIPE_ERRORFLAG_CRC16 AVR32_USBB_UPERR0_CRC16_MASK\r
-\r
- /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware timeout error occurred in the pipe. */\r
- #define PIPE_ERRORFLAG_TIMEOUT AVR32_USBB_UPERR0_TIMEOUT_MASK\r
-\r
- /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware PID error occurred in the pipe. */\r
- #define PIPE_ERRORFLAG_PID AVR32_USBB_UPERR0_PID_MASK\r
-\r
- /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware data PID error occurred in the pipe. */\r
- #define PIPE_ERRORFLAG_DATAPID AVR32_USBB_UPERR0_DATAPID_MASK\r
-\r
- /** Mask for \ref Pipe_GetErrorFlags(), indicating that a hardware data toggle error occurred in the pipe. */\r
- #define PIPE_ERRORFLAG_DATATGL AVR32_USBB_UPERR0_DATATGL_MASK\r
- //@}\r
-\r
- /** \name Pipe Token Masks */\r
- //@{\r
- /** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a SETUP token (for CONTROL type pipes),\r
- * which will trigger a control request on the attached device when data is written to the pipe.\r
- */\r
- #define PIPE_TOKEN_SETUP AVR32_USBB_UPCFG0_PTOKEN_SETUP\r
-\r
- /** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a IN token (for non-CONTROL type pipes),\r
- * indicating that the pipe data will flow from device to host.\r
- */\r
- #define PIPE_TOKEN_IN AVR32_USBB_UPCFG0_PTOKEN_IN\r
-\r
- /** Token mask for \ref Pipe_ConfigurePipe(). This sets the pipe as a OUT token (for non-CONTROL type pipes),\r
- * indicating that the pipe data will flow from host to device.\r
- */\r
- #define PIPE_TOKEN_OUT AVR32_USBB_UPCFG0_PTOKEN_OUT\r
- //@}\r
- \r
- /** \name Pipe Bank Mode Masks */\r
- //@{\r
- /** Mask for the bank mode selection for the \ref Pipe_ConfigurePipe() macro. This indicates that the pipe\r
- * should have one single bank, which requires less USB FIFO memory but results in slower transfers as\r
- * only one USB device (the AVR or the attached device) can access the pipe's bank at the one time.\r
- */\r
- #define PIPE_BANK_SINGLE AVR32_USBB_UPCFG0_PBK_SINGLE\r
-\r
- /** Mask for the bank mode selection for the \ref Pipe_ConfigurePipe() macro. This indicates that the pipe\r
- * should have two banks, which requires more USB FIFO memory but results in faster transfers as one\r
- * USB device (the AVR or the attached device) can access one bank while the other accesses the second\r
- * bank.\r
- */\r
- #define PIPE_BANK_DOUBLE AVR32_USBB_UPCFG0_PBK_DOUBLE\r
-\r
- /** Mask for the bank mode selection for the \ref Pipe_ConfigurePipe() macro. This indicates that the pipe\r
- * should have three banks, which requires more USB FIFO memory but results in faster transfers as one\r
- * USB device (the AVR or the attached device) can access one bank while the other accesses the remaining\r
- * banks.\r
- */\r
- #define PIPE_BANK_TRIPLE AVR32_USBB_UPCFG0_PBK_TRIPLE\r
- //@}\r
-\r
- /** Default size of the default control pipe's bank, until altered by the Endpoint0Size value\r
- * in the device descriptor of the attached device.\r
- */\r
- #define PIPE_CONTROLPIPE_DEFAULT_SIZE 64\r
-\r
- /** Total number of pipes (including the default control pipe at address 0) which may be used in\r
- * the device.\r
- */\r
- #define PIPE_TOTAL_PIPES 7\r
-\r
- /** Size in bytes of the largest pipe bank size possible in the device. Not all banks on each AVR\r
- * model supports the largest bank size possible on the device; different pipe numbers support\r
- * different maximum bank sizes. This value reflects the largest possible bank of any pipe on the\r
- * currently selected UC3B AVR model.\r
- */\r
- #define PIPE_MAX_SIZE 256\r
-\r
- /* Enums: */\r
- /** Enum for the possible error return codes of the \ref Pipe_WaitUntilReady() function.\r
- *\r
- * \ingroup Group_PipeRW_UC3B\r
- */\r
- enum Pipe_WaitUntilReady_ErrorCodes_t\r
- {\r
- PIPE_READYWAIT_NoError = 0, /**< Pipe ready for next packet, no error. */\r
- PIPE_READYWAIT_PipeStalled = 1, /**< The device stalled the pipe while waiting. */\r
- PIPE_READYWAIT_DeviceDisconnected = 2, /**< Device was disconnected from the host while waiting. */\r
- PIPE_READYWAIT_Timeout = 3, /**< The device failed to accept or send the next packet\r
- * within the software timeout period set by the\r
- * \ref USB_STREAM_TIMEOUT_MS macro.\r
- */\r
- };\r
-\r
- /* Inline Functions: */\r
- /** Indicates the number of bytes currently stored in the current pipes's selected bank.\r
- *\r
- * \note The return width of this function may differ, depending on the maximum pipe bank size\r
- * of the selected AVR model.\r
- *\r
- * \ingroup Group_PipeRW_UC3B\r
- *\r
- * \return Total number of bytes in the currently selected pipe's FIFO buffer.\r
- */\r
- static inline uint16_t Pipe_BytesInPipe(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
- static inline uint16_t Pipe_BytesInPipe(void)\r
- {\r
- return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].pbyct;\r
- }\r
-\r
- /** Returns the pipe address of the currently selected pipe. This is typically used to save the\r
- * currently selected pipe number so that it can be restored after another pipe has been manipulated.\r
- *\r
- * \return Index of the currently selected pipe.\r
- */\r
- static inline uint8_t Pipe_GetCurrentPipe(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
- static inline uint8_t Pipe_GetCurrentPipe(void)\r
- {\r
- return USB_SelectedPipe;\r
- }\r
-\r
- /** Selects the given pipe number. Any pipe operations which do not require the pipe number to be\r
- * indicated will operate on the currently selected pipe.\r
- *\r
- * \param[in] PipeNumber Index of the pipe to select.\r
- */\r
- static inline void Pipe_SelectPipe(const uint8_t PipeNumber) ATTR_ALWAYS_INLINE;\r
- static inline void Pipe_SelectPipe(const uint8_t PipeNumber)\r
- {\r
- USB_SelectedPipe = PipeNumber;\r
- }\r
-\r
- /** Resets the desired pipe, including the pipe banks and flags.\r
- *\r
- * \param[in] PipeNumber Index of the pipe to reset.\r
- */\r
- static inline void Pipe_ResetPipe(const uint8_t PipeNumber) ATTR_ALWAYS_INLINE;\r
- static inline void Pipe_ResetPipe(const uint8_t PipeNumber)\r
- {\r
- AVR32_USBB.uprst |= (AVR32_USBB_PRST0_MASK << PipeNumber);\r
- AVR32_USBB.uprst &= ~(AVR32_USBB_PRST0_MASK << PipeNumber);\r
- USB_PipeFIFOPos[USB_SelectedPipe] = &AVR32_USBB_SLAVE[USB_SelectedPipe * 0x10000];\r
- }\r
-\r
- /** Enables the currently selected pipe so that data can be sent and received through it to and from\r
- * an attached device.\r
- *\r
- * \pre The currently selected pipe must first be configured properly via \ref Pipe_ConfigurePipe().\r
- */\r
- static inline void Pipe_EnablePipe(void) ATTR_ALWAYS_INLINE;\r
- static inline void Pipe_EnablePipe(void)\r
- {\r
- AVR32_USBB.uprst |= (AVR32_USBB_PEN0_MASK << USB_SelectedPipe);\r
- }\r
-\r
- /** Disables the currently selected pipe so that data cannot be sent and received through it to and\r
- * from an attached device.\r
- */\r
- static inline void Pipe_DisablePipe(void) ATTR_ALWAYS_INLINE;\r
- static inline void Pipe_DisablePipe(void)\r
- {\r
- AVR32_USBB.uprst &= ~(AVR32_USBB_PEN0_MASK << USB_SelectedPipe);\r
- }\r
-\r
- /** Determines if the currently selected pipe is enabled, but not necessarily configured.\r
- *\r
- * \return Boolean \c true if the currently selected pipe is enabled, \c false otherwise.\r
- */\r
- static inline bool Pipe_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
- static inline bool Pipe_IsEnabled(void)\r
- {\r
- return ((AVR32_USBB.uprst & (AVR32_USBB_PEN0_MASK << USB_SelectedPipe)) ? true : false);\r
- }\r
-\r
- /** Gets the current pipe token, indicating the pipe's data direction and type.\r
- *\r
- * \return The current pipe token, as a \c PIPE_TOKEN_* mask.\r
- */\r
- static inline uint8_t Pipe_GetPipeToken(void) ATTR_ALWAYS_INLINE;\r
- static inline uint8_t Pipe_GetPipeToken(void)\r
- {\r
- return (&AVR32_USBB.UPCFG0)[USB_SelectedPipe].ptoken;\r
- }\r
-\r
- /** Sets the token for the currently selected pipe to one of the tokens specified by the \c PIPE_TOKEN_*\r
- * masks. This can be used on CONTROL type pipes, to allow for bidirectional transfer of data during\r
- * control requests, or on regular pipes to allow for half-duplex bidirectional data transfer to devices\r
- * which have two endpoints of opposite direction sharing the same endpoint address within the device.\r
- *\r
- * \param[in] Token New pipe token to set the selected pipe to, as a \c PIPE_TOKEN_* mask.\r
- */\r
- static inline void Pipe_SetPipeToken(const uint8_t Token) ATTR_ALWAYS_INLINE;\r
- static inline void Pipe_SetPipeToken(const uint8_t Token)\r
- {\r
- (&AVR32_USBB.UPCFG0)[USB_SelectedPipe].ptoken = Token;\r
- }\r
-\r
- /** Configures the currently selected pipe to allow for an unlimited number of IN requests. */\r
- static inline void Pipe_SetInfiniteINRequests(void) ATTR_ALWAYS_INLINE;\r
- static inline void Pipe_SetInfiniteINRequests(void)\r
- {\r
- (&AVR32_USBB.UPINRQ0)[USB_SelectedPipe].inmode = true;\r
- }\r
-\r
- /** Configures the currently selected pipe to only allow the specified number of IN requests to be\r
- * accepted by the pipe before it is automatically frozen.\r
- *\r
- * \param[in] TotalINRequests Total number of IN requests that the pipe may receive before freezing.\r
- */\r
- static inline void Pipe_SetFiniteINRequests(const uint8_t TotalINRequests) ATTR_ALWAYS_INLINE;\r
- static inline void Pipe_SetFiniteINRequests(const uint8_t TotalINRequests)\r
- {\r
- (&AVR32_USBB.UPINRQ0)[USB_SelectedPipe].inmode = false;\r
- (&AVR32_USBB.UPINRQ0)[USB_SelectedPipe].inrq = TotalINRequests;\r
- }\r
-\r
- /** Determines if the currently selected pipe is configured.\r
- *\r
- * \return Boolean \c true if the selected pipe is configured, \c false otherwise.\r
- */\r
- static inline bool Pipe_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
- static inline bool Pipe_IsConfigured(void)\r
- {\r
- return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].cfgok;\r
- }\r
-\r
- /** Retrieves the endpoint number of the endpoint within the attached device that the currently selected\r
- * pipe is bound to.\r
- *\r
- * \return Endpoint number the currently selected pipe is bound to.\r
- */\r
- static inline uint8_t Pipe_BoundEndpointNumber(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
- static inline uint8_t Pipe_BoundEndpointNumber(void)\r
- {\r
- return (&AVR32_USBB.UPCFG0)[USB_SelectedPipe].pepnum;\r
- }\r
-\r
- /** Sets the period between interrupts for an INTERRUPT type pipe to a specified number of milliseconds.\r
- *\r
- * \param[in] Milliseconds Number of milliseconds between each pipe poll.\r
- */\r
- static inline void Pipe_SetInterruptPeriod(const uint8_t Milliseconds) ATTR_ALWAYS_INLINE;\r
- static inline void Pipe_SetInterruptPeriod(const uint8_t Milliseconds)\r
- {\r
- (&AVR32_USBB.UPCFG0)[USB_SelectedPipe].intfrq = Milliseconds;\r
- }\r
-\r
- /** Returns a mask indicating which pipe's interrupt periods have elapsed, indicating that the pipe should\r
- * be serviced.\r
- *\r
- * \return Mask whose bits indicate which pipes have interrupted.\r
- */\r
- static inline uint8_t Pipe_GetPipeInterrupts(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
- static inline uint8_t Pipe_GetPipeInterrupts(void)\r
- {\r
- return ((AVR32_USBB.uhint & (AVR32_USBB_P6INT_MASK | AVR32_USBB_P5INT_MASK |\r
- AVR32_USBB_P4INT_MASK | AVR32_USBB_P3INT_MASK |\r
- AVR32_USBB_P2INT_MASK | AVR32_USBB_P1INT_MASK |\r
- AVR32_USBB_P0INT_MASK)) >> AVR32_USBB_P0INT_OFFSET);\r
- }\r
-\r
- /** Determines if the specified pipe number has interrupted (valid only for INTERRUPT type\r
- * pipes).\r
- *\r
- * \param[in] PipeNumber Index of the pipe whose interrupt flag should be tested.\r
- *\r
- * \return Boolean \c true if the specified pipe has interrupted, \c false otherwise.\r
- */\r
- static inline bool Pipe_HasPipeInterrupted(const uint8_t PipeNumber) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
- static inline bool Pipe_HasPipeInterrupted(const uint8_t PipeNumber)\r
- {\r
- return ((AVR32_USBB.uhint & (AVR32_USBB_P0INTES_MASK << USB_SelectedPipe)) ? true : false);\r
- }\r
-\r
- /** Unfreezes the selected pipe, allowing it to communicate with an attached device. */\r
- static inline void Pipe_Unfreeze(void) ATTR_ALWAYS_INLINE;\r
- static inline void Pipe_Unfreeze(void)\r
- {\r
- (&AVR32_USBB.UPCON0CLR)[USB_SelectedPipe].pfreezec = true;\r
- }\r
-\r
- /** Freezes the selected pipe, preventing it from communicating with an attached device. */\r
- static inline void Pipe_Freeze(void) ATTR_ALWAYS_INLINE;\r
- static inline void Pipe_Freeze(void)\r
- {\r
- (&AVR32_USBB.UPCON0SET)[USB_SelectedPipe].pfreezes = true;\r
- }\r
-\r
- /** Determines if the currently selected pipe is frozen, and not able to accept data.\r
- *\r
- * \return Boolean \c true if the currently selected pipe is frozen, \c false otherwise.\r
- */\r
- static inline bool Pipe_IsFrozen(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
- static inline bool Pipe_IsFrozen(void)\r
- {\r
- return (((&AVR32_USBB.UPCON0)[USB_SelectedPipe].pfreeze) ? true : false);\r
- }\r
-\r
- /** Clears the error flags for the currently selected pipe. */\r
- static inline void Pipe_ClearError(void) ATTR_ALWAYS_INLINE;\r
- static inline void Pipe_ClearError(void)\r
- {\r
- (&AVR32_USBB.uperr0)[USB_SelectedPipe] = 0;\r
- (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].overfic = true;\r
- }\r
-\r
- /** Determines if the master pipe error flag is set for the currently selected pipe, indicating that\r
- * some sort of hardware error has occurred on the pipe.\r
- *\r
- * \see \ref Pipe_GetErrorFlags() macro for information on retrieving the exact error flag.\r
- *\r
- * \return Boolean \c true if an error has occurred on the selected pipe, \c false otherwise.\r
- */\r
- static inline bool Pipe_IsError(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
- static inline bool Pipe_IsError(void)\r
- {\r
- return (((&AVR32_USBB.upsta0)[USB_SelectedPipe] &\r
- (AVR32_USBB_PERRI_MASK | AVR32_USBB_OVERFI_MASK)) ? true : false);\r
- }\r
-\r
- /** Gets a mask of the hardware error flags which have occurred on the currently selected pipe. This\r
- * value can then be masked against the \c PIPE_ERRORFLAG_* masks to determine what error has occurred.\r
- *\r
- * \return Mask comprising of \c PIPE_ERRORFLAG_* bits indicating what error has occurred on the selected pipe.\r
- */\r
- static inline uint8_t Pipe_GetErrorFlags(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
- static inline uint8_t Pipe_GetErrorFlags(void)\r
- {\r
- \r
- return (((&AVR32_USBB.uperr0)[USB_SelectedPipe] &\r
- (PIPE_ERRORFLAG_CRC16 | PIPE_ERRORFLAG_TIMEOUT |\r
- PIPE_ERRORFLAG_PID | PIPE_ERRORFLAG_DATAPID |\r
- PIPE_ERRORFLAG_DATATGL)) |\r
- (((&AVR32_USBB.upsta0)[USB_SelectedPipe] << 8) &\r
- PIPE_ERRORFLAG_OVERFLOW));\r
- }\r
- \r
- /** Retrieves the number of busy banks in the currently selected pipe, which have been queued for\r
- * transmission via the \ref Pipe_ClearOUT() command, or are awaiting acknowledgement via the\r
- * \ref Pipe_ClearIN() command.\r
- *\r
- * \ingroup Group_PipePacketManagement_UC3B\r
- *\r
- * \return Total number of busy banks in the selected pipe.\r
- */\r
- static inline uint8_t Pipe_GetBusyBanks(void)\r
- {\r
- return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].nbusybk;\r
- }\r
-\r
- /** Determines if the currently selected pipe may be read from (if data is waiting in the pipe\r
- * bank and the pipe is an IN direction, or if the bank is not yet full if the pipe is an OUT\r
- * direction). This function will return false if an error has occurred in the pipe, or if the pipe\r
- * is an IN direction and no packet (or an empty packet) has been received, or if the pipe is an OUT\r
- * direction and the pipe bank is full.\r
- *\r
- * \note This function is not valid on CONTROL type pipes.\r
- *\r
- * \ingroup Group_PipePacketManagement_UC3B\r
- *\r
- * \return Boolean \c true if the currently selected pipe may be read from or written to, depending\r
- * on its direction.\r
- */\r
- static inline bool Pipe_IsReadWriteAllowed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
- static inline bool Pipe_IsReadWriteAllowed(void)\r
- {\r
- return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].rwall;\r
- }\r
-\r
- /** Determines if a packet has been received on the currently selected IN pipe from the attached device.\r
- *\r
- * \ingroup Group_PipePacketManagement_UC3B\r
- *\r
- * \return Boolean \c true if the current pipe has received an IN packet, \c false otherwise.\r
- */\r
- static inline bool Pipe_IsINReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
- static inline bool Pipe_IsINReceived(void)\r
- {\r
- return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].rxini;\r
- }\r
-\r
- /** Determines if the currently selected OUT pipe is ready to send an OUT packet to the attached device.\r
- *\r
- * \ingroup Group_PipePacketManagement_UC3B\r
- *\r
- * \return Boolean \c true if the current pipe is ready for an OUT packet, \c false otherwise.\r
- */\r
- static inline bool Pipe_IsOUTReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
- static inline bool Pipe_IsOUTReady(void)\r
- {\r
- return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].txouti;\r
- }\r
-\r
- /** Determines if no SETUP request is currently being sent to the attached device on the selected\r
- * CONTROL type pipe.\r
- *\r
- * \ingroup Group_PipePacketManagement_UC3B\r
- *\r
- * \return Boolean \c true if the current pipe is ready for a SETUP packet, \c false otherwise.\r
- */\r
- static inline bool Pipe_IsSETUPSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
- static inline bool Pipe_IsSETUPSent(void)\r
- {\r
- return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].txstpi;\r
- }\r
-\r
- /** Sends the currently selected CONTROL type pipe's contents to the device as a SETUP packet.\r
- *\r
- * \ingroup Group_PipePacketManagement_UC3B\r
- */\r
- static inline void Pipe_ClearSETUP(void) ATTR_ALWAYS_INLINE;\r
- static inline void Pipe_ClearSETUP(void)\r
- {\r
- (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].txstpic = true;\r
- USB_PipeFIFOPos[USB_SelectedPipe] = &AVR32_USBB_SLAVE[USB_SelectedPipe * 0x10000];\r
- }\r
-\r
- /** Acknowledges the reception of a setup IN request from the attached device on the currently selected\r
- * pipe, freeing the bank ready for the next packet.\r
- *\r
- * \ingroup Group_PipePacketManagement_UC3B\r
- */\r
- static inline void Pipe_ClearIN(void) ATTR_ALWAYS_INLINE;\r
- static inline void Pipe_ClearIN(void)\r
- {\r
- (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].rxinic = true;\r
- (&AVR32_USBB.UPCON0CLR)[USB_SelectedPipe].fifoconc = true;\r
- USB_PipeFIFOPos[USB_SelectedPipe] = &AVR32_USBB_SLAVE[USB_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
- * the bank ready for the next packet.\r
- *\r
- * \ingroup Group_PipePacketManagement_UC3B\r
- */\r
- static inline void Pipe_ClearOUT(void) ATTR_ALWAYS_INLINE;\r
- static inline void Pipe_ClearOUT(void)\r
- {\r
- (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].txoutic = true;\r
- (&AVR32_USBB.UPCON0CLR)[USB_SelectedPipe].fifoconc = true;\r
- USB_PipeFIFOPos[USB_SelectedPipe] = &AVR32_USBB_SLAVE[USB_SelectedPipe * 0x10000];\r
- }\r
-\r
- /** Determines if the device sent a NAK (Negative Acknowledge) in response to the last sent packet on\r
- * the currently selected pipe. This occurs when the host sends a packet to the device, but the device\r
- * is not currently ready to handle the packet (i.e. its endpoint banks are full). Once a NAK has been\r
- * received, it must be cleared using \ref Pipe_ClearNAKReceived() before the previous (or any other) packet\r
- * can be re-sent.\r
- *\r
- * \ingroup Group_PipePacketManagement_UC3B\r
- *\r
- * \return Boolean \c true if an NAK has been received on the current pipe, \c false otherwise.\r
- */\r
- static inline bool Pipe_IsNAKReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
- static inline bool Pipe_IsNAKReceived(void)\r
- {\r
- return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].nakedi;\r
- }\r
-\r
- /** Clears the NAK condition on the currently selected pipe.\r
- *\r
- * \ingroup Group_PipePacketManagement_UC3B\r
- *\r
- * \see \ref Pipe_IsNAKReceived() for more details.\r
- */\r
- static inline void Pipe_ClearNAKReceived(void) ATTR_ALWAYS_INLINE;\r
- static inline void Pipe_ClearNAKReceived(void)\r
- {\r
- (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].nakedic = true;\r
- }\r
-\r
- /** Determines if the currently selected pipe has had the STALL condition set by the attached device.\r
- *\r
- * \ingroup Group_PipePacketManagement_UC3B\r
- *\r
- * \return Boolean \c true if the current pipe has been stalled by the attached device, \c false otherwise.\r
- */\r
- static inline bool Pipe_IsStalled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
- static inline bool Pipe_IsStalled(void)\r
- {\r
- return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].rxstalldi;\r
- }\r
-\r
- /** Clears the STALL condition detection flag on the currently selected pipe, but does not clear the\r
- * STALL condition itself (this must be done via a ClearFeature control request to the device).\r
- *\r
- * \ingroup Group_PipePacketManagement_UC3B\r
- */\r
- static inline void Pipe_ClearStall(void) ATTR_ALWAYS_INLINE;\r
- static inline void Pipe_ClearStall(void)\r
- {\r
- (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].rxstalldic = true;\r
- USB_PipeFIFOPos[USB_SelectedPipe] = &AVR32_USBB_SLAVE[USB_SelectedPipe * 0x10000];\r
- }\r
-\r
- /** Reads one byte from the currently selected pipe's bank, for OUT direction pipes.\r
- *\r
- * \ingroup Group_PipePrimitiveRW_UC3B\r
- *\r
- * \return Next byte in the currently selected pipe's FIFO buffer.\r
- */\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 *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
- }\r
-\r
- /** Writes one byte from the currently selected pipe's bank, for IN direction pipes.\r
- *\r
- * \ingroup Group_PipePrimitiveRW_UC3B\r
- *\r
- * \param[in] Byte Next byte to write into the the currently selected pipe's FIFO buffer.\r
- */\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
- *(USB_PipeFIFOPos[USB_SelectedPipe]++) = Byte;\r
- }\r
-\r
- /** Discards one byte from the currently selected pipe's bank, for OUT direction pipes.\r
- *\r
- * \ingroup Group_PipePrimitiveRW_UC3B\r
- */\r
- static inline void Pipe_Discard_Byte(void) ATTR_ALWAYS_INLINE;\r
- static inline void Pipe_Discard_Byte(void)\r
- {\r
- uint8_t Dummy;\r
-\r
- Dummy = *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
- }\r
-\r
- /** Reads two bytes from the currently selected pipe's bank in little endian format, for OUT\r
- * direction pipes.\r
- *\r
- * \ingroup Group_PipePrimitiveRW_UC3B\r
- *\r
- * \return Next word in the currently selected pipe's FIFO buffer.\r
- */\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
- uint16_t Byte1 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
- uint16_t Byte0 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
-\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
- * direction pipes.\r
- *\r
- * \ingroup Group_PipePrimitiveRW_UC3B\r
- *\r
- * \return Next word in the currently selected pipe's FIFO buffer.\r
- */\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
- uint16_t Byte0 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
- uint16_t Byte1 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
-\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
- * direction pipes.\r
- *\r
- * \ingroup Group_PipePrimitiveRW_UC3B\r
- *\r
- * \param[in] Word Next word to write to the currently selected pipe's FIFO buffer.\r
- */\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
- *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (Word >> 8);\r
- *(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
- * direction pipes.\r
- *\r
- * \ingroup Group_PipePrimitiveRW_UC3B\r
- *\r
- * \param[in] Word Next word to write to the currently selected pipe's FIFO buffer.\r
- */\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
- *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (Word & 0xFF);\r
- *(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
- * \ingroup Group_PipePrimitiveRW_UC3B\r
- */\r
- static inline void Pipe_Discard_Word(void) ATTR_ALWAYS_INLINE;\r
- static inline void Pipe_Discard_Word(void)\r
- {\r
- uint8_t Dummy;\r
-\r
- Dummy = *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
- Dummy = *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
- }\r
-\r
- /** Reads four bytes from the currently selected pipe's bank in little endian format, for OUT\r
- * direction pipes.\r
- *\r
- * \ingroup Group_PipePrimitiveRW_UC3B\r
- *\r
- * \return Next double word in the currently selected pipe's FIFO buffer.\r
- */\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
- uint32_t Byte3 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
- uint32_t Byte2 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
- uint32_t Byte1 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
- uint32_t Byte0 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
-\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
- * direction pipes.\r
- *\r
- * \ingroup Group_PipePrimitiveRW_UC3B\r
- *\r
- * \return Next double word in the currently selected pipe's FIFO buffer.\r
- */\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
- uint32_t Byte0 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
- uint32_t Byte1 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
- uint32_t Byte2 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
- uint32_t Byte3 = *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
-\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
- * direction pipes.\r
- *\r
- * \ingroup Group_PipePrimitiveRW_UC3B\r
- *\r
- * \param[in] DWord Next double word to write to the currently selected pipe's FIFO buffer.\r
- */\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
- *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (DWord >> 24);\r
- *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (DWord >> 16);\r
- *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (DWord >> 8);\r
- *(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
- * direction pipes.\r
- *\r
- * \ingroup Group_PipePrimitiveRW_UC3B\r
- *\r
- * \param[in] DWord Next double word to write to the currently selected pipe's FIFO buffer.\r
- */\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
- *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (DWord & 0xFF);\r
- *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (DWord >> 8);\r
- *(USB_PipeFIFOPos[USB_SelectedPipe]++) = (DWord >> 16);\r
- *(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
- * \ingroup Group_PipePrimitiveRW_UC3B\r
- */\r
- static inline void Pipe_Discard_DWord(void) ATTR_ALWAYS_INLINE;\r
- static inline void Pipe_Discard_DWord(void)\r
- {\r
- uint8_t Dummy;\r
-\r
- Dummy = *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
- Dummy = *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
- Dummy = *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
- Dummy = *(USB_PipeFIFOPos[USB_SelectedPipe]++);\r
- }\r
-\r
- /* External Variables: */\r
- /** Global indicating the maximum packet size of the default control pipe located at address\r
- * 0 in the device. This value is set to the value indicated in the attached device's device\r
- * descriptor once the USB interface is initialized into host mode and a device is attached\r
- * to the USB bus.\r
- *\r
- * \note This variable should be treated as read-only in the user application, and never manually\r
- * changed in value.\r
- */\r
- extern uint8_t USB_ControlPipeSize;\r
-\r
- /* Function Prototypes: */\r
- /** Configures the specified pipe number with the given pipe type, token, target endpoint number in the\r
- * attached device, bank size and banking mode.\r
- *\r
- * A newly configured pipe is frozen by default, and must be unfrozen before use via the \ref Pipe_Unfreeze()\r
- * before being used. Pipes should be kept frozen unless waiting for data from a device while in IN mode, or\r
- * sending data to the device in OUT mode. IN type pipes are also automatically configured to accept infinite\r
- * numbers of IN requests without automatic freezing - this can be overridden by a call to\r
- * \ref Pipe_SetFiniteINRequests().\r
- *\r
- * \param[in] Number Pipe number to configure. This must be more than 0 and less than \ref PIPE_TOTAL_PIPES.\r
- *\r
- * \param[in] Type Type of pipe to configure, an \c EP_TYPE_* mask. Not all pipe types are available on Low\r
- * Speed USB devices - refer to the USB 2.0 specification.\r
- *\r
- * \param[in] Token Pipe data token, either \ref PIPE_TOKEN_SETUP, \ref PIPE_TOKEN_OUT or \ref PIPE_TOKEN_IN.\r
- * All pipes (except Control type) are unidirectional - data may only be read from or\r
- * written to the pipe bank based on its direction, not both.\r
- *\r
- * \param[in] EndpointNumber Endpoint index within the attached device that the pipe should interface to.\r
- *\r
- * \param[in] Size Size of the pipe's bank, where packets are stored before they are transmitted to\r
- * the USB device, or after they have been received from the USB device (depending on\r
- * the pipe's data direction). The bank size must indicate the maximum packet size that\r
- * the pipe can handle.\r
- *\r
- * \param[in] Banks Number of banks to use for the pipe being configured, a \c PIPE_BANK_* mask. More banks\r
- * uses more USB DPRAM, but offers better performance. Isochronous type pipes <b>must</b>\r
- * have at least two banks.\r
- *\r
- * \note When the \c ORDERED_EP_CONFIG compile time option is used, Pipes <b>must</b> be configured in ascending order,\r
- * or bank corruption will occur.\r
- * \n\n\r
- *\r
- * \note Certain microcontroller model's pipes may have different maximum packet sizes based on the pipe's\r
- * index - refer to the chosen microcontroller's datasheet to determine the maximum bank size for each pipe.\r
- * \n\n\r
- *\r
- * \note The default control pipe should not be manually configured by the user application, as it is\r
- * automatically configured by the library internally.\r
- * \n\n\r
- *\r
- * \note This routine will automatically select the specified pipe upon success. Upon failure, the pipe which\r
- * failed to reconfigure correctly will be selected.\r
- *\r
- * \return Boolean \c true if the configuration succeeded, \c false otherwise.\r
- */\r
- bool Pipe_ConfigurePipe(const uint8_t Number,\r
- const uint8_t Type,\r
- const uint8_t Token,\r
- const uint8_t EndpointNumber,\r
- const uint16_t Size,\r
- const uint8_t Banks);\r
-\r
- /** Spin-loops until the currently selected non-control pipe is ready for the next packed of data to be read\r
- * or written to it, aborting in the case of an error condition (such as a timeout or device disconnect).\r
- *\r
- * \ingroup Group_PipeRW_UC3B\r
- *\r
- * \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum.\r
- */\r
- uint8_t Pipe_WaitUntilReady(void);\r
-\r
- /** Determines if a pipe has been bound to the given device endpoint address. If a pipe which is bound to the given\r
- * endpoint is found, it is automatically selected.\r
- *\r
- * \param[in] EndpointAddress Address and direction mask of the endpoint within the attached device to check.\r
- *\r
- * \return Boolean \c true if a pipe bound to the given endpoint address of the specified direction is found,\r
- * \c false otherwise.\r
- */\r
- bool Pipe_IsEndpointBound(const uint8_t EndpointAddress);\r
-\r
- /* Private Interface - For use in library only: */\r
- #if !defined(__DOXYGEN__)\r
- /* Macros: */\r
- #if !defined(ENDPOINT_CONTROLEP)\r
- #define ENDPOINT_CONTROLEP 0\r
- #endif\r
- \r
- /* Inline Functions: */\r
- static inline uint8_t Pipe_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE;\r
- static inline uint8_t Pipe_BytesToEPSizeMask(const uint16_t Bytes)\r
- {\r
- uint8_t MaskVal = 0;\r
- uint16_t CheckBytes = 8;\r
-\r
- while ((CheckBytes < Bytes) && (CheckBytes < PIPE_MAX_SIZE))\r
- {\r
- MaskVal++;\r
- CheckBytes <<= 1;\r
- }\r
-\r
- return (MaskVal << AVR32_USBB_PSIZE_OFFSET);\r
- }\r
-\r
- /* Function Prototypes: */\r
- void Pipe_ClearPipes(void);\r
- #endif\r
-\r
- /* Disable C linkage for C++ Compilers: */\r
- #if defined(__cplusplus)\r
- }\r
- #endif\r
-\r
-#endif\r
-\r
-/** @} */\r
-\r