FDC read problem on real hardware.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Waszka
Member
Member
Posts: 38
Joined: Tue Apr 22, 2014 11:30 am
Location: Poland

FDC read problem on real hardware.

Post 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).
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: FDC read problem on real hardware.

Post 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.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: FDC read problem on real hardware.

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Waszka
Member
Member
Posts: 38
Joined: Tue Apr 22, 2014 11:30 am
Location: Poland

Re: FDC read problem on real hardware.

Post 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
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: FDC read problem on real hardware.

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply