timer.c 1.2 KB

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