Modestus Moon OS  R4
CS 450 project
rtc.c File Reference
#include <core/rtc.h>
#include <string.h>
Include dependency graph for rtc.c:

Go to the source code of this file.

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 More...
 
void set_time (int hours, int minutes, int seconds)
 set_time sets the RTC 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...
 

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

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

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