time.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 2007
  3. * Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <asm/processer.h>
  25. static void tmu_timer_start (unsigned int timer)
  26. {
  27. if (timer > 2)
  28. return;
  29. *((volatile unsigned char *) TSTR0) |= (1 << timer);
  30. }
  31. int timer_init (void)
  32. {
  33. *(volatile u16 *)TCR0 = 0;
  34. tmu_timer_start (0);
  35. return 0;
  36. }
  37. unsigned long long get_ticks (void)
  38. {
  39. return (0 - *((volatile unsigned int *) TCNT0));
  40. }
  41. unsigned long get_timer (unsigned long base)
  42. {
  43. return ((0 - *((volatile unsigned int *) TCNT0)) - base);
  44. }
  45. void set_timer (unsigned long t)
  46. {
  47. *((volatile unsigned int *) TCNT0) = (0 - t);
  48. }
  49. void reset_timer (void)
  50. {
  51. set_timer (0);
  52. }
  53. void udelay (unsigned long usec)
  54. {
  55. unsigned int start = get_timer (0);
  56. unsigned int end = start + (usec * ((CFG_HZ + 500000) / 1000000));
  57. while (get_timer (0) < end)
  58. continue;
  59. }
  60. unsigned long get_tbclk (void)
  61. {
  62. return CFG_HZ;
  63. }