Bladeren bron

Prepare for firmware release v1.0.4

Alex Perez 3 jaren geleden
bovenliggende
commit
30e5ee5585

+ 19 - 16
lib/ZuluSCSI_platform_GD32F205/ZuluSCSI_platform.cpp

@@ -100,22 +100,25 @@ void azplatform_init()
 
     // Enable debug output on SWO pin
     DBG_CTL |= DBG_CTL_TRACE_IOEN;
-    CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
-    TPI->ACPR = SystemCoreClock / 2000000 - 1; // 2 Mbps baudrate for SWO
-    // TPI->ACPR = SystemCoreClock / 30000000 - 1; // 30 Mbps baudrate for SWO
-    TPI->SPPR = 2;
-    TPI->FFCR = 0x100; // TPIU packet framing disabled
-    // DWT->CTRL |= (1 << DWT_CTRL_EXCTRCENA_Pos);
-    // DWT->CTRL |= (1 << DWT_CTRL_CYCTAP_Pos)
-    //             | (15 << DWT_CTRL_POSTPRESET_Pos)
-    //             | (1 << DWT_CTRL_PCSAMPLENA_Pos)
-    //             | (3 << DWT_CTRL_SYNCTAP_Pos)
-    //             | (1 << DWT_CTRL_CYCCNTENA_Pos);
-    ITM->LAR = 0xC5ACCE55;
-    ITM->TCR = (1 << ITM_TCR_DWTENA_Pos)
-                | (1 << ITM_TCR_SYNCENA_Pos)
-                | (1 << ITM_TCR_ITMENA_Pos);
-    ITM->TER = 0xFFFFFFFF; // Enable all stimulus ports
+    if (TPI->ACPR == 0)
+    {
+        CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
+        TPI->ACPR = SystemCoreClock / 2000000 - 1; // 2 Mbps baudrate for SWO
+        // TPI->ACPR = SystemCoreClock / 30000000 - 1; // 30 Mbps baudrate for SWO
+        TPI->SPPR = 2;
+        TPI->FFCR = 0x100; // TPIU packet framing disabled
+        // DWT->CTRL |= (1 << DWT_CTRL_EXCTRCENA_Pos);
+        // DWT->CTRL |= (1 << DWT_CTRL_CYCTAP_Pos)
+        //             | (15 << DWT_CTRL_POSTPRESET_Pos)
+        //             | (1 << DWT_CTRL_PCSAMPLENA_Pos)
+        //             | (3 << DWT_CTRL_SYNCTAP_Pos)
+        //             | (1 << DWT_CTRL_CYCCNTENA_Pos);
+        ITM->LAR = 0xC5ACCE55;
+        ITM->TCR = (1 << ITM_TCR_DWTENA_Pos)
+                    | (1 << ITM_TCR_SYNCENA_Pos)
+                    | (1 << ITM_TCR_ITMENA_Pos);
+        ITM->TER = 0xFFFFFFFF; // Enable all stimulus ports
+    }
 
     // Enable needed clocks for GPIO
     rcu_periph_clock_enable(RCU_AF);

+ 2 - 2
src/ZuluSCSI.cpp

@@ -453,10 +453,10 @@ extern "C" int zuluscsi_main(void)
             blinkStatus(BLINK_ERROR_NO_SD_CARD);
             delay(1000);
             azplatform_reset_watchdog();
-          } while (!SD.begin(SD_CONFIG));
+          } while (!SD.begin(SD_CONFIG) && (!SD.card() || SD.sdErrorCode() != 0));
           azlog("SD card reinit succeeded");
           print_sd_info();
-          
+
           reinitSCSI();
           init_logfile();
         }

+ 5 - 0
src/ZuluSCSI_config.h

@@ -3,6 +3,11 @@
 
 #pragma once
 
