X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/d860e9e842c05e759214f5170f78783decae9956..7366f590f5ab89e954a176eb7cc7fa713ce07d3e:/LUFA/Drivers/USB/LowLevel/Pipe.c diff --git a/LUFA/Drivers/USB/LowLevel/Pipe.c b/LUFA/Drivers/USB/LowLevel/Pipe.c index ff4318c99..1376de495 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,17 +108,19 @@ 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; - while (Length--) + while (Length) { if (!(Pipe_IsReadWriteAllowed())) { @@ -122,7 +128,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())) @@ -131,25 +137,28 @@ uint8_t Pipe_Write_Stream_LE(const void* Data, uint16_t Length 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 ) { uint8_t* DataStream = (uint8_t*)(Data + Length - 1); uint8_t ErrorCode; + Pipe_SetToken(PIPE_TOKEN_OUT); + if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; - while (Length--) + while (Length) { if (!(Pipe_IsReadWriteAllowed())) { @@ -157,7 +166,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())) @@ -166,24 +175,27 @@ uint8_t Pipe_Write_Stream_BE(const void* Data, uint16_t Length 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 ) { uint8_t ErrorCode; + Pipe_SetToken(PIPE_TOKEN_IN); + if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; - while (Length--) + while (Length) { if (!(Pipe_IsReadWriteAllowed())) { @@ -191,7 +203,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())) @@ -200,25 +212,28 @@ uint8_t Pipe_Discard_Stream(uint16_t Length 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) + , StreamCallbackPtr_t Callback #endif ) { uint8_t* DataStream = (uint8_t*)Buffer; uint8_t ErrorCode; + Pipe_SetToken(PIPE_TOKEN_IN); + if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; - while (Length--) + while (Length) { if (!(Pipe_IsReadWriteAllowed())) { @@ -226,7 +241,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())) @@ -235,25 +250,28 @@ uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length 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) + , 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; - while (Length--) + while (Length) { if (!(Pipe_IsReadWriteAllowed())) { @@ -261,7 +279,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())) @@ -270,10 +288,11 @@ uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length else { *(DataStream--) = Pipe_Read_Byte(); + Length--; } } - return PIPE_RWSTREAM_ERROR_NoError; + return PIPE_RWSTREAM_NoError; } #endif