diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-07-11 23:39:33 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-07-11 23:39:33 +0000 |
commit | d357fd30cd6855f40dedf8050ee45067d0ee281f (patch) | |
tree | 7a162ac7ade2d63f3df2efddaf778ec795c7865a | |
parent | fb117bfced091fd2ee5a32f2ab39b6d7a48e0676 (diff) | |
download | px4-nuttx-d357fd30cd6855f40dedf8050ee45067d0ee281f.tar.gz px4-nuttx-d357fd30cd6855f40dedf8050ee45067d0ee281f.tar.bz2 px4-nuttx-d357fd30cd6855f40dedf8050ee45067d0ee281f.zip |
Add gettimeofday()
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1974 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r-- | nuttx/ChangeLog | 2 | ||||
-rw-r--r-- | nuttx/Documentation/NuttX.html | 2 | ||||
-rw-r--r-- | nuttx/Documentation/NuttxUserGuide.html | 28 | ||||
-rw-r--r-- | nuttx/include/sys/time.h | 75 | ||||
-rw-r--r-- | nuttx/sched/Makefile | 3 | ||||
-rw-r--r-- | nuttx/sched/clock_gettimeofday.c | 111 |
6 files changed, 220 insertions, 1 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 97bb304f1..e14afe9db 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -808,6 +808,8 @@ * lib/: Greatly simplified mktime() and gmtime_r(). The Gregorian and Julian time calculations were interesting, but not necessary in the typical embeddd system. + * sched/: Added gettimeofday(). This implementation is simply a thin + wrapper around clock_gettimer(). diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html index 627a5bd6c..908c927c8 100644 --- a/nuttx/Documentation/NuttX.html +++ b/nuttx/Documentation/NuttX.html @@ -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 Julian time calculations were interesting, but not necessary in the 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> diff --git a/nuttx/Documentation/NuttxUserGuide.html b/nuttx/Documentation/NuttxUserGuide.html index 05fa44f14..7c6bb0f0a 100644 --- a/nuttx/Documentation/NuttxUserGuide.html +++ b/nuttx/Documentation/NuttxUserGuide.html @@ -2469,6 +2469,7 @@ VxWorks provides the following comparable interface: <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="#timergetoverrun">2.7.11 timer_getoverrun</a></li> + <li><a href="#gettimeofday">2.7.12 gettimeofday</a></li> </ul> <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. </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%"> <tr bgcolor="#e4e4e4"> <td> diff --git a/nuttx/include/sys/time.h b/nuttx/include/sys/time.h new file mode 100644 index 000000000..31efe1868 --- /dev/null +++ b/nuttx/include/sys/time.h @@ -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 */ diff --git a/nuttx/sched/Makefile b/nuttx/sched/Makefile index 288aade45..84609a021 100644 --- a/nuttx/sched/Makefile +++ b/nuttx/sched/Makefile @@ -72,7 +72,8 @@ ifneq ($(CONFIG_DISABLE_SIGNALS),y) TIME_SRCS += sleep.c usleep.c endif 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 \ sig_action.c sig_procmask.c sig_pending.c sig_suspend.c \ diff --git a/nuttx/sched/clock_gettimeofday.c b/nuttx/sched/clock_gettimeofday.c new file mode 100644 index 000000000..ccc6fc9b3 --- /dev/null +++ b/nuttx/sched/clock_gettimeofday.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; +} |