+// Use variables for version number
+#define FW_VER_NUM      "1.0.4"
+#define FW_VER_SUFFIX   "release"
+#define ZULU_FW_VERSION FW_VER_NUM "-" FW_VER_SUFFIX
+
 // Configuration and log file paths
 #define CONFIGFILE  "zuluscsi.ini"
 #define LOGFILE     "zululog.txt"

+ 18 - 1
src/ZuluSCSI_disk.cpp

@@ -64,6 +64,9 @@ struct image_config_t: public S2S_TargetCfg
     // Standard SCSI uses left alignment
     // This field uses -1 for default when field is not set in .ini
     int rightAlignStrings;
+
+    // Maximum amount of bytes to prefetch
+    int prefetchbytes;
 };
 
 static image_config_t g_DiskImages[S2S_MAX_TARGETS];
@@ -247,6 +250,15 @@ bool scsiDiskOpenHDDImage(int target_idx, const char *filename, int scsi_id, int
 
         setDefaultDriveInfo(target_idx);
 
+        if (img.prefetchbytes > 0)
+        {
+            azlog("---- Read prefetch enabled: ", (int)img.prefetchbytes, " bytes");
+        }
+        else
+        {
+            azlog("---- Read prefetch disabled");
+        }
+
         return true;
     }
 
@@ -262,6 +274,7 @@ static void scsiDiskConfigDefaults(int target_idx)
     img.sectorsPerTrack = 63;
     img.headsPerCylinder = 255;
     img.quirks = S2S_CFG_QUIRKS_NONE;
+    img.prefetchbytes = PREFETCH_BUFFER_SIZE;
     memset(img.vendor, 0, sizeof(img.vendor));
     memset(img.prodId, 0, sizeof(img.prodId));
     memset(img.revision, 0, sizeof(img.revision));
@@ -279,6 +292,7 @@ static void scsiDiskLoadConfig(int target_idx, const char *section)
     img.headsPerCylinder = ini_getl(section, "HeadsPerCylinder", img.headsPerCylinder, CONFIGFILE);
     img.quirks = ini_getl(section, "Quirks", img.quirks, CONFIGFILE);
     img.rightAlignStrings = ini_getbool(section, "RightAlignStrings", -1, CONFIGFILE);
+    img.prefetchbytes = ini_getl(section, "PrefetchBytes", img.prefetchbytes, CONFIGFILE);
     
     char tmp[32];
     memset(tmp, 0, sizeof(tmp));
@@ -986,6 +1000,7 @@ static void doRead(uint32_t lba, uint32_t blocks)
             uint32_t count = sectors_in_prefetch - start_offset;
             if (count > transfer.blocks) count = transfer.blocks;
             scsiStartWrite(g_scsi_prefetch.buffer + start_offset * bytesPerSector, count * bytesPerSector);
+            azdbg("------ Found ", (int)count, " sectors in prefetch cache");
             transfer.currentBlock += count;
         }
 
@@ -1101,7 +1116,9 @@ static void diskDataIn()
 
 #ifdef PREFETCH_BUFFER_SIZE
         image_config_t &img = *(image_config_t*)scsiDev.target->cfg;
-        uint32_t prefetch_sectors = PREFETCH_BUFFER_SIZE / bytesPerSector;            
+        int prefetchbytes = img.prefetchbytes;
+        if (prefetchbytes > PREFETCH_BUFFER_SIZE) prefetchbytes = PREFETCH_BUFFER_SIZE;
+        uint32_t prefetch_sectors = prefetchbytes / bytesPerSector;
         uint32_t img_sector_count = img.file.size() / bytesPerSector;
         g_scsi_prefetch.sector = transfer.lba + transfer.blocks;
         g_scsi_prefetch.bytes = 0;

+ 1 - 1
src/ZuluSCSI_log.cpp

@@ -2,7 +2,7 @@
 #include "ZuluSCSI_config.h"
 #include "ZuluSCSI_platform.h"
 
