X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/e21b620bf6cc9fb1bb9e516efb57b1cb12c00085..0fcbe22c9eb68f5769bf57469e1bcf9b340d0ae3:/LUFA/Drivers/USB/LowLevel/Pipe.c diff --git a/LUFA/Drivers/USB/LowLevel/Pipe.c b/LUFA/Drivers/USB/LowLevel/Pipe.c index 4bd89ecb5..ab092796c 100644 --- a/LUFA/Drivers/USB/LowLevel/Pipe.c +++ b/LUFA/Drivers/USB/LowLevel/Pipe.c @@ -45,9 +45,11 @@ bool Pipe_ConfigurePipe(const uint8_t Number, const uint8_t Type, const uint8_t UPCFG1X = 0; - UPCFG0X = ((Type << EPTYPE0) | Token | (EndpointNumber << PEPNUM0)); + UPCFG0X = ((Type << EPTYPE0) | Token | ((EndpointNumber & PIPE_EPNUM_MASK) << PEPNUM0)); UPCFG1X = ((1 << ALLOC) | Banks | Pipe_BytesToEPSizeMask(Size)); + Pipe_SetInfiniteINRequests(); + return Pipe_IsConfigured(); } @@ -70,9 +72,11 @@ void Pipe_ClearPipes(void) uint8_t Pipe_WaitUntilReady(void) { + #if (USB_STREAM_TIMEOUT_MS < 0xFF) + uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS; + #else uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS; - - USB_INT_Clear(USB_INT_HSOFI); + #endif for (;;) { @@ -104,16 +108,58 @@ uint8_t Pipe_WaitUntilReady(void) 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 ) { uint8_t* DataStream = (uint8_t*)Data; uint8_t ErrorCode; + Pipe_SetToken(PIPE_TOKEN_OUT); + if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; + #if defined(FAST_STREAM_TRANSFERS) + uint8_t BytesRemToAlignment = (Pipe_BytesInPipe() & 0x07); + + if (Length >= 8) + { + Length -= BytesRemToAlignment; + + switch (BytesRemToAlignment) + { + default: + do + { + if (!(Pipe_IsReadWriteAllowed())) + { + Pipe_ClearOUT(); + + #if !defined(NO_STREAM_CALLBACKS) + if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) + return PIPE_RWSTREAM_CallbackAborted; + #endif + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + } + + Length -= 8; + + Pipe_Write_Byte(*(DataStream++)); + case 7: Pipe_Write_Byte(*(DataStream++)); + case 6: Pipe_Write_Byte(*(DataStream++)); + case 5: Pipe_Write_Byte(*(DataStream++)); + case 4: Pipe_Write_Byte(*(DataStream++)); + case 3: Pipe_Write_Byte(*(DataStream++)); + case 2: Pipe_Write_Byte(*(DataStream++)); + case 1: Pipe_Write_Byte(*(DataStream++)); + } while (Length >= 8); + } + } + #endif + while (Length) { if (!(Pipe_IsReadWriteAllowed())) @@ -122,7 +168,7 @@ uint8_t Pipe_Write_Stream_LE(const void* Data, uint16_t Length #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())) @@ -135,21 +181,63 @@ uint8_t Pipe_Write_Stream_LE(const void* Data, uint16_t 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 ) { uint8_t* DataStream = (uint8_t*)(Data + Length - 1); uint8_t ErrorCode; + Pipe_SetToken(PIPE_TOKEN_OUT); + if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; + #if defined(FAST_STREAM_TRANSFERS) + uint8_t BytesRemToAlignment = (Pipe_BytesInPipe() & 0x07); + + if (Length >= 8) + { + Length -= BytesRemToAlignment; + + switch (BytesRemToAlignment) + { + default: + do + { + if (!(Pipe_IsReadWriteAllowed())) + { + Pipe_ClearOUT(); + + #if !defined(NO_STREAM_CALLBACKS) + if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) + return PIPE_RWSTREAM_CallbackAborted; + #endif + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + } + + Length -= 8; + + Pipe_Write_Byte(*(DataStream--)); + case 7: Pipe_Write_Byte(*(DataStream--)); + case 6: Pipe_Write_Byte(*(DataStream--)); + case 5: Pipe_Write_Byte(*(DataStream--)); + case 4: Pipe_Write_Byte(*(DataStream--)); + case 3: Pipe_Write_Byte(*(DataStream--)); + case 2: Pipe_Write_Byte(*(DataStream--)); + case 1: Pipe_Write_Byte(*(DataStream--)); + } while (Length >= 8); + } + } + #endif + while (Length) { if (!(Pipe_IsReadWriteAllowed())) @@ -158,7 +246,7 @@ uint8_t Pipe_Write_Stream_BE(const void* Data, uint16_t Length #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())) @@ -171,20 +259,62 @@ uint8_t Pipe_Write_Stream_BE(const void* Data, uint16_t 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 ) { uint8_t ErrorCode; + Pipe_SetToken(PIPE_TOKEN_IN); + if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; + #if defined(FAST_STREAM_TRANSFERS) + uint8_t BytesRemToAlignment = (Pipe_BytesInPipe() & 0x07); + + if (Length >= 8) + { + Length -= BytesRemToAlignment; + + switch (BytesRemToAlignment) + { + default: + do + { + if (!(Pipe_IsReadWriteAllowed())) + { + Pipe_ClearIN(); + + #if !defined(NO_STREAM_CALLBACKS) + if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) + return PIPE_RWSTREAM_CallbackAborted; + #endif + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + } + + Length -= 8; + + Pipe_Discard_Byte(); + case 7: Pipe_Discard_Byte(); + case 6: Pipe_Discard_Byte(); + case 5: Pipe_Discard_Byte(); + case 4: Pipe_Discard_Byte(); + case 3: Pipe_Discard_Byte(); + case 2: Pipe_Discard_Byte(); + case 1: Pipe_Discard_Byte(); + } while (Length >= 8); + } + } + #endif + while (Length) { if (!(Pipe_IsReadWriteAllowed())) @@ -193,7 +323,7 @@ uint8_t Pipe_Discard_Stream(uint16_t Length #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())) @@ -206,21 +336,63 @@ uint8_t Pipe_Discard_Stream(uint16_t 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) + , StreamCallbackPtr_t Callback #endif ) { uint8_t* DataStream = (uint8_t*)Buffer; uint8_t ErrorCode; + Pipe_SetToken(PIPE_TOKEN_IN); + if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; + #if defined(FAST_STREAM_TRANSFERS) + uint8_t BytesRemToAlignment = (Pipe_BytesInPipe() & 0x07); + + if (Length >= 8) + { + Length -= BytesRemToAlignment; + + switch (BytesRemToAlignment) + { + default: + do + { + if (!(Pipe_IsReadWriteAllowed())) + { + Pipe_ClearIN(); + + #if !defined(NO_STREAM_CALLBACKS) + if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) + return PIPE_RWSTREAM_CallbackAborted; + #endif + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + } + + Length -= 8; + + *(DataStream++) = Pipe_Read_Byte(); + case 7: *(DataStream++) = Pipe_Read_Byte(); + case 6: *(DataStream++) = Pipe_Read_Byte(); + case 5: *(DataStream++) = Pipe_Read_Byte(); + case 4: *(DataStream++) = Pipe_Read_Byte(); + case 3: *(DataStream++) = Pipe_Read_Byte(); + case 2: *(DataStream++) = Pipe_Read_Byte(); + case 1: *(DataStream++) = Pipe_Read_Byte(); + } while (Length >= 8); + } + } + #endif + while (Length) { if (!(Pipe_IsReadWriteAllowed())) @@ -229,7 +401,7 @@ uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length #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())) @@ -242,21 +414,63 @@ uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t 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) + , StreamCallbackPtr_t Callback #endif ) { uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1); uint8_t ErrorCode; + Pipe_SetToken(PIPE_TOKEN_IN); + if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; + #if defined(FAST_STREAM_TRANSFERS) + uint8_t BytesRemToAlignment = (Pipe_BytesInPipe() & 0x07); + + if (Length >= 8) + { + Length -= BytesRemToAlignment; + + switch (BytesRemToAlignment) + { + default: + do + { + if (!(Pipe_IsReadWriteAllowed())) + { + Pipe_ClearIN(); + + #if !defined(NO_STREAM_CALLBACKS) + if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) + return PIPE_RWSTREAM_CallbackAborted; + #endif + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + } + + Length -= 8; + + *(DataStream--) = Pipe_Read_Byte(); + case 7: *(DataStream--) = Pipe_Read_Byte(); + case 6: *(DataStream--) = Pipe_Read_Byte(); + case 5: *(DataStream--) = Pipe_Read_Byte(); + case 4: *(DataStream--) = Pipe_Read_Byte(); + case 3: *(DataStream--) = Pipe_Read_Byte(); + case 2: *(DataStream--) = Pipe_Read_Byte(); + case 1: *(DataStream--) = Pipe_Read_Byte(); + } while (Length >= 8); + } + } + #endif + while (Length) { if (!(Pipe_IsReadWriteAllowed())) @@ -265,7 +479,7 @@ uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length #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())) @@ -278,7 +492,7 @@ uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length } } - return PIPE_RWSTREAM_ERROR_NoError; + return PIPE_RWSTREAM_NoError; } #endif