Calibrating the drive

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
Rahman

Calibrating the drive

Post by Rahman »

   i have written a function to calibrate the FDD head to cylinder 0. but, the function doesn't calibrate the drive to cylinder 0.instead it parks the head at the cylinder 112 or 36.
what's wrong with this code. is there any other condition to be handled?

StartFDDMotor();
SendByte(0x07);
SendByte(0x00);
StopFDDMotor();

SendByte(0x08);
r = ReadByte();
kprintf("\nResult = %d",r);

thanks
drizzt

Re:Calibrating the drive

Post by drizzt »

Before stopping the motor off you must give the controller the time to finish the recalibration...

If you use an interrupt-driven approach you can wait for the next interrupt (IRQ6) to verify when the controller has done the recalibration.

If you use polling there is a little complication, because the recalibrate command doesn't have a result phase... so you can't check the COMMAND BUSY bit of the MAIN STATUS REGISTER (MSR). Maybe, in this case, you have to check the TRK0 bit in the STATUS REGISTER A, but I'm not so sure...
Rahman

Re:Calibrating the drive

Post by Rahman »

now, i've corrected the problem.
But, when i issue the command to seek the FDD head to the cylinder specified once, it moves forward to only 1 cylinder. i have to repeatedly apply the command till the head reaches the cylinder specified. i just want to know, why is it so?

Code: Select all

if(fdd0->dev_fdd_ccylinder == cylinder)
    return;

while(fdd0->dev_fdd_ccylinder != cylinder)
{
   SendByte(0x0F);
   SendByte(0x00);
   SendByte(cylinder);
   SendByte(0x08);
   r = ReadByte();
   r = ReadByte();
   fdd0->dev_fdd_ccylinder = r;
   kprintf("\nCurrent Cylinder Pos. = %x",r);
}

Any help appreciated.
Tim

Re:Calibrating the drive

Post by Tim »

As drizzt said, you've got to wait for an interrupt. You're not giving the drive a chance to do the seek before you ask it whether it's finished :). I believe you can also poll on the status register, but waiting for an IRQ is preferable.
neowert

Re:Calibrating the drive

Post by neowert »

wouldnt polling the status register take up a lot of useful cpu time? If as soon as you told the FDD to seek, and you released control to other processes, you would be very efficent. That is one reason multitasking can be more efficent than single. You can do other things while waiting.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Calibrating the drive

Post by Pype.Clicker »

neowert wrote: wouldnt polling the status register take up a lot of useful cpu time? If as soon as you told the FDD to seek, and you released control to other processes, you would be very efficent. That is one reason multitasking can be more efficent than single. You can do other things while waiting.
Yes, provided that you already have a multitasking support and a way to wait for interrupts "but not longer than 3 seconds" stuff ...
There are many people that actually work on the FDD driver *before* they start working on multitasking (not my own case, but still, people do it)
Post Reply