From: Jason McMullan Date: Tue, 20 May 2008 09:57:26 -0400 Subject: [U-Boot-Users] [PATCH] Make sleep shell command is reliable for all architectures Message-ID: <20080520140054.9565865407@mcmullan-linux.hq.netapp.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On some architectures (MIPS is a good example), the timebase rolls over every few seconds. This patch alters the 'sleep' shell command to use a total counter of the udelay(100) sleeps instead of an end time marker to determine the end of the sleep, making the 'sleep' command capable of sleeping for any number of seconds on all architectures. Signed-off-by: Jason McMullan --- common/cmd_misc.c | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-) diff --git a/common/cmd_misc.c b/common/cmd_misc.c index 126b538..2b84896 100644 --- a/common/cmd_misc.c +++ b/common/cmd_misc.c @@ -29,7 +29,6 @@ int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { - ulong start = get_timer(0); ulong delay; if (argc != 2) { @@ -37,13 +36,18 @@ int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 1; } - delay = simple_strtoul(argv[1], NULL, 10) * CFG_HZ; + /* Sleep in 100ms increments, as some the time base of + * some architectures can roll over after only a few + * seconds (MIPS is a good example of this) + */ + delay = simple_strtoul(argv[1], NULL, 10) * 10; - while (get_timer(start) < delay) { + while (delay > 0) { if (ctrlc ()) { return (-1); } udelay (100); + delay--; } return 0; -- 1.5.4.3