Bin Meng | 9ad0417 | 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 | 9ad0417 | 2020-10-13 18:45:06 +0800 | [diff] [blame] | 7 | #include <command.h> |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 8 | #include <time.h> |
Tom Rini | ee8ed54 | 2025-05-14 16:46:00 -0600 | [diff] [blame^] | 9 | #include <linux/string.h> |
Bin Meng | 9ad0417 | 2020-10-13 18:45:06 +0800 | [diff] [blame] | 10 | |
| 11 | static int do_timer(struct cmd_tbl *cmdtp, int flag, int argc, |
| 12 | char *const argv[]) |
| 13 | { |
| 14 | static ulong start; |
| 15 | |
| 16 | if (argc != 2) |
| 17 | return CMD_RET_USAGE; |
| 18 | |
| 19 | if (!strcmp(argv[1], "start")) |
| 20 | start = get_timer(0); |
| 21 | |
| 22 | if (!strcmp(argv[1], "get")) { |
| 23 | ulong msecs = get_timer(start) * 1000 / CONFIG_SYS_HZ; |
| 24 | printf("%ld.%03d\n", msecs / 1000, (int)(msecs % 1000)); |
| 25 | } |
| 26 | |
| 27 | return 0; |
| 28 | } |
| 29 | |
| 30 | U_BOOT_CMD( |
| 31 | timer, 2, 1, do_timer, |
| 32 | "access the system timer", |
| 33 | "start - Reset the timer reference.\n" |
| 34 | "timer get - Print the time since 'start'." |
| 35 | ); |