From patchwork Mon Nov 28 21:40:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Weisser X-Patchwork-Id: 128080 X-Patchwork-Delegate: vapier@gentoo.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id D2CC41007D1 for ; Tue, 29 Nov 2011 08:40:39 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id ECEBE28167; Mon, 28 Nov 2011 22:40:37 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sncQxXaBdWIN; Mon, 28 Nov 2011 22:40:37 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AE90228180; Mon, 28 Nov 2011 22:40:35 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A8DA428180 for ; Mon, 28 Nov 2011 22:40:34 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QSrNnx4dxO-k for ; Mon, 28 Nov 2011 22:40:34 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-in-10.arcor-online.net (mail-in-10.arcor-online.net [151.189.21.50]) by theia.denx.de (Postfix) with ESMTPS id 0BB7B28167 for ; Mon, 28 Nov 2011 22:40:32 +0100 (CET) Received: from mail-in-07-z2.arcor-online.net (mail-in-07-z2.arcor-online.net [151.189.8.19]) by mx.arcor.de (Postfix) with ESMTP id 3DE492D671C; Mon, 28 Nov 2011 22:40:31 +0100 (CET) Received: from mail-in-17.arcor-online.net (mail-in-17.arcor-online.net [151.189.21.57]) by mail-in-07-z2.arcor-online.net (Postfix) with ESMTP id 395CEE1987; Mon, 28 Nov 2011 22:40:31 +0100 (CET) Received: from mat-frame.fritz.box (HSI-KBW-078-042-175-106.hsi3.kabel-badenwuerttemberg.de [78.42.175.106]) (Authenticated sender: weisserm@arcor.de) by mail-in-17.arcor-online.net (Postfix) with ESMTPA id 08669CBF7C; Mon, 28 Nov 2011 22:40:30 +0100 (CET) X-DKIM: Sendmail DKIM Filter v2.8.2 mail-in-17.arcor-online.net 08669CBF7C DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arcor.de; s=mail-in; t=1322516431; bh=CLXvptKTVX4y4KEhLKh+vtw2YZ0/WgTIiZ0sLGU/fsk=; h=From:To:Cc:Subject:Date:Message-Id; b=dtzFVnYvc4aaqDDAMkweX+FYagibvYVj8wvYLKJ0mXp9uLF7T4dvvPfxytF0FJQCJ dCVoK2msQE0zNx+oHt/RPrJmK7O/yWIEz80OctCxfij+lncgW+cGILdIlrO9X5Q8Er 7WcAFa9EKQ3D9SwaFFlwheTcLLI9oODK5FZCx8uQ= From: Matthias Weisser To: u-boot@lists.denx.de Date: Mon, 28 Nov 2011 22:40:29 +0100 Message-Id: <1322516429-8471-1-git-send-email-weisserm@arcor.de> X-Mailer: git-send-email 1.7.5.4 Subject: [U-Boot] [PATCH] sandbox: Add timer simulation X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Making sleep command work Signed-off-by: Matthias Weisser --- arch/sandbox/config.mk | 1 + arch/sandbox/cpu/cpu.c | 2 +- arch/sandbox/cpu/os.c | 15 +++++++++++++++ board/sandbox/sandbox/sandbox.c | 4 +++- include/os.h | 14 ++++++++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk index ab33026..2ec1bb7 100644 --- a/arch/sandbox/config.mk +++ b/arch/sandbox/config.mk @@ -18,3 +18,4 @@ # MA 02111-1307 USA PLATFORM_CPPFLAGS += -DCONFIG_SANDBOX -D__SANDBOX__ +PLATFORM_LIBS += -lrt diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c index c7bf8a9..a15d3c2 100644 --- a/arch/sandbox/cpu/cpu.c +++ b/arch/sandbox/cpu/cpu.c @@ -34,7 +34,7 @@ int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) /* delay x useconds */ void __udelay(unsigned long usec) { - /* Ignore this for now */ + os_usleep(usec); } unsigned long timer_get_us(void) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index b7c3bf5..d3357db 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -94,3 +95,17 @@ void *os_malloc(size_t length) return mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); } + +void os_usleep(unsigned long usec) +{ + usleep(usec); +} + +u64 os_get_nsec(void) +{ + struct timespec tp; + + clock_gettime(CLOCK_MONOTONIC, &tp); + + return tp.tv_sec * 1000000000ULL + tp.tv_nsec; +} diff --git a/board/sandbox/sandbox/sandbox.c b/board/sandbox/sandbox/sandbox.c index 95a5045..f376c74 100644 --- a/board/sandbox/sandbox/sandbox.c +++ b/board/sandbox/sandbox/sandbox.c @@ -21,6 +21,8 @@ #include +#include + /* * Pointer to initial global data area * @@ -34,7 +36,7 @@ void flush_cache(unsigned long start, unsigned long size) ulong get_timer(ulong base) { - return 0; + return (os_get_nsec() / 1000000) - base; } int timer_init(void) diff --git a/include/os.h b/include/os.h index fd4120c..f3af4f0 100644 --- a/include/os.h +++ b/include/os.h @@ -84,3 +84,17 @@ void os_tty_raw(int fd); * \return Pointer to length bytes or NULL on error */ void *os_malloc(size_t length); + +/** + * Access to the usleep function of the os + * + * \param usec Time to sleep in micro seconds + */ +void os_usleep(unsigned long usec); + +/** + * Gets a monotonic increasing number of nano seconds from the OS + * + * \return A monotonic increasing time scaled in nano seconds + */ +u64 os_get_nsec(void);