gettime.c 935 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
  4. *
  5. * Copyright (c) 2009, Code Aurora Forum. All rights reserved.
  6. *
  7. * (C) Copyright 2001
  8. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  9. */
  10. /*
  11. * Get Timer overflows after 2^32 / CONFIG_SYS_HZ (32Khz) = 131072 sec
  12. */
  13. #include <common.h>
  14. #include <command.h>
  15. static int do_gettime(struct cmd_tbl *cmdtp, int flag, int argc,
  16. char *const argv[])
  17. {
  18. unsigned long int val = get_timer(0);
  19. #ifdef CONFIG_SYS_HZ
  20. printf("Timer val: %lu\n", val);
  21. printf("Seconds : %lu\n", val / CONFIG_SYS_HZ);
  22. printf("Remainder : %lu\n", val % CONFIG_SYS_HZ);
  23. printf("sys_hz = %lu\n", (unsigned long int)CONFIG_SYS_HZ);
  24. #else
  25. printf("CONFIG_SYS_HZ not defined");
  26. printf("Timer Val %lu", val);
  27. #endif
  28. return 0;
  29. }
  30. U_BOOT_CMD(
  31. gettime, 1, 1, do_gettime,
  32. "get timer val elapsed",
  33. "get time elapsed from uboot start"
  34. );