14#define CMOS_ADDRESS 0x70
28static inline uint8_t cmos_read(uint8_t reg) {
34static inline bool rtc_updating(
void) {
40static inline uint8_t bcd_to_bin(uint8_t val) {
41 return ((val >> 4) * 10) + (val & 0x0F);
51 while (rtc_updating());
54 t.
second = cmos_read(0x00);
55 t.
minute = cmos_read(0x02);
56 t.
hour = cmos_read(0x04);
57 t.
day = cmos_read(0x07);
58 t.
month = cmos_read(0x08);
59 uint8_t year = cmos_read(0x09);
62 century = cmos_read(0x32);
65 regB = cmos_read(0x0B);
74 year = bcd_to_bin(year);
75 if (century) century = bcd_to_bin(century);
79 if (!(regB & 0x02) && (t.
hour & 0x80)) {
80 t.
hour = ((t.
hour & 0x7F) + 12) % 24;
85 t.
year = (century * 100) + year;
95static bool is_leap_year(uint16_t year) {
96 return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
99static const int days_in_month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
101static uint64_t MeGetEpoch(
void) {
106 for (uint16_t y = 1970; y < t.
year; y++)
107 days += 365 + (is_leap_year(y) ? 1 : 0);
109 for (uint8_t m = 1; m < t.
month; m++)
110 days += days_in_month[m - 1] + (m == 2 && is_leap_year(t.
year) ? 1 : 0);
115 uint64_t seconds = days * 86400ULL;
116 seconds += t.
hour * 3600ULL;
117 seconds += t.
minute * 60ULL;
FORCEINLINE void __outbyte(unsigned short port, unsigned char val)
FORCEINLINE unsigned char __inbyte(unsigned short port)