The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
rtc.c File Reference

CMOS real-time clock (MC146818 compatible). More...

#include "rtc.h"
#include "kernel/sync/spinlock.h"
#include "arch/arch.h"
#include "arch/x86/cpu/io.h"

Enumerations

enum  {
  CMOS_ADDRESS = 0x70 , CMOS_DATA = 0x71 , REG_SECONDS = 0x00 , REG_MINUTES = 0x02 ,
  REG_HOURS = 0x04 , REG_DAY = 0x07 , REG_MONTH = 0x08 , REG_YEAR = 0x09 ,
  REG_STATUS_A = 0x0A , REG_STATUS_B = 0x0B , REG_CENTURY = 0x32 , STATUS_A_UPDATING = 0x80 ,
  STATUS_B_BINARY = 0x04 , STATUS_B_24_HOUR = 0x02 , HOURS_PM = 0x80 , NMI_DISABLE = 0x80
}

Functions

bool rtc_read_unix_time (uint32_t *seconds_out)
 read the date and time from the CMOS clock (taken as UTC).

Detailed Description

CMOS real-time clock (MC146818 compatible).

the clock keeps seconds, minutes, hours, day, month and year in CMOS registers, in BCD or binary and 12 or 24 hour form (status register B says which). they change once a second; the registers are read until two reads agree, so a read is never torn by an update.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
CMOS_ADDRESS 
CMOS_DATA 
REG_SECONDS 
REG_MINUTES 
REG_HOURS 
REG_DAY 
REG_MONTH 
REG_YEAR 
REG_STATUS_A 
REG_STATUS_B 
REG_CENTURY 
STATUS_A_UPDATING 
STATUS_B_BINARY 
STATUS_B_24_HOUR 
HOURS_PM 
NMI_DISABLE 

Function Documentation

◆ rtc_read_unix_time()

bool rtc_read_unix_time ( uint32_t * seconds_out)

read the date and time from the CMOS clock (taken as UTC).

Parameters
seconds_outreceives the seconds since 1970-01-01 00:00 UTC.
Returns
false if the clock gives no valid date.