MonkOS  v0.1
A simple 64-bit operating system (x86_64)
timer.c File Reference

Programmable interval timer (8253/8254) controller. More...

#include <core.h>
#include <kernel/x86/cpu.h>
#include <kernel/device/timer.h>
#include <kernel/interrupt/interrupt.h>

Go to the source code of this file.

Macros

#define TIMER_PORT_DATA_CH0   0x40
 Channel 0 data port. More...
 
#define TIMER_PORT_DATA_CH1   0x41
 Channel 1 data port. More...
 
#define TIMER_PORT_DATA_CH2   0x42
 Channel 2 data port. More...
 
#define TIMER_PORT_CMD   0x43
 Timer command port. More...
 
#define MIN_FREQUENCY   19
 
#define MAX_FREQUENCY   1193181
 

Functions

static void isr_timer (const interrupt_context_t *context)
 
void timer_init (uint32_t frequency)
 Initialize the timer controller so that it interrupts the kernel at the requested frequency. More...
 
void timer_enable ()
 Enable timer interrupts. More...
 
void timer_disable ()
 Disable timer interrupts. More...
 

Detailed Description

Programmable interval timer (8253/8254) controller.

Definition in file timer.c.

Macro Definition Documentation

#define TIMER_PORT_DATA_CH0   0x40

Channel 0 data port.

Definition at line 16 of file timer.c.

Referenced by timer_init().

#define TIMER_PORT_DATA_CH1   0x41

Channel 1 data port.

Definition at line 17 of file timer.c.

#define TIMER_PORT_DATA_CH2   0x42

Channel 2 data port.

Definition at line 18 of file timer.c.

#define TIMER_PORT_CMD   0x43

Timer command port.

Definition at line 19 of file timer.c.

Referenced by timer_init().

#define MIN_FREQUENCY   19

Definition at line 22 of file timer.c.

Referenced by timer_init().

#define MAX_FREQUENCY   1193181

Definition at line 23 of file timer.c.

Referenced by timer_init().

Function Documentation

static void isr_timer ( const interrupt_context_t *  context)
static

Definition at line 26 of file timer.c.

Referenced by timer_init().

void timer_init ( uint32_t  frequency)

Initialize the timer controller so that it interrupts the kernel at the requested frequency.

Interrupts are enabled at the end of the function, so timer_enable does not need to be called after timer_init.

Due to the clock granularity (1193181Hz), the requested frequency may not be perfectly met.

Parameters
[in]frequencyThe interrupt frequency in Hz. Clamped to the range [19:1193181].

Definition at line 37 of file timer.c.

Referenced by kmain().

void timer_enable ( )

Enable timer interrupts.

Definition at line 65 of file timer.c.

void timer_disable ( )

Disable timer interrupts.

Definition at line 72 of file timer.c.