Page 1 of 1

FDC read problem on real hardware.

Posted: Mon Jul 07, 2014 1:12 pm
by Waszka
Hi all,
I've recently added FDC and FAT12 support to my OS.
The problem I'm facing is reading floppy on real hardware.
My routine for reading is quite simple:
1) Turn motors on
2) Wait ~400ms
3) Search for certain sector
4) Check if success
5) Yes? -> turn motor off and return pointer to data
6) No? -> GOTO 3

Everything works under bochs, but on real hardware it looks like floppy has some problems detecting sectors.
Generally when I want to have good read I have to first "jump" to distant sector (~250 from what I want to read) and then come back.
Doing this I ALWAYS get good read. Any consecutive read is also good but only if I decide to read the same sector.
If I decide to read next one, the floppy sometimes can't find sector (after 10th try routine returns with error - "Can't find sector") or it looks like it didn't transfer data.

Could this be caused by old hardware?
(Probably not because under linux I also have some errors reading floppy but in the end it always manages to succeed and everything works.
On the other hand from time to time it shows I/O error or /dev/fd0 not found but usually on second try it finds it).

Re: FDC read problem on real hardware.

Posted: Mon Jul 07, 2014 2:25 pm
by ~
You might try to use a new, unused floppy disk. Unless you know how to robustly manage media errors, you will have too many run-time troubles with defective floppy disks.

Re: FDC read problem on real hardware.

Posted: Mon Jul 07, 2014 2:45 pm
by Brendan
Hi,
Waszka wrote:My routine for reading is quite simple:
1) Turn motors on
2) Wait ~400ms
3) Search for certain sector
4) Check if success
5) Yes? -> turn motor off and return pointer to data
6) No? -> GOTO 3
That looks too simple to me. Try something more like:
0) Set "retries" counter to zero
1) Turn motors on
2) Wait ~400ms
3) Search for certain sector
4) Check if success
5) Yes? -> turn motor off and return pointer to data
6) If status says something is severely wrong, give up and return error immediately
7) Increase "retries" counter
8 ) if "retries" counter > 9 give up and return an error
9) If "retries" counter % 3 == 0 issue "recalibrate" command
10) GOTO 3[/quote]


Cheers,

Brendan

Re: FDC read problem on real hardware.

Posted: Mon Jul 07, 2014 3:33 pm
by Waszka
Thank Brendan, I'll try it tomorrow. :)

I managed to deal with the problem by not turning the motors off. When motor is spinning all the time, there are no errors, no other problems.
Could it be realted to not waiting enough time (but I'm pretty sure that I'm waiting 400ms.)? O_o

Re: FDC read problem on real hardware.

Posted: Mon Jul 07, 2014 5:50 pm
by Brendan
Hi,
Waszka wrote:Could it be realted to not waiting enough time (but I'm pretty sure that I'm waiting 400ms.)? O_o
The "ideal" amount of time to wait depends on several factors that you can't know (e.g. disk motor quality/wear, "rotational resistance" of the media, how much speed variation the drive's read/write circuitry can tolerate, etc).

There's 3 approaches to dealing with this:
  • use a very conservative delay (to cover "worst case") and be slower than necessary
  • use a "slightly optimistic" delay and retry if/when it's not enough
  • use an adaptive approach that begins with a very optimistic value (for "best case") and if/when the delay isn't enough retry but also increase the delay for next time; so that (eventually) you find the ideal delay via. trial and error.
In general, most people go for the second option - a "slightly optimistic" delay and retry if/when it's not enough. The first option is slow, and the third option is over-complicated.

Basically; to avoid being unnecessarily slow you have to have some sort of retry; and retrying when the problem is "invalid command" or "can't write to write-protected disk" or "no media in drive" won't help; which brings us back to the algorithm in my previous post ;).


Cheers,

Brendan