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

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