X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/e72f424f6450cf67d3ef57d347a4f8d86ec5a119..039a714ee46268c07928c79b30403f29d4040fe8:/LUFA/Drivers/USB/HighLevel/PipeStream.c diff --git a/LUFA/Drivers/USB/HighLevel/PipeStream.c b/LUFA/Drivers/USB/HighLevel/PipeStream.c index 72a7e64d3..4465471a8 100644 --- a/LUFA/Drivers/USB/HighLevel/PipeStream.c +++ b/LUFA/Drivers/USB/HighLevel/PipeStream.c @@ -1,13 +1,13 @@ /* LUFA Library - Copyright (C) Dean Camera, 2010. + Copyright (C) Dean Camera, 2011. dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com + www.lufa-lib.org */ /* - Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted @@ -35,74 +35,84 @@ #include "PipeStream.h" -uint8_t Pipe_Discard_Stream(uint16_t Length - __CALLBACK_PARAM) +uint8_t Pipe_Discard_Stream(uint16_t Length, + uint16_t* const BytesProcessed) { uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; Pipe_SetPipeToken(PIPE_TOKEN_IN); if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; - #if defined(FAST_STREAM_TRANSFERS) - uint8_t BytesRemToAlignment = (Pipe_BytesInPipe() & 0x07); + if (BytesProcessed != NULL) + Length -= *BytesProcessed; - if (Length >= 8) + while (Length) { - Length -= BytesRemToAlignment; + if (!(Pipe_IsReadWriteAllowed())) + { + Pipe_ClearIN(); + + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return PIPE_RWSTREAM_IncompleteTransfer; + } - switch (BytesRemToAlignment) + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + } + else { - 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); + Pipe_Discard_Byte(); + + Length--; + BytesInTransfer++; } } - #endif + + return PIPE_RWSTREAM_NoError; +} + +uint8_t Pipe_Null_Stream(uint16_t Length, + uint16_t* const BytesProcessed) +{ + uint8_t ErrorCode; + uint16_t BytesInTransfer = 0; + + Pipe_SetPipeToken(PIPE_TOKEN_OUT); + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + + if (BytesProcessed != NULL) + Length -= *BytesProcessed; while (Length) { if (!(Pipe_IsReadWriteAllowed())) { - Pipe_ClearIN(); + Pipe_ClearOUT(); - #if !defined(NO_STREAM_CALLBACKS) - if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return PIPE_RWSTREAM_CallbackAborted; - #endif + if (BytesProcessed != NULL) + { + *BytesProcessed += BytesInTransfer; + return PIPE_RWSTREAM_IncompleteTransfer; + } + + USB_USBTask(); if ((ErrorCode = Pipe_WaitUntilReady())) return ErrorCode; } else { - Pipe_Discard_Byte(); + Pipe_Write_Byte(0); + Length--; + BytesInTransfer++; } } @@ -117,7 +127,8 @@ uint8_t Pipe_Discard_Stream(uint16_t Length #define TEMPLATE_TOKEN PIPE_TOKEN_OUT #define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() #define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(*((uint8_t*)BufferPtr++)) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(*BufferPtr) #include "Template/Template_Pipe_RW.c" #define TEMPLATE_FUNC_NAME Pipe_Write_PStream_LE @@ -125,7 +136,8 @@ uint8_t Pipe_Discard_Stream(uint16_t Length #define TEMPLATE_TOKEN PIPE_TOKEN_OUT #define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() #define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr++)) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(pgm_read_byte(BufferPtr)) #include "Template/Template_Pipe_RW.c" #define TEMPLATE_FUNC_NAME Pipe_Write_EStream_LE @@ -133,7 +145,8 @@ uint8_t Pipe_Discard_Stream(uint16_t Length #define TEMPLATE_TOKEN PIPE_TOKEN_OUT #define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() #define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr++)) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(eeprom_read_byte(BufferPtr)) #include "Template/Template_Pipe_RW.c" #define TEMPLATE_FUNC_NAME Pipe_Write_Stream_BE @@ -141,7 +154,8 @@ uint8_t Pipe_Discard_Stream(uint16_t Length #define TEMPLATE_TOKEN PIPE_TOKEN_OUT #define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(*((uint8_t*)BufferPtr--)) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(*BufferPtr) #include "Template/Template_Pipe_RW.c" #define TEMPLATE_FUNC_NAME Pipe_Write_PStream_BE @@ -149,7 +163,8 @@ uint8_t Pipe_Discard_Stream(uint16_t Length #define TEMPLATE_TOKEN PIPE_TOKEN_OUT #define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr--)) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(pgm_read_byte(BufferPtr)) #include "Template/Template_Pipe_RW.c" #define TEMPLATE_FUNC_NAME Pipe_Write_EStream_BE @@ -157,7 +172,8 @@ uint8_t Pipe_Discard_Stream(uint16_t Length #define TEMPLATE_TOKEN PIPE_TOKEN_OUT #define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr--)) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(eeprom_read_byte(BufferPtr)) #include "Template/Template_Pipe_RW.c" #define TEMPLATE_FUNC_NAME Pipe_Read_Stream_LE @@ -165,7 +181,8 @@ uint8_t Pipe_Discard_Stream(uint16_t Length #define TEMPLATE_TOKEN PIPE_TOKEN_IN #define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN() #define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr++) = Pipe_Read_Byte() +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Pipe_Read_Byte() #include "Template/Template_Pipe_RW.c" #define TEMPLATE_FUNC_NAME Pipe_Read_EStream_LE @@ -173,7 +190,8 @@ uint8_t Pipe_Discard_Stream(uint16_t Length #define TEMPLATE_TOKEN PIPE_TOKEN_IN #define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN() #define TEMPLATE_BUFFER_OFFSET(Length) 0 -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr++, Pipe_Read_Byte()) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream += Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Pipe_Read_Byte()) #include "Template/Template_Pipe_RW.c" #define TEMPLATE_FUNC_NAME Pipe_Read_Stream_BE @@ -181,7 +199,8 @@ uint8_t Pipe_Discard_Stream(uint16_t Length #define TEMPLATE_TOKEN PIPE_TOKEN_IN #define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN() #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr--) = Pipe_Read_Byte() +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Pipe_Read_Byte() #include "Template/Template_Pipe_RW.c" #define TEMPLATE_FUNC_NAME Pipe_Read_EStream_BE @@ -189,7 +208,9 @@ uint8_t Pipe_Discard_Stream(uint16_t Length #define TEMPLATE_TOKEN PIPE_TOKEN_IN #define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN() #define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1) -#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr--, Pipe_Read_Byte()) +#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) DataStream -= Amount +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Pipe_Read_Byte()) #include "Template/Template_Pipe_RW.c" #endif +