2007-03-20 17:51:12 +01:00
|
|
|
/********************************************************************************
|
2008-11-16 17:36:30 +01:00
|
|
|
* include/time.h
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2014-03-31 17:25:50 +02:00
|
|
|
* Copyright (C) 2007-2011, 2013-2014 Gregory Nutt. All rights reserved.
|
2011-10-02 19:53:17 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* 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-16 17:36:30 +01:00
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
2007-02-18 00:21:28 +01: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-20 17:51:12 +01:00
|
|
|
********************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-11-16 17:36:30 +01:00
|
|
|
#ifndef __INCLUDE_TIME_H
|
|
|
|
#define __INCLUDE_TIME_H
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/********************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2007-03-20 17:51:12 +01:00
|
|
|
********************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
#include <nuttx/config.h>
|
2009-12-15 00:32:23 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
#include <sys/types.h>
|
2009-12-14 16:46:55 +01:00
|
|
|
#include <stdint.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/********************************************************************************
|
2009-12-15 00:32:23 +01:00
|
|
|
* Pre-processor Definitions
|
2007-03-20 17:51:12 +01:00
|
|
|
********************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-12-13 03:12:33 +01:00
|
|
|
/* Clock tick of the system (frequency Hz).
|
2011-04-12 16:14:47 +02:00
|
|
|
*
|
|
|
|
* NOTE: This symbolic name CLK_TCK has been removed from the standard. It is
|
|
|
|
* replaced with CLOCKS_PER_SEC. Both are defined here.
|
|
|
|
*
|
|
|
|
* The default value is 100Hz, but this default setting can be overridden by
|
2014-08-07 21:42:47 +02:00
|
|
|
* defining the clock interval in microseconds as CONFIG_USEC_PER_TICK in the
|
2011-04-12 16:14:47 +02:00
|
|
|
* board configuration file.
|
2007-06-09 17:49:44 +02:00
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-08-07 21:42:47 +02:00
|
|
|
#ifdef CONFIG_USEC_PER_TICK
|
|
|
|
# define CLK_TCK (1000000/CONFIG_USEC_PER_TICK)
|
|
|
|
# define CLOCKS_PER_SEC (1000000/CONFIG_USEC_PER_TICK)
|
2007-06-09 17:49:44 +02:00
|
|
|
#else
|
2011-05-06 23:10:00 +02:00
|
|
|
# define CLK_TCK (100)
|
|
|
|
# define CLOCKS_PER_SEC (100)
|
2007-06-09 17:49:44 +02:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-03-31 17:25:50 +02:00
|
|
|
/* CLOCK_REALTIME refers to the standard time source. For most
|
|
|
|
* implementations, the standard time source is the system timer interrupt.
|
|
|
|
* However, if the platform supports an RTC, then the standard time source
|
|
|
|
* will be the RTC for the clock_gettime() and clock_settime() interfaces
|
|
|
|
* (the system timer is still the time source for all of the interfaces).
|
|
|
|
*
|
|
|
|
* CLOCK_REALTIME represents the machine's best-guess as to the current
|
|
|
|
* wall-clock, time-of-day time. This means that CLOCK_REALTIME can jump
|
|
|
|
* forward and backward as the system time-of-day clock is changed.
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
2011-05-06 23:10:00 +02:00
|
|
|
#define CLOCK_REALTIME 0
|
|
|
|
|
2011-10-03 14:21:20 +02:00
|
|
|
/* If an RTC is supported, then the non-standard CLOCK_ACTIVETIME is also
|
2014-03-31 17:25:50 +02:00
|
|
|
* supported to manage time based on the system timer interrupt separately
|
|
|
|
* from the RTC. This may be necessary, for example, in certain cases where
|
|
|
|
* the system timer interrupt has been stopped in low power modes.
|
2011-10-03 14:21:20 +02:00
|
|
|
*
|
|
|
|
* CLOCK_ACTIVETIME is only recognized by clock_gettime() and clock_settime().
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_RTC
|
|
|
|
# define CLOCK_ACTIVETIME 1
|
|
|
|
#else
|
|
|
|
# define CLOCK_ACTIVETIME CLOCK_REALTIME
|
|
|
|
#endif
|
|
|
|
|
2014-03-31 17:25:50 +02:00
|
|
|
/* Clock that cannot be set and represents monotonic time since some
|
|
|
|
* unspecified starting point. It is not affected by changes in the
|
|
|
|
* system time-of-day clock.
|
|
|
|
*/
|
|
|
|
|
2014-06-23 19:01:31 +02:00
|
|
|
#ifdef CONFIG_CLOCK_MONOTONIC
|
2014-03-31 18:01:03 +02:00
|
|
|
# define CLOCK_MONOTONIC 2
|
|
|
|
#endif
|
2014-03-31 17:25:50 +02:00
|
|
|
|
2007-03-21 01:56:49 +01:00
|
|
|
/* This is a flag that may be passed to the timer_settime() function */
|
|
|
|
|
2011-05-06 23:10:00 +02:00
|
|
|
#define TIMER_ABSTIME 1
|
2007-03-21 01:56:49 +01:00
|
|
|
|
2014-08-12 14:18:22 +02:00
|
|
|
#ifndef CONFIG_LIBC_LOCALTIME
|
2009-07-12 17:16:00 +02:00
|
|
|
/* Local time is the same as gmtime in this implementation */
|
|
|
|
|
2011-05-06 23:10:00 +02:00
|
|
|
#define localtime(c) gmtime(c)
|
|
|
|
#define localtime_r(c,r) gmtime_r(c,r)
|
2014-08-12 14:18:22 +02:00
|
|
|
#endif
|
2009-07-12 17:16:00 +02:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/********************************************************************************
|
2013-12-13 03:12:33 +01:00
|
|
|
* Public Types
|
2007-03-20 17:51:12 +01:00
|
|
|
********************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2009-12-15 00:32:23 +01:00
|
|
|
typedef uint32_t time_t; /* Holds time in seconds */
|
2009-12-14 16:46:55 +01:00
|
|
|
typedef uint8_t clockid_t; /* Identifies one time base source */
|
2007-03-21 18:21:26 +01:00
|
|
|
typedef FAR void *timer_t; /* Represents one POSIX timer */
|
2007-02-18 00:21:28 +01: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 */
|
2014-08-12 14:18:22 +02:00
|
|
|
#ifdef CONFIG_LIBC_LOCALTIME
|
2007-02-18 00:21:28 +01:00
|
|
|
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-20 17:51:12 +01: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;
|
|
|
|
|
|
|
|
/********************************************************************************
|
2013-12-13 03:12:33 +01:00
|
|
|
* Public Data
|
2007-03-20 17:51:12 +01:00
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
/* extern char *tznames[]; not supported */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/********************************************************************************
|
2013-12-13 03:12:33 +01:00
|
|
|
* Public Function Prototypes
|
2007-03-20 17:51:12 +01:00
|
|
|
********************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define EXTERN extern "C"
|
|
|
|
extern "C" {
|
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
2013-12-13 03:12:33 +01:00
|
|
|
clock_t clock(void);
|
2011-04-12 16:14:47 +02:00
|
|
|
|
2013-12-13 03:12:33 +01:00
|
|
|
int clock_settime(clockid_t clockid, FAR const struct timespec *tp);
|
|
|
|
int clock_gettime(clockid_t clockid, FAR struct timespec *tp);
|
|
|
|
int clock_getres(clockid_t clockid, FAR struct timespec *res);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-08-12 14:18:22 +02:00
|
|
|
time_t mktime(FAR struct tm *tp);
|
2013-12-13 03:12:33 +01:00
|
|
|
FAR struct tm *gmtime(FAR const time_t *timer);
|
|
|
|
FAR struct tm *gmtime_r(FAR const time_t *timer, FAR struct tm *result);
|
|
|
|
size_t strftime(char *s, size_t max, FAR const char *format,
|
|
|
|
FAR const struct tm *tm);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-12-13 03:12:33 +01:00
|
|
|
time_t time(FAR time_t *tloc);
|
2011-04-12 16:14:47 +02:00
|
|
|
|
2013-12-13 03:12:33 +01:00
|
|
|
int timer_create(clockid_t clockid, FAR struct sigevent *evp,
|
|
|
|
FAR timer_t *timerid);
|
|
|
|
int timer_delete(timer_t timerid);
|
|
|
|
int timer_settime(timer_t timerid, int flags,
|
|
|
|
FAR const struct itimerspec *value,
|
|
|
|
FAR struct itimerspec *ovalue);
|
|
|
|
int timer_gettime(timer_t timerid, FAR struct itimerspec *value);
|
|
|
|
int timer_getoverrun(timer_t timerid);
|
|
|
|
|
|
|
|
int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp);
|
2007-03-20 17:51:12 +01:00
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-11-16 17:36:30 +01:00
|
|
|
#endif /* __INCLUDE_TIME_H */
|