mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
Add gettimeofday()
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1974 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -808,6 +808,8 @@
|
|||||||
* lib/: Greatly simplified mktime() and gmtime_r(). The Gregorian and
|
* lib/: Greatly simplified mktime() and gmtime_r(). The Gregorian and
|
||||||
Julian time calculations were interesting, but not necessary in the
|
Julian time calculations were interesting, but not necessary in the
|
||||||
typical embeddd system.
|
typical embeddd system.
|
||||||
|
* sched/: Added gettimeofday(). This implementation is simply a thin
|
||||||
|
wrapper around clock_gettimer().
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1481,6 +1481,8 @@ nuttx-0.4.10 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
|||||||
* lib/: Greatly simplified mktime() and gmtime_r(). The Gregorian and
|
* lib/: Greatly simplified mktime() and gmtime_r(). The Gregorian and
|
||||||
Julian time calculations were interesting, but not necessary in the
|
Julian time calculations were interesting, but not necessary in the
|
||||||
typical embeddd system.
|
typical embeddd system.
|
||||||
|
* sched/: Added gettimeofday(). This implementation is simply a thin
|
||||||
|
wrapper around clock_gettimer().
|
||||||
|
|
||||||
nuttx-0.4.10 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
nuttx-0.4.10 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
|
||||||
|
|||||||
@@ -2469,6 +2469,7 @@ VxWorks provides the following comparable interface:
|
|||||||
<li><a href="#timersettime">2.7.9 timer_settime</a></li>
|
<li><a href="#timersettime">2.7.9 timer_settime</a></li>
|
||||||
<li><a href="#timergettime">2.7.10 timer_gettime</a></li>
|
<li><a href="#timergettime">2.7.10 timer_gettime</a></li>
|
||||||
<li><a href="#timergetoverrun">2.7.11 timer_getoverrun</a></li>
|
<li><a href="#timergetoverrun">2.7.11 timer_getoverrun</a></li>
|
||||||
|
<li><a href="#gettimeofday">2.7.12 gettimeofday</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<H3><a name="clocksettime">2.7.1 clock_settime</a></H3>
|
<H3><a name="clocksettime">2.7.1 clock_settime</a></H3>
|
||||||
@@ -2917,6 +2918,33 @@ VxWorks provides the following comparable interface:
|
|||||||
interface of the same name.
|
interface of the same name.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<h3><a name="gettimeofday">2.7.12 gettimeofday</a></h3>
|
||||||
|
<p>
|
||||||
|
<b>Function Prototype:</b>
|
||||||
|
</p>
|
||||||
|
<pre>
|
||||||
|
#include <sys/time.h>
|
||||||
|
int gettimeofday(struct timeval *tp, void *tzp);
|
||||||
|
</pre>
|
||||||
|
<p>
|
||||||
|
<b>Description:</b>
|
||||||
|
This implementation of <code>gettimeofday()</code> is simply a thin wrapper around
|
||||||
|
<a href="#clockgettime"><code>clock_gettime()</code></a>.
|
||||||
|
It simply calls <code>clock_gettime()</code> using the <code>CLOCK_REALTIME</code> timer and
|
||||||
|
converts the result to the required <code>struct timeval</code>.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<b>Input Parameters:</b>
|
||||||
|
</p>
|
||||||
|
<ul>
|
||||||
|
<li><code>tp</code>. The current time will be returned to this user provided location.</li>
|
||||||
|
<li><code>tzp</code>. A reference to the timezone -- <i>IGNORED</i>.</li>
|
||||||
|
</ul>
|
||||||
|
<p>
|
||||||
|
<b>Returned Values:</b>
|
||||||
|
See <a href="#clockgettime"><code>clock_gettime()</code></a>.
|
||||||
|
</p>
|
||||||
|
|
||||||
<table width ="100%">
|
<table width ="100%">
|
||||||
<tr bgcolor="#e4e4e4">
|
<tr bgcolor="#e4e4e4">
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* include/sys/time.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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. Neither the name NuttX 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 COPYRIGHT HOLDERS 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
|
||||||
|
* COPYRIGHT OWNER 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.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __SYS_MMAN_H
|
||||||
|
#define __SYS_MMAN_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-Processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Type Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C" {
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
EXTERN int gettimeofday(struct timeval *tp, void *tzp);
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __SYS_MMAN_H */
|
||||||
+2
-1
@@ -72,7 +72,8 @@ ifneq ($(CONFIG_DISABLE_SIGNALS),y)
|
|||||||
TIME_SRCS += sleep.c usleep.c
|
TIME_SRCS += sleep.c usleep.c
|
||||||
endif
|
endif
|
||||||
CLOCK_SRCS = clock_initialize.c clock_settime.c clock_gettime.c clock_getres.c \
|
CLOCK_SRCS = clock_initialize.c clock_settime.c clock_gettime.c clock_getres.c \
|
||||||
clock_time2ticks.c clock_abstime2ticks.c clock_ticks2time.c
|
clock_time2ticks.c clock_abstime2ticks.c clock_ticks2time.c \
|
||||||
|
clock_gettimeofday.c
|
||||||
|
|
||||||
SIGNAL_SRCS = sig_initialize.c \
|
SIGNAL_SRCS = sig_initialize.c \
|
||||||
sig_action.c sig_procmask.c sig_pending.c sig_suspend.c \
|
sig_action.c sig_procmask.c sig_pending.c sig_suspend.c \
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* sched/clock_gettimeofday.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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. Neither the name NuttX 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 COPYRIGHT HOLDERS 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
|
||||||
|
* COPYRIGHT OWNER 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.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <debug.h>
|
||||||
|
#include "clock_internal.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Type Declarations
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Public Constant Data
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Variables
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Private Variables
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Function: gettimeofday
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Get the current time
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int gettimeofday(struct timeval *tp, void *tzp)
|
||||||
|
{
|
||||||
|
struct timespec ts;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
#ifdef CONFIG_DEBUG
|
||||||
|
if (!tp)
|
||||||
|
{
|
||||||
|
errno = EINVAL;
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Let clock_gettime do most of the work */
|
||||||
|
|
||||||
|
ret = clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
|
if (ret == OK)
|
||||||
|
{
|
||||||
|
/* Convert the struct timespec to a struct timeval */
|
||||||
|
|
||||||
|
tp->tv_sec = ts.tv_sec;
|
||||||
|
tp->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user