浏览代码

Add single LED blink on succesful boot, add hotplug support.

Petteri Aimonen 3 年之前
父节点
当前提交
327a7b1dd3
共有 3 个文件被更改,包括 51 次插入4 次删除
  1. 11 2
      README.md
  2. 39 2
      src/AzulSCSI.cpp
  3. 1 0
      utils/run_gdb.sh

+ 11 - 2
README.md

@@ -13,8 +13,9 @@ Log messages are stored in `azullog.txt`, which is cleared on every boot.
 Normally only basic initialization information is stored, but turning `DIPSW2` on will cause every SCSI command to be logged.
 Normally only basic initialization information is stored, but turning `DIPSW2` on will cause every SCSI command to be logged.
 
 
 The indicator LED will normally report disk access.
 The indicator LED will normally report disk access.
-It also reports following error conditions:
+It also reports following status conditions:
 
 
+- 1 fast blink on boot: Image file loaded successfully
 - 3 fast blinks: No images found on SD card
 - 3 fast blinks: No images found on SD card
 - 5 fast blinks: SD card not detected
 - 5 fast blinks: SD card not detected
 - Continuous morse pattern: firmware crashed, morse code indicates crash location
 - Continuous morse pattern: firmware crashed, morse code indicates crash location
@@ -44,7 +45,7 @@ Example format for config file:
 
 
 Performance
 Performance
 -----------
 -----------
-With verbose log messages disabled, expected SCSI performance is 1.7 MB/s read and 1.5 MB/s write.
+With verbose log messages disabled, expected SCSI performance is 2.4 MB/s read and 1.5 MB/s write.
 Slow SD card or fragmented filesystem can slow down access.
 Slow SD card or fragmented filesystem can slow down access.
 
 
 Seek performance is best if image files are contiguous.
 Seek performance is best if image files are contiguous.
@@ -52,6 +53,14 @@ For ExFAT filesystem this relies on a file flag set by PC.
 Current versions of exfat-fuse on Linux have an [issue](https://github.com/relan/exfat/pull/101) that causes the files not to be marked contiguous even when they are.
 Current versions of exfat-fuse on Linux have an [issue](https://github.com/relan/exfat/pull/101) that causes the files not to be marked contiguous even when they are.
 This is indicated by message `WARNING: file HD00_512.hda is not contiguous. This will increase read latency.` in the log.
 This is indicated by message `WARNING: file HD00_512.hda is not contiguous. This will increase read latency.` in the log.
 
 
+Hotplugging
+-----------
+The firmware supports hot-plug removal and reinsertion of SD card.
+The status led will blink continuously when card is not present, then blink once when card is reinserted successfully.
+
+It will depend on the host system whether it gets confused by hotplugging.
+Any IO requests issued when card is removed will be timeouted.
+
 Programming
 Programming
 -----------
 -----------
 The AzulSCSI v1 board can be programmed using USB connection in DFU mode.
 The AzulSCSI v1 board can be programmed using USB connection in DFU mode.

+ 39 - 2
src/AzulSCSI.cpp

@@ -941,7 +941,15 @@ void scsi_loop()
   }
   }
 
 
   // Wait until RST = H, BSY = H, SEL = L
   // Wait until RST = H, BSY = H, SEL = L
-  while (SCSI_IN(BSY) || !SCSI_IN(SEL) || SCSI_IN(RST));
+  uint32_t start = millis();
+  while (SCSI_IN(BSY) || !SCSI_IN(SEL) || SCSI_IN(RST))
+  {
+    if ((uint32_t)(millis() - start) > 1000)
+    {
+      // Service main loop while waiting for request
+      return;
+    }
+  }
 
 
   // BSY+ SEL-
   // BSY+ SEL-
   // If the ID to respond is not driven, wait for the next
   // If the ID to respond is not driven, wait for the next
@@ -1184,7 +1192,7 @@ int main(void)
     do
     do
     {
     {
       blinkStatus(BLINK_ERROR_NO_SD_CARD);
       blinkStatus(BLINK_ERROR_NO_SD_CARD);
-      delay(5000);
+      delay(1000);
     } while (!SD.begin(SD_CONFIG));
     } while (!SD.begin(SD_CONFIG));
     azlog("SD card init succeeded after retry");
     azlog("SD card init succeeded after retry");
   }
   }
@@ -1204,12 +1212,41 @@ int main(void)
   logfile = SD.open(LOGFILE, O_WRONLY | O_CREAT | O_TRUNC);
   logfile = SD.open(LOGFILE, O_WRONLY | O_CREAT | O_TRUNC);
   saveLog(logfile);
   saveLog(logfile);
 
 
+  if (g_scsi_id_mask != 0)
+  {
+    // Ok, there is an image
+    blinkStatus(1);
+  }
+
   uint32_t prev_log_save = millis();
   uint32_t prev_log_save = millis();
 
 
   while (1)
   while (1)
   {
   {
     scsi_loop();
     scsi_loop();
 
 
+    // Check SD card status for hotplug
+    uint32_t ocr;
+    if (!SD.card()->readOCR(&ocr))
+    {
+      if (!SD.card()->readOCR(&ocr))
+      {
+        azlog("SD card removed, trying to reinit");
+        do
+        {
+          blinkStatus(BLINK_ERROR_NO_SD_CARD);
+          delay(1000);
+        } while (!SD.begin(SD_CONFIG));
+        azlog("SD card reinit succeeded");
+        readSCSIDeviceConfig();
+        findHDDImages();
+
+        if (g_scsi_id_mask != 0)
+        {
+          blinkStatus(1);
+        }
+      }
+    }
+
     // Save log once a second if there are new log messages
     // Save log once a second if there are new log messages
     if ((uint32_t)(millis() - prev_log_save) > 1000)
     if ((uint32_t)(millis() - prev_log_save) > 1000)
     {
     {

+ 1 - 0
utils/run_gdb.sh

@@ -5,6 +5,7 @@
 
 
 killall orbuculum
 killall orbuculum
 killall orbcat
 killall orbcat
+rm -f swo.log
 
 
 arm-none-eabi-gdb \
 arm-none-eabi-gdb \
        -iex 'target extended | openocd -f interface/stlink.cfg -f target/stm32f1x.cfg -c "gdb_port pipe"' \
        -iex 'target extended | openocd -f interface/stlink.cfg -f target/stm32f1x.cfg -c "gdb_port pipe"' \