ソースを参照

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

Petteri Aimonen 2 年 前
コミット
d1e87a8f6a

+ 8 - 0
lib/BlueSCSI_platform_RP2040/BlueSCSI_platform.cpp

@@ -489,8 +489,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/BlueSCSI_platform_RP2040/BlueSCSI_platform.h

@@ -67,6 +67,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/BlueSCSI_platform_template/BlueSCSI_platform.cpp

@@ -52,6 +52,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/BlueSCSI_platform_template/BlueSCSI_platform.h

@@ -52,6 +52,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);

+ 3 - 1
src/BlueSCSI.cpp

@@ -629,7 +629,8 @@ extern "C" void bluescsi_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())
   {
@@ -695,6 +696,7 @@ extern "C" void bluescsi_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/BlueSCSI_disk.cpp

@@ -1550,6 +1550,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;
@@ -1713,6 +1715,11 @@ static void doRead(uint32_t lba, uint32_t blocks)
 
         if (transfer.currentBlock == transfer.blocks)
         {
+            while (!scsiIsWriteFinished(NULL))
+            {
+                platform_poll();
+            }
+
             scsiFinishWrite();
         }
 #endif
@@ -1781,6 +1788,8 @@ static void start_dataInTransfer(uint8_t *buffer, uint32_t count)
             log("start_dataInTransfer() timeout waiting for previous to finish");
             scsiDev.resetFlag = 1;
         }
+
+        platform_poll();
     }
     if (scsiDev.resetFlag) return;
 
@@ -1799,6 +1808,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()
@@ -1852,6 +1863,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) ||
@@ -1878,6 +1891,11 @@ static void diskDataIn()
         }
 #endif
 
+        while (!scsiIsWriteFinished(NULL))
+        {
+            platform_poll();
+        }
+
         scsiFinishWrite();
     }
 }