RTEMS
clocktodtoseconds.c
Go to the documentation of this file.
1 
8 /*
9  * COPYRIGHT (c) 1989-2007.
10  * On-Line Applications Research Corporation (OAR).
11  *
12  * The license and distribution terms for this file may be
13  * found in the file LICENSE in this distribution or at
14  * http://www.rtems.org/license/LICENSE.
15  */
16 
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20 
21 #include <rtems/rtems/clock.h>
22 #include <rtems/score/todimpl.h>
23 
24 #define TOD_SECONDS_AT_2100_03_01_00_00 4107538800UL
25 
26 /*
27  * The following array contains the number of days in all months
28  * up to the month indicated by the index of the second dimension.
29  * The first dimension should be 1 for leap years, and 0 otherwise.
30  */
31 const uint16_t _TOD_Days_to_date[2][13] = {
32  { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 },
33  { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }
34 };
35 
36 /*
37  * The following array contains the number of days in the years
38  * since the last leap year. The index should be 0 for leap
39  * years, and the number of years since the beginning of a leap
40  * year otherwise.
41  */
42 const uint16_t _TOD_Days_since_last_leap_year[4] = { 0, 366, 731, 1096 };
43 
44 
46  const rtems_time_of_day *the_tod
47 )
48 {
49  uint32_t time;
50  uint32_t year_mod_4;
51 
52  time = the_tod->day - 1;
53  year_mod_4 = the_tod->year & 3;
54 
55  if ( year_mod_4 == 0 )
56  time += _TOD_Days_to_date[ 1 ][ the_tod->month ];
57  else
58  time += _TOD_Days_to_date[ 0 ][ the_tod->month ];
59 
60  time += ( (the_tod->year - TOD_BASE_YEAR) / 4 ) *
61  ( (TOD_DAYS_PER_YEAR * 4) + 1);
62 
63  time += _TOD_Days_since_last_leap_year[ year_mod_4 ];
64 
65  time *= TOD_SECONDS_PER_DAY;
66 
67  time += ((the_tod->hour * TOD_MINUTES_PER_HOUR) + the_tod->minute)
69 
70  time += the_tod->second;
71 
72  /* The year 2100 is not a leap year */
73  if ( time
74  >= (TOD_SECONDS_AT_2100_03_01_00_00 - TOD_SECONDS_1970_THROUGH_1988)) {
75  time -= TOD_SECONDS_PER_DAY;
76  }
77 
79 
80  return( time );
81 }
This header file defines the Clock Manager API.
uint32_t Watchdog_Interval
Type is used to specify the length of intervals.
Definition: watchdogticks.h:38
This type is used to represent the calendar time in the Classic API.
Definition: types.h:258
#define TOD_SECONDS_PER_DAY
Definition: todimpl.h:75
uint32_t day
This member represents the day of the month with values from 1 to 31.
Definition: types.h:273
Time of Day Handler API.
#define TOD_DAYS_PER_YEAR
Definition: todimpl.h:64
Watchdog_Interval _TOD_To_seconds(const rtems_time_of_day *the_tod)
%
uint32_t month
This member represents the month of the year with values from 1 to 12.
Definition: types.h:268
#define TOD_SECONDS_PER_MINUTE
Definition: todimpl.h:49
#define TOD_MINUTES_PER_HOUR
Definition: todimpl.h:54
#define TOD_BASE_YEAR
Earliest year to which an time of day can be initialized.
Definition: todimpl.h:122
uint32_t hour
This member represents the hour of the day with values from 0 to 23.
Definition: types.h:278
uint32_t second
This member represents the second of the minute with values from 0 to 59.
Definition: types.h:290
uint32_t minute
This member represents the minute of the hour with values from 0 to 59.
Definition: types.h:284
uint32_t year
This member represents the year A.D.
Definition: types.h:262
#define TOD_SECONDS_1970_THROUGH_1988
Definition: todimpl.h:111