10#define CMOS_REG_SET 0x70
11#define CMOS_REG_IO 0x71
35#define RTCSB_24HR 0x02
45 static const int days_per_month[12] =
47 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
49 int sec, min, hour, mday, mon, year;
85 time = (year * 365 + (year - 1) / 4) * 24 * 60 * 60;
86 for (i = 1; i <= mon; i++)
87 time += days_per_month[i - 1] * 24 * 60 * 60;
88 if (mon > 2 && year % 4 == 0)
90 time += (mday - 1) * 24 * 60 * 60;
91 time += hour * 60 * 60;
102 return (
x & 0x0f) + ((
x >> 4) * 10);
static uint8_t inb(uint16_t port)
Reads and returns a byte from PORT.
static void outb(uint16_t port, uint8_t data)
Writes byte DATA to PORT.
static char x
Verifies that mapping over the data segment is disallowed.
#define RTC_REG_MIN
Minute: 0x00...0x59.
static int bcd_to_bin(uint8_t)
Returns the integer value of the given BCD byte.
#define RTC_REG_MDAY
Day of the month: 0x01...0x31.
static uint8_t cmos_read(uint8_t index)
Reads a byte from the CMOS register with the given INDEX and returns the byte read.
#define CMOS_REG_IO
Contains the selected data byte.
#define RTC_REG_MON
Month: 0x01...0x12.
time_t rtc_get_time(void)
Returns number of seconds since Unix epoch of January 1,.
#define RTC_REG_SEC
Indexes of CMOS registers with real-time clock functions.
#define RTC_REG_HOUR
Hour: 0x00...0x23.
#define CMOS_REG_SET
This code is an interface to the MC146818A-compatible real time clock found on PC motherboards.
#define RTC_REG_YEAR
Year: 0x00...0x99.