Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

arm_timer.c 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /* get timer returns the contents of the timer */
  13. static unsigned long get_timer(void)
  14. {
  15. return P2001_TIMER->Freerun_Timer;
  16. }
  17. /* ------ Calibrate the TSC -------
  18. * Time how long it takes to excute a loop that runs in known time.
  19. * And find the convertion needed to get to CLOCK_TICK_RATE
  20. */
  21. static unsigned long configure_timer(void)
  22. {
  23. return (1);
  24. }
  25. static unsigned long clocks_per_tick = 1;
  26. void setup_timers(void)
  27. {
  28. if (!clocks_per_tick) {
  29. clocks_per_tick = configure_timer();
  30. }
  31. }
  32. unsigned long currticks(void)
  33. {
  34. return get_timer(); /* /clocks_per_tick */
  35. }
  36. static unsigned long timer_timeout;
  37. static int __timer_running(void)
  38. {
  39. return get_timer() < timer_timeout;
  40. }
  41. void udelay(unsigned int usecs)
  42. {
  43. unsigned long now;
  44. now = get_timer();
  45. timer_timeout = now + usecs * ((clocks_per_tick * TICKS_PER_SEC)/(1000*1000));
  46. while(__timer_running());
  47. }
  48. void ndelay(unsigned int nsecs)
  49. {
  50. unsigned long now;
  51. now = get_timer();
  52. timer_timeout = now + nsecs * ((clocks_per_tick * TICKS_PER_SEC)/(1000*1000*1000));
  53. while(__timer_running());
  54. }
  55. void load_timer2(unsigned int timer2_ticks)
  56. {
  57. unsigned long now;
  58. unsigned long clocks;
  59. now = get_timer();
  60. clocks = timer2_ticks * ((clocks_per_tick * TICKS_PER_SEC)/CLOCK_TICK_RATE);
  61. timer_timeout = now + clocks;
  62. }
  63. int timer2_running(void)
  64. {
  65. return __timer_running();
  66. }