Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

42 Zeilen
1.6 KiB

  1. #include "kernel.h"
  2. #include "klibc.h"
  3. #include "timer.h"
  4. u32 ticks = 0;
  5. void timer_phase(int hz)
  6. {
  7. unsigned int divisor = 1193180 / hz; /* Calculate our divisor */
  8. /*
  9. 0x43 is the Mode/Command register
  10. From http://wiki.osdev.org/Programmable_Interval_Timer#Read_Back_Status_Byte :
  11. Bits Usage
  12. 6 and 7 Select channel :
  13. 0 0 = Channel 0
  14. 0 1 = Channel 1
  15. 1 0 = Channel 2
  16. 1 1 = Read-back command (8254 only)
  17. 4 and 5 Access mode :
  18. 0 0 = Latch count value command
  19. 0 1 = Access mode: lobyte only
  20. 1 0 = Access mode: hibyte only
  21. 1 1 = Access mode: lobyte/hibyte
  22. 1 to 3 Operating mode :
  23. 0 0 0 = Mode 0 (interrupt on terminal count)
  24. 0 0 1 = Mode 1 (hardware re-triggerable one-shot)
  25. 0 1 0 = Mode 2 (rate generator)
  26. 0 1 1 = Mode 3 (square wave generator)
  27. 1 0 0 = Mode 4 (software triggered strobe)
  28. 1 0 1 = Mode 5 (hardware triggered strobe)
  29. 1 1 0 = Mode 2 (rate generator, same as 010b)
  30. 1 1 1 = Mode 3 (square wave generator, same as 011b)
  31. 0 BCD/Binary mode: 0 = 16-bit binary, 1 = four-digit BCD
  32. */
  33. unsigned short command = 0b00110110;
  34. outb(0x43, command);
  35. outb(0x40, divisor & 0xFF); /* Set low byte of divisor */
  36. outb(0x40, divisor >> 8); /* Set high byte of divisor */
  37. }