PIT programming

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Tolga

PIT programming

Post 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?
blip

Re:PIT programming

Post 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.
Tolga

Re:PIT programming

Post by Tolga »

My PIT doesn't run. I only remapped irqs. Can the problem be that irq0 disabled?
Ryu

Re:PIT programming

Post 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

User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re:PIT programming

Post 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
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Tolga

Re:PIT programming

Post 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) );
}
DennisCGc

Re:PIT programming

Post by DennisCGc »

Do you send an EOI to the PIC?
Tolga

Re:PIT programming

Post by Tolga »

I remapped IRQs to 32 and 40. But I don't know EOI. What is it? :-\
Pyr0Mathic

Re:PIT programming

Post 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
Tolga

Re:PIT programming

Post by Tolga »

Hey. OK. This solved my problem. Thanks.
Post Reply