blob: c741b4aa029bdbf38da667467213c41c0bc87a72 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk38635852002-08-27 05:55:31 +00002/*
3 * (C) Copyright 2001
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk38635852002-08-27 05:55:31 +00005 */
6
wdenk38635852002-08-27 05:55:31 +00007#include <common.h>
8#include <command.h>
Simon Glass24b852a2015-11-08 23:47:45 -07009#include <console.h>
Simon Glassc05ed002020-05-10 11:40:11 -060010#include <linux/delay.h>
wdenk38635852002-08-27 05:55:31 +000011
Simon Glass09140112020-05-10 11:40:03 -060012static int do_sleep(struct cmd_tbl *cmdtp, int flag, int argc,
13 char *const argv[])
wdenk38635852002-08-27 05:55:31 +000014{
Stefan Roesec4c13df2005-10-20 16:36:44 +020015 ulong start = get_timer(0);
mario.six@gdsys.ccc4974632016-07-19 16:20:13 +020016 ulong mdelay = 0;
wdenk38635852002-08-27 05:55:31 +000017 ulong delay;
mario.six@gdsys.ccc4974632016-07-19 16:20:13 +020018 char *frpart;
wdenk38635852002-08-27 05:55:31 +000019
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
Simon Glass0b1284e2021-07-24 09:03:30 -060023 delay = dectoul(argv[1], NULL) * CONFIG_SYS_HZ;
wdenk38635852002-08-27 05:55:31 +000024
mario.six@gdsys.ccc4974632016-07-19 16:20:13 +020025 frpart = strchr(argv[1], '.');
26
27 if (frpart) {
28 uint mult = CONFIG_SYS_HZ / 10;
29 for (frpart++; *frpart != '\0' && mult > 0; frpart++) {
30 if (*frpart < '0' || *frpart > '9') {
31 mdelay = 0;
32 break;
33 }
34 mdelay += (*frpart - '0') * mult;
35 mult /= 10;
36 }
37 }
38
39 delay += mdelay;
40
Stefan Roesec4c13df2005-10-20 16:36:44 +020041 while (get_timer(start) < delay) {
Kim Phillips088f1b12012-10-29 13:34:31 +000042 if (ctrlc())
Marek Szyprowski54f884b2021-01-22 12:27:31 +010043 return CMD_RET_FAILURE;
Wolfgang Denk47e26b12010-07-17 01:06:04 +020044
Kim Phillips088f1b12012-10-29 13:34:31 +000045 udelay(100);
wdenk38635852002-08-27 05:55:31 +000046 }
Stefan Roesec4c13df2005-10-20 16:36:44 +020047
wdenk38635852002-08-27 05:55:31 +000048 return 0;
49}
Stefan Roesec4c13df2005-10-20 16:36:44 +020050
wdenk0d498392003-07-01 21:06:45 +000051U_BOOT_CMD(
Detlev Zundel99121212007-05-23 19:02:41 +020052 sleep , 2, 1, do_sleep,
Peter Tyser2fb26042009-01-27 18:03:12 -060053 "delay execution for some time",
wdenk8bde7f72003-06-27 21:31:46 +000054 "N\n"
mario.six@gdsys.ccc4974632016-07-19 16:20:13 +020055 " - delay execution for N seconds (N is _decimal_ and can be\n"
56 " fractional)"
wdenk8bde7f72003-06-27 21:31:46 +000057);