IBNOS
pit.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, Michael Müller
3  * Copyright (c) 2014, Sebastian Lackner
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  */
27 
28 #include <hardware/pit.h>
29 #include <hardware/pic.h>
30 #include <util/util.h>
31 #include <io/io.h>
32 
53 void pitSetValue(uint32_t channel, uint32_t mode, uint16_t value)
54 {
55  assert(channel < PIT_CHANNEL_COUNT);
56 
58  outb(PIT_CHANNEL_BASE + channel, value & 0xFF);
59  outb(PIT_CHANNEL_BASE + channel, value >> 8);
60 }
61 
72 void pitSetFrequency(uint32_t channel, uint32_t frequency)
73 {
74  uint32_t value;
75  assert(channel < PIT_CHANNEL_COUNT);
76  /*
77  * There are only a few values for which this assert would be true,
78  * so I commented it out since it is better to have a slilightly different
79  * frequency instead of being stuck with some unusable frequency. The only
80  * usable exception would be 82 Hz = ~12 ms.
81  */
82  /* assert((PIT_FREQUENCY % frequency) == 0); */
83  value = PIT_FREQUENCY / frequency;
84  assert(value);
85 
86  pitSetValue(channel, PIT_MODE_RATE_GENERATOR, value);
87 }
void pitSetValue(uint32_t channel, uint32_t mode, uint16_t value)
Internal function to set a value of the PIT.
Definition: pit.c:53
#define PIT_MODE_RATE_GENERATOR
Definition: pit.h:45
#define assert(ex)
Definition: util.h:61
#define PIT_MODE_PORT
Definition: pit.h:58
void outb(uint16_t port, uint8_t val)
Definition: io.h:35
#define PIT_CHANNEL_BASE
Definition: pit.h:54
#define PIT_LSB_MSB
Definition: pit.h:66
void pitSetFrequency(uint32_t channel, uint32_t frequency)
Set frequency of the programmable interval timer.
Definition: pit.c:72
#define PIT_CHANNEL_COUNT
Definition: pit.h:71
#define PIT_CONTROL_VALUE(FORMAT, MODE, REGISTER, CHANNEL)
Definition: pit.h:68
#define PIT_BINARY
Definition: pit.h:60
uint32_t value
Definition: paging.h:55
char mode[8]
Definition: filesystem.h:65
#define PIT_FREQUENCY
Definition: pit.h:72