Fix synchronous negotiation bug
authorMichael McMaster <michael@codesrc.com>
Sat, 27 Aug 2016 07:26:25 +0000 (17:26 +1000)
committerMichael McMaster <michael@codesrc.com>
Sat, 27 Aug 2016 07:26:25 +0000 (17:26 +1000)
Makefile
src/firmware/scsi.c
src/firmware/scsiPhy.c

index 0839fcd..350c858 100644 (file)
--- a/Makefile
+++ b/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" \
index e43afd2..ff54cd2 100755 (executable)
@@ -757,8 +757,8 @@ static void process_MessageOut()
                }\r
                else if (extmsg[0] == 1 && msgLen == 3) // Synchronous data request\r
                {\r
-                       int transferPeriod = extmsg[3];\r
-                       int offset = extmsg[4];\r
+                       int transferPeriod = extmsg[1];\r
+                       int offset = extmsg[2];\r
 \r
                        if (transferPeriod > 50) // 200ns, 5MB/s\r
                        {\r
@@ -766,11 +766,15 @@ static void process_MessageOut()
                                scsiDev.target->syncPeriod = 0;\r
                        } else {\r
                                scsiDev.target->syncOffset = offset < 15 ? offset : 15;\r
-                               if (transferPeriod <= 25)\r
+                               if (transferPeriod <= 12)\r
                                {\r
-                                       scsiDev.target->syncPeriod = 25; // 10MB/s\r
+                                       scsiDev.target->syncPeriod = 12; // 50ns, 20MB/s\r
+                               }\r
+                               else if (transferPeriod <= 25)\r
+                               {\r
+                                       scsiDev.target->syncPeriod = 25; // 100ns, 10MB/s\r
                                } else {\r
-                                       scsiDev.target->syncPeriod = 50; // 5MB/s\r
+                                       scsiDev.target->syncPeriod = 50; // 200ns, 5MB/s\r
                                }\r
                        }\r
 \r
index 71640f4..f424157 100755 (executable)
 \r
 #include <string.h>\r
 \r
+// 5MB/s\r
 // Assumes a 60MHz fpga clock.\r
 // 7:6 Hold count, 45ns\r
 // 5:3 Assertion count, 90ns\r
 // 2:0 Deskew count, 55ns\r
 #define SCSI_DEFAULT_TIMING ((0x3 << 6) | (0x6 << 3) | 0x4)\r
 \r
-// 7:6 Hold count, 10ns\r
+// 10MB/s\r
+// 7:6 Hold count, 17ns\r
 // 5:3 Assertion count, 30ns\r
 // 2:0 Deskew count, 25ns\r
-#define SCSI_FAST_TIMING ((0x1 << 6) | (0x2 << 3) | 0x2)\r
+#define SCSI_FAST10_TIMING ((0x1 << 6) | (0x2 << 3) | 0x2)\r
+\r
+// 20MB/s\r
+// 7:6 Hold count, 17ns\r
+// 5:3 Assertion count, 17ns\r
+// 2:0 Deskew count, 17ns\r
+#define SCSI_FAST20_TIMING ((0x1 << 6) | (0x1 << 3) | 0x1)\r
 \r
 // Private DMA variables.\r
 static int dmaInProgress = 0;\r
@@ -406,10 +414,15 @@ void scsiEnterPhase(int phase)
                if ((newPhase == DATA_IN || newPhase == DATA_OUT) &&\r
                        scsiDev.target->syncOffset)\r
                {\r
-                       if (scsiDev.target->syncPeriod == 25)\r
+                       if (scsiDev.target->syncPeriod == 12)\r
+                       {\r
+                               // SCSI2 FAST-20 Timing. 20MB/s.\r
+                               *SCSI_CTRL_TIMING = SCSI_FAST20_TIMING;\r
+                       }\r
+                       else if (scsiDev.target->syncPeriod == 25)\r
                        {\r
                                // SCSI2 FAST Timing. 10MB/s.\r
-                               *SCSI_CTRL_TIMING = SCSI_FAST_TIMING;\r
+                               *SCSI_CTRL_TIMING = SCSI_FAST10_TIMING;\r
                        } else {\r
                                // 5MB/s Timing\r
                                *SCSI_CTRL_TIMING = SCSI_DEFAULT_TIMING;\r