Skip to content

Commit

Permalink
Add single LED blink on succesful boot, add hotplug support.
Browse files Browse the repository at this point in the history
  • Loading branch information
PetteriAimonen committed Jan 21, 2022
1 parent 6b44b62 commit 327a7b1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,14 +45,22 @@ 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.
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.
Expand Down
41 changes: 39 additions & 2 deletions src/AzulSCSI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
}
Expand All @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions utils/run_gdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"' \
Expand Down

0 comments on commit 327a7b1

Please sign in to comment.