blob: 39d86835cff76122cc5940f521e5e4e6f2c2b11d [file] [log] [blame]
wdenk38635852002-08-27 05:55:31 +00001/*
2 * (C) Copyright 2001
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk38635852002-08-27 05:55:31 +00006 */
7
8/*
9 * Misc functions
10 */
11#include <common.h>
12#include <command.h>
Simon Glass24b852a2015-11-08 23:47:45 -070013#include <console.h>
wdenk38635852002-08-27 05:55:31 +000014
Kim Phillips088f1b12012-10-29 13:34:31 +000015static int do_sleep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000016{
Stefan Roesec4c13df2005-10-20 16:36:44 +020017 ulong start = get_timer(0);
wdenk38635852002-08-27 05:55:31 +000018 ulong delay;
19
Wolfgang Denk47e26b12010-07-17 01:06:04 +020020 if (argc != 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +000021 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000022
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020023 delay = simple_strtoul(argv[1], NULL, 10) * CONFIG_SYS_HZ;
wdenk38635852002-08-27 05:55:31 +000024
Stefan Roesec4c13df2005-10-20 16:36:44 +020025 while (get_timer(start) < delay) {
Kim Phillips088f1b12012-10-29 13:34:31 +000026 if (ctrlc())
Stefan Roesec4c13df2005-10-20 16:36:44 +020027 return (-1);
Wolfgang Denk47e26b12010-07-17 01:06:04 +020028
Kim Phillips088f1b12012-10-29 13:34:31 +000029 udelay(100);
wdenk38635852002-08-27 05:55:31 +000030 }
Stefan Roesec4c13df2005-10-20 16:36:44 +020031
wdenk38635852002-08-27 05:55:31 +000032 return 0;
33}
Stefan Roesec4c13df2005-10-20 16:36:44 +020034
wdenk0d498392003-07-01 21:06:45 +000035U_BOOT_CMD(
Detlev Zundel99121212007-05-23 19:02:41 +020036 sleep , 2, 1, do_sleep,
Peter Tyser2fb26042009-01-27 18:03:12 -060037 "delay execution for some time",
wdenk8bde7f72003-06-27 21:31:46 +000038 "N\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +020039 " - delay execution for N seconds (N is _decimal_ !!!)"
wdenk8bde7f72003-06-27 21:31:46 +000040);
Joe Hershbergerda83bcd2012-10-03 12:14:57 +000041
42#ifdef CONFIG_CMD_TIMER
43static 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
61U_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