timer.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * (C) Copyright 2002
  3. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  4. * Marius Groeger <mgroeger@sysgo.de>
  5. *
  6. * (C) Copyright 2002
  7. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  8. * Alex Zuepke <azu@sysgo.de>
  9. *
  10. * SPDX-License-Identifier: GPL-2.0+
  11. */
  12. #include <common.h>
  13. #include <SA-1100.h>
  14. ulong get_timer (ulong base)
  15. {
  16. return get_timer_masked ();
  17. }
  18. void __udelay (unsigned long usec)
  19. {
  20. udelay_masked (usec);
  21. }
  22. ulong get_timer_masked (void)
  23. {
  24. return OSCR;
  25. }
  26. void udelay_masked (unsigned long usec)
  27. {
  28. ulong tmo;
  29. ulong endtime;
  30. signed long diff;
  31. if (usec >= 1000) {
  32. tmo = usec / 1000;
  33. tmo *= CONFIG_SYS_HZ;
  34. tmo /= 1000;
  35. } else {
  36. tmo = usec * CONFIG_SYS_HZ;
  37. tmo /= (1000*1000);
  38. }
  39. endtime = get_timer_masked () + tmo;
  40. do {
  41. ulong now = get_timer_masked ();
  42. diff = endtime - now;
  43. } while (diff >= 0);
  44. }
  45. /*
  46. * This function is derived from PowerPC code (read timebase as long long).
  47. * On ARM it just returns the timer value.
  48. */
  49. unsigned long long get_ticks(void)
  50. {
  51. return get_timer(0);
  52. }
  53. /*
  54. * This function is derived from PowerPC code (timebase clock frequency).
  55. * On ARM it returns the number of timer ticks per second.
  56. */
  57. ulong get_tbclk (void)
  58. {
  59. return CONFIG_SYS_HZ;
  60. }