]> git.dujemihanovic.xyz Git - nameless-os.git/blob - include/arch/x86/time/i8254.h
Add Intel 8254 driver and print elapsed seconds
[nameless-os.git] / include / arch / x86 / time / i8254.h
1 #ifndef X86_I8254_H
2 #define X86_I8254_H
3
4 #include <stdint.h>
5 #include <io.h>
6 #include <irq/i8259a.h>
7
8 /* for setting reload value and reading current count */
9 #define PORT_CHANNEL_0_DATA 0x40
10 #define PORT_CHANNEL_1_DATA 0x41
11 #define PORT_CHANNEL_2_DATA 0x42
12
13 /* for configuring the channels */
14 #define PORT_MODE_CMD_REG 0x43
15
16 /* operating modes */
17 #define INT_ON_TERM_CNT 0x0
18 #define HW_RETRIGGER_ONESHOT 0x1
19 #define RATE_GENERATOR 0x2
20 #define SQUARE_WAVE_GENERATOR 0x3
21 #define SW_TRIGGERED_STROBE 0x4
22 #define HW_TRIGGERED_STROBE 0x5
23
24 /* access modes */
25 #define ACMODE_COUNTER_LATCH_CMD 0x0
26 #define ACMODE_LSB_ONLY 0x1
27 #define ACMODE_MSB_ONLY 0x2
28 #define ACMODE_LSB_MSB 0x3
29
30 union mode_command {
31 struct {
32 unsigned bcd: 1, /* if set, uses BCD for reload value */
33 opmode: 3, /* operating mode */
34 acmode: 2, /* access mode */
35 channel: 2; /* channel to configure */
36 } fields;
37 uint8_t command;
38 };
39
40 extern unsigned int ticks;
41 extern uint16_t reload;
42
43 extern void i8254_configure_channel(char channel, char opmode, uint16_t new_reload);
44 extern void i8254_irq_enable();
45
46 #endif