⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pipe.h

📁 userial is an Free project building an USB to I2C/SPI/GPIO bridge, using the Atmel AT90USB647 chip.
💻 H
📖 第 1 页 / 共 3 页
字号:
						/** Writes four bytes to the currently selected pipe's bank in big endian format, for IN			 *  direction pipes.			 */						static inline void Pipe_Write_DWord_BE(const uint32_t DWord)			{				Pipe_Write_Word_BE(DWord >> 16);				Pipe_Write_Word_BE(DWord);			}									/** Discards four bytes from the currently selected pipe's bank, for OUT direction pipes. */			static inline void Pipe_Ignore_DWord(void)			{				uint8_t Dummy;								Dummy = UPDATX;				Dummy = UPDATX;				Dummy = UPDATX;				Dummy = UPDATX;			}		/* External Variables: */			/** Global indicating the maximum packet size of the default control pipe located at address			 *  0 in the device. This value is set to the value indicated in the attached device's device		     *  descriptor once the USB interface is initialized into host mode and a device is attached			 *  to the USB bus.			 *			 *  \note This variable should be treated as read-only in the user application, and never manually			 *        changed in value.			 */			extern uint8_t USB_ControlPipeSize;		/* Function Prototypes: */			/** Configures the specified pipe number with the given pipe type, token, target endpoint number in the			 *  attached device, bank size and banking mode. Pipes should be allocated in ascending order by their			 *  address in the device (i.e. pipe 1 should be configured before pipe 2 and so on).			 *			 *  The pipe type may be one of the EP_TYPE_* macros listed in LowLevel.h, the token may be one of the			 *  PIPE_TOKEN_* masks.			 *			 *  The bank size must indicate the maximum packet size that the pipe can handle. Different pipe			 *  numbers can handle different maximum packet sizes - refer to the chosen USB AVR's datasheet to			 *  determine the maximum bank size for each pipe.			 *			 *  The banking mode may be either PIPE_BANK_SINGLE or PIPE_BANK_DOUBLE.			 *			 *  A newly configured pipe is frozen by default, and must be unfrozen before use via the Pipe_Unfreeze() macro.			 *			 *  \note This routine will select the specified pipe, and the pipe will remain selected once the			 *        routine completes regardless of if the pipe configuration succeeds.			 *			 *  \return Boolean true if the configuration is successful, false otherwise			 */			bool Pipe_ConfigurePipe(const uint8_t  Number, const uint8_t Type, const uint8_t Token, const uint8_t EndpointNumber,			                        const uint16_t Size, const uint8_t Banks);			/** Spinloops until the currently selected non-control pipe is ready for the next packed of data			 *  to be read or written to it.			 *			 *  \note This routine should not be called on CONTROL type pipes.			 *			 *  \return A value from the Pipe_WaitUntilReady_ErrorCodes_t enum.			 */			uint8_t Pipe_WaitUntilReady(void);							/** Writes the given number of bytes to the pipe from the given buffer in little endian,			 *  sending full packets to the device as needed. The last packet filled is not automatically sent;			 *  the user is responsible for manually sending the last written packet to the host via the			 *  Pipe_ClearCurrentBank() macro. Between each USB packet, the given stream callback function is			 *  executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.			 *			 *	The callback routine should be created using the STREAM_CALLBACK() macro. If the token			 *  NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are disabled			 *  and this function has the Callback parameter ommitted.			 *			 *  \param Buffer    Pointer to the source data buffer to read from.			 *  \param Length    Number of bytes to read for the currently selected pipe into the buffer.			 *  \param Callback  Name of a callback routine to call between sucessive USB packet transfers, NULL if no callback			 *			 *  \return A value from the Pipe_Stream_RW_ErrorCodes_t enum.			 */			uint8_t Pipe_Write_Stream_LE(const void* Buffer, uint16_t Length			#if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)			                             , uint8_t (* const Callback)(void)			#endif			                             ) ATTR_NON_NULL_PTR_ARG(1);							/** Writes the given number of bytes to the pipe from the given buffer in big endian,			 *  sending full packets to the device as needed. The last packet filled is not automatically sent;			 *  the user is responsible for manually sending the last written packet to the host via the			 *  Pipe_ClearCurrentBank() macro. Between each USB packet, the given stream callback function is			 *  executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.			 *			 *	The callback routine should be created using the STREAM_CALLBACK() macro. If the token			 *  NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are disabled			 *  and this function has the Callback parameter ommitted.			 *			 *  \param Buffer    Pointer to the source data buffer to read from.			 *  \param Length    Number of bytes to read for the currently selected pipe into the buffer.			 *  \param Callback  Name of a callback routine to call between sucessive USB packet transfers, NULL if no callback			 *			 *  \return A value from the Pipe_Stream_RW_ErrorCodes_t enum.			 */			uint8_t Pipe_Write_Stream_BE(const void* Buffer, uint16_t Length			#if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)			                             , uint8_t (* const Callback)(void)			#endif			                             ) ATTR_NON_NULL_PTR_ARG(1);			/** Reads and discards the given number of bytes from the pipe, discarding fully read packets from the host			 *  as needed. The last packet is not automatically discarded once the remaining bytes has been read; the			 *  user is responsible for manually discarding the last packet from the host via the Pipe_ClearCurrentBank() macro.			 *  Between each USB packet, the given stream callback function is executed repeatedly until the next packet is ready,			 *  allowing for early aborts of stream transfers.			 *			 *	The callback routine should be created using the STREAM_CALLBACK() macro. If the token			 *  NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are disabled			 *  and this function has the Callback parameter ommitted.			 *			 *  \param Length  Number of bytes to send via the currently selected pipe.			 *  \param Callback  Name of a callback routine to call between sucessive USB packet transfers, NULL if no callback			 *			 *  \return A value from the Pipe_Stream_RW_ErrorCodes_t enum.			 */			uint8_t Pipe_Discard_Stream(uint16_t Length			#if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)			                            , uint8_t (* const Callback)(void)			#endif			                            );			/** Reads the given number of bytes from the pipe into the given buffer in little endian,			 *  sending full packets to the device as needed. The last packet filled is not automatically sent;			 *  the user is responsible for manually sending the last written packet to the host via the			 *  Pipe_ClearCurrentBank() macro. Between each USB packet, the given stream callback function is			 *  executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.			 *			 *	The callback routine should be created using the STREAM_CALLBACK() macro. If the token			 *  NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are disabled			 *  and this function has the Callback parameter ommitted.			 *			 *  \param Buffer    Pointer to the source data buffer to write to.			 *  \param Length    Number of bytes to read for the currently selected pipe to read from.			 *  \param Callback  Name of a callback routine to call between sucessive USB packet transfers, NULL if no callback			 *			 *  \return A value from the Pipe_Stream_RW_ErrorCodes_t enum.			 */			uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length			#if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)			                            , uint8_t (* const Callback)(void)			#endif			                            ) ATTR_NON_NULL_PTR_ARG(1);			/** Reads the given number of bytes from the pipe into the given buffer in big endian,			 *  sending full packets to the device as needed. The last packet filled is not automatically sent;			 *  the user is responsible for manually sending the last written packet to the host via the			 *  Pipe_ClearCurrentBank() macro. Between each USB packet, the given stream callback function is			 *  executed repeatedly until the next packet is ready, allowing for early aborts of stream transfers.			 *			 *	The callback routine should be created using the STREAM_CALLBACK() macro. If the token			 *  NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are disabled			 *  and this function has the Callback parameter ommitted.			 *			 *  \param Buffer    Pointer to the source data buffer to write to.			 *  \param Length    Number of bytes to read for the currently selected pipe to read from.			 *  \param Callback  Name of a callback routine to call between sucessive USB packet transfers, NULL if no callback			 *			 *  \return A value from the Pipe_Stream_RW_ErrorCodes_t enum.			 */			uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length			#if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)			                            , uint8_t (* const Callback)(void)			#endif			                            ) ATTR_NON_NULL_PTR_ARG(1);						/* Function Aliases: */			/** Alias for Pipe_Discard_Byte().			 */			#define Pipe_Ignore_Byte()                 Pipe_Discard_Byte()			/** Alias for Pipe_Discard_Word().			 */			#define Pipe_Ignore_Word()                 Pipe_Discard_Word()					/** Alias for Pipe_Discard_DWord().			 */			#define Pipe_Ignore_DWord()                Pipe_Discard_DWord()			/** Alias for Pipe_Read_Word_LE(). By default USB transfers use little endian format, thus			 *  the command with no endianness specifier indicates little endian mode.			 */			#define Pipe_Read_Word()                   Pipe_Read_Word_LE()			/** Alias for Pipe_Write_Word_LE(). By default USB transfers use little endian format, thus			 *  the command with no endianness specifier indicates little endian mode.			 */			#define Pipe_Write_Word(Word)              Pipe_Write_Word_LE(Word)			/** Alias for Pipe_Read_DWord_LE(). By default USB transfers use little endian format, thus			 *  the command with no endianness specifier indicates little endian mode.			 */			#define Pipe_Read_DWord()                  Pipe_Read_DWord_LE()			/** Alias for Pipe_Write_DWord_LE(). By default USB transfers use little endian format, thus			 *  the command with no endianness specifier indicates little endian mode.			 */			#define Pipe_Write_DWord(DWord)            Pipe_Write_DWord_LE(DWord)			/** Alias for Pipe_Read_Stream_LE(). By default USB transfers use little endian format, thus			 *  the command with no endianness specifier indicates little endian mode.			 */			#if !defined(NO_STREAM_CALLBACKS)				#define Pipe_Read_Stream(Buffer, Length, Callback) Pipe_Read_Stream_LE(Buffer, Length, Callback)			#else				#define Pipe_Read_Stream(Buffer, Length)           Pipe_Read_Stream_LE(Buffer, Length)			#endif			/** Alias for Pipe_Write_Stream_LE(). By default USB transfers use little endian format, thus			 *  the command with no endianness specifier indicates little endian mode.			 */			#if !defined(NO_STREAM_CALLBACKS)				#define Pipe_Write_Stream(Buffer, Length, Callback) Pipe_Read_Stream_LE(Buffer, Length, Callback)			#else				#define Pipe_Write_Stream(Buffer, Length)           Pipe_Read_Stream_LE(Buffer, Length)			#endif				/* Private Interface - For use in library only: */	#if !defined(__DOXYGEN__)		/* Macros: */			#define PIPE_TOKEN_MASK                    (0x03 << PTOKEN0)			#define Pipe_AllocateMemory()          MACROS{ UPCFG1X |=  (1 << ALLOC);                               }MACROE			#define Pipe_DeallocateMemory()        MACROS{ UPCFG1X &= ~(1 << ALLOC);                               }MACROE		/* Function Prototypes: */			void Pipe_ClearPipes(void);		/* Inline Functions: */			static inline uint8_t Pipe_BytesToEPSizeMask(uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYSINLINE;			static inline uint8_t Pipe_BytesToEPSizeMask(uint16_t Bytes)			{				if (Bytes <= 8)				  return (0 << EPSIZE0);				else if (Bytes <= 16)				  return (1 << EPSIZE0);				else if (Bytes <= 32)				  return (2 << EPSIZE0);				else if (Bytes <= 64)				  return (3 << EPSIZE0);				else if (Bytes <= (8 << 4))				  return (4 << EPSIZE0);				else				  return (5 << EPSIZE0);			};	#endif	/* Disable C linkage for C++ Compilers: */		#if defined(__cplusplus)			}		#endif		#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -