Page 1 of 1

Floppy Read Error

Posted: Mon Jul 10, 2006 12:09 am
by Tolga
Hi all. I wrote my floppy read function. But it doesn't read.

Code: Select all

// Read Sector
void tfdc::read_sector( unsigned short lba, unsigned char sector_count, unsigned short selector, unsigned int offset )
{
   // Data
   tdma dma;

   // Setup DMA
   cli();
   dma.set_dma_channel( dma_channel );
   dma.disable_channel();
   dma.set_control_byte_mask( dma_single_mode, dma_address_increment, dma_auto_init, dma_read_transfer );
   dma.clear_flip_flop();
   dma.set_address( 0 );
   dma.set_transfer_length( sector_count * 512 );
   dma.set_buffer_info();
   sti();
   dma.enable_channel();

   // Prepare Driver
   prepare_driver( true );

   // Setup FDC
   outport( data_register, 70 );   // Single Track Operation, Double Density, Do Not Skip
   outport( data_register, fdc_floppy_driver + get_head( lba ) * 4 );
   outport( data_register, get_cylinder( lba ) );
   outport( data_register, get_head( lba ) );
   outport( data_register, get_sector( lba ) );
   outport( data_register, fdc_sector_size );
   outport( data_register, fdc_sector_count );
   outport( data_register, fdc_length_of_gap3 );
   outport( data_register, 0xFF );

   // Read Result
   fdc_command_status0      = inport( data_register );
   fdc_command_status1      = inport( data_register );
   fdc_command_status2      = inport( data_register );
}
I used this function; fdc.read_sector( 0, 1, 0x08, 0 );
It must read to 0 address. But it don't. What is the problem?

Thanks.

Re:Floppy Read Error

Posted: Mon Jul 10, 2006 4:32 am
by blip
Does dma_read_transfer contain a value that means "write to memory" instead of read? It's easy to get them mixed up. Also make sure the floppy density is correct. Do you get an error status from the FDC? Do the DMA's address and count registers change?

Re:Floppy Read Error

Posted: Mon Jul 10, 2006 5:53 am
by Tolga
dma_read_transfer, and others are constant. My "select_driver" function loads it.

Before read function, i read main status register. It is suitable for command. But read function isn't do something. I changed sector count to 50. Nothing changed. Because it doesn't do something with floppy. So i understand that error isn't about dma.

Re:Floppy Read Error

Posted: Mon Jul 10, 2006 8:11 am
by viral
Hello..
What are you doing in prepare_driver() function? I dont know whether your code is correct or not but I see many breakpoints in it. You are not waiting for interrupts.

First of all I would suggest you to use sendData(), getData() functions specified in Intels manuals, instead of normal outport,inport. These functions are nothing but wrapers around out,in with some looping.

Second thing whenever you initialize your floppy driver you have to give a "reset" command to fdc(dont know whether you are doing it or not). Once the initialization is done, every read/write command can follow these sequences:

1. Turn ON the fdc motor (and wait for interrupt).
2. Send Recalibration command (and wait for interrupt).
* if head is allready on desired cylinder then simulate sense_interrupt command.
* else send "seek" command wait for int(do sense_interrupt in ISR).
3. Send Read/Write commands with all arguements(and wait for interrupt).
4. Get status of the operation and copy the content from DMA buffer to desire buffer and turn off the motor.

I am doing this way and my driver is working properly..

Re:Floppy Read Error

Posted: Sat Jul 15, 2006 2:47 pm
by Tolga
---------------------------------------------------------
---------------------------------------------------------
---------------------------------------------------------

Hi. Floppy read error still continuing. I'm writing my processes:

1. Reset Controller (In this, occuring IRQ 6)
-> send 0x00 to DOR (Disable Everythink)
-> send 0x0C to DOR (Enable DMA & Controller)
-> wait some
-> send sense command and read results
-> send recalibarate command

2. Read Disk
-> Turn on Motor
-> Wait some
-> Send commands (Read Command and other bytes)

But after i sent second command for read operation, occuring int 0. I don't understand. What can i do? ???

Re:Floppy Read Error

Posted: Sun Jul 16, 2006 1:14 am
by blip
I think you need to also execute the SPECIFY command with the proper values and set the FDC to the proper data rate for the media density you're expecting. Page 41 of this document gives a flowchart of what you need to do to reset.

Re:Floppy Read Error

Posted: Sun Jul 16, 2006 4:28 am
by Kemp
I notice in the code you posted you are not waiting for things to happen (either way "scripted waits" or by waiting for the interrupt). Floppy drives can take a long time to do things.

Re:Floppy Read Error

Posted: Sun Jul 16, 2006 5:23 am
by Tolga
Now i added "wait for interrupt". I still writing codes. But i will send configure command. In this command, there is STR. I found a document about this. But i think document wrong.

http://www.mega-tokyo.com/osfaq/FloppyDriver

In this document, writing a formula for calculating SRT:

SRT_value = 16 - 0.008 * 500000 / 500000

And writing 8 for this result. But real result is 15,992.

What is the problem? What is real formula?

Re:Floppy Read Error

Posted: Wed Jul 19, 2006 2:00 pm
by Tolga
Hey thanks to everybody. But after read operation, i read status register 0. It is 128. This mean is invalid command. What can the problem be?

Re:Floppy Read Error

Posted: Wed Jul 19, 2006 4:42 pm
by bluecode
Tolga wrote:outport( data_register, 70 ); // Single Track Operation, Double Density, Do Not Skip
As you might have guessed, it's the wrong command :) the read track command ist 0x02 in the lower 5bits ;)