Răsfoiți Sursa

Merge pull request #31 from ZuluSCSI/dev_updates

Synchronize with development repository
Alex Perez 3 ani în urmă
părinte
comite
71929d3774
6 a modificat fișierele cu 94 adăugiri și 39 ștergeri
  1. 3 1
      platformio.ini
  2. 33 33
      src/ZuluSCSI.cpp
  3. 17 3
      src/ZuluSCSI_disk.cpp
  4. 19 0
      src/ZuluSCSI_log.cpp
  5. 3 0
      src/ZuluSCSI_log.h
  6. 19 2
      src/ZuluSCSI_main.cpp

+ 3 - 1
platformio.ini

@@ -14,8 +14,9 @@ build_flags =
     -DPREFETCH_BUFFER_SIZE=0
     -DMAX_SECTOR_SIZE=2048
     -DSCSI2SD_BUFFER_SIZE=4096
+    -DUSE_ARDUINO=1
 lib_deps =
-    SdFat=https://github.com/greiman/SdFat
+    SdFat=https://github.com/greiman/SdFat#2.1.2
     minIni
     ZuluSCSI_platform_template
     SCSI2SD
@@ -40,6 +41,7 @@ platform_packages =
     toolchain-gccarmnoneeabi@1.60301.0
     framework-spl-gd32@https://github.com/CommunityGD32Cores/gd32-pio-spl-package.git
 extra_scripts = src/build_bootloader.py
+debug_build_flags = -Os -ggdb -g3
 build_flags = 
      -Os -Wall -Wno-sign-compare -ggdb -g3 -Isrc
      -D__SYSTEM_CLOCK_120M_PLL_IRC8M=120000000

+ 33 - 33
src/ZuluSCSI.cpp

@@ -403,7 +403,7 @@ static void reinitSCSI()
   
 }
 
-extern "C" int zuluscsi_main(void)
+extern "C" void zuluscsi_setup(void)
 {
   azplatform_init();
   azplatform_late_init();
@@ -436,45 +436,45 @@ extern "C" int zuluscsi_main(void)
   azlog("FW Version: ", g_azlog_firmwareversion);
 
   init_logfile();
-  
-  uint32_t sd_card_check_time = 0;
+}
 
