My Kernel v0.1.0

We use the PIT channel 0 for our internal timer. More...

Collaboration diagram for Timer - x86:

Enumerations

enum  pit_channel
 The different PIT channels available.
 
enum  pit_mode
 The different programmable modes for a channel.
 

Functions

error_t pit_config_channel (pit_channel, u32 frequency, pit_mode)
 Configure a single PIT channel. More...
 
u16 pit_read_channel (pit_channel)
 Read the current value inside the channel's counter.
 

Variables

volatile clock_t timer_ticks_counter = 0
 This is where we keep track of the number of intervals reported by the timer. More...
 
volatile u32 timer_kernel_frequency = 0
 Frequency of the global timekeeping timer.
 

Detailed Description

i8254 Programmable Interval Timer (PIT)

Any interaction done with the PIT should be done through the functions defined inside this header.

Design

The i8254 PIT has an internal frequency of 1.19 MHz, and 3 separate counters. Each counter must be configured with one of 7 modes, and a frequency. To be more accurate we can only specify the divider, which applied to the internal PIT frequency (1.9MHz), computes the actual frequency fo the timer. Each time the counter reaches the computed limit, it triggers an IRQ_TIMER

See also

Implementation

We keep track of the number of IRQ_TIMER recieved, each one representing a kernel timer 'tick'.

Function Documentation

◆ pit_config_channel()

error_t pit_config_channel ( pit_channel  channel,
u32  frequency,
pit_mode  mode 
)

We can only specify the channel's frequency, and the interrupt trigger condition. The read/write policy is forcefully set to 16bits.

Note
The frequency should be between 19 and PIT_INTERNAL_FREQUENCY
Warning
Because all frequencies are not necessarily available (maths and boundaries), the resulting frequency might be slightly adjusted.
Returns
The new channel frequency (after adjustments), -1 if invalid channel

Variable Documentation

◆ timer_ticks_counter

volatile clock_t timer_ticks_counter = 0

This MUST be incremented EACH time we recieve an interrupt from the global timer.