Modestus Moon OS  R4
CS 450 project
rtc.h File Reference
#include <core/io.h>
#include <system.h>
Include dependency graph for rtc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define RTC_INDEX_REG   0x70
 
#define RTC_DATA_REG   0x71
 
#define SECONDS_INDEX   0x00
 
#define MINUTES_INDEX   0x02
 
#define HOURS_INDEX   0x04
 
#define DAY_OF_MONTH_INDEX   0x07
 
#define MONTHS_INDEX   0x08
 
#define YEAR_INDEX   0x09
 

Functions

void get_time (int *hours, int *minutes, int *seconds)
 get_time this function will retrieve the system time and place it in three pointers. Military time More...
 
void set_time (int hours, int minutes, int seconds)
 set_time sets the RTC time. Military time More...
 
void get_date (int *day, int *month, int *year)
 get_date this function will retrieve the system date and place in three pointers More...
 
void set_date (int day, int month, int year)
 set_date sets the RTC Date More...
 

Macro Definition Documentation

#define DAY_OF_MONTH_INDEX   0x07

Definition at line 13 of file rtc.h.

Referenced by get_date(), and set_date().

#define HOURS_INDEX   0x04

Definition at line 12 of file rtc.h.

Referenced by get_time(), and set_time().

#define MINUTES_INDEX   0x02

Definition at line 11 of file rtc.h.

Referenced by get_time(), and set_time().

#define MONTHS_INDEX   0x08

Definition at line 14 of file rtc.h.

Referenced by get_date(), and set_date().

#define RTC_DATA_REG   0x71

Definition at line 8 of file rtc.h.

Referenced by set_date(), and set_time().

#define RTC_INDEX_REG   0x70

Definition at line 7 of file rtc.h.

Referenced by get_date(), get_time(), set_date(), and set_time().

#define SECONDS_INDEX   0x00

Definition at line 10 of file rtc.h.

Referenced by get_time(), and set_time().

#define YEAR_INDEX   0x09

Definition at line 15 of file rtc.h.

Referenced by get_date(), and set_date().

Function Documentation

void get_date ( int *  day,
int *  month,
int *  year 
)

get_date this function will retrieve the system date and place in three pointers

Parameters
daypointer to int where the current day will be stored, UTC Time zone
monthspointer to int where the current month will be stored, UTC Time zone
yearpointer to int where the current year will be stored, UTC Time zone

Definition at line 56 of file rtc.c.

References DAY_OF_MONTH_INDEX, inb, MONTHS_INDEX, outb, RTC_INDEX_REG, and YEAR_INDEX.

Referenced by getDate().

57 {
58  char temp = 0;
60  temp = inb(0x71);
61  *day = ((temp & 0xf0) >>4 ) *10 + (temp & 0x0f);
62 
64  temp = inb(0x71);
65  *month = ((temp & 0xf0) >>4 ) *10 + (temp & 0x0f);
66 
68  temp = inb(0x71);
69  *year = ((temp & 0xf0) >>4 ) *10 + (temp & 0x0f);
70 }
#define RTC_INDEX_REG
Definition: rtc.h:7
#define MONTHS_INDEX
Definition: rtc.h:14
#define YEAR_INDEX
Definition: rtc.h:15
#define inb(port)
Definition: io.h:15
#define DAY_OF_MONTH_INDEX
Definition: rtc.h:13
#define outb(port, data)
Definition: io.h:8
void get_time ( int *  hours,
int *  minutes,
int *  seconds 
)

get_time this function will retrieve the system time and place it in three pointers. Military time

Parameters
hourspointer to int where the current hours will be stored, in UTC timezone
minutespointer to int where the current minutes will be stored, in UTC timezone
secondspointer to int where the current seconds will be stored, in UTC timezone

get_time this function will retrieve the system time and place it in three pointers. Military time

Parameters
hourspointer to int where the current hours will be stored, in UTC timezone
minutespointer to int where the current minutes will be stored, in UTC timezone
secondspointer to int where the current seconds will be stored, in UTC timezone

