interrupts.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * U-boot - interrupts.c Interrupt related routines
  3. *
  4. * Copyright (c) 2005-2008 Analog Devices Inc.
  5. *
  6. * This file is based on interrupts.c
  7. * Copyright 1996 Roman Zippel
  8. * Copyright 1999 D. Jeff Dionne <jeff@uclinux.org>
  9. * Copyright 2000-2001 Lineo, Inc. D. Jefff Dionne <jeff@lineo.ca>
  10. * Copyright 2002 Arcturus Networks Inc. MaTed <mated@sympatico.ca>
  11. * Copyright 2003 Metrowerks/Motorola
  12. * Copyright 2003 Bas Vermeulen <bas@buyways.nl>,
  13. * BuyWays B.V. (www.buyways.nl)
  14. *
  15. * (C) Copyright 2000-2004
  16. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  17. *
  18. * Licensed under the GPL-2 or later.
  19. */
  20. #include <common.h>
  21. #include <config.h>
  22. #include <asm/blackfin.h>
  23. #include "cpu.h"
  24. static ulong timestamp;
  25. static ulong last_time;
  26. static int int_flag;
  27. int irq_flags; /* needed by asm-blackfin/system.h */
  28. /* Functions just to satisfy the linker */
  29. /*
  30. * This function is derived from PowerPC code (read timebase as long long).
  31. * On Blackfin it just returns the timer value.
  32. */
  33. unsigned long long get_ticks(void)
  34. {
  35. return get_timer(0);
  36. }
  37. /*
  38. * This function is derived from PowerPC code (timebase clock frequency).
  39. * On Blackfin it returns the number of timer ticks per second.
  40. */
  41. ulong get_tbclk(void)
  42. {
  43. ulong tbclk;
  44. tbclk = CFG_HZ;
  45. return tbclk;
  46. }
  47. void enable_interrupts(void)
  48. {
  49. local_irq_restore(int_flag);
  50. }
  51. int disable_interrupts(void)
  52. {
  53. local_irq_save(int_flag);
  54. return 1;
  55. }
  56. void udelay(unsigned long usec)
  57. {
  58. unsigned long delay, start, stop;
  59. unsigned long cclk;
  60. cclk = (CONFIG_CCLK_HZ);
  61. while (usec > 1) {
  62. /*
  63. * how many clock ticks to delay?
  64. * - request(in useconds) * clock_ticks(Hz) / useconds/second
  65. */
  66. if (usec < 1000) {
  67. delay = (usec * (cclk / 244)) >> 12;
  68. usec = 0;
  69. } else {
  70. delay = (1000 * (cclk / 244)) >> 12;
  71. usec -= 1000;
  72. }
  73. asm volatile (" %0 = CYCLES;" : "=r" (start));
  74. do {
  75. asm volatile (" %0 = CYCLES; " : "=r" (stop));
  76. } while (stop - start < delay);
  77. }
  78. return;
  79. }
  80. #define MAX_TIM_LOAD 0xFFFFFFFF
  81. int timer_init(void)
  82. {
  83. *pTCNTL = 0x1;
  84. *pTSCALE = 0x0;
  85. *pTCOUNT = MAX_TIM_LOAD;
  86. *pTPERIOD = MAX_TIM_LOAD;
  87. *pTCNTL = 0x7;
  88. asm("CSYNC;");
  89. timestamp = 0;
  90. last_time = 0;
  91. return 0;
  92. }
  93. /*
  94. * Any network command or flash
  95. * command is started get_timer shall
  96. * be called before TCOUNT gets reset,
  97. * to implement the accurate timeouts.
  98. *
  99. * How ever milliconds doesn't return
  100. * the number that has been elapsed from
  101. * the last reset.
  102. *
  103. * As get_timer is used in the u-boot
  104. * only for timeouts this should be
  105. * sufficient
  106. */
  107. ulong get_timer(ulong base)
  108. {
  109. ulong milisec;
  110. /* Number of clocks elapsed */
  111. ulong clocks = (MAX_TIM_LOAD - (*pTCOUNT));
  112. /*
  113. * Find if the TCOUNT is reset
  114. * timestamp gives the number of times
  115. * TCOUNT got reset
  116. */
  117. if (clocks < last_time)
  118. timestamp++;
  119. last_time = clocks;
  120. /* Get the number of milliseconds */
  121. milisec = clocks / (CONFIG_CCLK_HZ / 1000);
  122. /*
  123. * Find the number of millisonds that
  124. * got elapsed before this TCOUNT cycle
  125. */
  126. milisec += timestamp * (MAX_TIM_LOAD / (CONFIG_CCLK_HZ / 1000));
  127. return (milisec - base);
  128. }
  129. void reset_timer(void)
  130. {
  131. timestamp = 0;
  132. }