UbixOS  2.0
pit.c
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2002-2018 The UbixOS Project.
3  * All rights reserved.
4  *
5  * This was developed by Christopher W. Olsen for the UbixOS Project.
6  *
7  * Redistribution and use in source and binary forms, with or without modification, are permitted
8  * provided that the following conditions are met:
9  *
10  * 1) Redistributions of source code must retain the above copyright notice, this list of
11  * conditions, the following disclaimer and the list of authors.
12  * 2) Redistributions in binary form must reproduce the above copyright notice, this list of
13  * conditions, the following disclaimer and the list of authors in the documentation and/or
14  * other materials provided with the distribution.
15  * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to
16  * endorse or promote products derived from this software without specific prior written
17  * permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <isa/pit.h>
30 #include <sys/io.h>
31 #include <lib/kprintf.h>
32 
33 /*****************************************************************************************
34 
35  Function: int pitInit()
36 
37  Description: This Function Will Initialize The Programmable Timer
38 
39  Notes:
40 
41  0040 r/w PIT counter 0, counter divisor (XT, AT, PS/2)
42  0041 r/w PIT counter 1, RAM refresh counter (XT, AT)
43  0042 r/w PIT counter 2, cassette & speaker (XT, AT, PS/2)
44  0043 r/w PIT mode port, control word register for counters 0-2
45 
46  bit 7-6 = 00 counter 0 select
47  = 01 counter 1 select (not PS/2)
48  = 10 counter 2 select
49  bit 5-4 = 00 counter latch command
50  = 01 read/write counter bits 0-7 only
51  = 10 read/write counter bits 8-15 only
52  = 11 read/write counter bits 0-7 first, then 8-15
53  bit 3-1 = 000 mode 0 select
54  = 001 mode 1 select - programmable one shot
55  = x10 mode 2 select - rate generator
56  = x11 mode 3 select - square wave generator
57  = 100 mode 4 select - software triggered strobe
58  = 101 mode 5 select - hardware triggered strobe
59  bit 0 = 0 binary counter 16 bits
60  = 1 BCD counter
61 
62  *****************************************************************************************/
63 int pit_init() {
64  outportByteP(0x43, 0x36);
65  outportByteP(0x40, ((1193180 / PIT_TIMER) & 0xFF));
66  outportByte(0x40, (((1193180 / PIT_TIMER) >> 8) & 0xFF));
67 
68  /* Print out information on the PIT */
69  kprintf("pit0 - Port [0x%X], Timer Hz: [%iHz]\n", 0x43, PIT_TIMER);
70 
71  /* Return so we know everything went well */
72  return (0x0);
73 }
74 
75 /***
76  $Log: pit.c,v $
77  Revision 1.1.1.1 2006/06/01 12:46:12 reddawg
78  ubix2
79 
80  Revision 1.2 2005/10/12 00:13:37 reddawg
81  Removed
82 
83  Revision 1.1.1.1 2005/09/26 17:24:03 reddawg
84  no message
85 
86  Revision 1.7 2004/07/16 04:06:32 reddawg
87  Tune ups this stuff should of been taken care of months ago
88 
89  Revision 1.6 2004/07/16 01:08:58 reddawg
90  Whew we work once again
91 
92  Revision 1.5 2004/07/09 13:29:15 reddawg
93  pit: pitInit to pit_init
94  Adjusted initialization routines
95 
96  Revision 1.4 2004/05/21 12:48:22 reddawg
97  Cleaned up
98 
99  Revision 1.3 2004/05/20 22:51:09 reddawg
100  Cleaned Up Warnings
101 
102  Revision 1.2 2004/05/10 02:23:24 reddawg
103  Minor Changes To Source Code To Prepare It For Open Source Release
104 
105  END
106  ***/
107 
outportByteP
void outportByteP(unsigned int port, unsigned char value)
outputut one byte to specified port with a delay
Definition: io.c:87
outportByte
void outportByte(unsigned int, unsigned char)
outputut one byte to specified port
Definition: io.c:72
pit.h
PIT_TIMER
#define PIT_TIMER
Definition: pit.h:32
kprintf.h
io.h
kprintf
int kprintf(const char *,...)
Definition: kprintf.c:259
pit_init
int pit_init()
Definition: pit.c:62