2007-03-21 00:51:12 +08:00
|
|
|
/********************************************************************************
|
2008-11-17 00:36:30 +08:00
|
|
|
* include/time.h
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
2011-03-30 10:59:01 +08:00
|
|
|
* Copyright (C) 2007-2011 Gregory Nutt. All rights reserved.
|
2007-02-18 07:21:28 +08:00
|
|
|
* 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.
|
2008-11-17 00:36:30 +08:00
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
2007-02-18 07:21:28 +08:00
|
|
|
* 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.
|
|
|
|
*
|
2007-03-21 00:51:12 +08:00
|
|
|
********************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2008-11-17 00:36:30 +08:00
|
|
|
#ifndef __INCLUDE_TIME_H
|
|
|
|
#define __INCLUDE_TIME_H
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2007-03-21 00:51:12 +08:00
|
|
|
/********************************************************************************
|
2007-02-18 07:21:28 +08:00
|
|
|
* Included Files
|
2007-03-21 00:51:12 +08:00
|
|
|
********************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2007-03-21 00:51:12 +08:00
|
|
|
#include <nuttx/config.h>
|
2009-12-15 07:32:23 +08:00
|
|
|
|
2007-03-21 00:51:12 +08:00
|
|
|
#include <sys/types.h>
|
2009-12-14 23:46:55 +08:00
|
|
|
#include <stdint.h>
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2007-03-21 00:51:12 +08:00
|
|
|
/********************************************************************************
|
2009-12-15 07:32:23 +08:00
|
|
|
* Pre-processor Definitions
|
2007-03-21 00:51:12 +08:00
|
|
|
********************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2007-06-09 23:49:44 +08:00
|
|
|
/* Clock tick of the system (frequency Hz). The default value is 100Hz, but this
|
|
|
|
* default setting can be overridden by defining the clock interval in
|
|
|
|
* milliseconds as CONFIG_MSEC_PER_TICK in the board configuration file.
|
|
|
|
*/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2007-06-09 23:49:44 +08:00
|
|
|
#ifdef CONFIG_MSEC_PER_TICK
|
|
|
|
# define CLK_TCK (1000/CONFIG_MSEC_PER_TICK)
|
|
|
|
#else
|
|
|
|
# define CLK_TCK (100)
|
|
|
|
#endif
|
2007-02-18 07:21:28 +08:00
|
|
|
|
|
|
|
/* This is the only clock_id supported by the "Clock and Timer
|
|
|
|
* Functions."
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define CLOCK_REALTIME 0
|
2007-03-21 00:51:12 +08:00
|
|
|
#define CLOCK_ABSTIME
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2007-03-21 08:56:49 +08:00
|
|
|
/* This is a flag that may be passed to the timer_settime() function */
|
|
|
|
|
|
|
|
#define TIMER_ABSTIME 1
|
|
|
|
|
2009-07-12 23:16:00 +08:00
|
|
|
/* Local time is the same as gmtime in this implementation */
|
|
|
|
|
|
|
|
#define localtime(c) gmtime(c)
|
|
|
|
#define localtime_r(c,r) gmtime_r(c,r)
|
|
|
|
|
2007-03-21 00:51:12 +08:00
|
|
|
/********************************************************************************
|
2007-02-18 07:21:28 +08:00
|
|
|
* Global Type Declarations
|
2007-03-21 00:51:12 +08:00
|
|
|
********************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2009-12-15 07:32:23 +08:00
|
|
|
typedef uint32_t time_t; /* Holds time in seconds */
|
2009-12-14 23:46:55 +08:00
|
|
|
typedef uint8_t clockid_t; /* Identifies one time base source */
|
2007-03-22 01:21:26 +08:00
|
|
|
typedef FAR void *timer_t; /* Represents one POSIX timer */
|
2007-02-18 07:21:28 +08:00
|
|
|
|
|
|
|
struct timespec
|
|
|
|
{
|
|
|
|
time_t tv_sec; /* Seconds */
|
|
|
|
long tv_nsec; /* Nanoseconds */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct timeval
|
|
|
|
{
|
|
|
|
time_t tv_sec; /* Seconds */
|
|
|
|
long tv_usec; /* Microseconds */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tm
|
|
|
|
{
|
|
|
|
int tm_sec; /* second (0-61, allows for leap seconds) */
|
|
|
|
int tm_min; /* minute (0-59) */
|
|
|
|
int tm_hour; /* hour (0-23) */
|
|
|
|
int tm_mday; /* day of the month (1-31) */
|
|
|
|
int tm_mon; /* month (0-11) */
|
|
|
|
int tm_year; /* years since 1900 */
|
|
|
|
#if 0 /* not supported */
|
|
|
|
int tm_wday; /* day of the week (0-6) */
|
|
|
|
int tm_yday; /* day of the year (0-365) */
|
|
|
|
int tm_isdst; /* non-0 if daylight savings time is in effect */
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2007-03-21 00:51:12 +08:00
|
|
|
/* Struct itimerspec is used to define settings for an interval timer */
|
|
|
|
|
|
|
|
struct itimerspec
|
|
|
|
{
|
|
|
|
struct timespec it_value; /* First time */
|
|
|
|
struct timespec it_interval; /* and thereafter */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* forward reference (defined in signal.h) */
|
|
|
|
|
|
|
|
struct sigevent;
|
|
|
|
|
|
|
|
/********************************************************************************
|
2007-02-18 07:21:28 +08:00
|
|
|
* Global Variables
|
2007-03-21 00:51:12 +08:00
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
/* extern char *tznames[]; not supported */
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2007-03-21 00:51:12 +08:00
|
|
|
/********************************************************************************
|
2007-02-18 07:21:28 +08:00
|
|
|
* Global Function Prototypes
|
2007-03-21 00:51:12 +08:00
|
|
|
********************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2007-03-21 00:51:12 +08:00
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define EXTERN extern "C"
|
|
|
|
extern "C" {
|
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
|
|
|
EXTERN int clock_settime(clockid_t clockid, const struct timespec *tp);
|
|
|
|
EXTERN int clock_gettime(clockid_t clockid, struct timespec *tp);
|
|
|
|
EXTERN int clock_getres(clockid_t clockid, struct timespec *res);
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2009-07-12 23:16:00 +08:00
|
|
|
EXTERN time_t mktime(const struct tm *tp);
|
2009-07-12 08:41:06 +08:00
|
|
|
EXTERN struct tm *gmtime(const time_t *clock);
|
2007-02-18 07:21:28 +08:00
|
|
|
EXTERN struct tm *gmtime_r(const time_t *clock, struct tm *result);
|
2009-07-12 23:16:00 +08:00
|
|
|
EXTERN size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2007-03-21 08:56:49 +08:00
|
|
|
EXTERN int timer_create(clockid_t clockid, FAR struct sigevent *evp, FAR timer_t *timerid);
|
2007-03-21 00:51:12 +08:00
|
|
|
EXTERN int timer_delete(timer_t timerid);
|
2007-03-21 08:56:49 +08:00
|
|
|
EXTERN int timer_settime(timer_t timerid, int flags, FAR const struct itimerspec *value,
|
|
|
|
FAR struct itimerspec *ovalue);
|
|
|
|
EXTERN int timer_gettime(timer_t timerid, FAR struct itimerspec *value);
|
2007-03-21 00:51:12 +08:00
|
|
|
EXTERN int timer_getoverrun(timer_t timerid);
|
|
|
|
|
2007-02-18 07:21:28 +08:00
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-11-17 00:36:30 +08:00
|
|
|
#endif /* __INCLUDE_TIME_H */
|