Reading floppy using ports...
Re:Reading floppy using ports...
I too face this problem. Whenever I try to read a sector(0,0,1) from the floppy drive, the controller couldn't find the specified sector ID. What could be the problem behind this?
any help appreciated.
any help appreciated.
Re:Reading floppy using ports...
We can't help you without seeing the code you are using
Re:Reading floppy using ports...
I have given my coding for just reading the sector 0,0,1 of the floppy drive. The FDC returns informing that it couldn't find the specified sector ID address mark. I have to complete this coding before the end of this month. so, plz help me. And I also wanted to know that should I initialize the floppy using any other command before reading the sector.
any help greatly appreciated.
Code: Select all
void sendb(UCHAR data)
{
UCHAR msr;
msr = inb(0x3F4); // Get MSR
while((msr & 0xC0) != 0x80) // Wait till FDC gets free
msr = inb(0x3F4);
outb(FDC_DATA, data); // Send byte to data register
kprintf("\nByte Sent %x", data);
}
UCHAR readb()
{
UCHAR msr;
msr = inb(0x3F4);
while((msr & 0xC0) != 0xC0)
msr = inb(0x3F4);
msr = inb(0x3F5);
return msr;
}
void readblock(UCHAR block, UCHAR *dBuffer)
{
UCHAR cyl, sect, head, i, st0, st1, st2, c,h,s,ns;
LBA2CHS(block, &cyl, &head, §);
outb (FDC_CCR, 0); // Data Transfer Rate (500kb/s)
floppy_status = FDS_READING;
StartFDDMotor();
sendb (0x66); // command to read a sector
sendb (0); // head 0 of drive 0
sendb (0); // cylinder
sendb (0); //head
sendb (1); //sector
sendb (2); // sector size
sendb (18); // sectors per track
sendb (0x1B); //FD_GAP3RW
sendb (0xFF);
while(floppy_status != FDS_IDLE);
st0 = readb();
st1 = readb();
st2 = readb();
c = readb();
h = readb();
s = readb();
ns = readb();
kprintf("\nST0 = %x",st0);
kprintf("\nST1 = %x",st1);
kprintf("\nST2 = %x",st2);
kprintf("\nCylinder = %x",c);
kprintf("\nHead = %x",h);
kprintf("\nSector = %x",s);
kprintf("\nSector Size = %x",ns);
StopFDDMotor();
}
Re:Reading floppy using ports...
That is an endless loop. Where is the code to read the status in the while loop?while(floppy_status != FDS_IDLE);
I think this is what you want
while(floppy_status != CONSTANT INDICATING FLOPPY IS FREE)
floppy_status = read floppy status port;
as the code is you are reading the result phase when the floppy controller is still in the data phase. This is because you set
floppy_status = FDS_READING and then did
while(floppy_status != FDS_IDLE). That is a BAD design. Floppy status should be what the controller returns as the status after you read the status port(s) and not what you set by yourself.
Besides that is what lead to your endless loop,
you set floppy_status = FDS_READING and then you are testing for floppy_status = FDS_IDLE without modifying the status
I suggest you write
wait_floppy_ready and wait_floppy_data routines.
Re:Reading floppy using ports...
I'm sorry. I forgot to post my floppy IRQ Handler. Now i've given the FDC IRQ.
any help appreciated
Code: Select all
void FDD_Irq()
{
int i;
kprintf("\nIRQ Called\n");
switch(fdd_status)
{
case FDS_READINGID:
fdd_status = FDS_IDLE;
break;
case FDS_READING:
// Reading the result registers
for(i=0;i<=6;i++)
kprintf("\n%x",ReadByte());
fdd_status = FDS_IDLE;
break;
case FDS_RESETTING:
fdd_status = FDS_IDLE;
break;
case FDS_CALIBRATING:
fdd_status = FDS_IDLE;
break;
case FDS_SEEKING:
fdd_status = FDS_IDLE;
break;
}
}
Re:Reading floppy using ports...
Is it necessary to initialize the FDC before issuing the read command? and also, how long should I wait to receive data from the data register after issuing the read command?
any help appreciated
any help appreciated
Re:Reading floppy using ports...
This floppy function gives me a value of 0x28 on BOCHS and 0x04 on my computer. Is the output correct? how can it be 0x04 in the st3 register?
Code: Select all
void chk_drive_status(void)
{
volatile BYTE st3=0,msr=0;
while( (inb(FDCA_BASE+MSR) & 0xC0)!=0x80 );
outb(FDCA_BASE+DR,CHK_DRIVE_STATUS);
outb(FDCA_BASE+DR,0x0);
while( (inb(FDCA_BASE+MSR) & 0x80)!=0x80);
st3=inb(FDCA_BASE+DR);
printf("\nST3=%x",st3);
}
Re:Reading floppy using ports...
Just curios. Is floppy programming really difficult or is it that most of you haven't witten floppy drivers as yet?
I;m asking because i haven't started out as yet.
I;m asking because i haven't started out as yet.
Only Human
Re:Reading floppy using ports...
It is isn't *that* simple, but neither it is very hard. Some time ago I tried and I in 2 weeks I had my driver only read a bootsector. But then, perhaps I wasn't experienced enough. Now I wrote the driver in a week's time. Thank God it works and I can focus on the file service
Re:Reading floppy using ports...
Great then what do i need before i start out? Right now my kernel has a memory manager with paging enabled and also has interrupts etc setup can i start out now.
then why hasn't anyone been able to answer these questions here?It is isn't *that* simple, but neither it is very hard.
Only Human
Re:Reading floppy using ports...
perhaps nobody took his time to reply.then why hasn't anyone been able to answer these questions here?
an interrupt manager, and the pic reprogrammed so you can catch fdc irqs.Great then what do i need before i start out?
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Reading floppy using ports...
Quoting a comment in 'linux/drivers/block/floppy.c'Neo wrote: then why hasn't anyone been able to answer these questions here?
most of the ppl that start with a floppy driver send their resume as "i see ST2 has 03, is it normal ?"/*
* This file is certainly a mess. I've tried my best to get it working,
* but I don't like programming floppies, and I have only one anyway.
* Urgel. I should check for more errors, and do more graceful error
* recovery. Seems there are problems with several drives. I've tried to
* correct them. No promises.
*/
how could i know if i haven't a cache hit for the floppy specs right at the moment ... I've used INT13 to read what i wanted from my boot floppy, but i do not consider floppy driver as something "interresting" to do ... i'm more focusing on hard disks ...
I saw Tim had a nice Floppy driver in the Mobius and that it was GPL ... i'll probably port that one when i'll have no other choice (after i ask for his blessing, of course
PCI and USB sounds more interresting to me ...
Re:Reading floppy using ports...
Feel free to use my source . The current version doesn't support multiple drives on one controller, though, and it probably won't do soon.
Re:Reading floppy using ports...
sir,what is the procedure to do a "check interrupt status" command with the floppy controller?
The one i have written right now goes like this
on printing ST0 and CYL i got ST0=8 and CYL=8.
is this procedure right? do i have to wait before reading the DR? if so what bits should i check for?
does the "check int status" itself issue an interrupt after completion?
do i have to include any delays anywhere?
The one i have written right now goes like this
Code: Select all
1) Read MSR and check if MRQ bit is set and DIO it is clear
2) send the command(0x08) to the Data register(DR)
3) read the DR twice first for ST0 and then for CYLinder no.
is this procedure right? do i have to wait before reading the DR? if so what bits should i check for?
does the "check int status" itself issue an interrupt after completion?
do i have to include any delays anywhere?