Modestus Moon OS  R4
CS 450 project
rtc.c
Go to the documentation of this file.
1 #include <core/rtc.h>
2 #include <string.h>
10 void get_time(int *hours, int *minutes, int *seconds)
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 }
25 
33 void set_time(int hours, int minutes, int seconds)
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 }
48 
56 void get_date(int *day, int *month, int *year)
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 }
71 
79 void set_date(int day, int month, int year)
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 HOURS_INDEX
Definition: rtc.h:12
#define MONTHS_INDEX
Definition: rtc.h:14
void get_date(int *day, int *month, int *year)
get_date this function will retrieve the system date and place in three pointers
Definition: rtc.c:56
void get_time(int *hours, int *minutes, int *seconds)
get_time this function will retrieve the system time and place it in three pointers ...
Definition: rtc.c:10
#define cli()
Definition: system.h:15
void set_date(int day, int month, int year)
set_date sets the RTC Date
Definition: rtc.c:79
#define sti()
Definition: system.h:14
#define YEAR_INDEX
Definition: rtc.h:15
void set_time(int hours, int minutes, int seconds)
set_time sets the RTC time
Definition: rtc.c:33
#define SECONDS_INDEX
Definition: rtc.h:10
#define inb(port)
Definition: io.h:15
#define RTC_DATA_REG
Definition: rtc.h:8
#define DAY_OF_MONTH_INDEX
Definition: rtc.h:13
#define MINUTES_INDEX
Definition: rtc.h:11
#define outb(port, data)
Definition: io.h:8