WKern
Loading...
Searching...
No Matches
pit.c
Go to the documentation of this file.
1
/*
2
WKern - A Bare Metal OS / Kernel I am maKing (For Fun)
3
Copyright (C) 2025 Wdboyes13
4
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
any later version.
9
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <https://www.gnu.org/licenses/>.
17
*/
18
19
#include <
io/kio.h
>
20
#include <
types/nums.h
>
21
// PIT ports
22
#define PIT_CHANNEL0 0x40
23
#define PIT_COMMAND 0x43
24
25
// Command byte bits for mode 3 (square wave generator)
26
#define PIT_ACCESS_LOHI 0x30
// access low byte then high byte
27
#define PIT_MODE3 0x06
// mode 3 (square wave)
28
29
// PIT frequency and divisor
30
#define PIT_FREQ 1193182
// base frequency in Hz
31
// Setup PIT for a given frequency (e.g., 100 Hz)
32
void
PitInit
(
u32
freq) {
33
u16
divisor = (
u16
)(
PIT_FREQ
/ freq);
34
Kprintf
(
"Divisor Set\n"
);
35
// Send command byte: channel 0, access mode lo/hi, mode 3, binary mode
36
Outb
(
PIT_COMMAND
,
PIT_ACCESS_LOHI
|
PIT_MODE3
);
37
Kprintf
(
"Command Byte Sent\n"
);
38
// Send divisor low byte
39
Outb
(
PIT_CHANNEL0
, divisor & 0xFF);
40
Kprintf
(
"Low byte sent\n"
);
41
// Send divisor high byte
42
Outb
(
PIT_CHANNEL0
, (divisor >> 8) & 0xFF);
43
Kprintf
(
"High byte sent\n"
);
44
}
Outb
void Outb(u16 port, u8 val)
Write a byte to the specified I/O port.
Definition
asm.c:30
PIT_FREQ
#define PIT_FREQ
Definition
idtirq.h:107
kio.h
Kprintf
void Kprintf(const char *fmt,...)
Formatted output to the screen.
Definition
printer.c:152
nums.h
u32
unsigned int u32
32-Bit Unsigned Int
Definition
nums.h:30
u16
unsigned short u16
16-Bit Unsigned Int
Definition
nums.h:36
PIT_MODE3
#define PIT_MODE3
Definition
pit.c:27
PIT_COMMAND
#define PIT_COMMAND
Definition
pit.c:23
PIT_ACCESS_LOHI
#define PIT_ACCESS_LOHI
Definition
pit.c:26
PIT_CHANNEL0
#define PIT_CHANNEL0
Definition
pit.c:22
PitInit
void PitInit(u32 freq)
Definition
pit.c:32
src
idt
pit.c
Generated on
for WKern by
1.14.0