X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/6a10d6b465be27db090d760dc0fbe722c94e4344..b9b03aadb219d06fbad9d110e508db93e45461af:/LUFA/Drivers/USB/LowLevel/Pipe.c diff --git a/LUFA/Drivers/USB/LowLevel/Pipe.c b/LUFA/Drivers/USB/LowLevel/Pipe.c index 743bb91f2..720da1772 100644 --- a/LUFA/Drivers/USB/LowLevel/Pipe.c +++ b/LUFA/Drivers/USB/LowLevel/Pipe.c @@ -27,7 +27,9 @@ arising out of or in connection with the use or performance of this software. */ -#include "USBMode.h" + +#include "../HighLevel/USBMode.h" + #if defined(USB_CAN_BE_HOST) #define INCLUDE_FROM_PIPE_C @@ -35,7 +37,7 @@ uint8_t USB_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE; -bool Pipe_ConfigurePipe(const uint8_t Number, const uint8_t Type, const uint8_t Token, const uint8_t EndpointNumber, +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) { Pipe_SelectPipe(Number); @@ -68,32 +70,43 @@ void Pipe_ClearPipes(void) uint8_t Pipe_WaitUntilReady(void) { - uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS; + #if (USB_STREAM_TIMEOUT_MS < 0xFF) + uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS; + #else + uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS; + #endif - USB_INT_Clear(USB_INT_HSOFI); - - while (!(Pipe_ReadWriteAllowed())) + for (;;) { + if (Pipe_GetPipeToken() == PIPE_TOKEN_IN) + { + if (Pipe_IsINReceived()) + return PIPE_READYWAIT_NoError; + } + else + { + if (Pipe_IsOUTReady()) + return PIPE_READYWAIT_NoError; + } + if (Pipe_IsStalled()) return PIPE_READYWAIT_PipeStalled; else if (!(USB_IsConnected)) return PIPE_READYWAIT_DeviceDisconnected; - if (USB_INT_HasOccurred(USB_INT_HSOFI)) + if (FrameElapsed) { - USB_INT_Clear(USB_INT_HSOFI); + FrameElapsed = false; if (!(TimeoutMSRem--)) return PIPE_READYWAIT_Timeout; } } - - return PIPE_READYWAIT_NoError; } uint8_t Pipe_Write_Stream_LE(const void* Data, uint16_t Length #if !defined(NO_STREAM_CALLBACKS) - , uint8_t (* const Callback)(void) + , StreamCallbackPtr_t Callback #endif ) { @@ -103,30 +116,33 @@ uint8_t Pipe_Write_Stream_LE(const void* Data, uint16_t Length if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; - while (Length--) + while (Length) { - if (!(Pipe_ReadWriteAllowed())) + if (!(Pipe_IsReadWriteAllowed())) { - Pipe_ClearCurrentBank(); + Pipe_ClearOUT(); #if !defined(NO_STREAM_CALLBACKS) if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return PIPE_RWSTREAM_ERROR_CallbackAborted; + return PIPE_RWSTREAM_CallbackAborted; #endif if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; } - - Pipe_Write_Byte(*(DataStream++)); + else + { + Pipe_Write_Byte(*(DataStream++)); + Length--; + } } - return PIPE_RWSTREAM_ERROR_NoError; + return PIPE_RWSTREAM_NoError; } uint8_t Pipe_Write_Stream_BE(const void* Data, uint16_t Length #if !defined(NO_STREAM_CALLBACKS) - , uint8_t (* const Callback)(void) + , StreamCallbackPtr_t Callback #endif ) { @@ -136,30 +152,33 @@ uint8_t Pipe_Write_Stream_BE(const void* Data, uint16_t Length if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; - while (Length--) + while (Length) { - if (!(Pipe_ReadWriteAllowed())) + if (!(Pipe_IsReadWriteAllowed())) { - Pipe_ClearCurrentBank(); + Pipe_ClearOUT(); #if !defined(NO_STREAM_CALLBACKS) if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return PIPE_RWSTREAM_ERROR_CallbackAborted; + return PIPE_RWSTREAM_CallbackAborted; #endif if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; } - - Pipe_Write_Byte(*(DataStream--)); + else + { + Pipe_Write_Byte(*(DataStream--)); + Length--; + } } - return PIPE_RWSTREAM_ERROR_NoError; + return PIPE_RWSTREAM_NoError; } uint8_t Pipe_Discard_Stream(uint16_t Length #if !defined(NO_STREAM_CALLBACKS) - , uint8_t (* const Callback)(void) + , StreamCallbackPtr_t Callback #endif ) { @@ -168,30 +187,33 @@ uint8_t Pipe_Discard_Stream(uint16_t Length if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; - while (Length--) + while (Length) { - if (!(Pipe_ReadWriteAllowed())) + if (!(Pipe_IsReadWriteAllowed())) { - Pipe_ClearCurrentBank(); + Pipe_ClearIN(); #if !defined(NO_STREAM_CALLBACKS) if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return PIPE_RWSTREAM_ERROR_CallbackAborted; + return PIPE_RWSTREAM_CallbackAborted; #endif if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; } - - Pipe_Discard_Byte(); + else + { + Pipe_Discard_Byte(); + Length--; + } } - return PIPE_RWSTREAM_ERROR_NoError; + return PIPE_RWSTREAM_NoError; } uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length - #if !defined(NO_STREAM_CALLBACKS) - , uint8_t (* const Callback)(void) +#if !defined(NO_STREAM_CALLBACKS) + , StreamCallbackPtr_t Callback #endif ) { @@ -201,30 +223,33 @@ uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; - while (Length--) + while (Length) { - if (!(Pipe_ReadWriteAllowed())) + if (!(Pipe_IsReadWriteAllowed())) { - Pipe_ClearCurrentBank(); + Pipe_ClearIN(); #if !defined(NO_STREAM_CALLBACKS) if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return PIPE_RWSTREAM_ERROR_CallbackAborted; + return PIPE_RWSTREAM_CallbackAborted; #endif if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; } - - *(DataStream++) = Pipe_Read_Byte(); + else + { + *(DataStream++) = Pipe_Read_Byte(); + Length--; + } } - return PIPE_RWSTREAM_ERROR_NoError; + return PIPE_RWSTREAM_NoError; } uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length - #if !defined(NO_STREAM_CALLBACKS) - , uint8_t (* const Callback)(void) +#if !defined(NO_STREAM_CALLBACKS) + , StreamCallbackPtr_t Callback #endif ) { @@ -234,25 +259,28 @@ uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; - while (Length--) + while (Length) { - if (!(Pipe_ReadWriteAllowed())) + if (!(Pipe_IsReadWriteAllowed())) { - Pipe_ClearCurrentBank(); + Pipe_ClearIN(); #if !defined(NO_STREAM_CALLBACKS) if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return PIPE_RWSTREAM_ERROR_CallbackAborted; + return PIPE_RWSTREAM_CallbackAborted; #endif if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; } - - *(DataStream--) = Pipe_Read_Byte(); + else + { + *(DataStream--) = Pipe_Read_Byte(); + Length--; + } } - return PIPE_RWSTREAM_ERROR_NoError; + return PIPE_RWSTREAM_NoError; } #endif