Bladeren bron

Add platform_poll() function for processing. (#193)

Petteri Aimonen 2 jaren geleden
bovenliggende
commit
104dddde63

+ 6 - 0
lib/ZuluSCSI_platform_GD32F205/ZuluSCSI_platform.cpp

@@ -484,6 +484,12 @@ void platform_reset_watchdog()
     // It gives us opportunity to collect better debug info than the
     // full hardware reset that would be caused by hardware watchdog.
     g_watchdog_timeout = WATCHDOG_CRASH_TIMEOUT;
+}
+
+// Poll function that is called every few milliseconds.
+// Can be left empty or used for platform-specific processing.
+void platform_poll()
+{
     adc_poll();
 }
 

+ 5 - 0
lib/ZuluSCSI_platform_GD32F205/ZuluSCSI_platform.h

@@ -96,6 +96,11 @@ void platform_disable_led(void);
 // Setup soft watchdog
 void platform_reset_watchdog();
 
+// Poll function that is called every few milliseconds.
+// The SD card is free to access during this time, and pauses up to
+// few milliseconds shouldn't disturb SCSI communication.
+void platform_poll();
+
 // Reinitialize SD card connection and save log from interrupt context.
 // This can be used in crash handlers.
 void platform_emergency_log_save();

+ 8 - 0
lib/ZuluSCSI_platform_RP2040/ZuluSCSI_platform.cpp

@@ -533,8 +533,16 @@ void platform_reset_watchdog()
         g_watchdog_initialized = true;
     }
 
+    // USB log is polled here also to make sure any log messages in fault states
+    // get passed to USB.
     usb_log_poll();
+}
 
+// Poll function that is called every few milliseconds.
+// Can be left empty or used for platform-specific processing.
+void platform_poll()
+{
+    usb_log_poll();
     adc_poll();
 }
 

+ 5 - 0
lib/ZuluSCSI_platform_RP2040/ZuluSCSI_platform.h

@@ -105,6 +105,11 @@ bool platform_is_initiator_mode_enabled();
 // Setup soft watchdog if supported
 void platform_reset_watchdog();
 
+// Poll function that is called every few milliseconds.
+// The SD card is free to access during this time, and pauses up to
+// few milliseconds shouldn't disturb SCSI communication.
+void platform_poll();
+
 // Set callback that will be called during data transfer to/from SD card.
 // This can be used to implement simultaneous transfer to SCSI bus.
 typedef void (*sd_callback_t)(uint32_t bytes_complete);

+ 7 - 0
lib/ZuluSCSI_platform_template/ZuluSCSI_platform.cpp

@@ -73,6 +73,13 @@ void platform_reset_watchdog()
 {
 }
 
+// Poll function that is called every few milliseconds.
+// Can be left empty or used for platform-specific processing.
+void platform_poll()
+{
+
+}
+
 /**********************************************/
 /* Mapping from data bytes to GPIO BOP values */
 /**********************************************/

+ 5 - 0
lib/ZuluSCSI_platform_template/ZuluSCSI_platform.h

@@ -73,6 +73,11 @@ void platform_disable_led(void);
 // Setup soft watchdog if supported
 void platform_reset_watchdog();
 
+// Poll function that is called every few milliseconds.
+// The SD card is free to access during this time, and pauses up to
+// few milliseconds shouldn't disturb SCSI communication.
+void platform_poll();
+
 // Set callback that will be called during data transfer to/from SD card.
 // This can be used to implement simultaneous transfer to SCSI bus.
 typedef void (*sd_callback_t)(uint32_t bytes_complete);

+ 2 - 0
src/ZuluSCSI.cpp

@@ -695,6 +695,7 @@ extern "C" void zuluscsi_main_loop(void)
   static uint32_t last_request_time = 0;
 
   platform_reset_watchdog();
+  platform_poll();
   
 #ifdef PLATFORM_HAS_INITIATOR_MODE
   if (platform_is_initiator_mode_enabled())
@@ -761,6 +762,7 @@ extern "C" void zuluscsi_main_loop(void)
         blinkStatus(BLINK_ERROR_NO_SD_CARD);
         delay(1000);
         platform_reset_watchdog();
+        platform_poll();
       }
     } while (!g_sdcard_present && !g_romdrive_active);
   }

+ 18 - 0
src/ZuluSCSI_disk.cpp

@@ -1566,6 +1566,8 @@ void diskDataOut()
            && scsiDev.phase == DATA_OUT
            && !scsiDev.resetFlag)
     {
+        platform_poll();
+
         // Figure out how many contiguous bytes are available for writing to SD card.
         uint32_t bufsize = sizeof(scsiDev.data);
         uint32_t start = g_disk_transfer.bytes_sd % bufsize;
@@ -1729,6 +1731,11 @@ static void doRead(uint32_t lba, uint32_t blocks)
 
         if (transfer.currentBlock == transfer.blocks)
         {
+            while (!scsiIsWriteFinished(NULL))
+            {
+                platform_poll();
+            }
+
             scsiFinishWrite();
         }
 #endif
@@ -1797,6 +1804,8 @@ static void start_dataInTransfer(uint8_t *buffer, uint32_t count)
             logmsg("start_dataInTransfer() timeout waiting for previous to finish");
             scsiDev.resetFlag = 1;
         }
+
+        platform_poll();
     }
     if (scsiDev.resetFlag) return;
 
@@ -1815,6 +1824,8 @@ static void start_dataInTransfer(uint8_t *buffer, uint32_t count)
 
     diskDataIn_callback(count);
     platform_set_sd_callback(NULL, NULL);
+
+    platform_poll();
 }
 
 static void diskDataIn()
@@ -1868,6 +1879,8 @@ static void diskDataIn()
 
         while (!scsiIsWriteFinished(NULL) && prefetch_sectors > 0 && !scsiDev.resetFlag)
         {
+            platform_poll();
+
             // Check if prefetch buffer is free
             g_disk_transfer.buffer = g_scsi_prefetch.buffer + g_scsi_prefetch.bytes;
             if (!scsiIsWriteFinished(g_disk_transfer.buffer) ||
@@ -1894,6 +1907,11 @@ static void diskDataIn()
         }
 #endif
 
+        while (!scsiIsWriteFinished(NULL))
+        {
+            platform_poll();
+        }
+
         scsiFinishWrite();
     }
 }