diff options
author | Tyler Murphy <=> | 2023-07-17 19:34:52 -0400 |
---|---|---|
committer | Tyler Murphy <=> | 2023-07-17 19:34:52 -0400 |
commit | 7a912d1b668ab86ffe088eca3ac7e6f78a04a0c5 (patch) | |
tree | 4e86ff20e73171285156631db043e12aaf63bf04 /kernel/src/arch/i686/drivers/rtc.c | |
parent | paging (diff) | |
download | finix-7a912d1b668ab86ffe088eca3ac7e6f78a04a0c5.tar.gz finix-7a912d1b668ab86ffe088eca3ac7e6f78a04a0c5.tar.bz2 finix-7a912d1b668ab86ffe088eca3ac7e6f78a04a0c5.zip |
refactoring
Diffstat (limited to '')
-rw-r--r-- | kernel/src/arch/i686/drivers/rtc.c (renamed from kernel/src/drivers/cmos.c) | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/kernel/src/drivers/cmos.c b/kernel/src/arch/i686/drivers/rtc.c index 5ac12c3..ba69d15 100644 --- a/kernel/src/drivers/cmos.c +++ b/kernel/src/arch/i686/drivers/rtc.c @@ -1,7 +1,8 @@ -#include "print.h" +#include "time.h" #include <stdint.h> #include <sys.h> -#include <time.h> +#include <arch/i686/drivers/rtc.h> +#include <arch/i686/asm.h> #define CMOS_WRITE_PORT 0x70 #define CMOS_READ_PORT 0x71 @@ -15,9 +16,16 @@ #define CMOS_REG_YEAR 0x09 #define CMOS_REG_CEN 0x32 +// Live buffers to work on data static struct Time time; static struct Time localtime; -static int cur_offset = 0; + +// Front buffers so interupts dont request data that is half done +static struct Time cur_time; +static struct Time cur_localtime; + +// Current set Time Zone +static enum Timezone last_timezone = UTC; static uint8_t cmos_read(uint8_t reg) { uint8_t hex, ret; @@ -46,10 +54,12 @@ static void update_localtime(void) { // set localtime localtime = time; - // do we acutally need to do anything - if (cur_offset == 0) return; - localtime.hour += cur_offset; - + // if tz is UTC, we dont need to do anythin + if (last_timezone == UTC) { + cur_localtime = localtime; + return; + } + // check if day rolled over change = localtime.hour < 0 ? -1 : localtime.hour >= 24 ? 1 : 0; if (!change) return; @@ -98,13 +108,11 @@ year: localtime.yday = 0; localtime.year -= 1900; + + cur_localtime = localtime; } -void rtc_set_timezone(int offset) { - cur_offset = offset; -} - void rtc_update(void) { time.sec = cmos_read(CMOS_REG_SEC); time.min = cmos_read(CMOS_REG_MIN); @@ -127,12 +135,18 @@ void rtc_update(void) { time.year -= 1900; update_localtime(); + + cur_time = time; } -struct Time *rtc_utctime(void) { - return &time; +struct Time rtc_utctime(void) { + return cur_time; } -struct Time *rtc_localtime(void) { - return &localtime; +struct Time rtc_localtime(enum Timezone tz) { + if (tz != last_timezone) { + last_timezone = tz; + update_localtime(); + } + return cur_localtime; } |