Don't check if the SD card is removed while in the middle of USB reads/writes
authorMichael McMaster <michael@codesrc.com>
Tue, 9 Mar 2021 11:58:04 +0000 (21:58 +1000)
committerMichael McMaster <michael@codesrc.com>
Tue, 9 Mar 2021 11:58:04 +0000 (21:58 +1000)
src/firmware/main.c
src/firmware/usb_device/usbd_composite.c
src/firmware/usb_device/usbd_composite.h

index d2d881660e162f5c58e01cbac1cf66116062803c..caea8e20a5d911ccc8de2b68e9384a2cf5562aa9 100755 (executable)
@@ -106,10 +106,10 @@ void mainLoop()
        s2s_configPoll();\r
 \r
 #ifdef S2S_USB_FS\r
-       s2s_usbDevicePoll(&hUsbDeviceFS);\r
+       int usbBusy = s2s_usbDevicePoll(&hUsbDeviceFS);\r
 #endif\r
 #ifdef S2S_USB_HS\r
-       s2s_usbDevicePoll(&hUsbDeviceHS);\r
+       int usbBusy = s2s_usbDevicePoll(&hUsbDeviceHS);\r
 #endif\r
 \r
 #if 0\r
@@ -117,7 +117,7 @@ void mainLoop()
 #endif\r
 \r
     // TODO test if USB transfer is in progress\r
-       if (unlikely(scsiDev.phase == BUS_FREE))\r
+       if (unlikely(scsiDev.phase == BUS_FREE) && !usbBusy)\r
        {\r
                if (unlikely(s2s_elapsedTime_ms(lastSDPoll) > 200))\r
                {\r
@@ -128,19 +128,23 @@ void mainLoop()
                                scsiPhyConfig();\r
                                scsiInit();\r
 \r
-/* TODO DEAL WITH THIS\r
                                if (isUsbStarted)\r
                                {\r
+#ifdef S2S_USB_FS\r
                                        USBD_Stop(&hUsbDeviceFS);\r
                                        s2s_delay_ms(128);\r
                                        USBD_Start(&hUsbDeviceFS);\r
+#endif\r
+#ifdef S2S_USB_HS\r
+                                       USBD_Stop(&hUsbDeviceHS);\r
+                                       s2s_delay_ms(128);\r
+                                       USBD_Start(&hUsbDeviceHS);\r
+#endif\r
                                }\r
-*/                     \r
                        }\r
-\r
                }\r
        }\r
-       else if ((scsiDev.phase >= 0) && (blockDev.state & DISK_PRESENT))\r
+       else if (usbBusy || ((scsiDev.phase >= 0) && (blockDev.state & DISK_PRESENT)))\r
        {\r
                // don't waste time scanning SD cards while we're doing disk IO\r
                lastSDPoll = s2s_getTime_ms();\r
index 32d98304c739b54c3b762d8edf6673ea505e3b59..a545b8ba96a05361e3bf00c59f3fcc628cbfef11 100755 (executable)
@@ -506,20 +506,26 @@ static uint8_t USBD_Composite_DataOut(USBD_HandleTypeDef  *pdev, uint8_t epnum)
        return USBD_OK;
 }
 
-void s2s_usbDevicePoll(USBD_HandleTypeDef  *pdev) {
+int s2s_usbDevicePoll(USBD_HandleTypeDef  *pdev) {
        USBD_CompositeClassData *classData = (USBD_CompositeClassData*) pdev->pClassData;
 
+    int busy = 0;
+
        if (classData->DataInReady)
        {
                classData->DataInReady = 0;
                MSC_BOT_DataIn(pdev);
+        busy = busy || 1;
        }
 
        if (classData->DataOutReady)
     {
                classData->DataOutReady = 0;
                MSC_BOT_DataOut(pdev);
+        busy = busy || 1;
        }
+
+    return busy;
 }
 
 
index dbb9778d05eeea9b11f06d858ba3c0bcaeb806af..7b331cd8d629ecd2d85d161575b919aba544f214 100755 (executable)
@@ -48,7 +48,8 @@ typedef struct {
 } USBD_CompositeClassData;
 
 
-void s2s_usbDevicePoll(USBD_HandleTypeDef* pdev);
+// Returns 1 if busy
+int s2s_usbDevicePoll(USBD_HandleTypeDef* pdev);
 
 static inline uint8_t USBD_Composite_IsConfigured(USBD_HandleTypeDef *pdev) {
        return pdev->dev_state == USBD_STATE_CONFIGURED;