Page 1 of 1

[SOLVED] Cant get floppy driver to work.

Posted: Sat Sep 20, 2008 8:30 am
by ruisleipa
Hello. I am (still) writing a floppy disk driver. I just can't get it working. No matter how I look the code and compare it to others and to specs I don't notice any errors. I even have written the driver from scratch a couple of times. Newest version just hangs waiting for an interrupt after the calibrate command. The interrupt waiting routines work and have worked before so they are not the reason.

I would really appreciate pointers about possible places worth looking in the code.

Thanks in advance.

EDIT: The code is in the last post

Re: Cant get floppy driver to work.

Posted: Sat Sep 20, 2008 11:29 am
by Stevo14
Make sure you send the sense interrupt command before reading the results.

Code: Select all

fdc_wait_irq();

for(i=0;i<4;i++)
{
	//sense interrupt command here
	fdc_read_cmd();
	fdc_read_cmd();			
}
	
fdc_write_cmd(FDC_CMD_SPECIFY);

Re: Cant get floppy driver to work.

Posted: Sun Sep 21, 2008 12:40 am
by ruisleipa
EDIT: Ok. Only the first sense (in fdc_reset()) goes to the controller. All later tries to write commads to the data register seem to timeout. I've already tried to make the timeout larger but it does not help.

I have made some changes and now reading ends with end of cylinder error if i take the specify part away. But if I put SPECIFY back it freezes after calibrate. Plus I get the following in the console when running in QEMU. Those come up just after sending SPECIFY etc. when I am sending the parameters for the command.

Code: Select all

FLOPPY ERROR: fdctrl_write_data: unknown command: 0x00
or

Code: Select all

FLOPPY ERROR: fdctrl_write_data: unknown command: 0xff
I can say for sure that the latter comes right after specify command.[/i][/color]

Updated sources are at the first post.

Re: Cant get floppy driver to work.

Posted: Sun Sep 21, 2008 11:34 pm
by ruisleipa
(Sorry, double post)

What might be the reason for timeouts after only one command sent to the floppy disk controller. When resetting, the first sense interrupt goes to the controller without any errors but all later tries to send data/commands fail. I have tried some other ways of checking werther the controller is ready to receive data, but those cause errors in QEMU:

FLOPPY ERROR: floppy_write_data(?): cannot write in STATUS mode

or

FLOPPY ERROR: floppy_read_data(?): cannot read in CMD mode

I have checked the 82077AA floppy controller datasheet and have made my routines the way that they are in the flowcharts.

Please could you help me finding the error in the code. [-o<

Re: Cant get floppy driver to work.

Posted: Mon Sep 22, 2008 12:26 am
by Stevo14
I would suggest that you take another look at the data sheet. I didn't take very much time to look over the code but, as an example, when you issue the seek command:

Code: Select all

fdc_write_byte(FDC_CMD_SEEK);
fdc_write_byte(fdc_drive|(head<<2));

the floppy driver expects a second parameter (see table 5-1 in the data sheet that you mentioned. Page ~21). In this case the second parameter is the new cylinder to seek to. Qemu gives you the errors because the floppy driver is still in the command phase of the seek command when you write the sense_interrupt command, causing it to seek to track 8 (the sense_interrupt command number) and causing further reads and writes to be out of sync with the floppy controller's mode. This may happen other places as well, I didn't look really closely, that's your job. :wink:

Re: Cant get floppy driver to work.

Posted: Mon Sep 22, 2008 2:15 am
by ruisleipa
Ok. Thanks for the tip. I wasn't focused in issuing commands themselves, but the functions transferring them. I have made some corrections now. I'll try the new code later this day since i'm in school now :)

Thank you for looking my code.

BTW: What do you think about my code itself. Does it look clear? What would you do otherwise?

Re: Cant get floppy driver to work.

Posted: Mon Sep 22, 2008 8:10 am
by ruisleipa
Thank you. No more errors from QEMU! Now i've got to find out why there is nothing in the DMA buffer after completing the read.

Re: Cant get floppy driver to work.

Posted: Mon Sep 22, 2008 1:55 pm
by Stevo14
mikkop92 wrote:Thank you. No more errors from QEMU!
Good to hear! :)
mikkop92 wrote:BTW: What do you think about my code itself. Does it look clear? What would you do otherwise?
The code itself looks fine. All of the common tasks are split into seperate functions, it is well formatted, easy to read etc. I hope you get DMA working, be sure to ask here if you get really stuck.

Re: Cant get floppy driver to work.

Posted: Thu Sep 25, 2008 9:58 am
by ruisleipa
I finally got DMA working!!!

I had accidentally set the no-dma bit in the specify command and also forgot to enable it in DOR. The driver now prints the content of the track to the screen.