Page 1 of 1

FDC Problem: read sector from disc

Posted: Fri Sep 03, 2004 5:29 pm
by rumpel
Hi,

the part of the floppy-driver works until it reaches the first read sector from, disc function. Seek and Specify work as expected, read sec.. returns no interrupt.

This is the used code:

Code: Select all


typedef struct {
   uchar head;
   uchar track;
   uchar sektor;
} disk_position_t;

void init_fdc(void)
{
   fdc_reset();
   
   fdc_recalibrate();
   fdc_seek(1);

   set_disk_position(1, &disk_pos);

   if(!fdc_read_sektor(&disk_pos)) {
      printf("Error: Can't read Sektor.\n");
   }
}
void fdc_reset(void)
{
   // reset
       motoroff();
   
   // select floppydrive
   outb(FD_DOR, 0x1c);

   // data rate: 500k/s
   outb(FD_DRS, 0);
   wait_fdc_irq(0);

   // specify floppy type:
   send_byte(FD_DATA, FD_SPECIFY);
   send_byte(FD_DATA, 0xdf);   //floppy_type.spec1);
   send_byte(FD_DATA, 0x02);   //floppy_type.spec2);
   
   clear_floppy_irq();
}
uchar fdc_seek(uchar track)
{
   send_byte(FD_DATA, FD_SEEK);
   send_byte(FD_DATA, 0);
   send_byte(FD_DATA, track);

   wait_fdc_irq(1);

   if((fdc_st0 != 0x20) || fdc_dp->track != track ) {
      printf("Floppy Disk Controller: fdc_seek fehlgeschlagen. ST0 = %d", fdc_st0);
      return(0);
   } else {
      return(1);
   }
}
uchar fdc_recalibrate(void)
{
   //motoron();

   send_byte(FD_DATA, FD_CALIBRATE);
   send_byte(FD_DATA, 0);

   wait_fdc_irq(1);
   //motoroff();
}

The functions making problems:

Code: Select all

void set_disk_position(int log_sek, disk_position_t *dp)   // Logischer Sektor => CHS
{
   dp->track   = (log_sek / 18) / 2;
   dp->head   = (log_sek / 18) % 2;
   dp->sektor   = ((log_sek % 18)+1);
}

int fdc_read_sektor(disk_position_t *dp)
{
   dma_block_t dma_block;

   if(!fdc_seek(dp->track)) {
      printf("fdc_read_sektor: fdc_seek returns error.\n");
      return 0;
   }
   
   
   setup_dmablock(&dma_block, 0x40000, 0x200);
   setup_dma(2, 0x46, &dma_block);
   clear_floppy_irq();
   send_byte(FD_DATA, 0xe6);
   send_byte(FD_DATA, dp->head << 2);
   send_byte(FD_DATA, dp->track);
   send_byte(FD_DATA, dp->head);
   send_byte(FD_DATA, dp->sektor);
   send_byte(FD_DATA, 2);   // sek = 512 Bytes
   send_byte(FD_DATA, 18);
   send_byte(FD_DATA, 0x1b);
   send_byte(FD_DATA, 0xff);
   
   fdc_st0 = 0xFF;
   wait_fdc_irq(0);
   

   if((fdc_st0 & 0xc0) != 0x00) {
      printf("fdc_read_sektor: Error %d.\n", fdc_st0 & 0xc0);
      return 0;
   }
   return 1;
}

Thank you, rumpel.

Re:FDC Problem: read sector from disc

Posted: Sat Sep 04, 2004 6:25 am
by Brendan
Hi,
rumpel wrote: the part of the floppy-driver works until it reaches the first read sector from, disc function. Seek and Specify work as expected, read sec.. returns no interrupt.
Take a look here:
http://www.mega-tokyo.com/forum/index.p ... eadid=6652

- Brendan