[U-Boot] [PATCH v1 (WIP) 08/16] [Timer]Create new userland timer API

Graeme Russ graeme.russ at gmail.com
Tue Jun 28 13:41:01 CEST 2011


Signed-off-by: Graeme Russ <graeme.russ at gmail.com>
---
 include/common.h |   36 ++++++++++++++++++++----------------
 lib/time.c       |   26 ++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/include/common.h b/include/common.h
index 340e585..9735d47 100644
--- a/include/common.h
+++ b/include/common.h
@@ -584,11 +584,29 @@ void	timer_interrupt	   (struct pt_regs *);
 void	external_interrupt (struct pt_regs *);
 void	irq_install_handler(int, interrupt_handler_t *, void *);
 void	irq_free_handler   (int);
-void	reset_timer	   (void);
-ulong	get_timer	   (ulong base);
 void	enable_interrupts  (void);
 int	disable_interrupts (void);
 
+/*
+ * Timer API
+ */
+void reset_timer (void);
+ulong get_timer (ulong base);
+u64 get_ticks(void);
+void wait_ticks(unsigned long);
+void __udelay(unsigned long);
+ulong usec2ticks(unsigned long usec);
+ulong ticks2usec(unsigned long ticks);
+int init_timebase(void);
+
+/* lib/time.c */
+void udelay(unsigned long);
+
+u32 time_now_ms(void);
+u32 time_since_ms(u32 from, u32 to);
+u32 time_max_since_ms(u32 from, u32 to);
+u32 time_resolution_ms(void);
+
 /* $(CPU)/.../commproc.c */
 int	dpram_init (void);
 uint	dpram_base(void);
@@ -616,17 +634,6 @@ void	flush_cache   (unsigned long, unsigned long);
 void	flush_dcache_range(unsigned long start, unsigned long stop);
 void	invalidate_dcache_range(unsigned long start, unsigned long stop);
 
-
-/* arch/$(ARCH)/lib/ticks.S */
-unsigned long long get_ticks(void);
-void	wait_ticks    (unsigned long);
-
-/* arch/$(ARCH)/lib/time.c */
-void	__udelay      (unsigned long);
-ulong	usec2ticks    (unsigned long usec);
-ulong	ticks2usec    (unsigned long ticks);
-int	init_timebase (void);
-
 /* lib/gunzip.c */
 int gunzip(void *, int, unsigned char *, unsigned long *);
 int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
@@ -644,9 +651,6 @@ void qsort(void *base, size_t nmemb, size_t size,
 	   int(*compar)(const void *, const void *));
 int strcmp_compar(const void *, const void *);
 
-/* lib/time.c */
-void	udelay        (unsigned long);
-
 /* lib/vsprintf.c */
 ulong	simple_strtoul(const char *cp,char **endp,unsigned int base);
 int strict_strtoul(const char *cp, unsigned int base, unsigned long *res);
diff --git a/lib/time.c b/lib/time.c
index a309c26..1563507 100644
--- a/lib/time.c
+++ b/lib/time.c
@@ -41,3 +41,29 @@ void udelay(unsigned long usec)
 		usec -= kv;
 	} while(usec);
 }
+
+u32 time_since_ms(u32 from)
+{
+	u32 delta = time_now_ms() - from;
+
+	/* round down */
+	if (delta < time_ms_resolution())
+		return 0;
+
+	return delta - time_resolution_ms();
+}
+
+u32 time_max_since_ms(u32 from)
+{
+	u32 delta = time_now_ms() - from;
+
+	return delta + time_resolution_ms();
+}
+
+__attribute__((weak))
+u32 time_resolution_ms(void) {return 1;}
+
+u32 time_now_ms(void)
+{
+	return get_timer(0);
+}
-- 
1.7.5.2.317.g391b14



More information about the U-Boot mailing list