timer.c 432 B

1234567891011121314151617181920212223242526
  1. #include <asm/port_io.h>
  2. #include <kernel/hw/timer.h>
  3. static size_t _current_ticks = 0;
  4. SECTION(".text.kinit")
  5. void init_pit(void)
  6. {
  7. // set interval
  8. asm_outb(PORT_PIT_CONTROL, 0x34);
  9. // send interval number
  10. // 0x2e9a = 11930 = 100Hz
  11. asm_outb(PORT_PIT_COUNT, 0x9a);
  12. asm_outb(PORT_PIT_COUNT, 0x2e);
  13. }
  14. void inc_tick(void)
  15. {
  16. ++_current_ticks;
  17. }
  18. size_t current_ticks(void)
  19. {
  20. return _current_ticks;
  21. }