Floppy Disk Controller does not want to write to sector 3
Posted: Wed Jun 05, 2013 9:24 pm
Hello, I am fairly new to operating system development. I have been lately trying to create a floppy disk controller driver that can read and write to and from a floppy. I have made the fdc to read and write, but when I tested it to write one sector (512bytes) the the third sector, my hex editor shows no change. I did the same test writing to the fourth sector, first sector, fifth sector, twentieth sector, everything worked. Writing to the third sector is the issue. I also did a test where I wrote 2 sectors (1 KB) starting at the third sector, and everything worked fine. Has anyone expirienced such problems with their fdc driver.
Here is the write sector code (the data I want to write is in the DMA already):
My first assumption for the solution to this issue was the floppy disk read/write protection, although I also cannot successfully read from the third sector with a sector size of 1. I can read successfully with a sector size of > 1 sector though. Could this be the issue?
Thank you.
Here is the write sector code (the data I want to write is in the DMA already):
Code: Select all
//the floppy must be on in order to read from it
floppy_motor(FLOPPY_MOTOR_ON, _CurrentDrive);
//set the dma to write
set_floppy_dma(FALSE);
//send command that we want to write to a sector with some generic flags
floppy_send_command(FDC_CMD_WRITE_SECT | FDC_CMD_EXT_MULTITRACK |
FDC_CMD_EXT_SKIP | FDC_CMD_EXT_DENSITY);
//specify which head and drive to use
floppy_send_command((head << 2) | _CurrentDrive);
floppy_send_command(track); //specify the track
floppy_send_command(head); //specify the head
floppy_send_command(sector); //specify the sector
floppy_send_command(FLOPPY_SECTOR_DTL_512); //specify to use 512 bytes per sector
k_printf("head: %d, track: %d, sector: %d, size %d\n", head, track, sector, (s32int)((size - 1) / SECTOR_SIZE) + 1);
/*send command to write the ceil of the number of sectors that make
* up size, (size - 1) / SECTOR_SIZE, add 1 to make it ceiling
*
* the -1 in (size - 1) is used if size == SECTOR_SIZE, then the output
* of this calculation would be still 1 sector, without the -1, the ouput
* would be 2 which is incorrect*/
floppy_send_command((s32int)((size - 1) / SECTOR_SIZE) + 1);
//state that we are using a 3.5in floppy disk
floppy_send_command(FLOPPY_GAP3_LENGTH_3_5);
floppy_send_command(0xff); //floppy data length, set to 0xff if sector size != 0
//wait for interupt
floppy_wait_irq();
//read the status info
u32int _st0, _st1, _st2, ncyl, ehead, esect, final;
_st0 = floppy_read_data();
_st1 = floppy_read_data();
_st2 = floppy_read_data();
ncyl = floppy_read_data();
ehead = floppy_read_data();
esect = floppy_read_data();
final = floppy_read_data();
//let the FDC aknowledge that the interupt has been handled
floppy_check_int(&st0, &cyl);
if(!(_st0 & 0xc0))
{
break;
}
Thank you.