Page 1 of 1

PIT programming

Posted: Fri Jul 14, 2006 5:33 am
by Tolga
Hi. I want to learn PIT programming. But i don't have a document. I search at google. But documents aren't advanced. Where can i found documents about pit programming?

Re:PIT programming

Posted: Fri Jul 14, 2006 5:46 am
by blip
There are plenty as I see it. From what I can find in a couple of minutes:
http://www.mega-tokyo.com/osfaq/PIT
http://heim.ifi.uio.no/~stanisls/helppc/8253.html
http://kos.enix.org/pub/82C54_PIT_Datasheet.pdf
http://en.wikipedia.org/wiki/8254
Try using 8254 in your search terms, like "8254 pit" minus the quotes.

Re:PIT programming

Posted: Fri Jul 14, 2006 3:06 pm
by Tolga
My PIT doesn't run. I only remapped irqs. Can the problem be that irq0 disabled?

Re:PIT programming

Posted: Fri Jul 14, 2006 4:10 pm
by Ryu
Tolga wrote: My PIT doesn't run. I only remapped irqs. Can the problem be that irq0 disabled?
It could be masked in the PIC, I'm assumming your using the legacy 8259A controller which can be unmasked something like:

Code: Select all

   mov      al, 11111010b      ; mask all but IRQ-0 & IRQ-2 (cascade)
   out      021h, al
   mov      al, 11111111b      ; mask all in slave
   out      0A1h, al


Re:PIT programming

Posted: Fri Jul 14, 2006 4:21 pm
by Combuster
No documents i've read say something about the mask register being set or cleared after a reprogram, so possibly its left masked.
However, my boxes have the irq's unmasked after the reprogram, and honestly i never cared to check if they are beforehand. However its good practice to always set the mask, who knows what dodgy boards are out.

I figured a thing or two while trying to get the PIT produce IRQ's at regular intervals
some things i figured over time:

- the PIT might not be preset by the bios to rate generator
- the PIT will only start counting when you wrote the entire count
- forgetting STI (yes, i made that error once, i figured when bochs complained about HLT with IF=0)

Most likely the bios hasnt set the PIT to rate generator for you (i have 2 boxes who put the PIT off-duty and at last 4 who leave them running), so most likely the fault is the bios here
Basically, you have to program the PIT if you want to use it, not just writing an irq0 handler

Re:PIT programming

Posted: Fri Jul 14, 2006 4:55 pm
by Tolga
I wrote mask all code.

Code: Select all

outport( 0x21, 250 );
outport( 0xA1, 255 );

pit_count      = 0;
pit.setup_channel_0( 0xFFFF );
After this, irq0 is occurring only one times.

setup_channel code

Code: Select all

void tpit::setup_channel_0( unsigned short frequency )
{
   // Variables
   unsigned short counter;

   // Calculate Counter
   counter = 0x1234DD / frequency;

   // Setup Mode
   outport( 0x43, 0x34 );

   // Send Low Count
   outport( 0x40, (counter % 256) );

   // Send High Count
   outport( 0x40, (counter / 256) );
}

Re:PIT programming

Posted: Fri Jul 14, 2006 5:03 pm
by DennisCGc
Do you send an EOI to the PIC?

Re:PIT programming

Posted: Fri Jul 14, 2006 5:35 pm
by Tolga
I remapped IRQs to 32 and 40. But I don't know EOI. What is it? :-\

Re:PIT programming

Posted: Fri Jul 14, 2006 5:42 pm
by Pyr0Mathic
Tolga wrote: I remapped IRQs to 32 and 40. But I don't know EOI. What is it? :-\
EOI is End of interupt.. i think :P
atleast you need this code somewhere in your interupt handler:
mov al,20h
out 20h,al
out 0a0h,al ; < --- this only if IRQ > 7

if you dont do that the PIC will simply wait untill it recieves that command, and if you never send it, then it wont invoke any new IRQ's since its waiting.

Regards
PyroMathic

Re:PIT programming

Posted: Fri Jul 14, 2006 5:48 pm
by Tolga
Hey. OK. This solved my problem. Thanks.