diff --git a/kernel.c b/kernel.c index 20e333d..4be1958 100644 --- a/kernel.c +++ b/kernel.c @@ -2,12 +2,14 @@ #include "types.h" #include "tests.h" #include "interrupts.h" +#include "pit.h" #include "stlio.h" #include "gdt.h" void kinit() { //gdt_configure(); init_idt(); + pit_install_timer(); test_dispatcher(); } diff --git a/pit.c b/pit.c new file mode 100644 index 0000000..b0ecfbc --- /dev/null +++ b/pit.c @@ -0,0 +1,19 @@ +#include "pit.h" +#include "types.h" +#include "interrupts.h" +#include "stlio.h" + +timer_ticks = 0; + +void inc_ticks(struct cpu_reg_state* cpu) { + timer_ticks++; + if(timer_ticks % 18 == 0) { + printf("One second passed\n"); + } +} + +void tick_width(u32 width) { +} +void pit_install_timer(void) { + init_irq_handler(0, inc_ticks); // timer interrupt request falls into int 0 +} \ No newline at end of file diff --git a/pit.h b/pit.h new file mode 100644 index 0000000..853b716 --- /dev/null +++ b/pit.h @@ -0,0 +1,13 @@ +#include "types.h" + +u32 timer_ticks; +// 60hz timer for now +#define PIT_TIMER_INTERVAL 100 +#define PIT_TIME_DATA0 0x40 +#define PIT_TIME_DATA1 0x41 +#define PIT_TIME_DATA2 0x42 + +// Sets the tick rate 100hz +void tick_width(u32); + +void inc_ticks(struct cpu_reg_state* cpu); \ No newline at end of file