AWS IoT FreeRTOS+POSIX
time.h
Go to the documentation of this file.
1 /*
2  * Amazon FreeRTOS POSIX V1.0.0
3  * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * http://aws.amazon.com/freertos
23  * http://www.FreeRTOS.org
24  */
25 
33 #ifndef _FREERTOS_POSIX_TIME_H_
34 #define _FREERTOS_POSIX_TIME_H_
35 
36 /* FreeRTOS+POSIX includes. */
38 #include "FreeRTOS_POSIX/signal.h"
39 
44 #define MICROSECONDS_PER_SECOND ( 1000000LL )
45 #define NANOSECONDS_PER_SECOND ( 1000000000LL )
46 #define NANOSECONDS_PER_TICK ( NANOSECONDS_PER_SECOND / configTICK_RATE_HZ )
53 #define CLOCK_REALTIME 0
54 #define CLOCK_MONOTONIC 1
61 #define CLOCKS_PER_SEC ( ( clock_t ) configTICK_RATE_HZ )
62 
70 #define TIMER_ABSTIME 0x01
71 
73 #if !defined( posixconfigENABLE_TIMESPEC ) || ( posixconfigENABLE_TIMESPEC == 1 )
74 
78  struct timespec
79  {
81  long tv_nsec;
82  };
83 #endif
84 
85 #if !defined( posixconfigENABLE_ITIMERSPEC ) || ( posixconfigENABLE_ITIMERSPEC == 1 )
86 
90  struct itimerspec
91  {
93  struct timespec it_value;
94  };
95 #endif
96 
97 #if !defined( posixconfigENABLE_TM ) || ( posixconfigENABLE_TM == 1 )
98 
102  struct tm
103  {
105  int tm_sec;
106  int tm_min;
107  int tm_hour;
108  int tm_mday;
109  int tm_mon;
110  int tm_year;
111  int tm_wday;
112  int tm_yday;
113  int tm_isdst;
114  };
115 #endif /* if !defined( posixconfigENABLE_TM ) || ( posixconfigENABLE_TM == 1 ) */
116 
127 clock_t clock( void );
128 
139 int clock_getcpuclockid( pid_t pid,
140  clockid_t * clock_id );
141 
152 int clock_getres( clockid_t clock_id,
153  struct timespec * res );
154 
165 int clock_gettime( clockid_t clock_id,
166  struct timespec * tp );
167 
180 int clock_nanosleep( clockid_t clock_id,
181  int flags,
182  const struct timespec * rqtp,
183  struct timespec * rmtp );
184 
194 int clock_settime( clockid_t clock_id,
195  const struct timespec * tp );
196 
213 struct tm * localtime_r( const time_t * timer,
214  struct tm * result );
215 
227 int nanosleep( const struct timespec * rqtp,
228  struct timespec * rmtp );
229 
241 size_t strftime( char * s,
242  size_t maxsize,
243  const char * format,
244  const struct tm * timeptr );
245 
255 time_t time( time_t * tloc );
256 
274 int timer_create( clockid_t clockid,
275  struct sigevent * evp,
276  timer_t * timerid );
277 
285 int timer_delete( timer_t timerid );
286 
294 int timer_getoverrun( timer_t timerid );
295 
303 int timer_gettime( timer_t timerid,
304  struct itimerspec * value );
305 
319 int timer_settime( timer_t timerid,
320  int flags,
321  const struct itimerspec * value,
322  struct itimerspec * ovalue );
323 
324 #endif /* ifndef _FREERTOS_POSIX_TIME_H_ */
int tm_min
Definition: time.h:106
Data types.
int timer_delete(timer_t timerid)
Delete a per-process timer.
Definition: FreeRTOS_POSIX_timer.c:166
int clock_gettime(clockid_t clock_id, struct timespec *tp)
Returns the current value for the specified clock, clock_id.
Definition: FreeRTOS_POSIX_clock.c:90
int tm_mday
Definition: time.h:108
struct timespec it_interval
Definition: time.h:92
int tm_year
Definition: time.h:110
int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, struct itimerspec *ovalue)
Set the time until the next expiration of the timer.
Definition: FreeRTOS_POSIX_timer.c:203
int timer_gettime(timer_t timerid, struct itimerspec *value)
Get the amount of time until the timer expires.
Definition: FreeRTOS_POSIX_timer.c:286
time_t tv_sec
Definition: time.h:80
int clock_getres(clockid_t clock_id, struct timespec *res)
Returns the resolution of a clock.
Definition: FreeRTOS_POSIX_clock.c:72
int clock_getcpuclockid(pid_t pid, clockid_t *clock_id)
Access a process CPU-time clock.
Definition: FreeRTOS_POSIX_clock.c:59
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
High resolution sleep.
Definition: FreeRTOS_POSIX_clock.c:229
int tm_mon
Definition: time.h:109
Signal event structure.
Definition: signal.h:61
int clock_settime(clockid_t clock_id, const struct timespec *tp)
Sets the time for the specified clock.
Definition: FreeRTOS_POSIX_clock.c:187
long tv_nsec
Definition: time.h:81
Signals.
int clockid_t
Used for clock ID type in the clock and timer functions. Enabled/disabled by posixconfigENABLE_CLOCKI...
Definition: types.h:52
struct tm * localtime_r(const time_t *timer, struct tm *result)
Convert a time value to a broken-down local time.
Definition: FreeRTOS_POSIX_clock.c:203
int timer_getoverrun(timer_t timerid)
Get the timer overrun count.
Definition: FreeRTOS_POSIX_timer.c:193
struct timespec it_value
Definition: time.h:93
time_t tm_tick
Definition: time.h:104
timer
Definition: time.h:90
int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, struct timespec *rmtp)
High resolution sleep with specifiable clock.
Definition: FreeRTOS_POSIX_clock.c:126
time_t time(time_t *tloc)
Get time.
Definition: FreeRTOS_POSIX_clock.c:284
clock_t clock(void)
Report CPU time used.
Definition: FreeRTOS_POSIX_clock.c:50
int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid)
Create a per-process timer.
Definition: FreeRTOS_POSIX_timer.c:114
calendar representation of time
Definition: time.h:102
int tm_wday
Definition: time.h:111
int tm_yday
Definition: time.h:112
uint32_t clock_t
Used for system times in clock ticks or CLOCKS_PER_SEC. Enabled/disabled by posixconfigENABLE_CLOCK_T...
Definition: types.h:44
void * timer_t
Used for timer ID returned by timer_create(). Enabled/disabled by posixconfigENABLE_TIMER_T.
Definition: types.h:150
represents an elapsed time
Definition: time.h:78
int tm_sec
Definition: time.h:105
int pid_t
Used for process IDs and process group IDs. Enabled/disabled by posixconfigENABLE_PID_T.
Definition: types.h:68
int tm_hour
Definition: time.h:107
int tm_isdst
Definition: time.h:113
int64_t time_t
Used for time in seconds. Enabled/disabled by posixconfigENABLE_TIME_T.
Definition: types.h:142
size_t strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
Convert date and time to a string.
Definition: FreeRTOS_POSIX_clock.c:259