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

Last change on this file since 4333 was 4333, checked in by Sam Hocevar, 10 years ago

Large source code cleanup, getting rid of spaces, tabs, and svn keywords.

File size: 2.1 KB
Line 
1/*
2 *  libcaca       Colour ASCII-Art library
3 *  Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
4 *                2009 Jean-Yves Lamoureux <jylam@lnxscene.org>
5 *                All Rights Reserved
6 *
7 *  This library is free software. It comes without any warranty, to
8 *  the extent permitted by applicable law. You can redistribute it
9 *  and/or modify it under the terms of the Do What The Fuck You Want
10 *  To Public License, Version 2, as published by Sam Hocevar. See
11 *  http://sam.zoy.org/wtfpl/COPYING for more details.
12 */
13
14#include "kernel.h"
15#include "klibc.h"
16#include "timer.h"
17
18u32 ticks = 0;
19
20void timer_phase(int hz)
21{
22    unsigned int divisor = 1193180 / hz;   /* Calculate our divisor */
23    /*
24      0x43 is the Mode/Command register
25
26     From http://wiki.osdev.org/Programmable_Interval_Timer#Read_Back_Status_Byte :
27     Bits         Usage
28     6 and 7      Select channel :
29                  0 0 = Channel 0
30                  0 1 = Channel 1
31                  1 0 = Channel 2
32                  1 1 = Read-back command (8254 only)
33     4 and 5      Access mode :
34                  0 0 = Latch count value command
35                  0 1 = Access mode: lobyte only
36                  1 0 = Access mode: hibyte only
37                  1 1 = Access mode: lobyte/hibyte
38     1 to 3       Operating mode :
39                  0 0 0 = Mode 0 (interrupt on terminal count)
40                  0 0 1 = Mode 1 (hardware re-triggerable one-shot)
41                  0 1 0 = Mode 2 (rate generator)
42                  0 1 1 = Mode 3 (square wave generator)
43                  1 0 0 = Mode 4 (software triggered strobe)
44                  1 0 1 = Mode 5 (hardware triggered strobe)
45                  1 1 0 = Mode 2 (rate generator, same as 010b)
46                  1 1 1 = Mode 3 (square wave generator, same as 011b)
47     0            BCD/Binary mode: 0 = 16-bit binary, 1 = four-digit BCD
48
49     */
50    unsigned short command = 0b00110110;
51    outb(0x43, command);
52    outb(0x40, divisor & 0xFF);            /* Set low byte of divisor */
53    outb(0x40, divisor >> 8);              /* Set high byte of divisor */
54}
Note: See TracBrowser for help on using the repository browser.