Move the length decrements in the pipe and endpoint stream functions to the point...
authorDean Camera <dean@fourwalledcubicle.com>
Sun, 26 Apr 2009 05:01:06 +0000 (05:01 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Sun, 26 Apr 2009 05:01:06 +0000 (05:01 +0000)
LUFA/Drivers/USB/LowLevel/Endpoint.c
LUFA/Drivers/USB/LowLevel/Pipe.c

index 4615baa..a872a00 100644 (file)
@@ -117,7 +117,7 @@ uint8_t Endpoint_Discard_Stream(uint16_t Length
        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
-       while (Length--)\r
+       while (Length)\r
        {\r
                if (!(Endpoint_IsReadWriteAllowed()))\r
                {\r
        {\r
                if (!(Endpoint_IsReadWriteAllowed()))\r
                {\r
@@ -134,6 +134,7 @@ uint8_t Endpoint_Discard_Stream(uint16_t Length
                else\r
                {\r
                        Endpoint_Discard_Byte();\r
                else\r
                {\r
                        Endpoint_Discard_Byte();\r
+                       Length--;\r
                }\r
        }\r
        \r
                }\r
        }\r
        \r
@@ -152,7 +153,7 @@ uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length
        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
-       while (Length--)\r
+       while (Length)\r
        {\r
                if (!(Endpoint_IsReadWriteAllowed()))\r
                {\r
        {\r
                if (!(Endpoint_IsReadWriteAllowed()))\r
                {\r
@@ -169,6 +170,7 @@ uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length
                else\r
                {\r
                        Endpoint_Write_Byte(*(DataStream++));\r
                else\r
                {\r
                        Endpoint_Write_Byte(*(DataStream++));\r
+                       Length--;\r
                }\r
        }\r
        \r
                }\r
        }\r
        \r
@@ -187,7 +189,7 @@ uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length
        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
-       while (Length--)\r
+       while (Length)\r
        {\r
                if (!(Endpoint_IsReadWriteAllowed()))\r
                {\r
        {\r
                if (!(Endpoint_IsReadWriteAllowed()))\r
                {\r
@@ -204,6 +206,7 @@ uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length
                else\r
                {\r
                        Endpoint_Write_Byte(*(DataStream--));\r
                else\r
                {\r
                        Endpoint_Write_Byte(*(DataStream--));\r
+                       Length--;\r
                }\r
        }\r
        \r
                }\r
        }\r
        \r
@@ -222,7 +225,7 @@ uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length
        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
-       while (Length--)\r
+       while (Length)\r
        {\r
                if (!(Endpoint_IsReadWriteAllowed()))\r
                {\r
        {\r
                if (!(Endpoint_IsReadWriteAllowed()))\r
                {\r
@@ -239,6 +242,7 @@ uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length
                else\r
                {\r
                        *(DataStream++) = Endpoint_Read_Byte();\r
                else\r
                {\r
                        *(DataStream++) = Endpoint_Read_Byte();\r
+                       Length--;\r
                }\r
        }\r
        \r
                }\r
        }\r
        \r
@@ -257,7 +261,7 @@ uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length
        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
-       while (Length--)\r
+       while (Length)\r
        {\r
                if (!(Endpoint_IsReadWriteAllowed()))\r
                {\r
        {\r
                if (!(Endpoint_IsReadWriteAllowed()))\r
                {\r
@@ -274,6 +278,7 @@ uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length
                else\r
                {\r
                        *(DataStream--) = Endpoint_Read_Byte();\r
                else\r
                {\r
                        *(DataStream--) = Endpoint_Read_Byte();\r
+                       Length--;\r
                }\r
        }\r
        \r
                }\r
        }\r
        \r
@@ -294,7 +299,6 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)
                while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))\r
                {\r
                        Endpoint_Write_Byte(*(DataStream++));\r
                while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))\r
                {\r
                        Endpoint_Write_Byte(*(DataStream++));\r
-                       \r
                        Length--;\r
                }\r
                \r
                        Length--;\r
                }\r
                \r
@@ -329,7 +333,6 @@ uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length)
                while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))\r
                {\r
                        Endpoint_Write_Byte(*(DataStream--));\r
                while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))\r
                {\r
                        Endpoint_Write_Byte(*(DataStream--));\r
-                       \r
                        Length--;\r
                }\r
                \r
                        Length--;\r
                }\r
                \r
@@ -362,7 +365,6 @@ uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length)
                while (Length && Endpoint_BytesInEndpoint())\r
                {\r
                        *(DataStream++) = Endpoint_Read_Byte();\r
                while (Length && Endpoint_BytesInEndpoint())\r
                {\r
                        *(DataStream++) = Endpoint_Read_Byte();\r
-                       \r
                        Length--;\r
                }\r
                \r
                        Length--;\r
                }\r
                \r
@@ -385,7 +387,6 @@ uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length)
                while (Length && Endpoint_BytesInEndpoint())\r
                {\r
                        *(DataStream--) = Endpoint_Read_Byte();\r
                while (Length && Endpoint_BytesInEndpoint())\r
                {\r
                        *(DataStream--) = Endpoint_Read_Byte();\r
-                       \r
                        Length--;\r
                }\r
                \r
                        Length--;\r
                }\r
                \r
index ff4318c..4bd89ec 100644 (file)
@@ -114,7 +114,7 @@ uint8_t Pipe_Write_Stream_LE(const void* Data, uint16_t Length
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
-       while (Length--)\r
+       while (Length)\r
        {\r
                if (!(Pipe_IsReadWriteAllowed()))\r
                {\r
        {\r
                if (!(Pipe_IsReadWriteAllowed()))\r
                {\r
@@ -131,6 +131,7 @@ uint8_t Pipe_Write_Stream_LE(const void* Data, uint16_t Length
                else\r
                {\r
                        Pipe_Write_Byte(*(DataStream++));\r
                else\r
                {\r
                        Pipe_Write_Byte(*(DataStream++));\r
+                       Length--;\r
                }\r
        }\r
 \r
                }\r
        }\r
 \r
@@ -149,7 +150,7 @@ uint8_t Pipe_Write_Stream_BE(const void* Data, uint16_t Length
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
-       while (Length--)\r
+       while (Length)\r
        {\r
                if (!(Pipe_IsReadWriteAllowed()))\r
                {\r
        {\r
                if (!(Pipe_IsReadWriteAllowed()))\r
                {\r
@@ -166,6 +167,7 @@ uint8_t Pipe_Write_Stream_BE(const void* Data, uint16_t Length
                else\r
                {\r
                        Pipe_Write_Byte(*(DataStream--));\r
                else\r
                {\r
                        Pipe_Write_Byte(*(DataStream--));\r
+                       Length--;\r
                }\r
        }\r
 \r
                }\r
        }\r
 \r
@@ -183,7 +185,7 @@ uint8_t Pipe_Discard_Stream(uint16_t Length
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
-       while (Length--)\r
+       while (Length)\r
        {\r
                if (!(Pipe_IsReadWriteAllowed()))\r
                {\r
        {\r
                if (!(Pipe_IsReadWriteAllowed()))\r
                {\r
@@ -200,6 +202,7 @@ uint8_t Pipe_Discard_Stream(uint16_t Length
                else\r
                {\r
                        Pipe_Discard_Byte();\r
                else\r
                {\r
                        Pipe_Discard_Byte();\r
+                       Length--;\r
                }\r
        }\r
 \r
                }\r
        }\r
 \r
@@ -218,7 +221,7 @@ uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
-       while (Length--)\r
+       while (Length)\r
        {\r
                if (!(Pipe_IsReadWriteAllowed()))\r
                {\r
        {\r
                if (!(Pipe_IsReadWriteAllowed()))\r
                {\r
@@ -235,6 +238,7 @@ uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length
                else\r
                {\r
                        *(DataStream++) = Pipe_Read_Byte();\r
                else\r
                {\r
                        *(DataStream++) = Pipe_Read_Byte();\r
+                       Length--;\r
                }\r
        }\r
 \r
                }\r
        }\r
 \r
@@ -253,7 +257,7 @@ uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
        if ((ErrorCode = Pipe_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
-       while (Length--)\r
+       while (Length)\r
        {\r
                if (!(Pipe_IsReadWriteAllowed()))\r
                {\r
        {\r
                if (!(Pipe_IsReadWriteAllowed()))\r
                {\r
@@ -270,6 +274,7 @@ uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length
                else\r
                {\r
                        *(DataStream--) = Pipe_Read_Byte();\r
                else\r
                {\r
                        *(DataStream--) = Pipe_Read_Byte();\r
+                       Length--;\r
                }\r
        }\r
        \r
                }\r
        }\r
        \r