Implement APIC, RTC, basic ACPI parser and timer support
[lunaix-os.git] / lunaix-os / includes / hal / rtc.h
1 #ifndef __LUNAIX_RTC_H
2 #define __LUNAIX_RTC_H
3
4 #include "io.h"
5
6 #define RTC_INDEX_PORT 0x70
7 #define RTC_TARGET_PORT 0x71
8
9 #define WITH_NMI_DISABLED 0x80
10
11 #define RTC_CURRENT_CENTRY 20
12
13 #define RTC_REG_YRS 0x9
14 #define RTC_REG_MTH 0x8
15 #define RTC_REG_DAY 0x7
16 #define RTC_REG_WDY 0x6
17 #define RTC_REG_HRS 0x4
18 #define RTC_REG_MIN 0x2
19 #define RTC_REG_SEC 0x0
20
21 #define RTC_REG_A 0xA
22 #define RTC_REG_B 0xB
23 #define RTC_REG_C 0xC
24 #define RTC_REG_D 0xD
25
26 #define RTC_BIN_ENCODED(reg)    (reg & 0x04)
27 #define RTC_24HRS_ENCODED(reg)  (reg & 0x02)
28
29 #define RTC_TIMER_BASE_FREQUENCY    1024
30 #define RTC_TIMER_ON                0x40
31
32 #define RTC_FREQUENCY_1024HZ    0b110
33 #define RTC_DIVIDER_33KHZ       (0b010 << 4)
34
35 typedef struct
36 {
37     uint32_t year;      // use int32 as we need to store the 4-digit year
38     uint8_t month;
39     uint8_t day;
40     uint8_t weekday;
41     uint8_t hour;
42     uint8_t minute;
43     uint8_t second;
44 } rtc_datetime;
45
46 void
47 rtc_init();
48
49 uint8_t
50 rtc_read_reg(uint8_t reg_selector);
51
52 void
53 rtc_write_reg(uint8_t reg_selector, uint8_t val);
54
55 void 
56 rtc_get_datetime(rtc_datetime* datetime);
57
58 void
59 rtc_enable_timer();
60
61 void
62 rtc_disable_timer();
63
64 #endif /* __LUNAIX_RTC_H */