2023-05-03 16:11:05 +02:00
|
|
|
/****************************************************************************
|
2008-11-16 17:36:30 +01:00
|
|
|
* include/time.h
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2023-05-03 16:11:05 +02: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
|
|
|
|
2023-05-03 16:11:05 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2023-05-03 16:11:05 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
#include <nuttx/config.h>
|
2016-08-25 16:00:50 +02:00
|
|
|
#include <nuttx/compiler.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
|
|
|
|
2023-05-03 16:11:05 +02:00
|
|
|
/****************************************************************************
|
2009-12-15 00:32:23 +01:00
|
|
|
* Pre-processor Definitions
|
2023-05-03 16:11:05 +02: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
|
|
|
*
|
2023-05-03 16:11:05 +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.
|
2011-04-12 16:14:47 +02:00
|
|
|
*
|
|
|
|
* 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
|
2023-05-20 00:32:34 +02:00
|
|
|
# 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
|
2023-05-20 00:32:34 +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
|
|
|
*/
|
|
|
|
|
2023-01-19 14:59:25 +01:00
|
|
|
#define CLOCK_REALTIME 0
|
2011-05-06 23:10:00 +02:00
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2023-01-19 14:59:25 +01:00
|
|
|
#define CLOCK_MONOTONIC 1
|
|
|
|
|
|
|
|
/* Clock that measures CPU time consumed by this process (i.e., CPU
|
|
|
|
* time consumed by all threads in the process).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define CLOCK_PROCESS_CPUTIME_ID 2
|
|
|
|
|
|
|
|
/* Clock that measures CPU time consumed by this thread */
|
|
|
|
|
|
|
|
#define CLOCK_THREAD_CPUTIME_ID 3
|
2014-03-31 17:25:50 +02:00
|
|
|
|
2020-12-05 09:40:48 +01:00
|
|
|
/* Monotonic system-wide clock that includes time spent in suspension. */
|
|
|
|
|
2023-01-19 14:59:25 +01:00
|
|
|
#define CLOCK_BOOTTIME 4
|
2020-12-05 09:40:48 +01:00
|
|
|
|
2017-11-12 00:44:59 +01:00
|
|
|
/* This is a flag that may be passed to the timer_settime() and
|
|
|
|
* clock_nanosleep() functions.
|
|
|
|
*/
|
2007-03-21 01:56:49 +01:00
|
|
|
|
2023-01-19 14:59:25 +01:00
|
|
|
#define TIMER_ABSTIME 1
|
2007-03-21 01:56:49 +01:00
|
|
|
|
2020-06-01 08:17:51 +02:00
|
|
|
/* Time base values for timespec_get. */
|
|
|
|
|
2023-01-19 14:59:25 +01:00
|
|
|
#define TIME_UTC 1
|
2020-06-01 08:17:51 +02:00
|
|
|
|
2021-07-28 16:44:44 +02:00
|
|
|
/* Redirect the timelocal and strftime_l */
|
2021-06-21 18:28:56 +02:00
|
|
|
|
2021-07-28 16:44:44 +02:00
|
|
|
#define timelocal mktime
|
|
|
|
#define strftime_l(s, m, f, t, l) strftime(s, m, f, t)
|
2020-09-16 15:17:42 +02:00
|
|
|
|
2023-05-03 16:11:05 +02:00
|
|
|
/****************************************************************************
|
2013-12-13 03:12:33 +01:00
|
|
|
* Public Types
|
2023-05-03 16:11:05 +02:00
|
|
|
****************************************************************************/
|
2016-08-25 16:00:50 +02:00
|
|
|
|
2015-02-15 20:00:44 +01:00
|
|
|
/* struct timespec is the standard representation of time as seconds and
|
|
|
|
* nanoseconds.
|
|
|
|
*/
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
struct timespec
|
|
|
|
{
|
|
|
|
time_t tv_sec; /* Seconds */
|
|
|
|
long tv_nsec; /* Nanoseconds */
|
|
|
|
};
|
|
|
|
|
2015-02-15 20:00:44 +01:00
|
|
|
/* struct tm is the standard representation for "broken out" time.
|
|
|
|
*
|
|
|
|
* REVISIT: This structure could be packed better using uint8_t's and
|
|
|
|
* uint16_t's. The standard definition does, however, call out type int for
|
|
|
|
* all of the members. NOTE: Any changes to this structure must be also be
|
2015-06-13 02:07:47 +02:00
|
|
|
* reflected in struct rtc_time defined in include/nuttx/timers/rtc.h; these
|
|
|
|
* two structures must be cast compatible.
|
2015-02-15 20:00:44 +01:00
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
struct tm
|
|
|
|
{
|
2020-09-16 15:12:05 +02:00
|
|
|
int tm_sec; /* Seconds (0-61, allows for leap seconds) */
|
|
|
|
int tm_min; /* Minutes (0-59) */
|
|
|
|
int tm_hour; /* Hours (0-23) */
|
|
|
|
int tm_mday; /* Day of the month (1-31) */
|
|
|
|
int tm_mon; /* Month (0-11) */
|
|
|
|
int tm_year; /* Years since 1900 */
|
|
|
|
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 */
|
|
|
|
long tm_gmtoff; /* Offset from UTC in seconds */
|
|
|
|
const char *tm_zone; /* Timezone abbreviation. */
|
2007-02-18 00:21:28 +01:00
|
|
|
};
|
|
|
|
|
2007-03-20 17:51:12 +01:00
|
|
|
/* Struct itimerspec is used to define settings for an interval timer */
|
|
|
|
|
|
|
|
struct itimerspec
|
|
|
|
{
|
2022-06-02 14:06:16 +02:00
|
|
|
struct timespec it_interval; /* Thereafter */
|
2007-03-20 17:51:12 +01:00
|
|
|
struct timespec it_value; /* First time */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* forward reference (defined in signal.h) */
|
|
|
|
|
|
|
|
struct sigevent;
|
|
|
|
|
2023-05-03 16:11:05 +02:00
|
|
|
/****************************************************************************
|
2013-12-13 03:12:33 +01:00
|
|
|
* Public Data
|
2023-05-03 16:11:05 +02:00
|
|
|
****************************************************************************/
|
2007-03-20 17:51:12 +01:00
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define EXTERN extern "C"
|
2015-02-15 20:00:44 +01:00
|
|
|
extern "C"
|
|
|
|
{
|
2007-03-20 17:51:12 +01:00
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
2015-04-14 18:46:05 +02:00
|
|
|
#ifdef CONFIG_LIBC_LOCALTIME
|
|
|
|
|
2015-02-15 22:18:35 +01:00
|
|
|
/* daylight - Daylight savings time flag */
|
2020-01-23 15:17:22 +01:00
|
|
|
|
2015-02-15 22:18:35 +01:00
|
|
|
/* EXTERN int daylight; not supported */
|
|
|
|
|
2015-02-18 02:21:07 +01:00
|
|
|
/* timezone - Difference from UTC and local standard time */
|
2020-01-23 15:17:22 +01:00
|
|
|
|
2015-02-15 22:18:35 +01:00
|
|
|
/* EXTERN long int timezone; not supported */
|
|
|
|
|
2015-04-14 18:46:05 +02:00
|
|
|
/* tzname[] - Timezone strings
|
|
|
|
* Setup by tzset()
|
|
|
|
*/
|
|
|
|
|
|
|
|
EXTERN FAR char *tzname[2];
|
|
|
|
#endif
|
2015-02-15 22:18:35 +01:00
|
|
|
|
2023-05-03 16:11:05 +02:00
|
|
|
/****************************************************************************
|
2015-02-15 22:18:35 +01:00
|
|
|
* Public Function Prototypes
|
2023-05-03 16:11:05 +02:00
|
|
|
****************************************************************************/
|
2015-02-15 22:18:35 +01:00
|
|
|
|
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);
|
2023-06-21 11:26:35 +02:00
|
|
|
int clock_getcpuclockid(pid_t pid, FAR clockid_t *clockid);
|
2020-06-26 08:40:13 +02:00
|
|
|
int timespec_get(FAR struct timespec *t, int b);
|
2020-06-01 08:17:51 +02:00
|
|
|
|
2021-06-21 18:28:56 +02:00
|
|
|
time_t timegm(FAR struct tm *tp);
|
2014-08-12 14:18:22 +02:00
|
|
|
time_t mktime(FAR struct tm *tp);
|
2021-06-21 18:28:56 +02:00
|
|
|
|
2015-06-12 19:52:49 +02:00
|
|
|
FAR struct tm *gmtime(FAR const time_t *timep);
|
|
|
|
FAR struct tm *gmtime_r(FAR const time_t *timep, FAR struct tm *result);
|
|
|
|
|
|
|
|
FAR struct tm *localtime(FAR const time_t *timep);
|
|
|
|
FAR struct tm *localtime_r(FAR const time_t *timep, FAR struct tm *result);
|
|
|
|
|
2015-02-15 23:38:18 +01:00
|
|
|
size_t strftime(FAR char *s, size_t max, FAR const char *format,
|
2022-12-12 08:43:47 +01:00
|
|
|
FAR const struct tm *tm) strftime_like(3);
|
2021-04-08 09:34:16 +02:00
|
|
|
FAR char *strptime(FAR const char *s, FAR const char *format,
|
2022-04-11 09:44:59 +02:00
|
|
|
FAR struct tm *tm);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-06-12 19:52:49 +02:00
|
|
|
FAR char *asctime(FAR const struct tm *tp);
|
|
|
|
FAR char *asctime_r(FAR const struct tm *tp, FAR char *buf);
|
|
|
|
FAR char *ctime(FAR const time_t *timep);
|
|
|
|
FAR char *ctime_r(FAR const time_t *timep, FAR char *buf);
|
|
|
|
|
|
|
|
time_t time(FAR time_t *timep);
|
2011-04-12 16:14:47 +02:00
|
|
|
|
2016-08-25 16:00:50 +02:00
|
|
|
#ifdef CONFIG_HAVE_DOUBLE
|
2016-08-24 23:43:57 +02:00
|
|
|
double difftime(time_t time1, time_t time0);
|
2024-05-15 04:39:58 +02:00
|
|
|
#elif defined(CONFIG_HAVE_FLOAT)
|
2016-08-25 16:00:50 +02:00
|
|
|
float difftime(time_t time1, time_t time0);
|
2016-08-24 23:43:57 +02:00
|
|
|
#endif
|
|
|
|
|
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);
|
|
|
|
|
2017-11-12 00:44:59 +01:00
|
|
|
int clock_nanosleep(clockid_t clockid, int flags,
|
|
|
|
FAR const struct timespec *rqtp,
|
|
|
|
FAR struct timespec *rmtp);
|
2013-12-13 03:12:33 +01:00
|
|
|
int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp);
|
2007-03-20 17:51:12 +01:00
|
|
|
|
2015-04-14 18:46:05 +02:00
|
|
|
#ifdef CONFIG_LIBC_LOCALTIME
|
|
|
|
void tzset(void);
|
|
|
|
#endif
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* __INCLUDE_TIME_H */
|