-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Ryand1234/rtc_time
Added rtc time module
- Loading branch information
Showing
12 changed files
with
131 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
sysroot/* | ||
*.a | ||
iso*/* | ||
.idea/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include<arch/i386/time.h> | ||
|
||
uint8_t read_cmos(uint8_t reg) | ||
{ | ||
outb(CMOS_ADDRESS, reg); | ||
return inb(CMOS_DATA); | ||
} | ||
|
||
void write_cmos(uint8_t reg, uint8_t value) | ||
{ | ||
outb(CMOS_ADDRESS, reg); | ||
outb(CMOS_DATA, value); | ||
} | ||
|
||
|
||
uint8_t bcd_to_binary(uint8_t bcd) { | ||
return ((bcd & 0xF0) >> 4) * 10 + (bcd & 0x0F); | ||
} | ||
|
||
void convert_bcd_to_binary(struct kernel_time* rtc_datetime) { | ||
rtc_datetime->second = bcd_to_binary(rtc_datetime->second); | ||
rtc_datetime->minute = bcd_to_binary(rtc_datetime->minute); | ||
rtc_datetime->hour = bcd_to_binary(rtc_datetime->hour); | ||
rtc_datetime->day = bcd_to_binary(rtc_datetime->day); | ||
rtc_datetime->month = bcd_to_binary(rtc_datetime->month); | ||
rtc_datetime->year = bcd_to_binary(rtc_datetime->year); | ||
rtc_datetime->century = bcd_to_binary(rtc_datetime->century); | ||
} | ||
|
||
struct kernel_time read_rtc_hardware_time() | ||
{ | ||
struct kernel_time time; | ||
|
||
outb(CMOS_ADDRESS, 0x8A); | ||
outb(CMOS_DATA, 0x20); | ||
|
||
time.second = read_cmos(0x00); | ||
time.minute = read_cmos(0x02); | ||
time.hour = read_cmos(0x04); | ||
time.day = read_cmos(0x07); | ||
time.month = read_cmos(0x08); | ||
time.year = read_cmos(0x09); | ||
time.century = read_cmos(0x32); | ||
|
||
outb(CMOS_ADDRESS, 0x8A); | ||
outb(CMOS_DATA, 0x00); | ||
return time; | ||
} | ||
|
||
struct kernel_time rtc_time() { | ||
struct kernel_time time = read_rtc_hardware_time(); | ||
convert_bcd_to_binary(&time); | ||
return time; | ||
} | ||
|
||
void show_time() { | ||
struct kernel_time time = rtc_time(); | ||
printf("current time: %d:%d:%d %d:%d:%d%d\n", time.hour, time.minute, time.second, time.day, time.month, time.century, time.year); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef ARCH_I386_TIME_H | ||
#define ARCH_I386_TIME_H | ||
|
||
#include<kernel/io.h> | ||
#include<stdint.h> | ||
#define CMOS_ADDRESS 0x70 | ||
#define CMOS_DATA 0x71 | ||
|
||
struct kernel_time { | ||
uint8_t second; | ||
uint8_t minute; | ||
uint8_t hour; | ||
uint8_t day; | ||
uint8_t month; | ||
uint8_t year; | ||
uint8_t century; | ||
}; | ||
|
||
void init_rtc(void); | ||
uint8_t read_cmos(uint8_t); | ||
void write_cmos(uint8_t, uint8_t); | ||
struct kernel_time read_rtc_hardware_time(void); | ||
struct kernel_time rtc_time(void); | ||
void convert_bcd_to_binary(struct kernel_time*); | ||
void update_system_time(void); | ||
struct kernel_time convert_timestamp_to_datetime(uint32_t); | ||
uint32_t convert_datetime_to_timestamp(struct kernel_time); | ||
void get_system_time(struct kernel_time *); | ||
int set_systme_time(struct kernel_time *); | ||
void show_time(void); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef KERNEL_IO_H | ||
#define KERNEL_IO_H | ||
#include<stdint.h> | ||
void outb(uint32_t , uint8_t ); | ||
|
||
uint8_t inb(uint32_t ); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include<kernel/io.h> | ||
|
||
void outb(uint32_t ad, uint8_t v) | ||
{ | ||
asm volatile("outb %%al, %%dx" :: "d" (ad), "a" (v)); | ||
} | ||
|
||
uint8_t inb(uint32_t ad) | ||
{ | ||
uint8_t v; | ||
asm volatile("inb %%dx, %%al" : "=a" (v) : "d" (ad)); | ||
return v; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
KERNEL_ARCH_CFLAGS= | ||
KERNEL_ARCH_CPPFLAGS= | ||
KERNEL_ARCH_LDFLAGS= | ||
KERNEL_ARCH_LIBS= | ||
|
||
KERNEL_KERNEL_OBJS=\ | ||
$(KERNELDIR)/kernel.o \ | ||
$(KERNELDIR)/io.o \ | ||
|