watchdog.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * (C) Copyright 2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. /*
  9. * Watchdog test
  10. *
  11. * The test verifies the watchdog timer operation.
  12. * On the first iteration, the test routine disables interrupts and
  13. * makes a 10-second delay. If the system does not reboot during this delay,
  14. * the watchdog timer is not operational and the test fails. If the system
  15. * reboots, on the second iteration the test routine reports a success.
  16. */
  17. #include <post.h>
  18. #include <watchdog.h>
  19. #if CONFIG_POST & CONFIG_SYS_POST_WATCHDOG
  20. static ulong gettbl (void)
  21. {
  22. ulong r;
  23. asm ("mftbl %0":"=r" (r));
  24. return r;
  25. }
  26. int watchdog_post_test (int flags)
  27. {
  28. if (flags & POST_REBOOT) {
  29. /* Test passed */
  30. return 0;
  31. } else {
  32. /* 10-second delay */
  33. int ints = disable_interrupts ();
  34. ulong base = gettbl ();
  35. ulong clk = get_tbclk ();
  36. while ((gettbl () - base) / 10 < clk);
  37. if (ints)
  38. enable_interrupts ();
  39. /*
  40. * If we have reached this point, the watchdog timer
  41. * does not work
  42. */
  43. return -1;
  44. }
  45. }
  46. #endif /* CONFIG_POST & CONFIG_SYS_POST_WATCHDOG */