gettime.c 934 B

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