diff options
| author | Miguel <m.i@gmx.at> | 2018-08-21 01:20:42 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-08-21 01:20:42 +0200 |
| commit | 690403fc51ecb51689cb72f224fccc0d301b7f7d (patch) | |
| tree | 44b6a93d95ac04461d02a9c411cbe5e3f4431ce4 /kernel/timer.c | |
| parent | 1963dbcd92c15094c99d2f900e4812611b6af733 (diff) | |
cleanup timer stuff and move to asm.
Diffstat (limited to 'kernel/timer.c')
| -rw-r--r-- | kernel/timer.c | 93 |
1 files changed, 19 insertions, 74 deletions
diff --git a/kernel/timer.c b/kernel/timer.c index 2bf1592..2d4c7ff 100644 --- a/kernel/timer.c +++ b/kernel/timer.c @@ -3,40 +3,7 @@ #include "asm/x86.h" -//TODO: volatile? spinlock? -static volatile uint64_t task_system_clock=0; static volatile uint64_t task_system_clock_start=0; -static volatile uint8_t interrupts_on = 0; - -// interrupt handler (do NOT call yourself!) -void timer_tick() -{ - task_system_clock++; - interrupts_on=1; -} - -// get value -uint64_t timer_get_ticks() -{ - uint64_t ret; -// x86_cli(); // do not disturb by timer_tick! - ret=task_system_clock; - // if(interrupts_on!=0)x86_sti(); // reenable (if clock was running already) - return ret; -} - -uint64_t timer_get_ms() -{ - uint64_t t=timer_get_ticks(); - uint64_t s=t/25; - uint64_t ms=t*1000/25-s*1000; - return s*1000+ms; -} - -uint64_t timer_get_uptime_ms() -{ - return timer_get_ms()-task_system_clock_start*1000; -} // CMOS RTC @@ -55,16 +22,16 @@ static int get_rtc_update_flag() { // get real time clock rom cmos (seconds since jan) static uint64_t get_rtc_time() { - int CURRENT_YEAR = 2018; // Change this each year! + int CURRENT_YEAR = 2018; // Change this each year! - int century_register = 0x00; // Set by ACPI table parsing code if possible + int century_register = 0x00; // Set by ACPI table parsing code if possible - unsigned char second; - unsigned char minute; - unsigned char hour; - unsigned char day; - unsigned char month; - unsigned int year; + unsigned char second; + unsigned char minute; + unsigned char hour; + unsigned char day; + unsigned char month; + unsigned int year; unsigned char century; unsigned char last_second; @@ -142,8 +109,6 @@ static uint64_t get_rtc_time() if(year < CURRENT_YEAR) year += 100; } - // return ((((uint64_t)year-1970)*356;//+month*30+day)*24+hour*60+minute)*60+second; - // thank you doug16k @ #osdev // https://github.com/doug65536/dgos/blob/eab7080e69360493381669e7ce0ff27587d3127a/kernel/lib/time.cc int days[] = { @@ -182,41 +147,21 @@ static uint64_t get_rtc_time() } -// TODO: put in asm file! -static void timer_config() -{ - __asm__("pusha"); - - __asm__("mov %0, %%dx"::"X" (1193180 / 25)); - - __asm__("mov $0b00110100, %al"); - __asm__("out %al,$0x43"); - - __asm__("mov %dx,%ax"); - - __asm__("out %al, $0x40"); - __asm__("xchg %ah,%al"); - __asm__("out %al, $0x40"); - - __asm__("popa"); - -} - // PIT uint64_t timer_init() { uint64_t epoch_time=get_rtc_time(); + task_system_clock_start=epoch_time*25; // since pit ticks 25times a second + pit_init(); + return epoch_time; +} - task_system_clock_start=epoch_time; - task_system_clock=epoch_time*25; - - timer_config(); +uint64_t timer_get_ms() +{ + return (pit_get_ticks()+task_system_clock_start)*40; +} - // config out timer on channel 0 : mode 2 (sys timer) - // http://en.wikipedia.org/wiki/Intel_8253#Control_Word_Register - // http://www.brokenthorn.com/Resources/OSDevPit.html - // int0 will be triggered ~25 times a second. - - //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Configured PIT Channel 0 : Mode 2 : 1/25 s."); - return epoch_time; +uint64_t timer_get_uptime_ms() +{ + return pit_get_ticks()*40; } |
