diff options
| author | Franklin Wei <frankhwei536@gmail.com> | 2015-02-07 11:03:48 -0500 |
|---|---|---|
| committer | Franklin Wei <frankhwei536@gmail.com> | 2015-02-07 11:03:48 -0500 |
| commit | c0df0ee6437aa2786b1a92bc6af1284958d104c7 (patch) | |
| tree | 5c6392aa761ba5028387bee72cc73149893ea508 /kernel/timer.c | |
| parent | 873a103fb71d6b7b1993a64535a7fa150317ca3c (diff) | |
| download | kappa-c0df0ee6437aa2786b1a92bc6af1284958d104c7.zip kappa-c0df0ee6437aa2786b1a92bc6af1284958d104c7.tar.gz kappa-c0df0ee6437aa2786b1a92bc6af1284958d104c7.tar.bz2 kappa-c0df0ee6437aa2786b1a92bc6af1284958d104c7.tar.xz | |
new rng, some rework of I/O
Diffstat (limited to 'kernel/timer.c')
| -rw-r--r-- | kernel/timer.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/kernel/timer.c b/kernel/timer.c index 571fcbe..2fbd8eb 100644 --- a/kernel/timer.c +++ b/kernel/timer.c @@ -1,10 +1,11 @@ #include <stdint.h> +#include "io.h" #include "isr.h" #include "timer.h" -uint64_t current_tick_data = 0; +volatile uint64_t current_tick_data = 0; -const uint64_t *current_tick = ¤t_tick_data; +volatile const uint64_t *current_tick = ¤t_tick_data; static void timer_callback(struct regs_t regs) { @@ -12,7 +13,24 @@ static void timer_callback(struct regs_t regs) ++current_tick_data; } -void timer_init(void) +void timer_init(uint32_t freq) { set_interrupt_handler(IRQ(0), timer_callback); + + current_tick_data = 0; + + uint32_t divisor = PIT_FREQ / freq; + + uint8_t hi = (divisor >> 8) & 0xFF; + uint8_t lo = (divisor >> 0) & 0xFF; + + outb(0x43, 0x36); + outb(0x40, lo); + outb(0x40, hi); +} + +void timer_delay(uint64_t ticks) +{ + uint64_t end = *current_tick + ticks; + while(*current_tick <= end); } |