timer.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* vi: set ts=8 sw=8 noet: */
  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. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #include <common.h>
  30. #include <asm/arch/ixp425.h>
  31. ulong get_timer (ulong base)
  32. {
  33. return get_timer_masked () - base;
  34. }
  35. void ixp425_udelay(unsigned long usec)
  36. {
  37. /*
  38. * This function has a max usec, but since it is called from udelay
  39. * we should not have to worry... be happy
  40. */
  41. unsigned long usecs = CFG_HZ/1000000L & ~IXP425_OST_RELOAD_MASK;
  42. *IXP425_OSST = IXP425_OSST_TIMER_1_PEND;
  43. usecs |= IXP425_OST_ONE_SHOT | IXP425_OST_ENABLE;
  44. *IXP425_OSRT1 = usecs;
  45. while (!(*IXP425_OSST & IXP425_OSST_TIMER_1_PEND));
  46. }
  47. void udelay (unsigned long usec)
  48. {
  49. while (usec--) ixp425_udelay(1);
  50. }
  51. static ulong reload_constant = 0xfffffff0;
  52. void reset_timer_masked (void)
  53. {
  54. ulong reload = reload_constant | IXP425_OST_ONE_SHOT | IXP425_OST_ENABLE;
  55. *IXP425_OSST = IXP425_OSST_TIMER_1_PEND;
  56. *IXP425_OSRT1 = reload;
  57. }
  58. ulong get_timer_masked (void)
  59. {
  60. /*
  61. * Note that it is possible for this to wrap!
  62. * In this case we return max.
  63. */
  64. ulong current = *IXP425_OST1;
  65. if (*IXP425_OSST & IXP425_OSST_TIMER_1_PEND)
  66. {
  67. return reload_constant;
  68. }
  69. return (reload_constant - current);
  70. }