Tenok
A Linux-like Real-Time Operating System for Robotics and Internet of Things
time.h
Go to the documentation of this file.
1 
4 #ifndef __TIME_H__
5 #define __TIME_H__
6 
7 #include <signal.h>
8 #include <stddef.h>
9 #include <stdint.h>
10 #include <sys/types.h>
11 
12 #define CLOCK_REALTIME 0
13 #define CLOCK_MONOTONIC 1
14 #define TIMER_ABSTIME 1
15 
16 struct timespec {
17  time_t tv_sec; /* Seconds */
18  long tv_nsec; /* Nanoseconds */
19 };
20 
21 struct itimerspec {
22  struct timespec it_value;
23  struct timespec it_interval;
24 };
25 
32 int clock_getres(clockid_t clockid, struct timespec *res);
33 
40 int clock_gettime(clockid_t clockid, struct timespec *tp);
41 
48 int clock_settime(clockid_t clockid, const struct timespec *tp);
49 
57 int timer_create(clockid_t clockid, struct sigevent *sevp, timer_t *timerid);
58 
64 int timer_delete(timer_t timerid);
65 
75 int timer_settime(timer_t timerid,
76  int flags,
77  const struct itimerspec *new_value,
78  struct itimerspec *old_value);
79 
86 int timer_gettime(timer_t timerid, struct itimerspec *curr_value);
87 
94 time_t time(time_t *tloc);
95 
102 int nanosleep(const struct timespec *req, struct timespec *rem);
103 
112 int clock_nanosleep(clockid_t clockid,
113  int flags,
114  const struct timespec *req,
115  struct timespec *rem);
116 
117 /* Broken down time. The layout matches newlib, whose implementations of the
118  * calendar helpers below are the ones that get linked
119  */
120 struct tm {
121  int tm_sec;
122  int tm_min;
123  int tm_hour;
124  int tm_mday;
125  int tm_mon;
126  int tm_year;
127  int tm_wday;
128  int tm_yday;
129  int tm_isdst;
130 };
131 
132 struct tm *localtime(const time_t *timep);
133 struct tm *localtime_r(const time_t *timep, struct tm *result);
134 struct tm *gmtime(const time_t *timep);
135 struct tm *gmtime_r(const time_t *timep, struct tm *result);
136 time_t mktime(struct tm *tm);
137 size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);
138 
139 /* Reads back what strftime() writes. The C library brings this one: it reads
140  * a string and writes a struct, and asks the system for nothing
141  */
142 char *strptime(const char *s, const char *format, struct tm *tm);
143 char *ctime(const time_t *timep);
144 char *ctime_r(const time_t *timep, char *buf);
145 
146 #endif
Definition: time.h:21
Definition: signal.h:88
Definition: time.h:16
Definition: time.h:120
int timer_settime(timer_t timerid, int flags, const struct itimerspec *new_value, struct itimerspec *old_value)
Arm or disarm the timer specified by the timer ID.
Definition: time.c:166
int nanosleep(const struct timespec *req, struct timespec *rem)
Suspend execution for a specified time.
Definition: time.c:289
int clock_settime(clockid_t clockid, const struct timespec *tp)
Set the time of the specified clock ID.
Definition: time.c:131
int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *req, struct timespec *rem)
High-resolution sleep with clock selection.
Definition: time.c:248
int timer_create(clockid_t clockid, struct sigevent *sevp, timer_t *timerid)
Create a new per-thread interval timer.
Definition: time.c:143
int clock_getres(clockid_t clockid, struct timespec *res)
Get the resolution (precision) of the specified clock ID.
Definition: time.c:100
time_t time(time_t *tloc)
Return the time as the number of seconds since 1970-01-01 00:00:00 +0000 (UTC)
Definition: time.c:185
int timer_gettime(timer_t timerid, struct itimerspec *curr_value)
Return the timer interval and the time until next expiration.
Definition: time.c:180
int clock_gettime(clockid_t clockid, struct timespec *tp)
Retrieve the time of the specified clock ID.
Definition: time.c:121
int timer_delete(timer_t timerid)
Delete the timer specified with the timer ID.
Definition: time.c:153