You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

55 line
2.1 KiB

  1. /*
  2. * libcaca Colour ASCII-Art library
  3. * Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
  4. * 2009 Jean-Yves Lamoureux <jylam@lnxscene.org>
  5. * All Rights Reserved
  6. *
  7. * This library is free software. It comes without any warranty, to
  8. * the extent permitted by applicable law. You can redistribute it
  9. * and/or modify it under the terms of the Do What The Fuck You Want
  10. * To Public License, Version 2, as published by Sam Hocevar. See
  11. * http://sam.zoy.org/wtfpl/COPYING for more details.
  12. */
  13. #include "kernel.h"
  14. #include "klibc.h"
  15. #include "timer.h"
  16. u32 ticks = 0;
  17. void timer_phase(int hz)
  18. {
  19. unsigned int divisor = 1193180 / hz; /* Calculate our divisor */
  20. /*
  21. 0x43 is the Mode/Command register
  22. From http://wiki.osdev.org/Programmable_Interval_Timer#Read_Back_Status_Byte :
  23. Bits Usage
  24. 6 and 7 Select channel :
  25. 0 0 = Channel 0
  26. 0 1 = Channel 1
  27. 1 0 = Channel 2
  28. 1 1 = Read-back command (8254 only)
  29. 4 and 5 Access mode :
  30. 0 0 = Latch count value command
  31. 0 1 = Access mode: lobyte only
  32. 1 0 = Access mode: hibyte only
  33. 1 1 = Access mode: lobyte/hibyte
  34. 1 to 3 Operating mode :
  35. 0 0 0 = Mode 0 (interrupt on terminal count)
  36. 0 0 1 = Mode 1 (hardware re-triggerable one-shot)
  37. 0 1 0 = Mode 2 (rate generator)
  38. 0 1 1 = Mode 3 (square wave generator)
  39. 1 0 0 = Mode 4 (software triggered strobe)
  40. 1 0 1 = Mode 5 (hardware triggered strobe)
  41. 1 1 0 = Mode 2 (rate generator, same as 010b)
  42. 1 1 1 = Mode 3 (square wave generator, same as 011b)
  43. 0 BCD/Binary mode: 0 = 16-bit binary, 1 = four-digit BCD
  44. */
  45. unsigned short command = 0b00110110;
  46. outb(0x43, command);
  47. outb(0x40, divisor & 0xFF); /* Set low byte of divisor */
  48. outb(0x40, divisor >> 8); /* Set high byte of divisor */
  49. }