-  while (1)
-  {
-    azplatform_reset_watchdog();
-    scsiPoll();
-    scsiDiskPoll();
-    scsiLogPhaseChange(scsiDev.phase);
+extern "C" void zuluscsi_main_loop(void)
+{
+  static uint32_t sd_card_check_time = 0;
 
-    // Save log periodically during status phase if there are new messages.
-    if (scsiDev.phase == STATUS)
-    {
-      save_logfile();
-    }
+  azplatform_reset_watchdog();
+  scsiPoll();
+  scsiDiskPoll();
+  scsiLogPhaseChange(scsiDev.phase);
 
-    // Check SD card status for hotplug
-    if (scsiDev.phase == BUS_FREE &&
-        (uint32_t)(millis() - sd_card_check_time) > 5000)
+  // Save log periodically during status phase if there are new messages.
+  if (scsiDev.phase == STATUS)
+  {
+    save_logfile();
+  }
+
+  // Check SD card status for hotplug
+  if (scsiDev.phase == BUS_FREE &&
+      (uint32_t)(millis() - sd_card_check_time) > 5000)
+  {
+    sd_card_check_time = millis();
+    uint32_t ocr;
+    if (!SD.card()->readOCR(&ocr))
     {
-      sd_card_check_time = millis();
-      uint32_t ocr;
       if (!SD.card()->readOCR(&ocr))
       {
-        if (!SD.card()->readOCR(&ocr))
+        azlog("SD card removed, trying to reinit");
+        do
         {
-          azlog("SD card removed, trying to reinit");
-          do
-          {
-            blinkStatus(BLINK_ERROR_NO_SD_CARD);
-            delay(1000);
-            azplatform_reset_watchdog();
-          } while (!SD.begin(SD_CONFIG) && (!SD.card() || SD.sdErrorCode() != 0));
-          azlog("SD card reinit succeeded");
-          print_sd_info();
-
-          reinitSCSI();
-          init_logfile();
-        }
+          blinkStatus(BLINK_ERROR_NO_SD_CARD);
+          delay(1000);
+          azplatform_reset_watchdog();
+        } while (!SD.begin(SD_CONFIG) && (!SD.card() || SD.sdErrorCode() != 0));
+        azlog("SD card reinit succeeded");
+        print_sd_info();
+
+        reinitSCSI();
+        init_logfile();
       }
     }
   }

+ 17 - 3
src/ZuluSCSI_disk.cpp

@@ -383,9 +383,10 @@ bool scsiDiskOpenHDDImage(int target_idx, const char *filename, int scsi_id, int
             return false;
         }
 
-        if (img.file.contiguousRange(NULL, NULL))
+        uint32_t sector_begin = 0, sector_end = 0;
+        if (img.file.contiguousRange(&sector_begin, &sector_end))
         {
-            azlog("---- Image file is contiguous.");
+            azlog("---- Image file is contiguous, SD card sectors ", (int)sector_begin, " to ", (int)sector_end);
         }
         else
         {
@@ -1137,7 +1138,7 @@ static void doRead(uint32_t lba, uint32_t blocks)
 
     if (unlikely(((uint64_t) lba) + blocks > capacity))
     {
-        azlog("WARNING: Host attempted write at sector ", (int)lba, "+", (int)blocks,
+        azlog("WARNING: Host attempted read at sector ", (int)lba, "+", (int)blocks,
               ", exceeding image size ", (int)capacity, " sectors (",
               (int)bytesPerSector, "B/sector)");
         scsiDev.status = CHECK_CONDITION;
@@ -1197,6 +1198,19 @@ void diskDataIn_callback(uint32_t bytes_complete)
         bytes_complete &= ~3;
     }
 
+    // Machintosh SCSI driver can get confused if pauses occur in middle of
+    // a sector, so schedule the transfers in sector sized blocks.
+    image_config_t &img = *(image_config_t*)scsiDev.target->cfg;
+    if (bytes_complete < g_disk_transfer.bytes_sd &&
+        img.quirks == S2S_CFG_QUIRKS_APPLE)
+    {
+        uint32_t bytesPerSector = scsiDev.target->liveCfg.bytesPerSector;
+        if (bytes_complete % bytesPerSector != 0)
+        {
+            bytes_complete -= bytes_complete % bytesPerSector;
+        }
+    }
+
     if (bytes_complete > g_disk_transfer.bytes_scsi)
     {
         // DMA is reading from SD card, bytes_complete bytes have already been read.

+ 19 - 0
src/ZuluSCSI_log.cpp

@@ -63,6 +63,25 @@ void azlog_raw(uint32_t value)
     azlog_raw(hexbuf);
 }
 
+// Log integer as hex
+void azlog_raw(uint64_t value)
+{
+    const char *nibble = "0123456789ABCDEF";
+    char hexbuf[19] = {
+        '0', 'x',
+        nibble[(value >> 60) & 0xF], nibble[(value >> 56) & 0xF],
+        nibble[(value >> 52) & 0xF], nibble[(value >> 48) & 0xF],
+        nibble[(value >> 44) & 0xF], nibble[(value >> 40) & 0xF],
+        nibble[(value >> 36) & 0xF], nibble[(value >> 32) & 0xF],
+        nibble[(value >> 28) & 0xF], nibble[(value >> 24) & 0xF],
+        nibble[(value >> 20) & 0xF], nibble[(value >> 16) & 0xF],
+        nibble[(value >> 12) & 0xF], nibble[(value >>  8) & 0xF],
+        nibble[(value >>  4) & 0xF], nibble[(value >>  0) & 0xF],
+        0
+    };
+    azlog_raw(hexbuf);
+}
+
 // Log integer as decimal
 void azlog_raw(int value)
 {

+ 3 - 0
src/ZuluSCSI_log.h

@@ -27,6 +27,9 @@ void azlog_raw(uint8_t value);
 // Log integer as hex
 void azlog_raw(uint32_t value);
 
+// Log integer as hex
+void azlog_raw(uint64_t value);
+
 // Log integer as decimal
 void azlog_raw(int value);
 

+ 19 - 2
src/ZuluSCSI_main.cpp

@@ -12,11 +12,28 @@ int main(void)
 
 #else
 
-extern "C" int zuluscsi_main(void);
+extern "C" void zuluscsi_setup(void);
+extern "C" void zuluscsi_main_loop(void);
 
+#ifdef USE_ARDUINO
+extern "C" void setup(void)
+{
+    zuluscsi_setup();
+}
+
+extern "C" void loop(void)
+{
+    zuluscsi_main_loop();
+}
+#else
 int main(void)
 {
-    return zuluscsi_main();
+    zuluscsi_setup();
+    while (1)
+    {
+        zuluscsi_main_loop();
+    }
 }
+#endif
 
 #endif