PKUOS - Pintos
Pintos source browser for PKU Operating System course
Macros | Functions
rtc.c File Reference
#include "devices/rtc.h"
#include <stdio.h>
#include "threads/io.h"
Include dependency graph for rtc.c:

Go to the source code of this file.

Macros

#define CMOS_REG_SET   0x70
 This code is an interface to the MC146818A-compatible real time clock found on PC motherboards. More...
 
#define CMOS_REG_IO   0x71
 Contains the selected data byte. More...
 
#define RTC_REG_SEC   0
 Indexes of CMOS registers with real-time clock functions. More...
 
#define RTC_REG_MIN   2
 Minute: 0x00...0x59. More...
 
#define RTC_REG_HOUR   4
 Hour: 0x00...0x23. More...
 
#define RTC_REG_MDAY   7
 Day of the month: 0x01...0x31. More...
 
#define RTC_REG_MON   8
 Month: 0x01...0x12. More...
 
#define RTC_REG_YEAR   9
 Year: 0x00...0x99. More...
 
#define RTC_REG_A   0x0a
 Indexes of CMOS control registers. More...
 
#define RTC_REG_B   0x0b
 Register B: 24/12 hour time, irq enables. More...
 
#define RTC_REG_C   0x0c
 Register C: pending interrupts. More...
 
#define RTC_REG_D   0x0d
 Register D: valid time? More...
 
#define RTCSA_UIP   0x80
 Register A. More...
 
#define RTCSB_SET   0x80
 Register B. More...
 
#define RTCSB_DM   0x04
 0 = BCD time format, 1 = binary format. More...
 
#define RTCSB_24HR   0x02
 0 = 12-hour format, 1 = 24-hour format. More...
 

Functions

static int bcd_to_bin (uint8_t x)
 Returns the integer value of the given BCD byte. More...
 
static uint8_t cmos_read (uint8_t index)
 Reads a byte from the CMOS register with the given INDEX and returns the byte read. More...
 
time_t rtc_get_time (void)
 Returns number of seconds since Unix epoch of January 1,. More...
 

Macro Definition Documentation

◆ CMOS_REG_IO

#define CMOS_REG_IO   0x71

Contains the selected data byte.

Definition at line 11 of file rtc.c.

◆ CMOS_REG_SET

#define CMOS_REG_SET   0x70

This code is an interface to the MC146818A-compatible real time clock found on PC motherboards.

See [MC146818A] for hardware details. I/O register addresses. Selects CMOS register exposed by REG_IO.

Definition at line 10 of file rtc.c.

◆ RTC_REG_A

#define RTC_REG_A   0x0a

Indexes of CMOS control registers.

Register A: update-in-progress.

Definition at line 24 of file rtc.c.

◆ RTC_REG_B

#define RTC_REG_B   0x0b

Register B: 24/12 hour time, irq enables.

Definition at line 25 of file rtc.c.

◆ RTC_REG_C

#define RTC_REG_C   0x0c

Register C: pending interrupts.

Definition at line 26 of file rtc.c.

◆ RTC_REG_D

#define RTC_REG_D   0x0d

Register D: valid time?

Definition at line 27 of file rtc.c.

◆ RTC_REG_HOUR

#define RTC_REG_HOUR   4

Hour: 0x00...0x23.

Definition at line 18 of file rtc.c.

◆ RTC_REG_MDAY

#define RTC_REG_MDAY   7

Day of the month: 0x01...0x31.

Definition at line 19 of file rtc.c.

◆ RTC_REG_MIN

#define RTC_REG_MIN   2

Minute: 0x00...0x59.

Definition at line 17 of file rtc.c.

◆ RTC_REG_MON

#define RTC_REG_MON   8

Month: 0x01...0x12.

Definition at line 20 of file rtc.c.

◆ RTC_REG_SEC

#define RTC_REG_SEC   0

Indexes of CMOS registers with real-time clock functions.

Note that all of these registers are in BCD format, so that 0x59 means 59, not 89. Second: 0x00...0x59.

Definition at line 16 of file rtc.c.

◆ RTC_REG_YEAR

#define RTC_REG_YEAR   9

Year: 0x00...0x99.

Definition at line 21 of file rtc.c.

◆ RTCSA_UIP

#define RTCSA_UIP   0x80

Register A.

Set while time update in progress.

Definition at line 30 of file rtc.c.

◆ RTCSB_24HR

#define RTCSB_24HR   0x02

0 = 12-hour format, 1 = 24-hour format.

Definition at line 35 of file rtc.c.

◆ RTCSB_DM

#define RTCSB_DM   0x04

0 = BCD time format, 1 = binary format.

Definition at line 34 of file rtc.c.

◆ RTCSB_SET

#define RTCSB_SET   0x80

Register B.

Disables update to let time be set.

Definition at line 33 of file rtc.c.

Function Documentation

◆ bcd_to_bin()

static int bcd_to_bin ( uint8_t  x)
static

Returns the integer value of the given BCD byte.

Definition at line 100 of file rtc.c.

References x.

Referenced by rtc_get_time().

Here is the caller graph for this function:

◆ cmos_read()

static uint8_t cmos_read ( uint8_t  index)
static

Reads a byte from the CMOS register with the given INDEX and returns the byte read.

Definition at line 108 of file rtc.c.

References CMOS_REG_IO, CMOS_REG_SET, inb(), and outb().

Referenced by rtc_get_time().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rtc_get_time()

time_t rtc_get_time ( void  )

Returns number of seconds since Unix epoch of January 1,.

Definition at line 43 of file rtc.c.

References bcd_to_bin(), cmos_read(), RTC_REG_HOUR, RTC_REG_MDAY, RTC_REG_MIN, RTC_REG_MON, RTC_REG_SEC, and RTC_REG_YEAR.

Referenced by parse_options().

Here is the call graph for this function:
Here is the caller graph for this function: