Tizen RT Libs&Environment  v1.0 D5
time.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the License.
16  *
17  ****************************************************************************/
18 /********************************************************************************
19  * include/time.h
20  *
21  * Copyright (C) 2007-2011, 2013-2014 Gregory Nutt. All rights reserved.
22  * Author: Gregory Nutt <gnutt@nuttx.org>
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  *
28  * 1. Redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer.
30  * 2. Redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in
32  * the documentation and/or other materials provided with the
33  * distribution.
34  * 3. Neither the name NuttX nor the names of its contributors may be
35  * used to endorse or promote products derived from this software
36  * without specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
41  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
42  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
43  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
45  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
46  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
48  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49  * POSSIBILITY OF SUCH DAMAGE.
50  *
51  ********************************************************************************/
58 
61 #ifndef __INCLUDE_TIME_H
62 #define __INCLUDE_TIME_H
63 
64 /********************************************************************************
65  * Included Files
66  ********************************************************************************/
67 
68 #include <tinyara/config.h>
69 
70 #include <sys/types.h>
71 #include <stdint.h>
72 
73 /********************************************************************************
74  * Pre-processor Definitions
75  ********************************************************************************/
76 
77 /* Clock tick of the system (frequency Hz).
78  *
79  * NOTE: This symbolic name CLK_TCK has been removed from the standard. It is
80  * replaced with CLOCKS_PER_SEC. Both are defined here.
81  *
82  * The default value is 100Hz, but this default setting can be overridden by
83  * defining the clock interval in microseconds as CONFIG_USEC_PER_TICK in the
84  * board configuration file.
85  */
90 #ifdef CONFIG_USEC_PER_TICK
91 #define CLK_TCK (1000000/CONFIG_USEC_PER_TICK)
92 #define CLOCKS_PER_SEC (1000000/CONFIG_USEC_PER_TICK)
93 #else
94 #define CLK_TCK (100)
95 #define CLOCKS_PER_SEC (100)
96 #endif
97 
98 /* CLOCK_REALTIME refers to the standard time source. For most
99  * implementations, the standard time source is the system timer interrupt.
100  * However, if the platform supports an RTC, then the standard time source
101  * will be the RTC for the clock_gettime() and clock_settime() interfaces
102  * (the system timer is still the time source for all of the interfaces).
103  *
104  * CLOCK_REALTIME represents the machine's best-guess as to the current
105  * wall-clock, time-of-day time. This means that CLOCK_REALTIME can jump
106  * forward and backward as the system time-of-day clock is changed.
107  */
108 
109 #define CLOCK_REALTIME 0
110 
111 /* Clock that cannot be set and represents monotonic time since some
112  * unspecified starting point. It is not affected by changes in the
113  * system time-of-day clock.
114  */
115 
116 #ifdef CONFIG_CLOCK_MONOTONIC
117 #define CLOCK_MONOTONIC 1
118 #endif
119 
120 /* This is a flag that may be passed to the timer_settime() function */
121 
122 #define TIMER_ABSTIME 1
123 
124 #ifndef CONFIG_LIBC_LOCALTIME
125 /* Local time is the same as gmtime in this implementation */
126 
132 #define localtime(c) gmtime(c)
133 
138 #define localtime_r(c, r) gmtime_r(c, r)
139 #endif
140 
141 /********************************************************************************
142  * Public Types
143  ********************************************************************************/
144 
145 typedef uint32_t time_t; /* Holds time in seconds */
146 typedef uint8_t clockid_t; /* Identifies one time base source */
147 typedef FAR void *timer_t; /* Represents one POSIX timer */
148 
152 struct timespec {
153  time_t tv_sec; /* Seconds */
154  long tv_nsec; /* Nanoseconds */
155 };
156 
160 struct timeval {
161  time_t tv_sec; /* Seconds */
162  long tv_usec; /* Microseconds */
163 };
164 
168 struct tm {
169  int tm_sec; /* second (0-61, allows for leap seconds) */
170  int tm_min; /* minute (0-59) */
171  int tm_hour; /* hour (0-23) */
172  int tm_mday; /* day of the month (1-31) */
173  int tm_mon; /* month (0-11) */
174  int tm_year; /* years since 1900 */
175 #ifdef CONFIG_LIBC_LOCALTIME
176  int tm_wday; /* day of the week (0-6) */
177  int tm_yday; /* day of the year (0-365) */
178  int tm_isdst; /* non-0 if daylight savings time is in effect */
179 #endif
180 };
181 
185 struct itimerspec {
186  struct timespec it_value; /* First time */
187  struct timespec it_interval; /* and thereafter */
188 };
189 
190 /* forward reference (defined in signal.h) */
191 
192 struct sigevent;
193 
196 /********************************************************************************
197  * Public Data
198  ********************************************************************************/
199 
200 /* extern char *tznames[]; not supported */
201 
202 /********************************************************************************
203  * Public Function Prototypes
204  ********************************************************************************/
205 
206 #undef EXTERN
207 #if defined(__cplusplus)
208 #define EXTERN extern "C"
209 extern "C" {
210 #else
211 #define EXTERN extern
212 #endif
213 
220 int clock_settime(clockid_t clockid, FAR const struct timespec *tp);
227 int clock_gettime(clockid_t clockid, FAR struct timespec *tp);
234 int clock_getres(clockid_t clockid, FAR struct timespec *res);
235 
241 time_t mktime(FAR struct tm *tp);
247 FAR struct tm *gmtime(FAR const time_t *timer);
253 FAR struct tm *gmtime_r(FAR const time_t *timer, FAR struct tm *result);
254 
255 #ifdef CONFIG_LIBC_LOCALTIME
256 
261 FAR struct tm *localtime(FAR const time_t *timer);
267 FAR struct tm *localtime_r(FAR const time_t *timer, FAR struct tm *result);
268 
269 #endif
270 
275 size_t strftime(char *s, size_t max, FAR const char *format, FAR const struct tm *tm);
276 
277 #ifdef CONFIG_ENABLE_IOTIVITY
278 
282 char *strptime(const char *buf, const char *fmt, struct tm *tm);
286 #ifdef CONFIG_HAVE_DOUBLE
287 double difftime(time_t time1, time_t time0);
288 #else
289 float difftime(time_t time1, time_t time0);
290 #endif
291 
294 #endif
295 
301 time_t time(FAR time_t *tloc);
302 
309 int timer_create(clockid_t clockid, FAR struct sigevent *evp, FAR timer_t *timerid);
316 int timer_delete(timer_t timerid);
323 int timer_settime(timer_t timerid, int flags, FAR const struct itimerspec *value, FAR struct itimerspec *ovalue);
330 int timer_gettime(timer_t timerid, FAR struct itimerspec *value);
335 int timer_getoverrun(timer_t timerid);
353 int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp);
354 
355 #undef EXTERN
356 #if defined(__cplusplus)
357 }
358 #endif
359 
360 #endif /* __INCLUDE_TIME_H */
FAR struct tm * gmtime_r(FAR const time_t *timer, FAR struct tm *result)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
uint8_t clockid_t
Definition: time.h:146
int timer_settime(timer_t timerid, int flags, FAR const struct itimerspec *value, FAR struct itimerspec *ovalue)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
long tv_nsec
Definition: time.h:154
int clock_getres(clockid_t clockid, FAR struct timespec *res)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int clock_gettime(clockid_t clockid, FAR struct timespec *tp)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
uint32_t time_t
Definition: time.h:145
int tm_mday
Definition: time.h:172
FAR void * timer_t
Definition: time.h:147
Structure for elements that define a queue signal. The following is used to attach a signal to a mess...
Definition: signal.h:230
#define localtime(c)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
Definition: time.h:132
time_t time(FAR time_t *tloc)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int timer_delete(timer_t timerid)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp)
high-resolution sleep
long tv_usec
Definition: time.h:162
int tm_min
Definition: time.h:170
structure represents an elapsed time
Definition: time.h:160
Struct itimerspec is used to define settings for an interval timer.
Definition: time.h:185
time_t mktime(FAR struct tm *tp)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int timer_gettime(timer_t timerid, FAR struct itimerspec *value)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
size_t strftime(char *s, size_t max, FAR const char *format, FAR const struct tm *tm)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int tm_mon
Definition: time.h:173
int clock_settime(clockid_t clockid, FAR const struct timespec *tp)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
Structure containing a calendar date and time.
Definition: time.h:168
time_t tv_sec
Definition: time.h:153
int tm_sec
Definition: time.h:169
structure represents an elapsed time
Definition: time.h:152
FAR struct tm * gmtime(FAR const time_t *timer)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int timer_create(clockid_t clockid, FAR struct sigevent *evp, FAR timer_t *timerid)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
int tm_hour
Definition: time.h:171
time_t tv_sec
Definition: time.h:161
#define localtime_r(c, r)
POSIX APIs (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
Definition: time.h:138
int tm_year
Definition: time.h:174