Browse Source

Improve IRQ handler responsiveness

Michael McMaster 4 years ago
parent
commit
2786ccdfe2

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

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

+ 16 - 9
lib/SCSI2SD/src/firmware/disk.c

@@ -657,7 +657,8 @@ void scsiDiskPoll()
 				}
 			}
 
-			if ((prep - i) > 0)
+			if (((prep - i) > 0) &&
+                scsiFifoReady())
 			{
 				int dmaBytes = SD_SECTOR_SIZE;
 				if ((i % sdPerScsi) == (sdPerScsi - 1))
@@ -679,20 +680,26 @@ void scsiDiskPoll()
 			phaseChangeDelayUs = 0;
 		}
 
+        // Wait for the SD transfer to complete before we disable IRQs.
+        // (Otherwise some cards will cause an error if we don't sent the
+        // stop transfer command via the DMA complete handler in time)
+		while (HAL_SD_GetState(&hsd) == HAL_SD_STATE_BUSY)
+		{
+			// Wait while keeping BSY.
+		}
+
 		// We've finished transferring the data to the FPGA, now wait until it's
 		// written to he SCSI bus.
-		__disable_irq();
 		while (!scsiPhyComplete() &&
 			likely(scsiDev.phase == DATA_IN) &&
 			likely(!scsiDev.resetFlag))
 		{
-			__WFI();
-		}
-		__enable_irq();
-
-		while (HAL_SD_GetState(&hsd) == HAL_SD_STATE_BUSY)
-		{
-			// Wait while keeping BSY.
+    		__disable_irq();
+		    if (!scsiPhyComplete() && likely(!scsiDev.resetFlag))
+            {
+			    __WFI();
+            }
+		    __enable_irq();
 		}
 
 		if (scsiDev.phase == DATA_IN)

+ 12 - 6
lib/SCSI2SD/src/firmware/scsiPhy.c

@@ -329,12 +329,15 @@ scsiRead(uint8_t* data, uint32_t count, int* parityError)
 
 		scsiReadPIO(data + i, chunk, parityError);
 
-		__disable_irq();
 		while (!scsiPhyComplete() && likely(!scsiDev.resetFlag))
 		{
-			__WFI();
+		    __disable_irq();
+            if (!scsiPhyComplete() && likely(!scsiDev.resetFlag))
+            {
+    			__WFI();
+            }
+		    __enable_irq();
 		}
-		__enable_irq();
 
 		i += chunk;
 	}
@@ -479,12 +482,15 @@ scsiWrite(const uint8_t* data, uint32_t count)
 
 		scsiWritePIO(data + i, chunk);
 
-		__disable_irq();
 		while (!scsiPhyComplete() && likely(!scsiDev.resetFlag))
 		{
-			__WFI();
+		    __disable_irq();
+		    if (!scsiPhyComplete() && likely(!scsiDev.resetFlag))
+            {
+    			__WFI();
+            }
+		    __enable_irq();
 		}
-		__enable_irq();
 
 		i += chunk;
 	}