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.