From 327a7b1dd3c5042e494782d0c36ccf6b5f770072 Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Fri, 21 Jan 2022 10:24:28 +0200 Subject: [PATCH] Add single LED blink on succesful boot, add hotplug support. --- README.md | 13 +++++++++++-- src/AzulSCSI.cpp | 41 +++++++++++++++++++++++++++++++++++++++-- utils/run_gdb.sh | 1 + 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3cb96f14..5809cf57 100644 --- a/README.md +++ b/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. 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 - 5 fast blinks: SD card not detected - Continuous morse pattern: firmware crashed, morse code indicates crash location @@ -44,7 +45,7 @@ Example format for config file: 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. 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. 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 ----------- The AzulSCSI v1 board can be programmed using USB connection in DFU mode. diff --git a/src/AzulSCSI.cpp b/src/AzulSCSI.cpp index d7655dc1..907d7275 100644 --- a/src/AzulSCSI.cpp +++ b/src/AzulSCSI.cpp @@ -941,7 +941,15 @@ void scsi_loop() } // 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- // If the ID to respond is not driven, wait for the next @@ -1184,7 +1192,7 @@ int main(void) do { blinkStatus(BLINK_ERROR_NO_SD_CARD); - delay(5000); + delay(1000); } while (!SD.begin(SD_CONFIG)); azlog("SD card init succeeded after retry"); } @@ -1204,12 +1212,41 @@ int main(void) logfile = SD.open(LOGFILE, O_WRONLY | O_CREAT | O_TRUNC); saveLog(logfile); + if (g_scsi_id_mask != 0) + { + // Ok, there is an image + blinkStatus(1); + } + uint32_t prev_log_save = millis(); while (1) { 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 if ((uint32_t)(millis() - prev_log_save) > 1000) { diff --git a/utils/run_gdb.sh b/utils/run_gdb.sh index 5391117b..cbcae0f6 100755 --- a/utils/run_gdb.sh +++ b/utils/run_gdb.sh @@ -5,6 +5,7 @@ killall orbuculum killall orbcat +rm -f swo.log arm-none-eabi-gdb \ -iex 'target extended | openocd -f interface/stlink.cfg -f target/stm32f1x.cfg -c "gdb_port pipe"' \