cmd_misc.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. static int do_sleep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  13. {
  14. ulong start = get_timer(0);
  15. ulong delay;
  16. if (argc != 2)
  17. return CMD_RET_USAGE;
  18. delay = simple_strtoul(argv[1], NULL, 10) * CONFIG_SYS_HZ;
  19. while (get_timer(start) < delay) {
  20. if (ctrlc())
  21. return (-1);
  22. udelay(100);
  23. }
  24. return 0;
  25. }
  26. U_BOOT_CMD(
  27. sleep , 2, 1, do_sleep,
  28. "delay execution for some time",
  29. "N\n"
  30. " - delay execution for N seconds (N is _decimal_ !!!)"
  31. );
  32. #ifdef CONFIG_CMD_TIMER
  33. static int do_timer(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  34. {
  35. static ulong start;
  36. if (argc != 2)
  37. return CMD_RET_USAGE;
  38. if (!strcmp(argv[1], "start"))
  39. start = get_timer(0);
  40. if (!strcmp(argv[1], "get")) {
  41. ulong msecs = get_timer(start) * 1000 / CONFIG_SYS_HZ;
  42. printf("%ld.%03d\n", msecs / 1000, (int)(msecs % 1000));
  43. }
  44. return 0;
  45. }
  46. U_BOOT_CMD(
  47. timer, 2, 1, do_timer,
  48. "access the system timer",
  49. "start - Reset the timer reference.\n"
  50. "timer get - Print the time since 'start'."
  51. );
  52. #endif