diff options
author | Dean Camera <dean@fourwalledcubicle.com> | 2009-04-26 05:01:06 +0000 |
---|---|---|
committer | Dean Camera <dean@fourwalledcubicle.com> | 2009-04-26 05:01:06 +0000 |
commit | e21b620bf6cc9fb1bb9e516efb57b1cb12c00085 (patch) | |
tree | 4df534c35d2aa8b6d57a26fe18651c9a12d412b2 /LUFA/Drivers | |
parent | a504a3a010ec2441dda0209f195492fb36e7c97b (diff) | |
download | lufa-e21b620bf6cc9fb1bb9e516efb57b1cb12c00085.tar.gz lufa-e21b620bf6cc9fb1bb9e516efb57b1cb12c00085.tar.bz2 lufa-e21b620bf6cc9fb1bb9e516efb57b1cb12c00085.zip |
Move the length decrements in the pipe and endpoint stream functions to the point at which the buffers are operated on, to prevent decrements during iterations where no data is exchanged (thanks to Francisco Moraes).
Diffstat (limited to 'LUFA/Drivers')
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/Endpoint.c | 19 | ||||
-rw-r--r-- | LUFA/Drivers/USB/LowLevel/Pipe.c | 15 |
2 files changed, 20 insertions, 14 deletions
diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.c b/LUFA/Drivers/USB/LowLevel/Endpoint.c index 4615baa69..a872a00ff 100644 --- a/LUFA/Drivers/USB/LowLevel/Endpoint.c +++ b/LUFA/Drivers/USB/LowLevel/Endpoint.c @@ -117,7 +117,7 @@ uint8_t Endpoint_Discard_Stream(uint16_t Length if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
- while (Length--)
+ while (Length)
{
if (!(Endpoint_IsReadWriteAllowed()))
{
@@ -134,6 +134,7 @@ uint8_t Endpoint_Discard_Stream(uint16_t Length else
{
Endpoint_Discard_Byte();
+ Length--;
}
}
@@ -152,7 +153,7 @@ uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
- while (Length--)
+ while (Length)
{
if (!(Endpoint_IsReadWriteAllowed()))
{
@@ -169,6 +170,7 @@ uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length else
{
Endpoint_Write_Byte(*(DataStream++));
+ Length--;
}
}
@@ -187,7 +189,7 @@ uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
- while (Length--)
+ while (Length)
{
if (!(Endpoint_IsReadWriteAllowed()))
{
@@ -204,6 +206,7 @@ uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length else
{
Endpoint_Write_Byte(*(DataStream--));
+ Length--;
}
}
@@ -222,7 +225,7 @@ uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
- while (Length--)
+ while (Length)
{
if (!(Endpoint_IsReadWriteAllowed()))
{
@@ -239,6 +242,7 @@ uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length else
{
*(DataStream++) = Endpoint_Read_Byte();
+ Length--;
}
}
@@ -257,7 +261,7 @@ uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
- while (Length--)
+ while (Length)
{
if (!(Endpoint_IsReadWriteAllowed()))
{
@@ -274,6 +278,7 @@ uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length else
{
*(DataStream--) = Endpoint_Read_Byte();
+ Length--;
}
}
@@ -294,7 +299,6 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length) while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))
{
Endpoint_Write_Byte(*(DataStream++));
-
Length--;
}
@@ -329,7 +333,6 @@ uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length) while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))
{
Endpoint_Write_Byte(*(DataStream--));
-
Length--;
}
@@ -362,7 +365,6 @@ uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length) while (Length && Endpoint_BytesInEndpoint())
{
*(DataStream++) = Endpoint_Read_Byte();
-
Length--;
}
@@ -385,7 +387,6 @@ uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length) while (Length && Endpoint_BytesInEndpoint())
{
*(DataStream--) = Endpoint_Read_Byte();
-
Length--;
}
diff --git a/LUFA/Drivers/USB/LowLevel/Pipe.c b/LUFA/Drivers/USB/LowLevel/Pipe.c index ff4318c99..4bd89ecb5 100644 --- a/LUFA/Drivers/USB/LowLevel/Pipe.c +++ b/LUFA/Drivers/USB/LowLevel/Pipe.c @@ -114,7 +114,7 @@ uint8_t Pipe_Write_Stream_LE(const void* Data, uint16_t Length if ((ErrorCode = Pipe_WaitUntilReady()))
return ErrorCode;
- while (Length--)
+ while (Length)
{
if (!(Pipe_IsReadWriteAllowed()))
{
@@ -131,6 +131,7 @@ uint8_t Pipe_Write_Stream_LE(const void* Data, uint16_t Length else
{
Pipe_Write_Byte(*(DataStream++));
+ Length--;
}
}
@@ -149,7 +150,7 @@ uint8_t Pipe_Write_Stream_BE(const void* Data, uint16_t Length if ((ErrorCode = Pipe_WaitUntilReady()))
return ErrorCode;
- while (Length--)
+ while (Length)
{
if (!(Pipe_IsReadWriteAllowed()))
{
@@ -166,6 +167,7 @@ uint8_t Pipe_Write_Stream_BE(const void* Data, uint16_t Length else
{
Pipe_Write_Byte(*(DataStream--));
+ Length--;
}
}
@@ -183,7 +185,7 @@ uint8_t Pipe_Discard_Stream(uint16_t Length if ((ErrorCode = Pipe_WaitUntilReady()))
return ErrorCode;
- while (Length--)
+ while (Length)
{
if (!(Pipe_IsReadWriteAllowed()))
{
@@ -200,6 +202,7 @@ uint8_t Pipe_Discard_Stream(uint16_t Length else
{
Pipe_Discard_Byte();
+ Length--;
}
}
@@ -218,7 +221,7 @@ uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length if ((ErrorCode = Pipe_WaitUntilReady()))
return ErrorCode;
- while (Length--)
+ while (Length)
{
if (!(Pipe_IsReadWriteAllowed()))
{
@@ -235,6 +238,7 @@ uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length else
{
*(DataStream++) = Pipe_Read_Byte();
+ Length--;
}
}
@@ -253,7 +257,7 @@ uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length if ((ErrorCode = Pipe_WaitUntilReady()))
return ErrorCode;
- while (Length--)
+ while (Length)
{
if (!(Pipe_IsReadWriteAllowed()))
{
@@ -270,6 +274,7 @@ uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length else
{
*(DataStream--) = Pipe_Read_Byte();
+ Length--;
}
}
|