From 5db68783feac487e7e7f729e347ad26981c15aa0 Mon Sep 17 00:00:00 2001 From: Matt Harlum Date: Wed, 6 Sep 2023 19:06:20 +0000 Subject: [PATCH] Tweak timeouts * Increase loop wait from 100us to 1ms - this makes the timers more accurate on slow 68000 systems * Increase ATA BSY wait to 10s - Spinning rust can take a while to spool up and become ready * Skip ata_identify drq wait if error/fault is indicated - this will usually be an ATAPI drive and there's no point waiting --- ata.c | 22 ++++++++++------------ ata.h | 8 ++++---- atapi.h | 4 ++-- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/ata.c b/ata.c index a906ea3..e5b19e4 100644 --- a/ata.c +++ b/ata.c @@ -139,7 +139,7 @@ bool ata_identify(struct IDEUnit *unit, UWORD *buffer) //if (!ata_wait_ready(unit,ATA_RDY_WAIT_COUNT)) // return HFERR_SelTimeout; ata_wait_not_busy(unit,ATA_BSY_WAIT_COUNT); - + *unit->drive->sectorCount = 0; *unit->drive->lbaLow = 0; *unit->drive->lbaMid = 0; @@ -147,17 +147,15 @@ bool ata_identify(struct IDEUnit *unit, UWORD *buffer) *unit->drive->error_features = 0; *unit->drive->status_command = ATA_CMD_IDENTIFY; - if (!ata_wait_drq(unit,5000)) { - if (*unit->drive->status_command & (ata_flag_error | ata_flag_df)) { - Warn("ATA: IDENTIFY Status: Error\n"); - Warn("ATA: last_error: %08lx\n",&unit->last_error[0]); - // Save error information - unit->last_error[0] = *unit->drive->error_features; - unit->last_error[1] = *unit->drive->lbaHigh; - unit->last_error[2] = *unit->drive->lbaMid; - unit->last_error[3] = *unit->drive->lbaLow; - unit->last_error[4] = *unit->drive->status_command; - } + if (*unit->drive->status_command & (ata_flag_error | ata_flag_df) || !ata_wait_drq(unit,500)) { + Warn("ATA: IDENTIFY Status: Error\n"); + Warn("ATA: last_error: %08lx\n",&unit->last_error[0]); + // Save error information + unit->last_error[0] = *unit->drive->error_features; + unit->last_error[1] = *unit->drive->lbaHigh; + unit->last_error[2] = *unit->drive->lbaMid; + unit->last_error[3] = *unit->drive->lbaLow; + unit->last_error[4] = *unit->drive->status_command; return false; } diff --git a/ata.h b/ata.h index 8e8294b..35e7c49 100644 --- a/ata.h +++ b/ata.h @@ -72,15 +72,15 @@ enum xfer_dir { WRITE }; -#define ATA_DRQ_WAIT_LOOP_US 100 +#define ATA_DRQ_WAIT_LOOP_US 1000 #define ATA_DRQ_WAIT_S 1 #define ATA_DRQ_WAIT_COUNT (ATA_DRQ_WAIT_S * 1000 * (1000 / ATA_DRQ_WAIT_LOOP_US)) -#define ATA_BSY_WAIT_LOOP_US 100 -#define ATA_BSY_WAIT_S 3 +#define ATA_BSY_WAIT_LOOP_US 1000 +#define ATA_BSY_WAIT_S 10 #define ATA_BSY_WAIT_COUNT (ATA_BSY_WAIT_S * 1000 * (1000 / ATA_BSY_WAIT_LOOP_US)) -#define ATA_RDY_WAIT_LOOP_US 100 +#define ATA_RDY_WAIT_LOOP_US 1000 #define ATA_RDY_WAIT_S 3 #define ATA_RDY_WAIT_COUNT (ATA_RDY_WAIT_S * 1000 * (1000 / ATA_RDY_WAIT_LOOP_US)) diff --git a/atapi.h b/atapi.h index 7a56187..a02d4c7 100644 --- a/atapi.h +++ b/atapi.h @@ -19,11 +19,11 @@ #define ATAPI_CMD_PACKET 0xA0 #define ATAPI_CMD_IDENTIFY 0xA1 -#define ATAPI_DRQ_WAIT_LOOP_US 100 +#define ATAPI_DRQ_WAIT_LOOP_US 1000 #define ATAPI_DRQ_WAIT_MS 500 #define ATAPI_DRQ_WAIT_COUNT (ATAPI_DRQ_WAIT_MS * (1000 / ATAPI_DRQ_WAIT_LOOP_US)) -#define ATAPI_BSY_WAIT_LOOP_US 100 +#define ATAPI_BSY_WAIT_LOOP_US 1000 #define ATAPI_BSY_WAIT_S 5 #define ATAPI_BSY_WAIT_COUNT (ATAPI_BSY_WAIT_S * 1000 * (1000 / ATAPI_BSY_WAIT_LOOP_US))