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