[−][src]Module sunrise_kernel::devices::pit
Programmable Interval Timer
channels
There are 3 channels :
-
channel 0, wired to irq0. We use this one in rate generator mode, to keep track of the time
-
channel 1, "unusable, and may not even exist" ... whoah
-
channel 2, wired to pc speaker. We use this one in "one shot" mode to implement a simple wait function. Output is ANDed with a gate controlled by port 0x61 bit #1 before going to the pc speaker, we use this to enable/disable the speaker. However the channel can only track one countdown at a time, so we have to switch to channel 0 timers when we want to wait as soon as we have interruptions working
operating modes
Each channel can operate in different modes. The ones we use are:
-
Mode 0 - Countdown (poorly named "Interrupt on Terminal Count"). Used on channel 2 to create countdowns. Set the reset value, countdowns starts. When countdown goes to 0, OUT goes HIGH, and stays high.
-
Mode 2 - Rate generator. Used on channel 0 to create recurring irqs. Set the reset value. Countdown starts. When countdown goes to 0, OUT goes LOW for 1 clock cycle, and HIGH again, and countdown restarts.
commands
Pit commands are sent on port 0x43. See OSDEV
To write channel reload values we always use the Access mode "lobyte/hibyte"
port 0x61
The PIT makes great use of the IO port 0x61 :
- bit #0 is channel 2 GATE control
- bit #1 is SPKR control
- bit #4 is channel 1 OUT status
- bit #5 is channel 2 OUT status
References
Structs
PITChannel2 | Channel 2 |
PITPorts | We put the PIT ports in a structure to have them under a single mutex |
PIT_PORTS | The mutex wrapping the ports |
Port61Flags | The port 0x61 flags we use. |
Enums
ChannelSelector | Used internally to select which channel to apply operations to. |
Constants
CHAN_0_DIVISOR | The channel 0 reset value |
CHAN_0_FREQUENCY | The frequency of channel 0 irqs, in hertz. One every 10 millisecond. |
OSCILLATOR_FREQ | The oscillator frequency when not divided, in hertz. |
Functions
disable⚠ | Prevent the PIT from generating interrupts. |
init_channel_0⚠ | Initialize the channel 0 to send recurring irqs. |
spin_wait_ms | Spin waits for at least |