interrupts.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * (C) Copyright 2003
  3. * Texas Instruments <www.ti.com>
  4. *
  5. * (C) Copyright 2002
  6. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  7. * Marius Groeger <mgroeger@sysgo.de>
  8. *
  9. * (C) Copyright 2002
  10. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  11. * Alex Zuepke <azu@sysgo.de>
  12. *
  13. * (C) Copyright 2002-2004
  14. * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
  15. *
  16. * (C) Copyright 2004
  17. * Philippe Robin, ARM Ltd. <philippe.robin@arm.com>
  18. *
  19. * See file CREDITS for list of people who contributed to this
  20. * project.
  21. *
  22. * This program is free software; you can redistribute it and/or
  23. * modify it under the terms of the GNU General Public License as
  24. * published by the Free Software Foundation; either version 2 of
  25. * the License, or (at your option) any later version.
  26. *
  27. * This program is distributed in the hope that it will be useful,
  28. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. * GNU General Public License for more details.
  31. *
  32. * You should have received a copy of the GNU General Public License
  33. * along with this program; if not, write to the Free Software
  34. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  35. * MA 02111-1307 USA
  36. */
  37. #include <common.h>
  38. #include <arm946es.h>
  39. #define TIMER_LOAD_VAL 0xffffffff
  40. extern void reset_cpu(ulong addr);
  41. #ifdef CONFIG_INTEGRATOR
  42. /* Timer functionality supplied by Integrator board (AP or CP) */
  43. #else
  44. static ulong timestamp;
  45. static ulong lastdec;
  46. /* nothing really to do with interrupts, just starts up a counter. */
  47. int interrupt_init (void)
  48. {
  49. /* init the timestamp and lastdec value */
  50. reset_timer_masked();
  51. return (0);
  52. }
  53. /*
  54. * timer without interrupts
  55. */
  56. void reset_timer (void)
  57. {
  58. reset_timer_masked ();
  59. }
  60. ulong get_timer (ulong base)
  61. {
  62. return get_timer_masked () - base;
  63. }
  64. void set_timer (ulong t)
  65. {
  66. timestamp = t;
  67. }
  68. /* delay x useconds AND perserve advance timstamp value */
  69. void udelay(unsigned long usec)
  70. {
  71. udelay_masked(usec);
  72. }
  73. void reset_timer_masked (void)
  74. {
  75. /* reset time */
  76. lastdec = READ_TIMER; /* capure current decrementer value time */
  77. timestamp = 0; /* start "advancing" time stamp from 0 */
  78. }
  79. ulong get_timer_raw (void)
  80. {
  81. ulong now = READ_TIMER; /* current tick value */
  82. if (lastdec >= now) { /* normal mode (non roll) */
  83. /* normal mode */
  84. timestamp += lastdec - now; /* move stamp fordward with absoulte diff ticks */
  85. } else { /* we have overflow of the count down timer */
  86. /* nts = ts + ld + (TLV - now)
  87. * ts=old stamp, ld=time that passed before passing through -1
  88. * (TLV-now) amount of time after passing though -1
  89. * nts = new "advancing time stamp"...it could also roll and cause problems.
  90. */
  91. timestamp += lastdec + TIMER_LOAD_VAL - now;
  92. }
  93. lastdec = now;
  94. return timestamp;
  95. }
  96. ulong get_timer_masked (void)
  97. {
  98. return get_timer_raw() / TIMER_LOAD_VAL;
  99. }
  100. /* waits specified delay value and resets timestamp */
  101. void udelay_masked (unsigned long usec)
  102. {
  103. ulong tmo;
  104. if(usec >= 1000){ /* if "big" number, spread normalization to seconds */
  105. tmo = usec / 1000; /* start to normalize for usec to ticks per sec */
  106. tmo *= CONFIG_SYS_HZ_CLOCK; /* find number of "ticks" to wait to achieve target */
  107. tmo /= 1000; /* finish normalize. */
  108. }else{ /* else small number, don't kill it prior to HZ multiply */
  109. tmo = usec * CONFIG_SYS_HZ_CLOCK;
  110. tmo /= (1000*1000);
  111. }
  112. reset_timer_masked (); /* set "advancing" timestamp to 0, set lastdec vaule */
  113. while (get_timer_raw () < tmo) /* wait for time stamp to overtake tick number.*/
  114. /*NOP*/;
  115. }
  116. /*
  117. * This function is derived from PowerPC code (read timebase as long long).
  118. * On ARM it just returns the timer value.
  119. */
  120. unsigned long long get_ticks(void)
  121. {
  122. return get_timer(0);
  123. }
  124. /*
  125. * This function is derived from PowerPC code (timebase clock frequency).
  126. * On ARM it returns the number of timer ticks per second.
  127. */
  128. ulong get_tbclk (void)
  129. {
  130. ulong tbclk;
  131. tbclk = CONFIG_SYS_HZ;
  132. return tbclk;
  133. }
  134. #endif /* CONFIG_INTEGRATOR */