Definition at line 10 of file rtc.c.

References HOURS_INDEX, inb, MINUTES_INDEX, outb, RTC_INDEX_REG, and SECONDS_INDEX.

Referenced by getTime().

11 {
12  char temp = 0;
14  temp = inb(0x71);
15  *seconds = ((temp & 0xf0) >>4 ) *10 + (temp & 0x0f);
16 
18  temp = inb(0x71);
19  *minutes = ((temp & 0xf0) >>4 ) *10 + (temp & 0x0f);
20 
22  temp = inb(0x71);
23  *hours = ((temp & 0xf0) >>4 ) *10 + (temp & 0x0f);
24 }
#define RTC_INDEX_REG
Definition: rtc.h:7
#define HOURS_INDEX
Definition: rtc.h:12
#define SECONDS_INDEX
Definition: rtc.h:10
#define inb(port)
Definition: io.h:15
#define MINUTES_INDEX
Definition: rtc.h:11
#define outb(port, data)
Definition: io.h:8
void set_date ( int  day,
int  month,
int  year 
)

set_date sets the RTC Date

Parameters
daythe day to set the clock to, must be valid for the month. UTC Time zone
monththe month to set the clock to, must be between 1 and 12. UTC Time zone
yearthe year to set the clock to, must be less than 100. UTC Time zone

Definition at line 79 of file rtc.c.

References cli, DAY_OF_MONTH_INDEX, MONTHS_INDEX, outb, RTC_DATA_REG, RTC_INDEX_REG, sti, and YEAR_INDEX.

Referenced by setDate().

80 {
81  sti();
82 
84  outb(RTC_DATA_REG, ((day/10)<<4)|(day%10));
85 
87  outb(RTC_DATA_REG, ((month/10)<<4)|(month%10));
88 
90  outb(RTC_DATA_REG, (((year-(year/100)*100)/10)<<4)|(year%10) );
91 
92  cli();
93 }
#define RTC_INDEX_REG
Definition: rtc.h:7
#define MONTHS_INDEX
Definition: rtc.h:14
#define cli()
Definition: system.h:15
#define sti()
Definition: system.h:14
#define YEAR_INDEX
Definition: rtc.h:15
#define RTC_DATA_REG
Definition: rtc.h:8
#define DAY_OF_MONTH_INDEX
Definition: rtc.h:13
#define outb(port, data)
Definition: io.h:8
void set_time ( int  hours,
int  minutes,
int  seconds 
)

set_time sets the RTC time. Military time

Parameters
hoursthe hours to set the clock to, must be less than 24. In UTC Time zone
minutesthe minutes to set the clock to, must be less than 60. In UTC Time zone
secondsthe seconds to set the clock to, must be less than 60. In UTC Time zone

set_time sets the RTC time. Military time

Parameters
hoursthe hours to set the clock to, must be less than 24. In UTC Time zone
minutesthe minutes to set the clock to, must be less than 60. In UTC Time zone
secondsthe seconds to set the clock to, must be less than 60. In UTC Time zone

Definition at line 33 of file rtc.c.

References cli, HOURS_INDEX, MINUTES_INDEX, outb, RTC_DATA_REG, RTC_INDEX_REG, SECONDS_INDEX, and sti.

Referenced by setTime().

34 {
35  sti();
36 
38  outb(RTC_DATA_REG, ((hours/10)<<4)|(hours%10) );
39 
41  outb(RTC_DATA_REG, ((minutes/10)<<4)|(minutes%10) );
42 
44  outb(RTC_DATA_REG, ((seconds/10)<<4)|(seconds%10) );
45 
46  cli();
47 }
#define RTC_INDEX_REG
Definition: rtc.h:7
#define HOURS_INDEX
Definition: rtc.h:12
#define cli()
Definition: system.h:15
#define sti()
Definition: system.h:14
#define SECONDS_INDEX
Definition: rtc.h:10
#define RTC_DATA_REG
Definition: rtc.h:8
#define MINUTES_INDEX
Definition: rtc.h:11
#define outb(port, data)
Definition: io.h:8