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 Denkd79de1d2013-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 Glassa73bda42015-11-08 23:47:45 -070013#include <console.h>
wdenk38635852002-08-27 05:55:31 +000014
Kim Phillipsdc00a682012-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 Roesef1d66992005-10-20 16:36:44 +020017 ulong start = get_timer(0);
wdenk38635852002-08-27 05:55:31 +000018 ulong delay;
19
Wolfgang Denk3b683112010-07-17 01:06:04 +020020 if (argc != 2)
Simon Glassa06dfc72011-12-10 08:44:01 +000021 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000022
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020023 delay = simple_strtoul(argv[1], NULL, 10) * CONFIG_SYS_HZ;
wdenk38635852002-08-27 05:55:31 +000024
Stefan Roesef1d66992005-10-20 16:36:44 +020025 while (get_timer(start) < delay) {
Kim Phillipsdc00a682012-10-29 13:34:31 +000026 if (ctrlc())
Stefan Roesef1d66992005-10-20 16:36:44 +020027 return (-1);
Wolfgang Denk3b683112010-07-17 01:06:04 +020028
Kim Phillipsdc00a682012-10-29 13:34:31 +000029 udelay(100);
wdenk38635852002-08-27 05:55:31 +000030 }
Stefan Roesef1d66992005-10-20 16:36:44 +020031
wdenk38635852002-08-27 05:55:31 +000032 return 0;
33}
Stefan Roesef1d66992005-10-20 16:36:44 +020034
wdenkf287a242003-07-01 21:06:45 +000035U_BOOT_CMD(
Detlev Zundel409a2852007-05-23 19:02:41 +020036 sleep , 2, 1, do_sleep,
Peter Tyserdfb72b82009-01-27 18:03:12 -060037 "delay execution for some time",
wdenk57b2d802003-06-27 21:31:46 +000038 "N\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +020039 " - delay execution for N seconds (N is _decimal_ !!!)"
wdenk57b2d802003-06-27 21:31:46 +000040);
Joe Hershberger59f3f522012-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