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