42 return (bcd >> 4) * 10 + (bcd & 0x0F);
51 asm volatile(
"pause");
65 fullYear = cent * 100 + year;
69 fullYear = (year >= 70) ? (1900 + year) : (2000 + year);
72 struct tm stime = (
struct tm){
78 .tm_year = fullYear - 1900,
98 LOG_ERR(
"rtc failed to get ACPI device config for '%s'\n", deviceName);
105 LOG_ERR(
"rtc device '%s' has invalid port resources\n", deviceName);
117 LOG_ERR(
"failed to register RTC\n");
133 LOG_ERR(
"failed to initialize RTC\n");
143MODULE_INFO(
"RTC Driver",
"Kai Norberg",
"A driver for the CMOS Real Time Clock", OS_VERSION,
"MIT",
"PNP0B00");
static void io_out8(port_t port, uint8_t val)
Write an 8-bit value to an I/O port.
static uint8_t io_in8(port_t port)
Read an 8-bit value from an I/O port.
uint16_t port_t
I/O port type.
static uint64_t rtc_init(const char *deviceName)
static uint8_t centuryRegister
static int rtc_update_in_progress(void)
static time_t rtc_read_epoch(void)
static port_t addressPort
static uint8_t rtc_read(uint8_t reg)
static clock_source_t source
static uint8_t rtc_bcd_to_bin(uint8_t bcd)
#define LOG_ERR(format,...)
#define MODULE_INFO(_name, _author, _description, _version, _licence, _deviceTypes)
Macro to define module information.
@ MODULE_EVENT_DEVICE_ATTACH
uint64_t clock_source_register(const clock_source_t *source)
Register a system timer source.
#define LOCK_CREATE()
Create a lock initializer.
#define LOCK_SCOPE(lock)
Acquires a lock for the reminder of the current scope.
#define NULL
Pointer error value.
#define ERR
Integer error value.
acpi_device_cfg_t * acpi_device_cfg_lookup(const char *name)
Retrieves the ACPI device configuration for a device by its name.
uint64_t acpi_device_cfg_get_port(acpi_device_cfg_t *cfg, uint64_t index, port_t *out)
Retrieves an the nth IO port assigned to an ACPI device.
#define FADT_SIGNATURE
FADT table signature.
sdt_header_t * acpi_tables_lookup(const char *signature, uint64_t minSize, uint64_t n)
Lookup the n'th table matching the signature.
uint64_t _module_procedure(const module_event_t *event)
ACPI device configuration structure.
Fixed ACPI Description Table.
A simple ticket lock implementation.
struct module_event_t::@4::@6 deviceAttach
_PUBLIC time_t mktime(struct tm *timeptr)
long long unsigned time_t