ticks.S 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * (C) Copyright 2000, 2001
  3. * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com.
  4. * base on code by
  5. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <ppc_asm.tmpl>
  26. #include <ppc_defs.h>
  27. #include <config.h>
  28. #include <watchdog.h>
  29. /*
  30. * unsigned long long get_ticks(void);
  31. *
  32. * read timebase as "long long"
  33. */
  34. .globl get_ticks
  35. get_ticks:
  36. 1: mftbu r3
  37. mftb r4
  38. mftbu r5
  39. cmp 0,r3,r5
  40. bne 1b
  41. blr
  42. /*
  43. * Delay for a number of ticks
  44. */
  45. .globl wait_ticks
  46. wait_ticks:
  47. mflr r8 /* save link register */
  48. mr r7, r3 /* save tick count */
  49. bl get_ticks /* Get start time */
  50. /* Calculate end time */
  51. addc r7, r4, r7 /* Compute end time lower */
  52. addze r6, r3 /* and end time upper */
  53. WATCHDOG_RESET /* Trigger watchdog, if needed */
  54. 1: bl get_ticks /* Get current time */
  55. subfc r4, r4, r7 /* Subtract current time from end time */
  56. subfe. r3, r3, r6
  57. bge 1b /* Loop until time expired */
  58. mtlr r8 /* restore link register */
  59. blr