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

Last change on this file since 4158 was 4158, checked in by Jean-Yves Lamoureux, 10 years ago
  • Fix indentation and add licensing and copyright headers to kernel
File size: 1.9 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
30       http://wiki.osdev.org/Programmable_Interval_Timer#Read_Back_Status_Byte
31       : Bits Usage 6 and 7 Select channel : 0 0 = Channel 0 0 1 = Channel 1
32       1 0 = Channel 2 1 1 = Read-back command (8254 only) 4 and 5 Access mode
33       : 0 0 = Latch count value command 0 1 = Access mode: lobyte only 1 0 =
34       Access mode: hibyte only 1 1 = Access mode: lobyte/hibyte 1 to 3
35       Operating mode : 0 0 0 = Mode 0 (interrupt on terminal count) 0 0 1 =
36       Mode 1 (hardware re-triggerable one-shot) 0 1 0 = Mode 2 (rate
37       generator) 0 1 1 = Mode 3 (square wave generator) 1 0 0 = Mode 4
38       (software triggered strobe) 1 0 1 = Mode 5 (hardware triggered strobe)
39       1 1 0 = Mode 2 (rate generator, same as 010b) 1 1 1 = Mode 3 (square
40       wave generator, same as 011b) 0 BCD/Binary mode: 0 = 16-bit binary, 1 =
41       four-digit BCD
42
43     */
44    unsigned short command = 0 b00110110;
45    outb(0x43, command);
46    outb(0x40, divisor & 0xFF); /* Set low byte of divisor */
47    outb(0x40, divisor >> 8);   /* Set high byte of divisor */
48}
Note: See TracBrowser for help on using the repository browser.