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.

arm_timer.c 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2004 Tobias Lorenz
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include "etherboot.h"
  9. #include "timer.h"
  10. #include "latch.h"
  11. #include "hardware.h"
  12. #include "init.h"
  13. /* get timer returns the contents of the timer */
  14. static unsigned long get_timer(void)
  15. {
  16. return P2001_TIMER->Freerun_Timer;
  17. }
  18. /* ------ Calibrate the TSC -------
  19. * Time how long it takes to excute a loop that runs in known time.
  20. * And find the convertion needed to get to CLOCK_TICK_RATE
  21. */
  22. static unsigned long configure_timer(void)
  23. {
  24. return (1);
  25. }
  26. static unsigned long clocks_per_tick = 1;
  27. static void setup_timers(void)
  28. {
  29. if (!clocks_per_tick) {
  30. clocks_per_tick = configure_timer();
  31. }
  32. }
  33. unsigned long currticks(void)
  34. {
  35. return get_timer(); /* /clocks_per_tick */
  36. }
  37. static unsigned long timer_timeout;
  38. static int __timer_running(void)
  39. {
  40. return get_timer() < timer_timeout;
  41. }
  42. void udelay(unsigned int usecs)
  43. {
  44. unsigned long now;
  45. now = get_timer();
  46. timer_timeout = now + usecs * ((clocks_per_tick * TICKS_PER_SEC)/(1000*1000));
  47. while(__timer_running());
  48. }
  49. void ndelay(unsigned int nsecs)
  50. {
  51. unsigned long now;
  52. now = get_timer();
  53. timer_timeout = now + nsecs * ((clocks_per_tick * TICKS_PER_SEC)/(1000*1000*1000));
  54. while(__timer_running());
  55. }
  56. void load_timer2(unsigned int timer2_ticks)
  57. {
  58. unsigned long now;
  59. unsigned long clocks;
  60. now = get_timer();
  61. clocks = timer2_ticks * ((clocks_per_tick * TICKS_PER_SEC)/CLOCK_TICK_RATE);
  62. timer_timeout = now + clocks;
  63. }
  64. int timer2_running(void)
  65. {
  66. return __timer_running();
  67. }
  68. INIT_FN ( INIT_TIMERS, setup_timers, NULL, NULL );