Function comments (v1)
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <stdint.h>
|
||||
#include "io/serial/serial.h"
|
||||
#include <kernel.h>
|
||||
#include "config.h"
|
||||
|
||||
/*
|
||||
For now, the timer module will be using the PIC.
|
||||
@@ -20,6 +21,13 @@ volatile uint64_t ticks = 0;
|
||||
|
||||
extern struct init_status init;
|
||||
|
||||
/*
|
||||
* pic_remap - Remap the Programmable Interrupt Controller
|
||||
*
|
||||
* By default, interrupts are mapped at the wrong place.
|
||||
* This function remaps interrupt numbers so interrupts
|
||||
* don't conflict with each other.
|
||||
*/
|
||||
void pic_remap()
|
||||
{
|
||||
uint8_t master_mask = inb(0x21);
|
||||
@@ -47,6 +55,12 @@ void pic_remap()
|
||||
outb(0xA1, slave_mask);
|
||||
}
|
||||
|
||||
/*
|
||||
* pic_enable - Enable the Programmable Interrupt Controller
|
||||
*
|
||||
* This function enables IRQ0 and IRQ1, which correspond to
|
||||
* the timer and keyboard interrupts, respectively.
|
||||
*/
|
||||
void pic_enable()
|
||||
{
|
||||
// Enabling IRQ0 (unmasking it) but not the others
|
||||
@@ -57,12 +71,15 @@ void pic_enable()
|
||||
}
|
||||
|
||||
/*
|
||||
Base frequency = 1.193182 MHz
|
||||
1 tick per ms (divide by 1000) = roughly 1193 Hz
|
||||
*/
|
||||
* pit_init - Initialization of the Programmable Interval Timer
|
||||
*
|
||||
* The PIT is the simplest timer we can get working on x86.
|
||||
* It has a base frequency of 1.193182 MHz.
|
||||
* A custom frequency can be set using TIMER_FREQUENCY macro.
|
||||
*/
|
||||
void pit_init()
|
||||
{
|
||||
uint32_t frequency = 1000; // 1 kHz
|
||||
uint32_t frequency = TIMER_FREQUENCY;
|
||||
uint32_t divisor = 1193182 / frequency;
|
||||
|
||||
// Set PIT to mode 3, channel 0
|
||||
@@ -73,8 +90,12 @@ void pit_init()
|
||||
outb(0x40, (divisor >> 8) & 0xFF);
|
||||
}
|
||||
|
||||
// Wait n ticks
|
||||
// Given that there's a tick every 1ms, wait n milliseconds
|
||||
/*
|
||||
* timer_wait - Wait for X ticks
|
||||
*
|
||||
* By default, the timer frequency is 1000Hz, meaning
|
||||
* ticks are equal to milliseconds.
|
||||
*/
|
||||
void timer_wait(uint64_t wait_ticks)
|
||||
{
|
||||
uint64_t then = ticks + wait_ticks;
|
||||
@@ -83,6 +104,11 @@ void timer_wait(uint64_t wait_ticks)
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* timer_init - Initialization of the timer
|
||||
*
|
||||
* This function wakes the PIT.
|
||||
*/
|
||||
void timer_init()
|
||||
{
|
||||
// Remapping the PIC, because at startup it conflicts with
|
||||
|
||||
Reference in New Issue
Block a user