Преглед изворни кода

Add SD keep-alive to ensure it responds immediately

Michael McMaster пре 4 година
родитељ
комит
7e2844503b

+ 1 - 0
lib/SCSI2SD/CHANGELOG

@@ -1,6 +1,7 @@
 20210628        6.4.11
     - Remove the "Blind Writes" option from scsi2sd-util. The firmware no longer
     requires this option for improved write performance
+    - Fix firmware hang if there was no activity for a few minutes
 
 20210508        6.4.4
     - More bug fixes for firmware hanging during read/writes

+ 1 - 1
lib/SCSI2SD/src/firmware/config.c

@@ -36,7 +36,7 @@
 
 #include <string.h>
 
-static const uint16_t FIRMWARE_VERSION = 0x064A;
+static const uint16_t FIRMWARE_VERSION = 0x064B;
 
 // Optional static config
 extern uint8_t* __fixed_config;

+ 9 - 2
lib/SCSI2SD/src/firmware/main.c

@@ -42,6 +42,7 @@
 
 const char* Notice = "Copyright (C) 2020 Michael McMaster <michael@codesrc.com>";
 uint32_t lastSDPoll;
+uint32_t lastSDKeepAlive;
 
 static int isUsbStarted;
 
@@ -131,7 +132,7 @@ void mainInit()
     s2s_ledOff();
 #endif
 
-    lastSDPoll = s2s_getTime_ms();
+    lastSDPoll = lastSDKeepAlive = s2s_getTime_ms();
 }
 
 void mainLoop()
@@ -180,11 +181,17 @@ void mainLoop()
                 }
             }
         }
+        else if (lastSDKeepAlive > 10000) // 10 seconds
+        {
+            // 2021 boards fail if there's no commands sent in a while
+            sdKeepAlive();
+            lastSDKeepAlive = s2s_getTime_ms();
+        }
     }
     else if (usbBusy || ((scsiDev.phase >= 0) && (blockDev.state & DISK_PRESENT)))
     {
         // don't waste time scanning SD cards while we're doing disk IO
-        lastSDPoll = s2s_getTime_ms();
+        lastSDPoll = lastSDKeepAlive = s2s_getTime_ms();
     }
 }
 

+ 4 - 4
lib/SCSI2SD/src/firmware/scsi.c

@@ -56,13 +56,13 @@ void enter_BusFree()
 		s2s_delay_us(2);
 	}
 
-#if 0
-	if (scsiDev.status != GOOD && isDebugEnabled())
+//#if 0
+	if (scsiDev.status != GOOD)// && isDebugEnabled())
 	{
 		// We want to capture debug information for failure cases.
-		s2s_delay_ms(64);
+		s2s_delay_ms(80);
 	}
-#endif
+//#endif
 
 
 	scsiEnterBusFree();

+ 4 - 0
lib/SCSI2SD/src/firmware/sd.c

@@ -222,3 +222,7 @@ int sdIsBusy()
     return HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_8) == 0;
 }
 
+void sdKeepAlive()
+{
+    /*HAL_SD_CardStateTypeDef cardState = */HAL_SD_GetCardState(&hsd);
+}

+ 1 - 0
lib/SCSI2SD/src/firmware/sd.h

@@ -37,6 +37,7 @@ int sdInit(void);
 void sdReadDMA(uint32_t lba, uint32_t sectors, uint8_t* outputBuffer);
 int sdReadDMAPoll(uint32_t remainingSectors);
 void sdCompleteTransfer();
+void sdKeepAlive();
 
 int sdIsBusy();