[SOLVED] Cant get floppy driver to work.

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
ruisleipa
Member
Member
Posts: 46
Joined: Wed Sep 10, 2008 8:39 am
Location: Finland

[SOLVED] Cant get floppy driver to work.

Post 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
Last edited by ruisleipa on Thu Sep 25, 2008 9:58 am, edited 3 times in total.
http://code.google.com/p/rmmtos/ - Real Mode MultiTasking Operating System
User avatar
Stevo14
Member
Member
Posts: 179
Joined: Fri Mar 07, 2008 3:40 am
Location: Arad, Romania

Re: Cant get floppy driver to work.

Post 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);
ruisleipa
Member
Member
Posts: 46
Joined: Wed Sep 10, 2008 8:39 am
Location: Finland

Re: Cant get floppy driver to work.

Post 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.
http://code.google.com/p/rmmtos/ - Real Mode MultiTasking Operating System
ruisleipa
Member
Member
Posts: 46
Joined: Wed Sep 10, 2008 8:39 am
Location: Finland

Re: Cant get floppy driver to work.

Post 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<
Attachments
fdc.c
(10.64 KiB) Downloaded 45 times
fdc.h
(1.64 KiB) Downloaded 56 times
http://code.google.com/p/rmmtos/ - Real Mode MultiTasking Operating System
User avatar
Stevo14
Member
Member
Posts: 179
Joined: Fri Mar 07, 2008 3:40 am
Location: Arad, Romania

Re: Cant get floppy driver to work.

Post 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:
ruisleipa
Member
Member
Posts: 46
Joined: Wed Sep 10, 2008 8:39 am
Location: Finland

Re: Cant get floppy driver to work.

Post 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?
http://code.google.com/p/rmmtos/ - Real Mode MultiTasking Operating System
ruisleipa
Member
Member
Posts: 46
Joined: Wed Sep 10, 2008 8:39 am
Location: Finland

Re: Cant get floppy driver to work.

Post 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.
http://code.google.com/p/rmmtos/ - Real Mode MultiTasking Operating System
User avatar
Stevo14
Member
Member
Posts: 179
Joined: Fri Mar 07, 2008 3:40 am
Location: Arad, Romania

Re: Cant get floppy driver to work.

Post 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.
ruisleipa
Member
Member
Posts: 46
Joined: Wed Sep 10, 2008 8:39 am
Location: Finland

Re: Cant get floppy driver to work.

Post 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.
http://code.google.com/p/rmmtos/ - Real Mode MultiTasking Operating System
Post Reply