Minor updates to the Benito programmer - remove redundant PORT register manipulations.
[pub/USBasp.git] / Demos / Device / ClassDriver / MassStorage / Lib / DataflashManager.c
index f335b67..5f12d02 100644 (file)
@@ -43,6 +43,7 @@
  *  the pre-selected data OUT endpoint. This routine reads in OS sized blocks from the endpoint and writes\r
  *  them to the dataflash in Dataflash page sized blocks.\r
  *\r
+ *  \param[in] MSInterfaceInfo  Pointer to a structure containing a Mass Storage Class configuration and state.\r
  *  \param[in] BlockAddress  Data block starting address for the write sequence\r
  *  \param[in] TotalBlocks   Number of blocks of data to write\r
  */\r
@@ -68,7 +69,11 @@ 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
+       while (!(Endpoint_IsReadWriteAllowed()))\r
+       {\r
+               if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+                 return;\r
+       }\r
 \r
        while (TotalBlocks)\r
        {\r
@@ -84,7 +89,11 @@ 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
+                               while (!(Endpoint_IsReadWriteAllowed()))\r
+                               {\r
+                                       if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+                                         return;\r
+                               }\r
                        }\r
 \r
                        /* Check if end of dataflash page reached */\r
@@ -174,6 +183,7 @@ void DataflashManager_WriteBlocks(USB_ClassInfo_MS_Device_t* MSInterfaceInfo, co
  *  the pre-selected data IN endpoint. This routine reads in Dataflash page sized blocks from the Dataflash\r
  *  and writes them in OS sized blocks to the endpoint.\r
  *\r
+ *  \param[in] MSInterfaceInfo  Pointer to a structure containing a Mass Storage Class configuration and state.\r
  *  \param[in] BlockAddress  Data block starting address for the read sequence\r
  *  \param[in] TotalBlocks   Number of blocks of data to read\r
  */\r
@@ -195,7 +205,11 @@ 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
+       while (!(Endpoint_IsReadWriteAllowed()))\r
+       {\r
+               if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+                 return;\r
+       }\r
        \r
        while (TotalBlocks)\r
        {\r
@@ -211,7 +225,11 @@ 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
+                               while (!(Endpoint_IsReadWriteAllowed()))\r
+                               {\r
+                                       if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+                                         return;\r
+                               }\r
                        }\r
                        \r
                        /* Check if end of dataflash page reached */\r