b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Misc functions |
| 10 | */ |
| 11 | #include <common.h> |
| 12 | #include <command.h> |
| 13 | |
| 14 | static int do_sleep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 15 | { |
| 16 | ulong start = get_timer(0); |
| 17 | ulong delay; |
| 18 | |
| 19 | if (argc != 2) |
| 20 | return CMD_RET_USAGE; |
| 21 | |
| 22 | delay = simple_strtoul(argv[1], NULL, 10) * CONFIG_SYS_HZ; |
| 23 | |
| 24 | while (get_timer(start) < delay) { |
| 25 | if (ctrlc()) |
| 26 | return (-1); |
| 27 | |
| 28 | udelay(100); |
| 29 | } |
| 30 | |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | U_BOOT_CMD( |
| 35 | sleep , 2, 1, do_sleep, |
| 36 | "delay execution for some time", |
| 37 | "N\n" |
| 38 | " - delay execution for N seconds (N is _decimal_ !!!)" |
| 39 | ); |
| 40 | |
| 41 | #ifdef CONFIG_CMD_TIMER |
| 42 | static int do_timer(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 43 | { |
| 44 | static ulong start; |
| 45 | |
| 46 | if (argc != 2) |
| 47 | return CMD_RET_USAGE; |
| 48 | |
| 49 | if (!strcmp(argv[1], "start")) |
| 50 | start = get_timer(0); |
| 51 | |
| 52 | if (!strcmp(argv[1], "get")) { |
| 53 | ulong msecs = get_timer(start) * 1000 / CONFIG_SYS_HZ; |
| 54 | printf("%ld.%03d\n", msecs / 1000, (int)(msecs % 1000)); |
| 55 | } |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | U_BOOT_CMD( |
| 61 | timer, 2, 1, do_timer, |
| 62 | "access the system timer", |
| 63 | "start - Reset the timer reference.\n" |
| 64 | "timer get - Print the time since 'start'." |
| 65 | ); |
| 66 | #endif |