Page 2 of 3

Re:Floppy driver tutorial

Posted: Thu Jan 12, 2006 3:08 pm
by Vladaz
Yes, I have:)

Re:Floppy driver tutorial

Posted: Thu Jan 12, 2006 4:19 pm
by Dex4u
This is the wait for floppy int in my driver

Code: Select all

 ;----------------------------------------------------;
 ; Wait Done                 ;waits for a floppy int. ;
 ;----------------------------------------------------;

WaitDone:
mov   [Timer],30  ; 20 = about 1 second,we use (1.5 seconds).
mov   [TimerOn],1  ; start couting.
WaitDoneLoop:
mov   al,[TimerOn]  ; we test if
or    al,al                ; timeout is up yet?.
jz    WaitDoneError  ; if it is we exit,with error.
mov   ax,[done]       ; if not we check for floppt int.
or    ax,ax
jz    WaitDoneLoop ; if not do another loop.
clc                         ; we end here if we have a int:-)
ret

WaitDoneError:      ;we end up here if we run out of time:-(.
stc
ret
It is called like this:

Code: Select all

mov   [done],0  ; we need to wait
call  WaitDone  ; for floppy int.
jc    FddReadError  ; jump to error exit,if timeout.
And here is what appans whan a floppy int comes
Also Note this code go in your ISR, so when it firers, it sets [done] to 1.

Code: Select all

or    [done],1
Thats how it works, if your using C, you will need to convert it.

Re:Floppy driver tutorial

Posted: Thu Jan 12, 2006 5:17 pm
by Vladaz
So that's just makes a thing "where to go if something happens". But how to check that floppy interrupt, when it comes and else? I mean, maybe there you have to check some port or anything else or is it enough?

Re:Floppy driver tutorial

Posted: Thu Jan 12, 2006 5:29 pm
by Phugoid
Uh. You have to write an interrupt handler that will set the byte at "done" to use that code, as Dex4u just pointed out. You don't directly "check" for when an interrupt comes. It just comes and interrupts you. It causes the processor to drop what it's doing and execute the code in the appropriate interrupt handler. When the interrupt handler is finished, the processor resumes executing the code that was interrupted. You can think of it as subroutine that can be called by devices.

Re:Floppy driver tutorial

Posted: Thu Jan 12, 2006 5:34 pm
by Dex4u
@Vladaz.
You miss understand the code, first the var [done] is set to 0 , when the floppy irq fires, it sets the [done] var to 1 .
We test the var [done] if its 0, we loop, if its 1 we exit with no error, if it has not fired by 1.5 seconds we exit with a timeout error.

The "or [done],1 " code goes in your floppy ISR.

Re:Floppy driver tutorial

Posted: Thu Jan 12, 2006 5:38 pm
by Vladaz
Oh. Now I get it:) But how Floppy Interrupt can know when to fire?:)

And I have another question about the another function:
start_dma();
Any ideas?:)

Re:Floppy driver tutorial

Posted: Thu Jan 12, 2006 6:17 pm
by Dex4u
I can not see how you have got your IDT working, but do not know about hardware int's and software int's and things like Dma, i think you should read up on these before going on with your floppy driver.

Re:Floppy driver tutorial

Posted: Thu Jan 12, 2006 11:43 pm
by Candy
Dex4u wrote: This is the wait for floppy int in my driver
What's the point of interrupt-driven programming if you're going to convert it into a polling loop?

Re:Floppy driver tutorial

Posted: Fri Jan 13, 2006 4:17 am
by bubach
It's single tasking.

Re:Floppy driver tutorial

Posted: Fri Jan 13, 2006 4:26 am
by Pype.Clicker
Vladaz wrote: Oh. Now I get it:) But how Floppy Interrupt can know when to fire?:)

And I have another question about the another function:
start_dma();
Any ideas?:)
http://www.osdev.org/osfaq2/index.php/DMA ?

Re:Floppy driver tutorial

Posted: Fri Jan 13, 2006 6:07 am
by dushara
Hi I don't know how to reply to an individual message so I'm writing here:

@ Code Slasher,

extern _floppy_int_count
_floppy_int:
inc word [_floppy_int_count]
mov al,0x20 ;acknowledge interrupt to PIC
out 0x20,al
iret


then in the C code,
Code:

unsigned short floppy_int_count=0;
void wait_floppy_interrupt()
{
while(floppy_int_count <= 0);
floppy_int_count--;
return;
}


shouldn't floppy_int_count be declared volatile?

Re:Floppy driver tutorial

Posted: Fri Jan 13, 2006 7:45 am
by Slasher
If you want, you can declare it as volatile. Doesn't make much difference, as only used in 2 places.

Note: That code is used to show a principle. In my os, the driver actually does to sleep instead of polling.

Re:Floppy driver tutorial

Posted: Fri Jan 13, 2006 10:53 am
by Dex4u
Candy wrote:What's the point of interrupt-driven programming if you're going to convert it into a polling loop?
Yes i was waiting for someone to point this out ;D .
As bubach said it single tasking. but maybe if we add multi-threading support, we may rethink this.

Re:Floppy driver tutorial

Posted: Fri Jan 13, 2006 2:00 pm
by Vladaz
And actually, I'm now searching for the information about making the functions usleep() or sleep(). I will appreciate any good ideas. Or maybe even source code:)

Re:Floppy driver tutorial

Posted: Fri Jan 13, 2006 2:43 pm
by Phugoid
Hi,

I've got two good ideas:
1. Tell us what sleep and usleep are supposed to do.
2. Come up with the solution completely on your own without asking for source code, and learn from it.