This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Re: ecos and gettimeofday()
- From: Alexander Neundorf <neundorf at kde dot org>
- To: ecos-discuss at ecos dot sourceware dot org
- Cc: Andrew Lunn <andrew at lunn dot ch>
- Date: Wed, 19 Oct 2005 23:49:18 +0200
- Subject: Re: [ECOS] ecos and gettimeofday()
- References: <200509292331.26058.neundorf@kde.org> <200510142130.57867.neundorf@kde.org> <20051016095516.GB7857@lunn.ch>
- Reply-to: neundorf at kde dot org
On Sunday 16 October 2005 11:55, Andrew Lunn wrote:
...
> I suggest you add gettimeofday() to the end of time.cxx.
Ok, how about the attached version ?
Additionally I'd like to move the rest of misc.c into its own
CYGPKG_POSIX_MISC component, but I haven't figured out yet what
cyg_posix_function_start() and cyg_posix_function_finish() exactly do.
What are they required for ?
I'm not sure that I didn't miss any dependencies, I don't know the _complete_
ecos source tree, I guess the maintainers can do this better.
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 posix.orig/current/ChangeLog posix/current/ChangeLog
--- posix.orig/current/ChangeLog 2004-10-04 13:49:19.000000000 +0200
+++ posix/current/ChangeLog 2005-10-19 23:16:26.000000000 +0200
@@ -1,3 +1,10 @@
+2005-10-18 Alexander Neundorf <neundorf@kde.org>
+
+ src/time.cxx: add gettimeofday() implementation
+ cdl/posix.cdl: make some decriptions a bit more verbose.
+ move mutex.cxx into its own component (CYGPKG_POSIX_PTHREAD_MUTEX).
+ move compilation of mqueue.cxx into the CYGPKG_POSIX_MQUEUES component
+
2004-10-01 Oyvind Harboe <oyvind.harboe@zylin.com>
* src/signal.cxx: place the CYGBLD_ATTRIB_INIT_PRI such that it
diff -rbupN posix.orig/current/cdl/posix.cdl posix/current/cdl/posix.cdl
--- posix.orig/current/cdl/posix.cdl 2003-02-24 15:08:21.000000000 +0100
+++ posix/current/cdl/posix.cdl 2005-10-19 23:44:28.000000000 +0200
@@ -51,7 +51,10 @@
cdl_package CYGPKG_POSIX {
display "POSIX compatibility layer"
description "This package enables the POSIX compatibility
- layer that implements IEEE 1003.1."
+ layer that implements IEEE 1003.1.
+ Without enabling more components of this package
+ it provides the sysconf(),
+ getXXXid() and setXXXid() functions."
doc ref/posix-compatibility.html
include_dir cyg/posix
@@ -73,9 +76,17 @@ cdl_package CYGPKG_POSIX {
requires { CYGBLD_ISO_PTHREAD_MUTEX_HEADER == \
"<cyg/posix/mutex.h>" }
- compile mqueue.cxx mutex.cxx misc.cxx
+ compile misc.cxx
compile -library=libextras.a startup.cxx
+ cdl_component CYGPKG_POSIX_PTHREAD_MUTEX {
+
+ display "POSIX pthread mutexes"
+ flavor bool
+ compile mutex.cxx
+ default_value 1
+ description "This component provides support for POSIX pthreads mutexes."
+
cdl_option _POSIX_THREAD_PRIO_INHERIT {
display "POSIX mutex priority inheritance feature test macro"
flavor bool
@@ -95,6 +106,8 @@ cdl_package CYGPKG_POSIX {
for supporting priority ceiling protocol in mutexes."
}
+ }
+
# ----------------------------------------------------------------
# Scheduling component
@@ -145,11 +158,14 @@ cdl_package CYGPKG_POSIX {
"<cyg/posix/time.h>" }
requires { CYGBLD_ISO_POSIX_CLOCKS_HEADER == \
"<cyg/posix/time.h>" }
+ requires { CYGBLD_ISO_STRUCTTIMEVAL_HEADER == \
+ "<cyg/posix/sys/time.h>" }
requires CYGPKG_KERNEL
requires CYGVAR_KERNEL_COUNTERS_CLOCK
compile time.cxx
description "This component provides configuration controls for
- the POSIX clocks."
+ the POSIX clocks and the sleep(), nanosleep()
+ and gettimeofday() functions."
}
# ----------------------------------------------------------------
@@ -198,11 +214,13 @@ cdl_package CYGPKG_POSIX {
display "POSIX message queues"
flavor bool
default_value 1
+ compile mqueue.cxx
implements CYGINT_ISO_MQUEUE
requires CYGPKG_KERNEL
requires CYGINT_ISO_MALLOC
requires CYGINT_ISO_ERRNO
requires CYGINT_ISO_STRING_STRFUNCS
+ requires CYGPKG_POSIX_PTHREAD_MUTEX
description "This component provides configuration controls for
POSIX message queues."
diff -rbupN posix.orig/current/cdl/pthread.cdl posix/current/cdl/pthread.cdl
--- posix.orig/current/cdl/pthread.cdl 2002-05-24 00:59:56.000000000 +0200
+++ posix/current/cdl/pthread.cdl 2005-10-19 21:42:33.000000000 +0200
@@ -55,6 +55,7 @@ cdl_option CYGPKG_POSIX_PTHREAD_REQUIREM
implements CYGINT_ISO_PTHREADTYPES
implements CYGINT_ISO_PTHREAD_IMPL
requires CYGPKG_POSIX_SCHED
+ requires CYGPKG_POSIX_PTHREAD_MUTEX
requires CYGSEM_KERNEL_SCHED_TIMESLICE_ENABLE
requires CYGSEM_KERNEL_SCHED_ASR_SUPPORT
requires CYGSEM_KERNEL_SCHED_ASR_GLOBAL
diff -rbupN posix.orig/current/doc/posix.sgml posix/current/doc/posix.sgml
--- posix.orig/current/doc/posix.sgml 2003-02-24 15:08:21.000000000 +0100
+++ posix/current/doc/posix.sgml 2005-10-19 23:20:36.000000000 +0200
@@ -1046,6 +1046,7 @@ int timer_settime( timer_t
int timer_gettime( timer_t timerid, struct itimerspec *value );
int timer_getoverrun( timer_t timerid );
int nanosleep( const struct timespec *rqtp, struct timespec *rmtp);
+int gettimeofday(struct timeval *tv, struct timezone* tz);
</screen>
</sect2>
diff -rbupN posix.orig/current/include/sys/time.h posix/current/include/sys/time.h
--- posix.orig/current/include/sys/time.h 1970-01-01 01:00:00.000000000 +0100
+++ posix/current/include/sys/time.h 2005-10-19 22:54:15.000000000 +0200
@@ -0,0 +1,214 @@
+//==========================================================================
+//
+// 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)
+
+
+int gettimeofday __P((struct timeval *, struct timezone *));
+
+/* the following functions are not supported by eCos */
+#if 0
+
+void microtime __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 *));
+
+
+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 posix.orig/current/src/misc.cxx posix/current/src/misc.cxx
--- posix.orig/current/src/misc.cxx 2002-05-24 00:59:59.000000000 +0200
+++ posix/current/src/misc.cxx 2005-10-19 23:43:45.000000000 +0200
@@ -65,7 +65,9 @@
#include "pprivate.h" // POSIX private header
#include <unistd.h>
+#ifdef CYGPKG_POSIX_UTSNAME
#include <sys/utsname.h> // My header
+#endif
#include <string.h> // strcpy
#include <limits.h>
#include <time.h>
@@ -93,6 +95,7 @@
// -------------------------------------------------------------------------
// uname()
+#ifdef CYGPKG_POSIX_UTSNAME
__externC int uname( struct utsname *name )
{
CYG_REPORT_FUNCTYPE( "returning %d" );
@@ -106,6 +109,7 @@ __externC int uname( struct utsname *nam
CYG_REPORT_RETVAL(0);
return 0;
}
+#endif
// -------------------------------------------------------------------------
// sysconf()
diff -rbupN posix.orig/current/src/mqueue.cxx posix/current/src/mqueue.cxx
--- posix.orig/current/src/mqueue.cxx 2003-12-02 06:48:46.000000000 +0100
+++ posix/current/src/mqueue.cxx 2005-10-19 21:32:37.000000000 +0200
@@ -58,8 +58,6 @@
#include <pkgconf/posix.h>
-#ifdef CYGPKG_POSIX_MQUEUES
-
#include <pkgconf/kernel.h>
/* INCLUDES */
@@ -1000,6 +998,4 @@ mq_getattr( mqd_t mqdes, struct mq_attr
//------------------------------------------------------------------------
-#endif // ifdef CYGPKG_POSIX_MQUEUES
-
/* EOF mqueue.cxx */
diff -rbupN posix.orig/current/src/time.cxx posix/current/src/time.cxx
--- posix.orig/current/src/time.cxx 2003-01-31 12:53:14.000000000 +0100
+++ posix/current/src/time.cxx 2005-10-19 23:40:50.000000000 +0200
@@ -55,8 +55,6 @@
#include <pkgconf/posix.h>
-#ifdef CYGPKG_POSIX_CLOCKS
-
#include <pkgconf/hal.h>
#include <pkgconf/kernel.h>
@@ -67,9 +65,11 @@
#include "pprivate.h" // POSIX private header
#include <time.h> // our header
+#include <sys/time.h>
#include <cyg/kernel/thread.hxx>
#include <cyg/kernel/clock.hxx>
+#include <cyg/kernel/kapi.h>
#include <cyg/kernel/thread.inl>
#include <cyg/kernel/clock.inl>
@@ -694,7 +694,19 @@ externC unsigned int sleep( unsigned int
TIME_RETURN(0);
}
-#endif // ifdef CYGPKG_POSIX_CLOCKS
+// -------------------------------------------------------------------------
+// gettimeofday()
+// Get the current time in a struct timeval
+externC int gettimeofday(struct timeval* tv, struct timezone* tz)
+{
+ int ticks_per_second = 1000000000/(CYGNUM_HAL_RTC_NUMERATOR/CYGNUM_HAL_RTC_DENOMINATOR);
+ cyg_tick_count_t cur_time = cyg_current_time();
+ int tix = cur_time % ticks_per_second;
+ tv->tv_sec = cur_time / ticks_per_second;
+ tv->tv_usec = (tix * 1000000)/ticks_per_second;
+ return 0;
+}
+
// -------------------------------------------------------------------------
// EOF time.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