problem in floppy driver

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
shahzad

problem in floppy driver

Post by shahzad »

i'm writing a floppy driver.but when i execute reset command and read value in data register
it returns 128 which i think is not correct.
please tell me what's causing problem.
whats the correct value that i should recieve;

here is output of my code

interrupt recieved
controller is ready to accept commands
status1=128

Code: Select all

int  main(void)
{

reset_floppy();

  if(interrupt)
   {
   printf("\ninterrupt recieved");
   check_controller_status();
   }


}

/////////////////////////
reset_floppy()
{

outportb(0x3f2,0x00); 
outportb(0x3f2,0x0c);
}
////////////////////////////
check_controller_status()
{
unsigned char status=0,status1=0;
status=inportb(0x03f4);
if(status==0x80)
{
printf("\ncontroller is ready to accept commands");
outportb(0x03f5,0x08);
wait_floppy_data();
status1=inportb(0x3f5);
printf(" \nstatus1=%u ",status1);
}
else
printf("\nnot ready to accept commands");

}

/////////////////////////////////////////
void wait_floppy_data()
{
while(((inportb(0x03f4))&0xd0)!=0xd0);
return;
}

shahzad

Re:problem in floppy driver

Post by shahzad »

people generally don't check the status of registers ,first time they execute the reset command.
can u explain why they don't do this.
bkilgore

Re:problem in floppy driver

Post by bkilgore »

The reset "command" isnt really a command so much... there is no command/result phase. If you reset the controller by not maintaining the NOT-RESET bit, then the controller resets. Because it is not a command and has no result, the status register will not contain any meaningful information about the reset, only the default values loaded when the controller initializes (which wil probably say something about abormal termination or something). Also, there is no real need to see if the reset works, since it is a hard reset, the controller will reset no matter what.
shahzad

Re:problem in floppy driver

Post by shahzad »

OK.in fabian's floppy driver ,he uses instruction

Code: Select all

inb(0x80)
for delay purposes.can u tell me what is contained at that port address and how it contributes in delay.
Tim

Re:problem in floppy driver

Post by Tim »

There isn't anything at that port address, which is why it's safe to use as a delay. The delay happens because, like all port I/O, the processor must wait for the motherboard hardware to finish the IN operation before continuing. One cycle on, say, the PCI bus might take fifty or a hundred CPU cycles.

However, there are more reliable methods for introducing delays. For short, accurate delays, I would poll on the real-time clock.
Post Reply