2002-08-27 05:55:31 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2001
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2002-08-27 05:55:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Misc functions
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
2015-11-09 06:47:45 +00:00
|
|
|
#include <console.h>
|
2002-08-27 05:55:31 +00:00
|
|
|
|
2012-10-29 13:34:31 +00:00
|
|
|
static int do_sleep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
2002-08-27 05:55:31 +00:00
|
|
|
{
|
2005-10-20 14:36:44 +00:00
|
|
|
ulong start = get_timer(0);
|
2016-07-19 14:20:13 +00:00
|
|
|
ulong mdelay = 0;
|
2002-08-27 05:55:31 +00:00
|
|
|
ulong delay;
|
2016-07-19 14:20:13 +00:00
|
|
|
char *frpart;
|
2002-08-27 05:55:31 +00:00
|
|
|
|
2010-07-16 23:06:04 +00:00
|
|
|
if (argc != 2)
|
2011-12-10 08:44:01 +00:00
|
|
|
return CMD_RET_USAGE;
|
2002-08-27 05:55:31 +00:00
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
delay = simple_strtoul(argv[1], NULL, 10) * CONFIG_SYS_HZ;
|
2002-08-27 05:55:31 +00:00
|
|
|
|
2016-07-19 14:20:13 +00:00
|
|
|
frpart = strchr(argv[1], '.');
|
|
|
|
|
|
|
|
if (frpart) {
|
|
|
|
uint mult = CONFIG_SYS_HZ / 10;
|
|
|
|
for (frpart++; *frpart != '\0' && mult > 0; frpart++) {
|
|
|
|
if (*frpart < '0' || *frpart > '9') {
|
|
|
|
mdelay = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mdelay += (*frpart - '0') * mult;
|
|
|
|
mult /= 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delay += mdelay;
|
|
|
|
|
2005-10-20 14:36:44 +00:00
|
|
|
while (get_timer(start) < delay) {
|
2012-10-29 13:34:31 +00:00
|
|
|
if (ctrlc())
|
2005-10-20 14:36:44 +00:00
|
|
|
return (-1);
|
2010-07-16 23:06:04 +00:00
|
|
|
|
2012-10-29 13:34:31 +00:00
|
|
|
udelay(100);
|
2002-08-27 05:55:31 +00:00
|
|
|
}
|
2005-10-20 14:36:44 +00:00
|
|
|
|
2002-08-27 05:55:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-10-20 14:36:44 +00:00
|
|
|
|
2003-07-01 21:06:45 +00:00
|
|
|
U_BOOT_CMD(
|
2007-05-23 17:02:41 +00:00
|
|
|
sleep , 2, 1, do_sleep,
|
2009-01-28 00:03:12 +00:00
|
|
|
"delay execution for some time",
|
2003-06-27 21:31:46 +00:00
|
|
|
"N\n"
|
2016-07-19 14:20:13 +00:00
|
|
|
" - delay execution for N seconds (N is _decimal_ and can be\n"
|
|
|
|
" fractional)"
|
2003-06-27 21:31:46 +00:00
|
|
|
);
|
2012-10-03 12:14:57 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_CMD_TIMER
|
|
|
|
static int do_timer(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
|
|
|
{
|
|
|
|
static ulong start;
|
|
|
|
|
|
|
|
if (argc != 2)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
if (!strcmp(argv[1], "start"))
|
|
|
|
start = get_timer(0);
|
|
|
|
|
|
|
|
if (!strcmp(argv[1], "get")) {
|
|
|
|
ulong msecs = get_timer(start) * 1000 / CONFIG_SYS_HZ;
|
|
|
|
printf("%ld.%03d\n", msecs / 1000, (int)(msecs % 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
timer, 2, 1, do_timer,
|
|
|
|
"access the system timer",
|
|
|
|
"start - Reset the timer reference.\n"
|
|
|
|
"timer get - Print the time since 'start'."
|
|
|
|
);
|
|
|
|
#endif
|