-const char *g_azlog_firmwareversion = "1.0.3" " " __DATE__ " " __TIME__;
+const char *g_azlog_firmwareversion = ZULU_FW_VERSION " " __DATE__ " " __TIME__;
 bool g_azlog_debug = true;
 
 // This memory buffer can be read by debugger and is also saved to zululog.txt

+ 40 - 1
src/ZuluSCSI_log_trace.cpp

@@ -12,6 +12,7 @@ extern "C" {
 static bool g_LogData = false;
 static int g_InByteCount = 0;
 static int g_OutByteCount = 0;
+static uint16_t g_DataChecksum = 0;
 
 static const char *getCommandName(uint8_t cmd)
 {
@@ -142,18 +143,36 @@ static void printNewPhase(int phase)
 
 void scsiLogPhaseChange(int new_phase)
 {
+    static int old_scsi_id = 0;
     static int old_phase = BUS_FREE;
+    static int old_sync_period = 0;
 
     if (new_phase != old_phase)
     {
         if (old_phase == DATA_IN || old_phase == DATA_OUT)
         {
-            azdbg("---- Total IN: ", g_InByteCount, " OUT: ", g_OutByteCount);
+            azdbg("---- Total IN: ", g_InByteCount, " OUT: ", g_OutByteCount, " CHECKSUM: ", (int)g_DataChecksum);
         }
         g_InByteCount = g_OutByteCount = 0;
+        g_DataChecksum = 0;
+
+        if (old_phase >= 0 &&
+            old_scsi_id == scsiDev.target->targetId &&
+            old_sync_period != scsiDev.target->syncPeriod)
+        {
+            // Add a log message when negotiated synchronous speed changes.
+            int syncper = scsiDev.target->syncPeriod;
+            int syncoff = scsiDev.target->syncOffset;
+            int mbyte_per_s = (1000 + syncper * 2) / (syncper * 4);
+            azlog("SCSI ID ", (int)scsiDev.target->targetId,
+                  " negotiated synchronous mode ", mbyte_per_s, " MB/s ",
+                  "(period 4x", syncper, " ns, offset ", syncoff, " bytes)");
+        }
 
         printNewPhase(new_phase);
         old_phase = new_phase;
+        old_sync_period = scsiDev.target->syncPeriod;
+        old_scsi_id = scsiDev.target->targetId;
     }
 }
 
@@ -164,6 +183,16 @@ void scsiLogDataIn(const uint8_t *buf, uint32_t length)
         azdbg("------ IN: ", bytearray(buf, length));
     }
 
+    if (g_azlog_debug)
+    {
+        // BSD checksum algorithm
+        for (uint32_t i = 0; i < length; i++)
+        {
+            g_DataChecksum = (g_DataChecksum >> 1) + ((g_DataChecksum & 1) << 15);
+            g_DataChecksum += buf[i];
+        }
+    }
+
     g_InByteCount += length;
 }
 
@@ -179,5 +208,15 @@ void scsiLogDataOut(const uint8_t *buf, uint32_t length)
         azdbg("------ OUT: ", bytearray(buf, length));
     }
 
+    if (g_azlog_debug)
+    {
+        // BSD checksum algorithm
+        for (uint32_t i = 0; i < length; i++)
+        {
+            g_DataChecksum = (g_DataChecksum >> 1) + ((g_DataChecksum & 1) << 15);
+            g_DataChecksum += buf[i];
+        }
+    }
+
     g_OutByteCount += length;
 }

+ 1 - 0
zuluscsi.ini

@@ -24,6 +24,7 @@ MaxSyncSpeed = 10 # Set to 5 or 10 to enable synchronous SCSI mode, 0 to disable
 #SectorsPerTrack = 63
 #HeadsPerCylinder = 255
 #RightAlignStrings = 0 # Right-align SCSI vendor / product strings, defaults on if Quirks = 1
+#PrefetchBytes = 8192 # Maximum number of bytes to prefetch after a read request, 0 to disable
 
 # Settings can be overriden for individual devices.
 [SCSI2]