timer.c 707 B

12345678910111213141516171819202122232425262728293031323334
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2001
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. static int do_timer(struct cmd_tbl *cmdtp, int flag, int argc,
  9. char *const argv[])
  10. {
  11. static ulong start;
  12. if (argc != 2)
  13. return CMD_RET_USAGE;
  14. if (!strcmp(argv[1], "start"))
  15. start = get_timer(0);
  16. if (!strcmp(argv[1], "get")) {
  17. ulong msecs = get_timer(start) * 1000 / CONFIG_SYS_HZ;
  18. printf("%ld.%03d\n", msecs / 1000, (int)(msecs % 1000));
  19. }
  20. return 0;
  21. }
  22. U_BOOT_CMD(
  23. timer, 2, 1, do_timer,
  24. "access the system timer",
  25. "start - Reset the timer reference.\n"
  26. "timer get - Print the time since 'start'."
  27. );