atmega_common/avr-libc-extra/time.h
1 /*
2  * (C)2012 Michael Duane Rice All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer. Redistributions in binary
10  * form must reproduce the above copyright notice, this list of conditions
11  * and the following disclaimer in the documentation and/or other materials
12  * provided with the distribution. Neither the name of the copyright holders
13  * nor the names of contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /* \cond DOXYGEN_BLACKLIST */
30 
31 /* $Id$ */
32 
101 #ifndef TIME_H
102 #define TIME_H
103 
104 #include <stdint.h>
105 #include <sys/types.h>
106 
107 #ifdef __cplusplus
108 extern "C" {
109 #endif
110 
112  /* @{ */
113 
118  time_t time(time_t *timer);
119 
124  int32_t difftime(time_t time1, time_t time0);
125 
126 
155  struct tm {
156  int tm_sec;
157  int tm_min;
158  int tm_hour;
159  int tm_mday;
160  int tm_wday;
161  int tm_mon;
162  int tm_year;
163  int tm_yday;
164  int tm_isdst;
165  };
166 
167 
168  /* We have to provide clock_t / CLOCKS_PER_SEC so that libstdc++-v3 can
169  be built. We define CLOCKS_PER_SEC via a symbol _CLOCKS_PER_SEC_
170  so that the user can provide the value on the link line, which should
171  result in little or no run-time overhead compared with a constant. */
172  typedef unsigned long clock_t;
173  extern char *_CLOCKS_PER_SEC_;
174 #define CLOCKS_PER_SEC ((clock_t) _CLOCKS_PER_SEC_)
175  extern clock_t clock(void);
176 
186  time_t mktime(struct tm * timeptr);
187 
197  time_t mk_gmtime(const struct tm * timeptr);
198 
203  struct tm *gmtime(const time_t * timer);
204 
208  void gmtime_r(const time_t * timer, struct tm * timeptr);
209 
214  struct tm *localtime(const time_t * timer);
215 
219  void localtime_r(const time_t * timer, struct tm * timeptr);
220 
226  char *asctime(const struct tm * timeptr);
227 
231  void asctime_r(const struct tm * timeptr, char *buf);
232 
236  char *ctime(const time_t * timer);
237 
241  void ctime_r(const time_t * timer, char *buf);
242 
247  char *isotime(const struct tm * tmptr);
248 
252  void isotime_r(const struct tm *, char *);
253 
261  size_t strftime(char *s, size_t maxsize, const char *format, const struct tm * timeptr);
262 
278  void set_dst(int (*) (const time_t *, int32_t *));
279 
287  void set_zone(int32_t);
288 
312  void set_system_time(time_t timestamp);
313 
331  void system_tick(void);
332 
336  enum _WEEK_DAYS_ {
337  SUNDAY,
338  MONDAY,
339  TUESDAY,
340  WEDNESDAY,
341  THURSDAY,
342  FRIDAY,
343  SATURDAY
344  };
345 
349  enum _MONTHS_ {
350  JANUARY,
351  FEBRUARY,
352  MARCH,
353  APRIL,
354  MAY,
355  JUNE,
356  JULY,
357  AUGUST,
358  SEPTEMBER,
359  OCTOBER,
360  NOVEMBER,
361  DECEMBER
362  };
363 
367  uint8_t is_leap_year(int16_t year);
368 
372  uint8_t month_length(int16_t year, uint8_t month);
373 
378  uint8_t week_of_year(const struct tm * timeptr, uint8_t start);
379 
384  uint8_t week_of_month(const struct tm * timeptr, uint8_t start);
385 
390  struct week_date{
391  int year;
392  int week;
393  int day;
394  };
395 
401  struct week_date * iso_week_date( int year, int yday);
402 
406  void iso_week_date_r( int year, int yday, struct week_date *);
407 
411  uint32_t fatfs_time(const struct tm * timeptr);
412 
414 #define ONE_HOUR 3600
415 
417 #define ONE_DEGREE 3600
418 
420 #define ONE_DAY 86400
421 
432 #define UNIX_OFFSET 946684800
433 
444 #define NTP_OFFSET 3155673600
445 
446  /*
447  * ===================================================================
448  * Ephemera
449  */
450 
459  void set_position(int32_t latitude, int32_t longitude);
460 
465  int16_t equation_of_time(const time_t * timer);
466 
475  int32_t daylight_seconds(const time_t * timer);
476 
480  time_t solar_noon(const time_t * timer);
481 
485  time_t sun_rise(const time_t * timer);
486 
490  time_t sun_set(const time_t * timer);
491 
493  double solar_declination(const time_t * timer);
494 
500  int8_t moon_phase(const time_t * timer);
501 
506  unsigned long gm_sidereal(const time_t * timer);
507 
512  unsigned long lm_sidereal(const time_t * timer);
513 
514  struct timespec {
515  time_t tv_sec;
516  long tv_nsec;
517  };
518 
519  /* @} */
520 
521 /* /endcond */
522 
523 #ifdef __cplusplus
524 }
525 #endif
526 
527 #endif /* TIME_H */
528 
int tm_min
Minutes after the hour [0, 59].
int tm_mday
Day of the month [1, 31].
int tm_year
Years since 1900.
time_t tv_sec
seconds
Definition: msp430_types.h:51
int tm_mon
Months since January [0, 11].
long tv_nsec
nanoseconds
Definition: msp430_types.h:52
Datatype to represent time.
int tm_wday
Days since Sunday [0, 6].
int tm_yday
Days since January 1st [0, 365].
Definition of struct timespec for the MSP430.
Definition: msp430_types.h:50
int tm_sec
Seconds after the minute [0, 60].
int tm_hour
Hours since midnight [0, 23].
int tm_isdst
Daylight saving time is in effect (positive if true, 0 if not, negative if n/a)