misc.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * (C) Copyright 2001
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /*
  8. * Misc functions
  9. */
  10. #include <common.h>
  11. #include <command.h>
  12. #include <console.h>
  13. static int do_sleep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  14. {
  15. ulong start = get_timer(0);
  16. ulong delay;
  17. if (argc != 2)
  18. return CMD_RET_USAGE;
  19. delay = simple_strtoul(argv[1], NULL, 10) * CONFIG_SYS_HZ;
  20. while (get_timer(start) < delay) {
  21. if (ctrlc())
  22. return (-1);
  23. udelay(100);
  24. }
  25. return 0;
  26. }
  27. U_BOOT_CMD(
  28. sleep , 2, 1, do_sleep,
  29. "delay execution for some time",
  30. "N\n"
  31. " - delay execution for N seconds (N is _decimal_ !!!)"
  32. );
  33. #ifdef CONFIG_CMD_TIMER
  34. static int do_timer(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  35. {
  36. static ulong start;
  37. if (argc != 2)
  38. return CMD_RET_USAGE;
  39. if (!strcmp(argv[1], "start"))
  40. start = get_timer(0);
  41. if (!strcmp(argv[1], "get")) {
  42. ulong msecs = get_timer(start) * 1000 / CONFIG_SYS_HZ;
  43. printf("%ld.%03d\n", msecs / 1000, (int)(msecs % 1000));
  44. }
  45. return 0;
  46. }
  47. U_BOOT_CMD(
  48. timer, 2, 1, do_timer,
  49. "access the system timer",
  50. "start - Reset the timer reference.\n"
  51. "timer get - Print the time since 'start'."
  52. );
  53. #endif