2018-05-07 05:58:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2002-08-27 13:55:31 +08:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2001
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Misc functions
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
2015-11-09 14:47:45 +08:00
|
|
|
#include <console.h>
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2012-10-29 21:34:31 +08:00
|
|
|
static int do_sleep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
2002-08-27 13:55:31 +08:00
|
|
|
{
|
2005-10-20 22:36:44 +08:00
|
|
|
ulong start = get_timer(0);
|
2016-07-19 22:20:13 +08:00
|
|
|
ulong mdelay = 0;
|
2002-08-27 13:55:31 +08:00
|
|
|
ulong delay;
|
2016-07-19 22:20:13 +08:00
|
|
|
char *frpart;
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2010-07-17 07:06:04 +08:00
|
|
|
if (argc != 2)
|
2011-12-10 16:44:01 +08:00
|
|
|
return CMD_RET_USAGE;
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2008-10-16 21:01:15 +08:00
|
|
|
delay = simple_strtoul(argv[1], NULL, 10) * CONFIG_SYS_HZ;
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2016-07-19 22:20:13 +08: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 22:36:44 +08:00
|
|
|
while (get_timer(start) < delay) {
|
2012-10-29 21:34:31 +08:00
|
|
|
if (ctrlc())
|
2005-10-20 22:36:44 +08:00
|
|
|
return (-1);
|
2010-07-17 07:06:04 +08:00
|
|
|
|
2012-10-29 21:34:31 +08:00
|
|
|
udelay(100);
|
2002-08-27 13:55:31 +08:00
|
|
|
}
|
2005-10-20 22:36:44 +08:00
|
|
|
|
2002-08-27 13:55:31 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2005-10-20 22:36:44 +08:00
|
|
|
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
2007-05-24 01:02:41 +08:00
|
|
|
sleep , 2, 1, do_sleep,
|
2009-01-28 08:03:12 +08:00
|
|
|
"delay execution for some time",
|
2003-06-28 05:31:46 +08:00
|
|
|
"N\n"
|
2016-07-19 22:20:13 +08:00
|
|
|
" - delay execution for N seconds (N is _decimal_ and can be\n"
|
|
|
|
" fractional)"
|
2003-06-28 05:31:46 +08:00
|
|
|
);
|
2012-10-03 20:14:57 +08: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
|