How to set IRQ so as to initiate Counter 1???

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
Insignia
Posts: 3
Joined: Thu Dec 11, 2008 5:31 am

How to set IRQ so as to initiate Counter 1???

Post by Insignia »

Hey guys,
I am on the process of developing a program in which i need to set the counter1 of the timer. As such, IRQ for timer is 0, but its common to all the 3 counters. Are there any ways in which we can set the counter1 specifically without affecting the functionality of the counter0???
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: How to set IRQ so as to initiate Counter 1???

Post by AJ »

Hi,

I assume that on IRQ0, you are using the PIT and are referring to channels 0, 1 and 2. You are probably using channel 0 (not 1) on the PC architecture.

Channel 1 used to be used for RAM timing, but is now unneeded and is usually unconnected, so it can't be used for an interrupt, so you can forget about that.

Channel 2 is connected directly to the PC speaker, so you can forget that for causing interrupts on IRQ0 too - for now just concentrate on channel 0. When you initialise the PIT, you specify the channel number in the command register and there is a separate data register for each channel. For this reason, you shouldn't accidentally interfere with channels 1 and 2.

I suggest you have a look at the PIT article on the wiki.

Cheers,
Adam
LoseThos
Member
Member
Posts: 112
Joined: Tue Oct 30, 2007 6:41 pm
Location: Las Vegas, NV USA
Contact:

Re: How to set IRQ so as to initiate Counter 1???

Post by LoseThos »

Code: Select all

void InitTimer()
{
  OutP(0x43,0x34);
  OutP(0x40,SYS_TIMER0_PERIOD);
  OutP(0x40,SYS_TIMER0_PERIOD>>8);
}


void InitIrqs()
{
//Init 8259
  OutP(0x20,0x11); //IW1
  OutP(0xA0,0x11); //IW1
  PortNop;
  OutP(0x21,0x20); //IW2
  OutP(0xA1,0x28); //IW2
  PortNop;
  OutP(0x21,0x04); //IW3
  OutP(0xA1,0x02); //IW3
  PortNop;
  OutP(0x21,0x0D); //IW4
  OutP(0xA1,0x09); //IW4
  PortNop;
  OutP(0x21,0xFA); //Mask all but IRQ0 (timer) and IRQ2 Cascade
  OutP(0xA1,0xFF);
  PortNop;
}
That should help.

Here's the speaker code:

Code: Select all

      if (freq) {
	period=SYS_TIMER_FREQ/freq;
	OutP(0x43,0xB6);
	OutP(0x42,period);
	OutP(0x42,period>>8);
	OutP(0x61,3|InP(0x61));
      } else
	OutP(0x61,InP(0x61)&~3);
The speaker is very handy for debugging, especially in the start-up portions of an operating system where you can't easily output stuff. I often make it make tones to tell me how far it got.
Insignia
Posts: 3
Joined: Thu Dec 11, 2008 5:31 am

Re: How to set IRQ so as to initiate Counter 1???

Post by Insignia »

Thanks a lot... :)
Insignia
Posts: 3
Joined: Thu Dec 11, 2008 5:31 am

Re: How to set IRQ so as to initiate Counter 1???

Post by Insignia »

Hi,
for my previous operation in 8254 timer chip, i was using Counter 0 (IRQ0)as a reference counter for a process where in the IRQ handler i was updating the count, but now i want to use counter 1 as the reference counter. As per your previous reply IRQ0 cannot be used for the counter 1. Please suggest any other ways (latching and reading the down counter etc.) to use the COUNTER 1 as reference.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: How to set IRQ so as to initiate Counter 1???

Post by AJ »

I can think of a couple of ways. Firstly, have a global tick counter and use a getTickCount() function whenever you need the current value. If you take the tick count at the start and end of a code region, you can use the difference to find out how many ticks elapsed. This doesn't restrict the PIT to a single process.

Alternatively, you also have the RTC interrupt and the APIC timer. The APIC timers are generally suited quite well to scheduling because you have one timer per local APIC. This leaves the PIT free for whatever else you want.

Cheers,
Adam
Post Reply