aboutsummaryrefslogtreecommitdiffstats
path: root/LUFA/Drivers/USB/HighLevel/EndpointStream.c
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2011-01-10 18:43:34 +0000
committerDean Camera <dean@fourwalledcubicle.com>2011-01-10 18:43:34 +0000
commitf555ad7ced743a19eb1eefaf5eaf536fcbe58d80 (patch)
treef4b5a0aca1ac3898544effcc366380935a97d720 /LUFA/Drivers/USB/HighLevel/EndpointStream.c
parent477a2047f48d4c59bdcef37a18847f0c6a4d758b (diff)
downloadlufa-f555ad7ced743a19eb1eefaf5eaf536fcbe58d80.tar.gz
lufa-f555ad7ced743a19eb1eefaf5eaf536fcbe58d80.tar.bz2
lufa-f555ad7ced743a19eb1eefaf5eaf536fcbe58d80.zip
Altered all endpoint/pipe stream transfers so that the new BytesProcessed parameter now points to a location where the number of bytes in the transfer that have been completed can be stored (or NULL if entire transaction should be performed in one chunk).
Added new Endpoint_Null_Stream() and Pipe_Null_stream() functions. Removed the NO_STREAM_CALLBACKS compile time option due to the new partial stream transfer feature replacing it. Fixed errors in the incomplete Test and Measurement device demo preventing proper operation (thanks to Pavel Plotnikov).
Diffstat (limited to 'LUFA/Drivers/USB/HighLevel/EndpointStream.c')
-rw-r--r--LUFA/Drivers/USB/HighLevel/EndpointStream.c120
1 files changed, 93 insertions, 27 deletions
diff --git a/LUFA/Drivers/USB/HighLevel/EndpointStream.c b/LUFA/Drivers/USB/HighLevel/EndpointStream.c
index c2bb3922c..974af682c 100644
--- a/LUFA/Drivers/USB/HighLevel/EndpointStream.c
+++ b/LUFA/Drivers/USB/HighLevel/EndpointStream.c
@@ -36,13 +36,17 @@
#include "EndpointStream.h"
#if !defined(CONTROL_ONLY_DEVICE)
-uint8_t Endpoint_Discard_Stream(uint16_t Length
- __CALLBACK_PARAM)
+uint8_t Endpoint_Discard_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed)
{
- uint8_t ErrorCode;
+ uint8_t ErrorCode;
+ uint16_t BytesInTransfer = 0;
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
+
+ if (BytesProcessed != NULL)
+ Length -= *BytesProcessed;
while (Length)
{
@@ -50,10 +54,11 @@ uint8_t Endpoint_Discard_Stream(uint16_t Length
{
Endpoint_ClearOUT();
- #if !defined(NO_STREAM_CALLBACKS)
- if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
- return ENDPOINT_RWSTREAM_CallbackAborted;
- #endif
+ if (BytesProcessed != NULL)
+ {
+ *BytesProcessed += BytesInTransfer;
+ return ENDPOINT_RWSTREAM_IncompleteTransfer;
+ }
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
@@ -61,7 +66,48 @@ uint8_t Endpoint_Discard_Stream(uint16_t Length
else
{
Endpoint_Discard_Byte();
+
+ Length--;
+ BytesInTransfer++;
+ }
+ }
+
+ return ENDPOINT_RWSTREAM_NoError;
+}
+
+uint8_t Endpoint_Null_Stream(uint16_t Length,
+ uint16_t* const BytesProcessed)
+{
+ uint8_t ErrorCode;
+ uint16_t BytesInTransfer = 0;
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+
+ if (BytesProcessed != NULL)
+ Length -= *BytesProcessed;
+
+ while (Length)
+ {
+ if (!(Endpoint_IsReadWriteAllowed()))
+ {
+ Endpoint_ClearIN();
+
+ if (BytesProcessed != NULL)
+ {
+ *BytesProcessed += BytesInTransfer;
+ return ENDPOINT_RWSTREAM_IncompleteTransfer;
+ }
+
+ if ((ErrorCode = Endpoint_WaitUntilReady()))
+ return ErrorCode;
+ }
+ else
+ {
+ Endpoint_Write_Byte(0);
+
Length--;
+ BytesInTransfer++;
}
}
@@ -72,122 +118,142 @@ uint8_t Endpoint_Discard_Stream(uint16_t Length
#define TEMPLATE_BUFFER_TYPE const void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr++))
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*BufferPtr)
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE
#define TEMPLATE_BUFFER_TYPE const void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr++))
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte(BufferPtr))
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE
#define TEMPLATE_BUFFER_TYPE const void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr++))
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte(BufferPtr))
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE
#define TEMPLATE_BUFFER_TYPE const void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr--))
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*BufferPtr)
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE
#define TEMPLATE_BUFFER_TYPE const void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr--))
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte(BufferPtr))
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE
#define TEMPLATE_BUFFER_TYPE const void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr--))
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte(BufferPtr))
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE
#define TEMPLATE_BUFFER_TYPE void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr++) = Endpoint_Read_Byte()
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_Byte()
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE
#define TEMPLATE_BUFFER_TYPE void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr++, Endpoint_Read_Byte())
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_Byte())
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE
#define TEMPLATE_BUFFER_TYPE void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr--) = Endpoint_Read_Byte()
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_Byte()
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE
#define TEMPLATE_BUFFER_TYPE void*
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr--, Endpoint_Read_Byte())
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_Byte())
#include "Template/Template_Endpoint_RW.c"
#endif
#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE
#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr++))
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*BufferPtr)
#include "Template/Template_Endpoint_Control_W.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE
#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr++))
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte(BufferPtr))
#include "Template/Template_Endpoint_Control_W.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE
#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr++))
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte(BufferPtr))
#include "Template/Template_Endpoint_Control_W.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*((uint8_t*)BufferPtr--))
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*BufferPtr)
#include "Template/Template_Endpoint_Control_W.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr--))
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte(BufferPtr))
#include "Template/Template_Endpoint_Control_W.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr--))
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte(BufferPtr))
#include "Template/Template_Endpoint_Control_W.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE
#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr++) = Endpoint_Read_Byte()
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_Byte()
#include "Template/Template_Endpoint_Control_R.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE
#define TEMPLATE_BUFFER_OFFSET(Length) 0
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr++, Endpoint_Read_Byte())
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr += Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_Byte())
#include "Template/Template_Endpoint_Control_R.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *((uint8_t*)BufferPtr--) = Endpoint_Read_Byte()
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *BufferPtr = Endpoint_Read_Byte()
#include "Template/Template_Endpoint_Control_R.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE
#define TEMPLATE_BUFFER_OFFSET(Length) (Length - 1)
-#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte((uint8_t*)BufferPtr--, Endpoint_Read_Byte())
+#define TEMPLATE_BUFFER_MOVE(BufferPtr, Amount) BufferPtr -= Amount
+#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_update_byte(BufferPtr, Endpoint_Read_Byte())
#include "Template/Template_Endpoint_Control_R.c"
#endif