Skip to content

Commit 3c7bb89

Browse files
lbmengtrini
authored andcommitted
cmd: Split out timer command from the sleep command
CONFIG_CMD_TIMER merits a single file instead of co-exist in the sleep command file. Signed-off-by: Bin Meng <[email protected]>
1 parent 1606085 commit 3c7bb89

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

cmd/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ obj-$(CONFIG_CMD_SMC) += smccc.o
141141
obj-$(CONFIG_CMD_SYSBOOT) += sysboot.o pxe_utils.o
142142
obj-$(CONFIG_CMD_TERMINAL) += terminal.o
143143
obj-$(CONFIG_CMD_TIME) += time.o
144+
obj-$(CONFIG_CMD_TIMER) += timer.o
144145
obj-$(CONFIG_CMD_TRACE) += trace.o
145146
obj-$(CONFIG_HUSH_PARSER) += test.o
146147
obj-$(CONFIG_CMD_TPM) += tpm-common.o

cmd/sleep.c

-28
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,3 @@ U_BOOT_CMD(
5555
" - delay execution for N seconds (N is _decimal_ and can be\n"
5656
" fractional)"
5757
);
58-
59-
#ifdef CONFIG_CMD_TIMER
60-
static int do_timer(struct cmd_tbl *cmdtp, int flag, int argc,
61-
char *const argv[])
62-
{
63-
static ulong start;
64-
65-
if (argc != 2)
66-
return CMD_RET_USAGE;
67-
68-
if (!strcmp(argv[1], "start"))
69-
start = get_timer(0);
70-
71-
if (!strcmp(argv[1], "get")) {
72-
ulong msecs = get_timer(start) * 1000 / CONFIG_SYS_HZ;
73-
printf("%ld.%03d\n", msecs / 1000, (int)(msecs % 1000));
74-
}
75-
76-
return 0;
77-
}
78-
79-
U_BOOT_CMD(
80-
timer, 2, 1, do_timer,
81-
"access the system timer",
82-
"start - Reset the timer reference.\n"
83-
"timer get - Print the time since 'start'."
84-
);
85-
#endif

cmd/timer.c

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*
3+
* (C) Copyright 2001
4+
* Wolfgang Denk, DENX Software Engineering, [email protected].
5+
*/
6+
7+
#include <common.h>
8+
#include <command.h>
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+
);

0 commit comments

Comments
 (0)