Changed over manual loops waiting for endpoints to be ready to use the library Endpoi...
authorDean Camera <dean@fourwalledcubicle.com>
Wed, 5 Aug 2009 09:37:45 +0000 (09:37 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Wed, 5 Aug 2009 09:37:45 +0000 (09:37 +0000)
Demos/Device/ClassDriver/MassStorage/Lib/DataflashManager.c
Demos/Device/ClassDriver/MassStorage/MassStorage.h
Demos/Device/LowLevel/CDC/CDC.c
Demos/Device/LowLevel/DualCDC/DualCDC.c
Demos/Device/LowLevel/MassStorage/Lib/DataflashManager.c
Demos/Device/LowLevel/MassStorage/MassStorage.h
Demos/Device/LowLevel/USBtoSerial/USBtoSerial.c
LUFA/Drivers/USB/Class/Device/CDC.c
LUFA/Drivers/USB/HighLevel/USBInterrupt.c

index 5f12d02..3858d38 100644 (file)
@@ -69,11 +69,8 @@ void DataflashManager_WriteBlocks(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, co
        Dataflash_SendAddressBytes(0, CurrDFPageByte);\r
 \r
        /* Wait until endpoint is ready before continuing */\r
-       while (!(Endpoint_IsReadWriteAllowed()))\r
-       {\r
-               if (USB_DeviceState == DEVICE_STATE_Unattached)\r
-                 return;\r
-       }\r
+       if (Endpoint_WaitUntilReady())\r
+         return;\r
 \r
        while (TotalBlocks)\r
        {\r
@@ -89,11 +86,8 @@ void DataflashManager_WriteBlocks(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, co
                                Endpoint_ClearOUT();\r
                                \r
                                /* Wait until the host has sent another packet */\r
-                               while (!(Endpoint_IsReadWriteAllowed()))\r
-                               {\r
-                                       if (USB_DeviceState == DEVICE_STATE_Unattached)\r
-                                         return;\r
-                               }\r
+                               if (Endpoint_WaitUntilReady())\r
+                                 return;\r
                        }\r
 \r
                        /* Check if end of dataflash page reached */\r
@@ -205,11 +199,8 @@ void DataflashManager_ReadBlocks(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, con
        Dataflash_SendByte(0x00);\r
        \r
        /* Wait until endpoint is ready before continuing */\r
-       while (!(Endpoint_IsReadWriteAllowed()))\r
-       {\r
-               if (USB_DeviceState == DEVICE_STATE_Unattached)\r
-                 return;\r
-       }\r
+       if (Endpoint_WaitUntilReady())\r
+         return;\r
        \r
        while (TotalBlocks)\r
        {\r
@@ -225,11 +216,8 @@ void DataflashManager_ReadBlocks(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, con
                                Endpoint_ClearIN();\r
                                \r
                                /* Wait until the endpoint is ready for more data */\r
-                               while (!(Endpoint_IsReadWriteAllowed()))\r
-                               {\r
-                                       if (USB_DeviceState == DEVICE_STATE_Unattached)\r
-                                         return;\r
-                               }\r
+                               if (Endpoint_WaitUntilReady())\r
+                                 return;\r
                        }\r
                        \r
                        /* Check if end of dataflash page reached */\r
index e6b2bf9..930e8f4 100644 (file)
@@ -70,7 +70,7 @@
                #define LEDMASK_USB_BUSY         (LEDS_LED2)\r
                \r
                /** Total number of logical drives within the device - must be non-zero. */\r
-               #define TOTAL_LUNS                2\r
+               #define TOTAL_LUNS                1\r
                \r
                /** Blocks in each LUN, calculated from the total capacity divided by the total number of Logical Units in the device. */\r
                #define LUN_MEDIA_BLOCKS         (VIRTUAL_MEMORY_BLOCKS / TOTAL_LUNS)\r
index 9ee744e..12cd8c4 100644 (file)
@@ -62,11 +62,8 @@ static int CDC_putchar(char c, FILE *stream)
        if (!(LineEncoding.BaudRateBPS))\r
          return -1;\r
        \r
-       while (!(Endpoint_IsReadWriteAllowed()))\r
-       {\r
-               if (USB_DeviceState != DEVICE_STATE_Configured)\r
-                 return -1;\r
-       }\r
+       if (Endpoint_WaitUntilReady())\r
+         return -1;\r
 \r
        Endpoint_Write_Byte(c);\r
        Endpoint_ClearIN();\r
@@ -85,11 +82,8 @@ static int CDC_getchar(FILE *stream)
        \r
        for (;;)\r
        {\r
-               while (!(Endpoint_IsReadWriteAllowed()))\r
-               {\r
-                       if (USB_DeviceState != DEVICE_STATE_Configured)\r
-                         return -1;\r
-               }\r
+               if (Endpoint_WaitUntilReady())\r
+                 return -1;\r
        \r
                if (!(Endpoint_BytesInEndpoint()))\r
                {\r
@@ -327,11 +321,7 @@ void CDC_Task(void)
                if (IsFull)\r
                {\r
                        /* Wait until the endpoint is ready for another packet */\r
-                       while (!(Endpoint_IsINReady()))\r
-                       {\r
-                               if (USB_DeviceState == DEVICE_STATE_Unattached)\r
-                                 return;\r
-                       }\r
+                       Endpoint_WaitUntilReady();\r
                        \r
                        /* Send an empty packet to ensure that the host does not buffer data sent to it */\r
                        Endpoint_ClearIN();\r
index c49a1ad..7a84c8d 100644 (file)
@@ -274,11 +274,7 @@ void CDC1_Task(void)
                Endpoint_ClearIN();\r
 \r
                /* Wait until the endpoint is ready for another packet */\r
-               while (!(Endpoint_IsINReady()))\r
-               {\r
-                       if (USB_DeviceState == DEVICE_STATE_Unattached)\r
-                         return;\r
-               }\r
+               Endpoint_WaitUntilReady();\r
                \r
                /* Send an empty packet to ensure that the host does not buffer data sent to it */\r
                Endpoint_ClearIN();\r
@@ -329,11 +325,7 @@ void CDC2_Task(void)
                Endpoint_ClearIN();\r
 \r
                /* Wait until the endpoint is ready for the next packet */\r
-               while (!(Endpoint_IsINReady()))\r
-               {\r
-                       if (USB_DeviceState == DEVICE_STATE_Unattached)\r
-                         return;\r
-               }\r
+               Endpoint_WaitUntilReady();\r
 \r
                /* Send an empty packet to prevent host buffering */\r
                Endpoint_ClearIN();\r
index 2bd03c9..9cd0279 100644 (file)
@@ -68,11 +68,8 @@ void DataflashManager_WriteBlocks(const uint32_t BlockAddress, uint16_t TotalBlo
        Dataflash_SendAddressBytes(0, CurrDFPageByte);\r
 \r
        /* Wait until endpoint is ready before continuing */\r
-       while (!(Endpoint_IsReadWriteAllowed()))\r
-       {\r
-               if (USB_DeviceState == DEVICE_STATE_Unattached)\r
-                 return;\r
-       }\r
+       if (Endpoint_WaitUntilReady())\r
+         return;\r
        \r
        while (TotalBlocks)\r
        {\r
@@ -88,11 +85,8 @@ void DataflashManager_WriteBlocks(const uint32_t BlockAddress, uint16_t TotalBlo
                                Endpoint_ClearOUT();\r
                                \r
                                /* Wait until the host has sent another packet */\r
-                               while (!(Endpoint_IsReadWriteAllowed()))\r
-                               {\r
-                                       if (USB_DeviceState == DEVICE_STATE_Unattached)\r
-                                         return;\r
-                               }\r
+                               if (Endpoint_WaitUntilReady())\r
+                                 return;\r
                        }\r
 \r
                        /* Check if end of dataflash page reached */\r
@@ -203,11 +197,8 @@ void DataflashManager_ReadBlocks(const uint32_t BlockAddress, uint16_t TotalBloc
        Dataflash_SendByte(0x00);\r
        \r
        /* Wait until endpoint is ready before continuing */\r
-       while (!(Endpoint_IsReadWriteAllowed()))\r
-       {\r
-               if (USB_DeviceState == DEVICE_STATE_Unattached)\r
-                 return;\r
-       }\r
+       if (Endpoint_WaitUntilReady())\r
+         return;\r
        \r
        while (TotalBlocks)\r
        {\r
@@ -223,11 +214,8 @@ void DataflashManager_ReadBlocks(const uint32_t BlockAddress, uint16_t TotalBloc
                                Endpoint_ClearIN();\r
                                \r
                                /* Wait until the endpoint is ready for more data */\r
-                               while (!(Endpoint_IsReadWriteAllowed()))\r
-                               {\r
-                                       if (USB_DeviceState == DEVICE_STATE_Unattached)\r
-                                         return;\r
-                               }\r
+                               if (Endpoint_WaitUntilReady())\r
+                                 return;\r
                        }\r
                        \r
                        /* Check if end of dataflash page reached */\r
index 868daf0..65407c8 100644 (file)
@@ -64,7 +64,7 @@
                /** Total number of Logical Units (drives) in the device. The total device capacity is shared equally between\r
                 *  each drive - this can be set to any positive non-zero amount.\r
                 */\r
-               #define TOTAL_LUNS                 2\r
+               #define TOTAL_LUNS                 1\r
                \r
                /** Blocks in each LUN, calculated from the total capacity divided by the total number of Logical Units in the device. */\r
                #define LUN_MEDIA_BLOCKS           (VIRTUAL_MEMORY_BLOCKS / TOTAL_LUNS)    \r
index bb1b4da..736c0af 100644 (file)
@@ -263,11 +263,7 @@ void CDC_Task(void)
        if ((Tx_Buffer.Elements) && LineEncoding.BaudRateBPS)\r
        {\r
                /* Wait until Serial Tx Endpoint Ready for Read/Write */\r
-               while (!(Endpoint_IsReadWriteAllowed()))\r
-               {\r
-                       if (USB_DeviceState == DEVICE_STATE_Unattached)\r
-                         return;\r
-               }\r
+               Endpoint_WaitUntilReady();\r
                \r
                /* Write the bytes from the buffer to the endpoint while space is available */\r
                while (Tx_Buffer.Elements && Endpoint_IsReadWriteAllowed())\r
@@ -287,11 +283,7 @@ void CDC_Task(void)
                if (IsFull && !(Tx_Buffer.Elements))\r
                {\r
                        /* Wait until Serial Tx Endpoint Ready for Read/Write */\r
-                       while (!(Endpoint_IsReadWriteAllowed()))\r
-                       {\r
-                               if (USB_DeviceState == DEVICE_STATE_Unattached)\r
-                                 return;\r
-                       }\r
+                       Endpoint_WaitUntilReady();\r
                                \r
                        /* Send an empty packet to terminate the transfer */\r
                        Endpoint_ClearIN();\r
index 9da0ed1..0d6b378 100644 (file)
@@ -126,12 +126,7 @@ void CDC_Device_USBTask(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)
        if (!(Endpoint_IsReadWriteAllowed()))\r
        {\r
                Endpoint_ClearIN();\r
-\r
-               while (!(Endpoint_IsReadWriteAllowed()))\r
-               {\r
-                       if (USB_DeviceState == DEVICE_STATE_Unattached)\r
-                         return;\r
-               }\r
+               Endpoint_WaitUntilReady();\r
        }       \r
        \r
        Endpoint_ClearIN();\r
@@ -156,12 +151,7 @@ void CDC_Device_SendByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo, con
        if (!(Endpoint_IsReadWriteAllowed()))\r
        {\r
                Endpoint_ClearIN();\r
-               \r
-               while (!(Endpoint_IsReadWriteAllowed()))\r
-               {\r
-                       if (USB_DeviceState == DEVICE_STATE_Unattached)\r
-                         return;               \r
-               }\r
+               Endpoint_WaitUntilReady();\r
        }\r
 \r
        Endpoint_Write_Byte(Data);      \r
index a039dff..00fe7d1 100644 (file)
@@ -223,7 +223,7 @@ ISR(USB_GEN_vect, ISR_BLOCK)
 }\r
 \r
 #if defined(INTERRUPT_CONTROL_ENDPOINT)\r
-ISR(USB_COM_vect, ISR_NOBLOCK)\r
+ISR(USB_COM_vect, ISR_BLOCK)\r
 {\r
        uint8_t PrevSelectedEndpoint = Endpoint_GetCurrentEndpoint();\r
 \r
@@ -231,6 +231,6 @@ ISR(USB_COM_vect, ISR_NOBLOCK)
 \r
        USB_INT_Clear(USB_INT_ENDPOINT_SETUP);\r
        \r
-       Endpoint_SelectEndpoint(PrevSelectedEndpoint);  \r
+       Endpoint_SelectEndpoint(PrevSelectedEndpoint);\r
 }\r
 #endif\r