Question about the JMolloy PIT Code

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
User avatar
Primis
Member
Member
Posts: 62
Joined: Fri May 14, 2010 3:46 pm
Libera.chat IRC: Primis
Location: New York, NY
Contact:

Question about the JMolloy PIT Code

Post by Primis »

While I was reading up on the 8254 PIT chip, I had thought it wise to make a header with all the bitmaps for the different parts of the command, that way I could make a really clear init function with somthing along the lines of:

Code: Select all

outb(PIT_CMD, PIT_CHANNEL_0 | PIT_LHBYTE | PIT_MODE_2 | PIT_BIN_MODE);
Now here's where it gets interesting. While I was doing this, I had been looking at the last time I had implemented this feature, which was a blind copy from James Molloy's Kerenl tutorial about 3 years ago. I had noticed that my old code looked like this:

Code: Select all

outb(0x43, 0x36);
Now, upon looking up the bitmap of that code against my newly made header defines, I noticed somthing that didn't add up; The old code was using a the square wave mode (Mode 3), not the rate generator mode (Mode 2). Now upon further investigation, I had noticed this is the same in both James' code, and in it's inspiration bkerndev. Am I missing somthing blaringly obvious here? Is that a typo in their code? Is there one on the wiki? Would this work regardless due to rising edge interrupts on the pic? If someone could shed some light on this, I would be very grateful.
"On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."
Image
Techel
Member
Member
Posts: 215
Joined: Fri Jan 30, 2015 4:57 pm
Location: Germany
Contact:

Re: Question about the JMolloy PIT Code

Post by Techel »

Both modes 2 and 3 can be used to achieve periodic timer interrupts
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Question about the JMolloy PIT Code

Post by Brendan »

Hi,
Primis wrote:Would this work regardless due to rising edge interrupts on the pic?
Yes.

The only difference would be with odd counts. For example, if you try to use count = 1111 then with rate generator you'd get an IRQ every 1111 ticks, and with square wave you'd get an IRQ after 110 ticks then one after 112 ticks then 110 ticks then 112 ticks...


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply