This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ecos and gettimeofday()


Hi,

On Thursday 13 October 2005 19:12, Andrew Lunn wrote:
> Jifl message made is clear that the implementation does not belong in
> the header file. libc is the wrong as well. The correct place would be
> posix since this is a posix function. It might be possible to persuade
> me it could go in a package of its own, but i'm not sure about that.

Ok, attached is a new version of the patch (still not meant for inclusion). 
Now gettimeofday() is implemented in posix/src/gettimeofday.cxx. Additionally 
I modified posix.cdl so that gettimeofday.cxx can be compiled separately 
without the rest of the posix package. The rest of the posix package is now 
combined in a CYGPKG_POSIX_BASIC, which is enabled by default, but can be 
disabled now too. Probably the name is not the best.
What do you think ?

> Also your implementation is not so great. Look at Nick's in the ppp
> code. Nick's is less arithmetic and less likely to cause an overflow.

From net/ppp/current/src/sys-ecos.c:

int gettimeofday(struct timeval *tv, struct timezone *tz)
{
    cyg_tick_count_t time = cyg_current_time();
    tv->tv_sec = time/CYGNUM_HAL_RTC_DENOMINATOR;
    tv->tv_usec = (time%CYGNUM_HAL_RTC_DENOMINATOR)*10000;
    return 0;
}

IMHO according to 
http://sources.redhat.com/ecos/docs-latest/ref/hal-clocks-and-timers.html 
also this version is not completely correct:

"CYGNUM_HAL_RTC_NUMERATOR and CYGNUM_HAL_RTC_DENOMINATOR specify the 
resolution of the clock interrupt. [...] The result of dividing the numerator 
by the denominator should correspond to the number of nanoseconds between 
clock interrupts. For example a numerator of 1000000000 and a denominator of 
100 means that there are 10000000 nanoseconds (or 10 milliseconds) between 
clock interrupts."

While the calculation in ppp/ returns the correct result for the numbers as 
given in the documentation, if I understand the documentation correctly, the 
same 10 ms tick could also be specified e.g. with 
CYGNUM_HAL_RTC_NUMERATOR=10000000 and CYGNUM_HAL_RTC_DENOMINATOR=1. The 
documentation doesn't mention that CYGNUM_HAL_RTC_NUMERATOR has always to be 
1,000,000,000.

The version I implemented takes both, NUMERATOR and DENOMINATOR into account. 
The 64 bit of cyg_tick_count_t shouldn't overflow too fast.

int gettimeofday(struct timeval* tv, struct timezone* tz)
{
   cyg_tick_count_t time_us = cyg_current_time() * 
(CYGNUM_HAL_RTC_NUMERATOR/CYGNUM_HAL_RTC_DENOMINATOR/1000);
   tv->tv_sec =  time_us / 1000000;
   tv->tv_usec = time_us % 1000000;
   return 0;
}

So, let me know what you think and I'll prepare a complete patch.

Bye
Alex
-- 
Work: alexander.neundorf@jenoptik.com - http://www.jenoptik-los.de
Home: neundorf@kde.org                - http://www.kde.org
      alex@neundorf.net               - http://www.neundorf.net
diff -rbupN /usr/src/ecos-stuff/ecos-unchanged/packages/isoinfra/current/include/sys/time.h isoinfra/current/include/sys/time.h
--- /usr/src/ecos-stuff/ecos-unchanged/packages/isoinfra/current/include/sys/time.h	1970-01-01 01:00:00.000000000 +0100
+++ isoinfra/current/include/sys/time.h	2005-10-14 20:53:10.000000000 +0200
@@ -0,0 +1,91 @@
+#ifndef CYGONCE_ISO_SYS_TIME_H
+#define CYGONCE_ISO_SYS_TIME_H
+/*========================================================================
+//
+//      sys/time.h
+//
+//      struct timeval and gettimeofday()
+//
+//========================================================================
+//####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 2005  Alexander Neundorf
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later version.
+//
+// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with eCos; if not, write to the Free Software Foundation, Inc.,
+// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or inline functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// License. However the source code for this file must still be made available
+// in accordance with section (3) of the GNU General Public License.
+//
+// This exception does not invalidate any other reasons why a work based on
+// this file might be covered by the GNU General Public License.
+//
+// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
+// at http://sources.redhat.com/ecos/ecos-license/
+// -------------------------------------------
+//####ECOSGPLCOPYRIGHTEND####
+//========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s):     Alexander Neundorf <neundorf@kde.org>
+// Contributors:  
+// Date:          2005-10-04
+// Purpose:       This file provides the time macros, types and functions
+//                required by ISO C and POSIX 1003.1.
+// Description:   The real contents of this file get set from the
+//                configuration (set by the implementation)
+// Usage:         #include <time.h>
+//
+//####DESCRIPTIONEND####
+//
+//======================================================================
+*/
+
+/* CONFIGURATION */
+
+#include <pkgconf/isoinfra.h>          /* Configuration header */
+
+/* INCLUDES */
+
+/* This is the "standard" way to get NULL and size_t from stddef.h,
+ * which is the canonical location of the definitions.
+ */
+#define __need_NULL
+#define __need_size_t
+#include <stddef.h>
+
+#include <time.h>
+#ifdef CYGBLD_ISO_STRUCTTIMEVAL_HEADER
+# include CYGBLD_ISO_STRUCTTIMEVAL_HEADER
+#else
+
+/*
+ * Structure returned by gettimeofday(2),
+ * and used in other calls such as select(2).
+ */
+struct timeval {
+	time_t	tv_sec;		/* seconds */
+	time_t	tv_usec;	/* and microseconds */
+};
+
+#endif
+
+
+#endif /* CYGONCE_ISO_SYS_TIME_H multiple inclusion protection */
+
+/* EOF sys/time.h */
diff -rbupN /usr/src/ecos-stuff/ecos-unchanged/packages/isoinfra/current/include/time.h isoinfra/current/include/time.h
--- /usr/src/ecos-stuff/ecos-unchanged/packages/isoinfra/current/include/time.h	2002-05-24 01:06:43.000000000 +0200
+++ isoinfra/current/include/time.h	2005-10-12 18:21:15.000000000 +0200
@@ -99,23 +99,7 @@ typedef long clock_t;
 #  define __clock_t_defined
 #endif
 
-#ifdef CYGBLD_ISO_STRUCTTIMEVAL_HEADER
-# include CYGBLD_ISO_STRUCTTIMEVAL_HEADER
-#else
-# ifndef _POSIX_SOURCE
-
-/*
- * Structure returned by gettimeofday(2),
- * and used in other calls such as select(2).
- */
-struct timeval {
-	long	tv_sec;		/* seconds */
-	long	tv_usec;	/* and microseconds */
-};
-
-# endif /* _POSIX_SOURCE */
-#endif
-
+#include <sys/time.h>
 
 #ifdef CYGINT_ISO_POSIX_CLOCK_TYPES
 # include CYGBLD_ISO_POSIX_CLOCK_TYPES_HEADER
diff -rbupN /usr/src/ecos-stuff/ecos-unchanged/packages/compat/posix/current/cdl/posix.cdl compat/posix/current/cdl/posix.cdl
--- /usr/src/ecos-stuff/ecos-unchanged/packages/compat/posix/current/cdl/posix.cdl	2003-02-24 15:08:21.000000000 +0100
+++ compat/posix/current/cdl/posix.cdl	2005-10-14 20:53:49.000000000 +0200
@@ -49,12 +49,32 @@
 # ====================================================================
 
 cdl_package CYGPKG_POSIX {
+
     display        "POSIX compatibility layer"
     description    "This package enables the POSIX compatibility
                     layer that implements IEEE 1003.1."
     doc            ref/posix-compatibility.html
     include_dir    cyg/posix
     
+    # ----------------------------------------------------------------
+    # gettimeofday()
+    
+    cdl_component CYGPKG_POSIX_GETTIMEOFDAY {
+	display          "POSIX gettimeofday()"
+	flavor           bool
+	default_value    1
+	description      "This component provides the gettimeofday() function"
+        requires         CYGPKG_KERNEL
+        requires         { CYGBLD_ISO_STRUCTTIMEVAL_HEADER == \
+                             "<cyg/posix/sys/time.h>" }
+        
+        compile          gettimeofday.cxx
+    }
+
+    cdl_component CYGPKG_POSIX_BASIC {
+	display          "basic POSIX functions"
+	default_value    1
+
     requires       CYGPKG_KERNEL
     requires       CYGPKG_ISOINFRA
     requires       CYGPKG_ERROR
@@ -94,6 +114,7 @@ cdl_package CYGPKG_POSIX {
         description	"This option defines the POSIX feature test macro
                          for supporting priority ceiling protocol in mutexes."
     }
+    }
     
     # ----------------------------------------------------------------
     # Scheduling component
@@ -105,6 +126,8 @@ cdl_package CYGPKG_POSIX {
 	description      "This component provides controls over scheduling
 	                  in POSIX."
         requires         CYGPKG_POSIX_CLOCKS
+        requires         CYGPKG_POSIX_BASIC
+        active_if        CYGPKG_POSIX_BASIC
         compile          sched.cxx
 
 	cdl_option _POSIX_PRIORITY_SCHEDULING {
@@ -122,6 +145,8 @@ cdl_package CYGPKG_POSIX {
     # Pthreads component
 
     cdl_component CYGPKG_POSIX_PTHREAD {
+        requires         CYGPKG_POSIX_BASIC
+        active_if        CYGPKG_POSIX_BASIC
 	display          "POSIX pthread configuration"
 	flavor           bool
 	default_value    1
@@ -147,6 +172,8 @@ cdl_package CYGPKG_POSIX {
                              "<cyg/posix/time.h>" }
         requires         CYGPKG_KERNEL
         requires         CYGVAR_KERNEL_COUNTERS_CLOCK
+        requires         CYGPKG_POSIX_BASIC
+        active_if        CYGPKG_POSIX_BASIC
         compile          time.cxx
 	description      "This component provides configuration controls for
 	                  the POSIX clocks."
@@ -171,6 +198,8 @@ cdl_package CYGPKG_POSIX {
         requires         CYGPKG_POSIX_PTHREAD
         requires         CYGPKG_POSIX_CLOCKS
         requires         CYGPKG_POSIX_SIGNALS
+        requires         CYGPKG_POSIX_BASIC
+        active_if        CYGPKG_POSIX_BASIC
 	description      "This component provides configuration controls for
 	                  the POSIX timers."
     }
@@ -183,6 +212,8 @@ cdl_package CYGPKG_POSIX {
 	flavor           bool
 	default_value    1
         implements       CYGINT_ISO_SEMAPHORES
+        requires         CYGPKG_POSIX_BASIC
+        active_if        CYGPKG_POSIX_BASIC
         requires         { CYGBLD_ISO_SEMAPHORES_HEADER == \
                              "<cyg/posix/semaphore.h>" }
 	description      "This component provides configuration controls for
@@ -199,6 +230,8 @@ cdl_package CYGPKG_POSIX {
 	flavor           bool
 	default_value    1
         implements       CYGINT_ISO_MQUEUE
+        requires         CYGPKG_POSIX_BASIC
+        active_if        CYGPKG_POSIX_BASIC
         requires         CYGPKG_KERNEL
         requires         CYGINT_ISO_MALLOC
         requires         CYGINT_ISO_ERRNO
@@ -251,6 +284,8 @@ cdl_package CYGPKG_POSIX {
 	requires	 CYGPKG_KERNEL_EXCEPTIONS
         requires         CYGPKG_POSIX_PTHREAD
         requires         CYGPKG_POSIX_TIMERS
+        requires         CYGPKG_POSIX_BASIC
+        active_if        CYGPKG_POSIX_BASIC
         implements       CYGINT_POSIX_REALTIME_SIGNALS
         implements       CYGINT_ISO_SIGSETJMP
         requires         { CYGBLD_ISO_SIGSETJMP_HEADER == \
@@ -273,6 +308,8 @@ cdl_package CYGPKG_POSIX {
 	display           "POSIX utsname configuration"
 	flavor            bool
 	default_value     1
+        requires         CYGPKG_POSIX_BASIC
+        active_if        CYGPKG_POSIX_BASIC
 	requires          { CYGBLD_ISO_UTSNAME_HEADER == \
                             "<cyg/posix/utsname.h>" }
 	description       "This component provides configuration controls for
diff -rbupN /usr/src/ecos-stuff/ecos-unchanged/packages/compat/posix/current/include/sys/time.h compat/posix/current/include/sys/time.h
--- /usr/src/ecos-stuff/ecos-unchanged/packages/compat/posix/current/include/sys/time.h	1970-01-01 01:00:00.000000000 +0100
+++ compat/posix/current/include/sys/time.h	2005-10-12 19:04:41.000000000 +0200
@@ -0,0 +1,219 @@
+//==========================================================================
+//
+//      include/sys/time.h
+//
+//      
+//
+//==========================================================================
+//####BSDCOPYRIGHTBEGIN####
+//
+// -------------------------------------------
+//
+// Portions of this software may have been derived from OpenBSD or other sources,
+// and are covered by the appropriate copyright disclaimers included herein.
+//
+// -------------------------------------------
+//
+//####BSDCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s):    gthomas
+// Contributors: gthomas
+// Date:         2000-01-10
+// Purpose:      
+// Description:  
+//              
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+
+/*	$OpenBSD: time.h,v 1.9 1999/12/06 19:36:42 aaron Exp $	*/
+/*	$NetBSD: time.h,v 1.18 1996/04/23 10:29:33 mycroft Exp $	*/
+
+/*
+ * Copyright (c) 1982, 1986, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)time.h	8.2 (Berkeley) 7/10/94
+ */
+
+#ifndef _SYS_TIME_H_
+#define _SYS_TIME_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <sys/types.h>
+#include <sys/cdefs.h>
+#include <time.h>
+
+/*
+ * Structure returned by gettimeofday(2) system call,
+ * and used in other calls.
+ */
+struct timeval {
+	long	tv_sec;		/* seconds */
+	long	tv_usec;	/* and microseconds */
+};
+
+
+#define	TIMEVAL_TO_TIMESPEC(tv, ts) {					\
+	(ts)->tv_sec = (tv)->tv_sec;					\
+	(ts)->tv_nsec = (tv)->tv_usec * 1000;				\
+}
+#define	TIMESPEC_TO_TIMEVAL(tv, ts) {					\
+	(tv)->tv_sec = (ts)->tv_sec;					\
+	(tv)->tv_usec = (ts)->tv_nsec / 1000;				\
+}
+
+struct timezone {
+	int	tz_minuteswest;	/* minutes west of Greenwich */
+	int	tz_dsttime;	/* type of dst correction */
+};
+
+#define	DST_NONE	0	/* not on dst */
+#define	DST_USA		1	/* USA style dst */
+#define	DST_AUST	2	/* Australian style dst */
+#define	DST_WET		3	/* Western European dst */
+#define	DST_MET		4	/* Middle European dst */
+#define	DST_EET		5	/* Eastern European dst */
+#define	DST_CAN		6	/* Canada */
+
+/* Operations on timevals. */
+#define	timerclear(tvp)		(tvp)->tv_sec = (tvp)->tv_usec = 0
+#define	timerisset(tvp)		((tvp)->tv_sec || (tvp)->tv_usec)
+#define	timercmp(tvp, uvp, cmp)						\
+	(((tvp)->tv_sec == (uvp)->tv_sec) ?				\
+	    ((tvp)->tv_usec cmp (uvp)->tv_usec) :			\
+	    ((tvp)->tv_sec cmp (uvp)->tv_sec))
+#define	timeradd(tvp, uvp, vvp)						\
+	do {								\
+		(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;		\
+		(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;	\
+		if ((vvp)->tv_usec >= 1000000) {			\
+			(vvp)->tv_sec++;				\
+			(vvp)->tv_usec -= 1000000;			\
+		}							\
+	} while (0)
+#define	timersub(tvp, uvp, vvp)						\
+	do {								\
+		(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;		\
+		(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;	\
+		if ((vvp)->tv_usec < 0) {				\
+			(vvp)->tv_sec--;				\
+			(vvp)->tv_usec += 1000000;			\
+		}							\
+	} while (0)
+
+/* Operations on timespecs. */
+#define	timespecclear(tsp)		(tsp)->tv_sec = (tsp)->tv_nsec = 0
+#define	timespecisset(tsp)		((tsp)->tv_sec || (tsp)->tv_nsec)
+#define	timespeccmp(tsp, usp, cmp)					\
+	(((tsp)->tv_sec == (usp)->tv_sec) ?				\
+	    ((tsp)->tv_nsec cmp (usp)->tv_nsec) :			\
+	    ((tsp)->tv_sec cmp (usp)->tv_sec))
+#define	timespecadd(tsp, usp, vsp)					\
+	do {								\
+		(vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec;		\
+		(vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec;	\
+		if ((vsp)->tv_nsec >= 1000000000L) {			\
+			(vsp)->tv_sec++;				\
+			(vsp)->tv_nsec -= 1000000000L;			\
+		}							\
+	} while (0)
+#define	timespecsub(tsp, usp, vsp)					\
+	do {								\
+		(vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;		\
+		(vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec;	\
+		if ((vsp)->tv_nsec < 0) {				\
+			(vsp)->tv_sec--;				\
+			(vsp)->tv_nsec += 1000000000L;			\
+		}							\
+	} while (0)
+
+
+//#if defined(_KERNEL) || defined(_STANDALONE)
+void	microtime __P((struct timeval *tv));
+int	gettimeofday __P((struct timeval *, struct timezone *));
+
+//#endif /* !_KERNEL */
+
+//#endif /* !_SYS_TIME_H_ */
+
+/* the following functions are not supported by eCos */
+#if 0
+
+int	adjtime __P((const struct timeval *, struct timeval *));
+int	clock_getres __P((clockid_t, struct timespec *));
+int	clock_gettime __P((clockid_t, struct timespec *));
+int	clock_settime __P((clockid_t, const struct timespec *));
+int	futimes __P((int, const struct timeval *));
+int	getitimer __P((int, struct itimerval *));
+int	nanosleep __P((const struct timespec *, struct timespec *));
+int	setitimer __P((int, const struct itimerval *, struct itimerval *));
+int	settimeofday __P((const struct timeval *, const struct timezone *));
+int	utimes __P((const char *, const struct timeval *));
+
+
+int	itimerdecr __P((struct itimerval *itp, int usec));
+int	itimerfix __P((struct timeval *tv));
+void	settime __P((struct timeval *tv));
+
+int	adjtime __P((const struct timeval *, struct timeval *));
+int	clock_getres __P((clockid_t, struct timespec *));
+int	clock_gettime __P((clockid_t, struct timespec *));
+int	clock_settime __P((clockid_t, const struct timespec *));
+int	futimes __P((int, const struct timeval *));
+int	getitimer __P((int, struct itimerval *));
+int	nanosleep __P((const struct timespec *, struct timespec *));
+int	setitimer __P((int, const struct itimerval *, struct itimerval *));
+int	settimeofday __P((const struct timeval *, const struct timezone *));
+int	utimes __P((const char *, const struct timeval *));
+
+/*
+ * Structure defined by POSIX.1b to be like a timeval.
+ */
+struct timespec {
+	time_t	tv_sec;		/* seconds */
+	long	tv_nsec;	/* and nanoseconds */
+};
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
diff -rbupN /usr/src/ecos-stuff/ecos-unchanged/packages/compat/posix/current/src/gettimeofday.cxx compat/posix/current/src/gettimeofday.cxx
--- /usr/src/ecos-stuff/ecos-unchanged/packages/compat/posix/current/src/gettimeofday.cxx	1970-01-01 01:00:00.000000000 +0100
+++ compat/posix/current/src/gettimeofday.cxx	2005-10-13 22:37:23.000000000 +0200
@@ -0,0 +1,76 @@
+//==========================================================================
+//
+//      gettimeofday.cxx
+//
+//      POSIX gettimeofday() function implementation
+//
+//==========================================================================
+//####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later version.
+//
+// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with eCos; if not, write to the Free Software Foundation, Inc.,
+// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or inline functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// License. However the source code for this file must still be made available
+// in accordance with section (3) of the GNU General Public License.
+//
+// This exception does not invalidate any other reasons why a work based on
+// this file might be covered by the GNU General Public License.
+//
+// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
+// at http://sources.redhat.com/ecos/ecos-license/
+// -------------------------------------------
+//####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s):           nickg
+// Contributors:        nickg
+// Date:                2000-03-27
+// Purpose:             POSIX time functions implementation
+// Description:         This file contains the implementation of the POSIX time
+//                      functions.
+//              
+//              
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#include <cyg/kernel/kapi.h>          // base kernel types
+
+#include <time.h>                       // our header
+#include <sys/time.h>                   // our header
+
+// Get the current time in a struct timeval
+externC int gettimeofday(struct timeval* tv, struct timezone* tz)
+{
+   cyg_tick_count_t time_us = cyg_current_time() * (CYGNUM_HAL_RTC_NUMERATOR/CYGNUM_HAL_RTC_DENOMINATOR/1000);
+   tv->tv_sec =  time_us / 1000000;
+   tv->tv_usec = time_us % 1000000;
+   return 0;
+}
+
+externC void microtime(struct timeval* tv)
+{
+   gettimeofday(tv, 0);
+}
+
+// -------------------------------------------------------------------------
+// EOF gettimeofday.cxx

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]