source: libcaca/trunk/kernel/drivers/timer.c @ 4154

Last change on this file since 4154 was 4154, checked in by Jean-Yves Lamoureux, 10 years ago
  • Total kernel rewrite
File size: 1.6 KB
Line 
1
2#include "kernel.h"
3#include "klibc.h"
4#include "timer.h"
5
6u32 ticks = 0;
7
8void timer_phase(int hz)
9{
10    unsigned int divisor = 1193180 / hz;   /* Calculate our divisor */
11    /*
12      0x43 is the Mode/Command register
13     
14     From http://wiki.osdev.org/Programmable_Interval_Timer#Read_Back_Status_Byte :
15     Bits         Usage
16     6 and 7      Select channel :
17                  0 0 = Channel 0
18                  0 1 = Channel 1
19                  1 0 = Channel 2
20                  1 1 = Read-back command (8254 only)
21     4 and 5      Access mode :
22                  0 0 = Latch count value command
23                  0 1 = Access mode: lobyte only
24                  1 0 = Access mode: hibyte only
25                  1 1 = Access mode: lobyte/hibyte
26     1 to 3       Operating mode :
27                  0 0 0 = Mode 0 (interrupt on terminal count)
28                  0 0 1 = Mode 1 (hardware re-triggerable one-shot)
29                  0 1 0 = Mode 2 (rate generator)
30                  0 1 1 = Mode 3 (square wave generator)
31                  1 0 0 = Mode 4 (software triggered strobe)
32                  1 0 1 = Mode 5 (hardware triggered strobe)
33                  1 1 0 = Mode 2 (rate generator, same as 010b)
34                  1 1 1 = Mode 3 (square wave generator, same as 011b)
35     0            BCD/Binary mode: 0 = 16-bit binary, 1 = four-digit BCD
36     
37     */
38    unsigned short command = 0b00110110;
39    outb(0x43, command);
40    outb(0x40, divisor & 0xFF);            /* Set low byte of divisor */
41    outb(0x40, divisor >> 8);              /* Set high byte of divisor */
42}
Note: See TracBrowser for help on using the repository browser.