Page 1 of 1
Calibrating the drive
Posted: Wed Dec 17, 2003 11:52 am
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
Re:Calibrating the drive
Posted: Thu Dec 18, 2003 3:54 pm
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...
Re:Calibrating the drive
Posted: Fri Dec 19, 2003 11:26 am
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.
Re:Calibrating the drive
Posted: Fri Dec 19, 2003 11:45 am
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.
Re:Calibrating the drive
Posted: Sun Dec 21, 2003 11:51 am
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.
Re:Calibrating the drive
Posted: Tue Dec 23, 2003 4:50 am
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)