Selaa lähdekoodia

Fix synchronous negotiation bug

Michael McMaster 9 vuotta sitten
vanhempi
sitoutus
6d1957316b
3 muutettua tiedostoa jossa 27 lisäystä ja 12 poistoa
  1. 1 3
      lib/SCSI2SD/Makefile
  2. 9 5
      lib/SCSI2SD/src/firmware/scsi.c
  3. 17 4
      lib/SCSI2SD/src/firmware/scsiPhy.c

+ 1 - 3
lib/SCSI2SD/Makefile

@@ -6,9 +6,7 @@ CPPFLAGS=-DSTM32F205xx -DUSE_HAL_DRIVER -Wall -Werror
 CFLAGS=-mcpu=cortex-m3 -mthumb -mslow-flash-data \
 	-std=gnu11 \
 	-specs=nosys.specs \
-	-g \
-
-#	-Os -g \
+	-Os -g \
 
 LDFLAGS= \
 	"-Tsrc/firmware/link.ld" \

+ 9 - 5
lib/SCSI2SD/src/firmware/scsi.c

@@ -757,8 +757,8 @@ static void process_MessageOut()
 		}
 		else if (extmsg[0] == 1 && msgLen == 3) // Synchronous data request
 		{
-			int transferPeriod = extmsg[3];
-			int offset = extmsg[4];
+			int transferPeriod = extmsg[1];
+			int offset = extmsg[2];
 
 			if (transferPeriod > 50) // 200ns, 5MB/s
 			{
@@ -766,11 +766,15 @@ static void process_MessageOut()
 				scsiDev.target->syncPeriod = 0;
 			} else {
 				scsiDev.target->syncOffset = offset < 15 ? offset : 15;
-				if (transferPeriod <= 25)
+				if (transferPeriod <= 12)
 				{
-					scsiDev.target->syncPeriod = 25; // 10MB/s
+					scsiDev.target->syncPeriod = 12; // 50ns, 20MB/s
+				}
+				else if (transferPeriod <= 25)
+				{
+					scsiDev.target->syncPeriod = 25; // 100ns, 10MB/s
 				} else {
-					scsiDev.target->syncPeriod = 50; // 5MB/s
+					scsiDev.target->syncPeriod = 50; // 200ns, 5MB/s
 				}
 			}
 

+ 17 - 4
lib/SCSI2SD/src/firmware/scsiPhy.c

@@ -28,16 +28,24 @@
 
 #include <string.h>
 
+// 5MB/s
 // Assumes a 60MHz fpga clock.
 // 7:6 Hold count, 45ns
 // 5:3 Assertion count, 90ns
 // 2:0 Deskew count, 55ns
 #define SCSI_DEFAULT_TIMING ((0x3 << 6) | (0x6 << 3) | 0x4)
 
-// 7:6 Hold count, 10ns
+// 10MB/s
+// 7:6 Hold count, 17ns
 // 5:3 Assertion count, 30ns
 // 2:0 Deskew count, 25ns
-#define SCSI_FAST_TIMING ((0x1 << 6) | (0x2 << 3) | 0x2)
+#define SCSI_FAST10_TIMING ((0x1 << 6) | (0x2 << 3) | 0x2)
+
+// 20MB/s
+// 7:6 Hold count, 17ns
+// 5:3 Assertion count, 17ns
+// 2:0 Deskew count, 17ns
+#define SCSI_FAST20_TIMING ((0x1 << 6) | (0x1 << 3) | 0x1)
 
 // Private DMA variables.
 static int dmaInProgress = 0;
@@ -406,10 +414,15 @@ void scsiEnterPhase(int phase)
 		if ((newPhase == DATA_IN || newPhase == DATA_OUT) &&
 			scsiDev.target->syncOffset)
 		{
-			if (scsiDev.target->syncPeriod == 25)
+			if (scsiDev.target->syncPeriod == 12)
+			{
+				// SCSI2 FAST-20 Timing. 20MB/s.
+				*SCSI_CTRL_TIMING = SCSI_FAST20_TIMING;
+			}
+			else if (scsiDev.target->syncPeriod == 25)
 			{
 				// SCSI2 FAST Timing. 10MB/s.
-				*SCSI_CTRL_TIMING = SCSI_FAST_TIMING;
+				*SCSI_CTRL_TIMING = SCSI_FAST10_TIMING;
 			} else {
 				// 5MB/s Timing
 				*SCSI_CTRL_TIMING = SCSI_DEFAULT_TIMING;