Tizen RT Libs&Environment  v1.1 D4
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 
165 struct timezone {
166  int tz_minuteswest; /* minutes west of Greenwich */
167  int tz_dsttime; /* type of DST correction */
168 };
169 
173 struct tm {
174  int tm_sec; /* second (0-61, allows for leap seconds) */
175  int tm_min; /* minute (0-59) */
176  int tm_hour; /* hour (0-23) */
177  int tm_mday; /* day of the month (1-31) */
178  int tm_mon; /* month (0-11) */
179  int tm_year; /* years since 1900 */
180 #if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED)
181  int tm_wday; /* day of the week (0-6) */
182  int tm_yday; /* day of the year (0-365) */
183  int tm_isdst; /* non-0 if daylight savings time is in effect */
184 #endif
185 };
186 
190 struct itimerspec {
191  struct timespec it_value; /* First time */
192  struct timespec it_interval; /* and thereafter */
193 };
194 
195 /* forward reference (defined in signal.h) */
196 
197 struct sigevent;
198 
202 /********************************************************************************
203  * Public Data
204  ********************************************************************************/
205 
206 /* extern char *tznames[]; not supported */
207 
208 /********************************************************************************
209  * Public Function Prototypes
210  ********************************************************************************/
211 
212 #undef EXTERN
213 #if defined(__cplusplus)
214 #define EXTERN extern "C"
215 extern "C" {
216 #else
217 #define EXTERN extern
218 #endif
219 
228 int clock_settime(clockid_t clockid, FAR const struct timespec *tp);
237 int clock_gettime(clockid_t clockid, FAR struct timespec *tp);
246 int clock_getres(clockid_t clockid, FAR struct timespec *res);
247 
255 time_t mktime(FAR struct tm *tp);
263 FAR struct tm *gmtime(FAR const time_t *timer);
271 FAR struct tm *gmtime_r(FAR const time_t *timer, FAR struct tm *result);
272 
273 #ifdef CONFIG_LIBC_LOCALTIME
274 
281 FAR struct tm *localtime(FAR const time_t *timer);
289 FAR struct tm *localtime_r(FAR const time_t *timer, FAR struct tm *result);
290 
291 #endif
292 
299 size_t strftime(char *s, size_t max, FAR const char *format, FAR const struct tm *tm);
300 
305 #if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED)
306 
309 FAR char *asctime(FAR const struct tm *tp);
313 FAR char *asctime_r(FAR const struct tm *tp, FAR char *buf);
317 FAR char *ctime(FAR const time_t *timep);
321 FAR char *ctime_r(FAR const time_t *timep, FAR char *buf);
322 #endif
323 
327 #ifdef CONFIG_ENABLE_IOTIVITY
328 
332 char *strptime(const char *buf, const char *fmt, struct tm *tm);
336 #ifdef CONFIG_HAVE_DOUBLE
337 double difftime(time_t time1, time_t time0);
338 #else
339 float difftime(time_t time1, time_t time0);
340 #endif
341 
344 #endif
345 
353 time_t time(FAR time_t *tloc);
354 
363 int timer_create(clockid_t clockid, FAR struct sigevent *evp, FAR timer_t *timerid);
372 int timer_delete(timer_t timerid);
381 int timer_settime(timer_t timerid, int flags, FAR const struct itimerspec *value, FAR struct itimerspec *ovalue);
390 int timer_gettime(timer_t timerid, FAR struct itimerspec *value);
395 int timer_getoverrun(timer_t timerid);
414 int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp);
415 
416 #undef EXTERN
417 #if defined(__cplusplus)
418 }
419 #endif
420 
421 #endif /* __INCLUDE_TIME_H */
FAR struct tm * gmtime_r(FAR const time_t *timer, FAR struct tm *result)
convert a time value to a broken-down UTC time
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)
per-process timers
int tz_minuteswest
Definition: time.h:166
long tv_nsec
Definition: time.h:154
int clock_getres(clockid_t clockid, FAR struct timespec *res)
clock and timer functions
int clock_gettime(clockid_t clockid, FAR struct timespec *tp)
clock and timer functions
uint32_t time_t
Definition: time.h:145
int tz_dsttime
Definition: time.h:167
int tm_mday
Definition: time.h:177
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:231
#define localtime(c)
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
Definition: time.h:132
time_t time(FAR time_t *tloc)
get time
int timer_delete(timer_t timerid)
delete a per-process timer
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:175
structure represents an elapsed time
Definition: time.h:160
Struct itimerspec is used to define settings for an interval timer.
Definition: time.h:190
time_t mktime(FAR struct tm *tp)
convert broken-down time into time since the Epoch
int timer_gettime(timer_t timerid, FAR struct itimerspec *value)
per-process timers
size_t strftime(char *s, size_t max, FAR const char *format, FAR const struct tm *tm)
convert date and time to a string
int tm_mon
Definition: time.h:178
int clock_settime(clockid_t clockid, FAR const struct timespec *tp)
clock and timer functions
struct timespec it_interval
Definition: time.h:192
Structure containing a calendar date and time.
Definition: time.h:173
time_t tv_sec
Definition: time.h:153
struct timespec it_value
Definition: time.h:191
int tm_sec
Definition: time.h:174
structure represents an elapsed time
Definition: time.h:152
FAR struct tm * gmtime(FAR const time_t *timer)
convert a time value to a broken-down UTC time
Definition: time.h:165
int timer_create(clockid_t clockid, FAR struct sigevent *evp, FAR timer_t *timerid)
create a per-process timer
int tm_hour
Definition: time.h:176
time_t tv_sec
Definition: time.h:161
#define localtime_r(c, r)
POSIX API (refer to : http://pubs.opengroup.org/onlinepubs/9699919799/)
Definition: time.h:138
int tm_year
Definition: time.h:179