Page 1 of 1

How to make the PIT

Posted: Thu Aug 01, 2013 9:22 am
by Johnyburd
How do I make the PIT so I can make the CPU sleep for a certain number of milliseconds. I've read the wiki article, but I can't figure it out. I have functions for inportb and outportb.
Thanks,
Johnyburd

Re: How to make the PIT

Posted: Thu Aug 01, 2013 3:27 pm
by MadZarx
Johnyburd wrote:How do I make the PIT so I can make the CPU sleep for a certain number of milliseconds. I've read the wiki article, but I can't figure it out. I have functions for inportb and outportb.
Thanks,
Johnyburd
I had you problem but finally I could roll my own PIT mini driver. First of all you need to load the GDT and IDT then enable ISRs and you should be able to handle them and then write a PIC mini driver or an IRQ handler to be able to catch PIT interrupts. Then write a sleep function for your self.
It's not that hard.

Re: How to make the PIT

Posted: Thu Aug 01, 2013 4:17 pm
by Johnyburd
About that... I think I have the PICs working, but I don't know, and can I use grub's gdt?

#define PIC1 0x20
#define PIC2 0xA0

#define ICW1 0x11
#define ICW4 0x01

/* init_pics()
* init the PICs and remap them
*/
void init_pics(int pic1, int pic2)
{
/* send ICW1 */
outb(PIC1, ICW1);
outb(PIC2, ICW1);

/* send ICW2 */
outb(PIC1 + 1, pic1); /* remap */
outb(PIC2 + 1, pic2); /* pics */

/* send ICW3 */
outb(PIC1 + 1, 4); /* IRQ2 -> connection to slave */
outb(PIC2 + 1, 2);

/* send ICW4 */
outb(PIC1 + 1, ICW4);
outb(PIC2 + 1, ICW4);

/* disable all IRQs */
outb(PIC1 + 1, 0xFF);
}
this is what I used for the PIC, so is that all I need to do?

Re: How to make the PIT

Posted: Thu Aug 01, 2013 9:45 pm
by MadZarx
I don't know whether you can use grub's GDT or not but I don't prefer. I guess that you haven't an ISR handler. These are the steps needed to be able to use keyboard and timer:
1) Set up GDT then IDT (Be careful about the shifts)
2) Write an ISRs handler in assembly and map them to IDT entries 0 - 31 (There maybe some other ways for setting up ISRs)
3) Write an IRQ handler in assembly again and map them to IDT entries 32-47
4) Before setting up the IRQs you need to initialize the PICs with your snippet code but the ICW2 should be 0x20 and 0x28 (The index of IRQs in IDT entries)
5) Now initialize the PIT and map it to IRQ 0 or ISR 32. Then you can use the timer but the timer doesn't need any initializations. :mrgreen:
6) Go on for the next steps :mrgreen: :roll:

Re: How to make the PIT

Posted: Fri Aug 02, 2013 12:47 pm
by Johnyburd
Okay thanks! :D