Преглед на файлове

Initiator: Use longer timeout in START STOP command (#504)

YAMAHA CRW2100S takes up to 30 seconds to initialize.
Set timeout to 60 seconds for the start command.
Petteri Aimonen преди 9 месеца
родител
ревизия
5e6068ce49
променени са 2 файла, в които са добавени 13 реда и са изтрити 3 реда
  1. 10 2
      src/ZuluSCSI_initiator.cpp
  2. 3 1
      src/ZuluSCSI_initiator.h

+ 10 - 2
src/ZuluSCSI_initiator.cpp

@@ -586,7 +586,7 @@ int scsiInitiatorRunCommand(int target_id,
                             const uint8_t *command, size_t cmdLen,
                             uint8_t *bufIn, size_t bufInLen,
                             const uint8_t *bufOut, size_t bufOutLen,
-                            bool returnDataPhase)
+                            bool returnDataPhase, uint32_t timeout)
 {
 
     if (!scsiHostPhySelect(target_id, g_initiator_state.initiator_id))
@@ -600,8 +600,15 @@ int scsiInitiatorRunCommand(int target_id,
 
     SCSI_PHASE phase;
     int status = -1;
+    uint32_t start = millis();
     while ((phase = (SCSI_PHASE)scsiHostPhyGetPhase()) != BUS_FREE)
     {
+        // If explicit timeout is specified, prevent watchdog from triggering too early.
+        if ((uint32_t)(millis() - start) < timeout)
+        {
+            platform_reset_watchdog();
+        }
+
         platform_poll();
 
         if (phase == MESSAGE_IN)
@@ -750,10 +757,11 @@ bool scsiStartStopUnit(int target_id, bool start)
         }
     }
 
+    uint32_t timeout = 60000; // Some drives can take long to initialize
     int status = scsiInitiatorRunCommand(target_id,
                                          command, sizeof(command),
                                          response, sizeof(response),
-                                         NULL, 0);
+                                         NULL, 0, false, timeout);
 
     if (status == 2)
     {

+ 3 - 1
src/ZuluSCSI_initiator.h

@@ -38,11 +38,13 @@ void scsiInitiatorMainLoop();
 int scsiInitiatorGetOwnID();
 
 // Select target and execute SCSI command
+// If timeout is specified, it overrides the default watchdog timeout.
 int scsiInitiatorRunCommand(int target_id,
                             const uint8_t *command, size_t cmdLen,
                             uint8_t *bufIn, size_t bufInLen,
                             const uint8_t *bufOut, size_t bufOutLen,
-                            bool returnDataPhase = false);
+                            bool returnDataPhase = false,
+                            uint32_t timeout = 0);
 
 // Execute READ CAPACITY command
 bool scsiInitiatorReadCapacity(int target_id, uint32_t *sectorcount, uint32_t *sectorsize);