X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FStorage%2FFDD%2Ffdd.c;h=3b886e164b667afe8d07a05c72e5332f68ad17d8;hb=48de21e1b27fcb2595aabe2669bdec80567961df;hp=4a9ec2d48c098aec1d35e74cd8a273f25e48d41b;hpb=aaf21fdf21db89849c419315e3d9ff956ed60d5d;p=tpg%2Facess2.git diff --git a/Modules/Storage/FDD/fdd.c b/Modules/Storage/FDD/fdd.c index 4a9ec2d4..3b886e16 100644 --- a/Modules/Storage/FDD/fdd.c +++ b/Modules/Storage/FDD/fdd.c @@ -69,7 +69,7 @@ enum FloppyPorts { enum FloppyCommands { FIX_DRIVE_DATA = 0x03, - HECK_DRIVE_STATUS = 0x04, + CHECK_DRIVE_STATUS = 0x04, CALIBRATE_DRIVE = 0x07, CHECK_INTERRUPT_STATUS = 0x08, SEEK_TRACK = 0x0F, @@ -213,7 +213,7 @@ int FDD_Install(char **Arguments) void FDD_UnloadModule() { int i; - //DevFS_DelDevice( &gFDD_DriverInfo ); + DevFS_DelDevice( &gFDD_DriverInfo ); Mutex_Acquire(&glFDD); for(i=0;i<4;i++) { Time_RemoveTimer(gFDD_Devices[i].timer); @@ -402,9 +402,6 @@ int FDD_int_ReadWriteSector(Uint32 Disk, Uint64 SectorAddr, int Write, void *Buf LOG("Sending command"); - //Threads_Wait(100); // Wait for Head to settle - Time_Delay(100); - for( i = 0; i < FDD_MAX_READWRITE_ATTEMPTS; i ++ ) { if( Write ) @@ -581,6 +578,10 @@ int FDD_int_SeekTrack(int disk, int head, int track) // Set Track in structure gFDD_Devices[disk].track[head] = track; + + // Wait for Head to settle + Time_Delay(100); + return 1; } @@ -663,11 +664,12 @@ inline void FDD_WaitIRQ() void FDD_SensInt(int base, Uint8 *sr0, Uint8 *cyl) { + Uint8 byte; FDD_int_SendByte(base, CHECK_INTERRUPT_STATUS); - if(sr0) *sr0 = FDD_int_GetByte(base); - else FDD_int_GetByte(base); - if(cyl) *cyl = FDD_int_GetByte(base); - else FDD_int_GetByte(base); + byte = FDD_int_GetByte(base); + if(sr0) *sr0 = byte; + byte = FDD_int_GetByte(base); + if(cyl) *cyl = byte; } /** @@ -676,22 +678,26 @@ void FDD_SensInt(int base, Uint8 *sr0, Uint8 *cyl) */ void FDD_int_SendByte(int base, char byte) { - volatile int state; - int timeout = 128; - for( ; timeout--; ) + int timeout = 128; + + while( (inb(base + PORT_MAINSTATUS) & 0xC0) != 0x80 && timeout-- ) + inb(0x80); //Delay + + if( timeout >= 0 ) { - state = inb(base + PORT_MAINSTATUS); - if ((state & 0xC0) == 0x80) - { - outb(base + PORT_DATA, byte); - return; - } - inb(0x80); //Delay + #if 0 && DEBUG + static int totalTimeout = 0; + static int totalCount = 0; + totalTimeout += timeout; + totalCount ++; + LOG("timeout = %i, average %i", timeout, totalTimeout/totalCount); + #endif + outb(base + PORT_DATA, byte); + } + else + { + Log_Warning("FDD", "FDD_int_SendByte: Timeout sending byte 0x%x to base 0x%x\n", byte, base); } - - #if WARN - Warning("FDD_int_SendByte - Timeout sending byte 0x%x to base 0x%x\n", byte, base); - #endif } /** @@ -700,16 +706,27 @@ void FDD_int_SendByte(int base, char byte) */ int FDD_int_GetByte(int base) { - volatile int state; - int timeout; - for( timeout = 128; timeout--; ) + int timeout = 128; + + while( (inb(base + PORT_MAINSTATUS) & 0xd0) != 0xd0 && timeout-- ) + inb(0x80); //Delay + + if( timeout >= 0 ) { - state = inb((base + PORT_MAINSTATUS)); - if ((state & 0xd0) == 0xd0) - return inb(base + PORT_DATA); - inb(0x80); + #if 0 && DEBUG + static int totalTimeout = 0; + static int totalCount = 0; + totalTimeout += timeout; + totalCount ++; + LOG("timeout = %i, average %i", timeout, totalTimeout/totalCount); + #endif + return inb(base + PORT_DATA); + } + else + { + Log_Warning("FDD", "FDD_int_GetByte: Timeout reading byte from base 0x%x\n", base); + return -1; } - return -1; } /**