Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2001 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 7 | #include <common.h> |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 8 | #include <command.h> |
Simon Glass | a73bda4 | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 9 | #include <console.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 10 | #include <linux/delay.h> |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 11 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 12 | static int do_sleep(struct cmd_tbl *cmdtp, int flag, int argc, |
| 13 | char *const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 14 | { |
Stefan Roese | f1d6699 | 2005-10-20 16:36:44 +0200 | [diff] [blame] | 15 | ulong start = get_timer(0); |
mario.six@gdsys.cc | ae2eba6 | 2016-07-19 16:20:13 +0200 | [diff] [blame] | 16 | ulong mdelay = 0; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 17 | ulong delay; |
mario.six@gdsys.cc | ae2eba6 | 2016-07-19 16:20:13 +0200 | [diff] [blame] | 18 | char *frpart; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 19 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 20 | if (argc != 2) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 21 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 22 | |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 23 | delay = dectoul(argv[1], NULL) * CONFIG_SYS_HZ; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 24 | |
mario.six@gdsys.cc | ae2eba6 | 2016-07-19 16:20:13 +0200 | [diff] [blame] | 25 | 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 Roese | f1d6699 | 2005-10-20 16:36:44 +0200 | [diff] [blame] | 41 | while (get_timer(start) < delay) { |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 42 | if (ctrlc()) |
Marek Szyprowski | 196e0dc | 2021-01-22 12:27:31 +0100 | [diff] [blame] | 43 | return CMD_RET_FAILURE; |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 44 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 45 | udelay(100); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 46 | } |
Stefan Roese | f1d6699 | 2005-10-20 16:36:44 +0200 | [diff] [blame] | 47 | |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 48 | return 0; |
| 49 | } |
Stefan Roese | f1d6699 | 2005-10-20 16:36:44 +0200 | [diff] [blame] | 50 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 51 | U_BOOT_CMD( |
Detlev Zundel | 409a285 | 2007-05-23 19:02:41 +0200 | [diff] [blame] | 52 | sleep , 2, 1, do_sleep, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 53 | "delay execution for some time", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 54 | "N\n" |
mario.six@gdsys.cc | ae2eba6 | 2016-07-19 16:20:13 +0200 | [diff] [blame] | 55 | " - delay execution for N seconds (N is _decimal_ and can be\n" |
| 56 | " fractional)" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 57 | ); |