how to know which port to be programmmed?

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
asmboozer

how to know which port to be programmmed?

Post by asmboozer »

in the bran's tutorial at
http://www.osdever.net/bkerndev/index.php?the_id=90
To set the rate at which channel 0 of the timer fires off an IRQ0, we must use our outportb function to write to I/O ports. There is a Data register for each of the timer's 3 channels at 0x40, 0x41, and 0x42 respectively
I have read the 82c54 datasheet, I can not understand why it's the port 0x40,0x41,0x42,0x43 to be programmed.


which book have remarks on it?
LongHorn

Re:how to know which port to be programmmed?

Post by LongHorn »

Because it is the port used by the PIT. that's how internally they are wired.
Every book with the name "80x86 and harware interfacing". Because there is a dozens of books i couldn't remember those author names.

Code: Select all

how to know which port to be programmmed?
that's why you have to study the datasheets along with them. that's why there is hardly no information on specific motherboards, soundcards etc. PIT seems to be generalized. It is found in almost all the computers. What if the computer have a different Timer circuit?
paulbarker

Re:how to know which port to be programmmed?

Post by paulbarker »

I can't remember where I found this info but channel 1 is the one you want. Channel 2 is no longer in use and channel 3 is wired to the internal speaker.

Here are the ports:

Code: Select all

#define PIT_CHANNEL0        0x40
#define PIT_CHANNEL1        0x41
#define PIT_CHANNEL2        0x42
#define PIT_COMMAND_REG     0x43
And here is some setup code (hz is the interrupt frequency wanted):

Code: Select all

    /*
        Setup the PIT operating mode.
        We want:
            - Channel 0
            - Access lobyte then hibyte
            - Mode 3 (square-wave generator)
            - Binary values (not BCD)

        Our value is therefore 0b00110110, in hex thats 0x34.
    */
    io_outb_p(0x36, PIT_COMMAND_REG);

    /* Now set the divisor. */
    uint div = PIT_INTERNAL_FREQ / hz;
    io_outb_p((char)(div & 0xff), PIT_CHANNEL0);
    io_outb_p((char)(div >> 8), PIT_CHANNEL0);
I think the PIT is a lot easier to learn how to program by reading code than unclear data sheets.
LongHorn

Re:how to know which port to be programmmed?

Post by LongHorn »

What is that meant by channel 2 is no longer in use. I found the same in bkerndev. You can use whatever counter you want, provided that you set the bits correctly in command registers. Nobody is trying to learn PIT. There are lot of modes you can use. But most probably people are using 1 or 2 modes only. Hey i also don't want to learn this thing but it is on my syllabus. I was forced to draw timing diagrams for all 6 modes. But i hardly remember those timing circuits now.
dc0d32

Re:how to know which port to be programmmed?

Post by dc0d32 »

simply because other modes are neither suitable nor becessary for the things that we are doing. for example, the square wave auto reload mode is the one you need in order to produce sound through speaker. you shouldn't use the channel in, let's say mode 1, because that is not you do in order to produe a sound (you can definitely use that mode to generate some sound, but the waveform will not be uniform). And all those timing diagrams that we have drawn in our exams, u will need to use them if u are designing robotic devices, not in our case.

it is a good idea to understand how the interfacing internaly works. eg. in PIT's case, which address line combination chooses which channel, registers etc,

BTW, do you really think that it is necessary to learn PIT, all it's modes along with timing diagrams; to get it working for your OS? The PCs that we generally use have the fixed wiring, and probably won't change in near future. learning which channels are wired to which lines, and the modes that they can be, and are to be programmed in, is, IMHO, enough, the only exception being some different timer arch, or your own fabricated motherboard.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:how to know which port to be programmmed?

Post by Pype.Clicker »

asmboozer wrote: I have read the 82c54 datasheet, I can not understand why it's the port 0x40,0x41,0x42,0x43 to be programmed.
That's because the datasheet talk about the chip : a generic timer generator. you'll see things such as "when SEL=3, register accessed is command register".

Considering how the chip is wired with the ISA bus, interrupt controller, etc. it comes that accessing I/O port 0x43 activates the chip and sets SEL=3, and things alike.
which book have remarks on it?
RBIL should have quotes on it too.
asmboozer

Re:how to know which port to be programmmed?

Post by asmboozer »

RBIL should have quotes on it too.
what's RBIL?

i found some info on it in the helppc program.

why is there no such programmer guide from intel?
paulbarker

Re:how to know which port to be programmmed?

Post by paulbarker »

@LongHorn:

Correct me if I am wrong, but the 3 channels have very specific uses and are hard wired to perform certain functions. You cannot just use any channel for any purpose.

Channel 1 is wired to IRQ0.
Channel 2 was used to refresh dynamic RAM periodically, but this is now handled internally by the RAM controller. This channel is now disconnected.
Channel 3 is wired directly to the internal speaker so setting channel 3 to a square wave at 1kHz produces a 1kHz tone from the speaker.

Again, I can't remember where I found this so I may be wrong, this is just from memory.

@asmboozer:

RBIL is the Ralf Brown Interrupts List and is one of the most useful bits of info you will read.
JAAman

Re:how to know which port to be programmmed?

Post by JAAman »

you tell what the RBIL is -- but you didnt tell where to find it:

## ---- ----- RBIL

there are other places, but this is the one in my OSdev bookmark folder
Post Reply