xref: /openbmc/u-boot/cmd/misc.c (revision ee7bb5be)
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 #include <console.h>
14 
15 static int do_sleep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
16 {
17 	ulong start = get_timer(0);
18 	ulong delay;
19 
20 	if (argc != 2)
21 		return CMD_RET_USAGE;
22 
23 	delay = simple_strtoul(argv[1], NULL, 10) * CONFIG_SYS_HZ;
24 
25 	while (get_timer(start) < delay) {
26 		if (ctrlc())
27 			return (-1);
28 
29 		udelay(100);
30 	}
31 
32 	return 0;
33 }
34 
35 U_BOOT_CMD(
36 	sleep ,    2,    1,     do_sleep,
37 	"delay execution for some time",
38 	"N\n"
39 	"    - delay execution for N seconds (N is _decimal_ !!!)"
40 );
41 
42 #ifdef CONFIG_CMD_TIMER
43 static int do_timer(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
44 {
45 	static ulong start;
46 
47 	if (argc != 2)
48 		return CMD_RET_USAGE;
49 
50 	if (!strcmp(argv[1], "start"))
51 		start = get_timer(0);
52 
53 	if (!strcmp(argv[1], "get")) {
54 		ulong msecs = get_timer(start) * 1000 / CONFIG_SYS_HZ;
55 		printf("%ld.%03d\n", msecs / 1000, (int)(msecs % 1000));
56 	}
57 
58 	return 0;
59 }
60 
61 U_BOOT_CMD(
62 	timer,    2,    1,     do_timer,
63 	"access the system timer",
64 	"start - Reset the timer reference.\n"
65 	"timer get   - Print the time since 'start'."
66 );
67 #endif
68