source: rtems/cpukit/rtems/src/clocktodtoseconds.c @ 8d7aea0d

4.115
Last change on this file since 8d7aea0d was 8d7aea0d, checked in by Sebastian Huber <sebastian.huber@…>, on 09/29/11 at 09:55:54

2011-09-29 Sebastian Huber <sebastian.huber@…>

  • score/include/rtems/score/tod.h: Declare _TOD_Set_with_timestamp() and _TOD_Get_as_timestamp().
  • score/src/coretodset.c: Define _TOD_Set_with_timestamp().
  • score/src/coretodget.c: Define _TOD_Get_as_timestamp().
  • rtems/src/clockset.c: Use _TOD_Set_with_timestamp().
  • score/include/rtems/score/timestamp64.h, score/src/ts64set.c: Changed parameter types of _Timestamp64_Set().
  • rtems/src/clocktodtoseconds.c: Year 2100 is not a leap year.
  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 *  Time of Day (TOD) Handler - Classic TOD to Seconds
3 *
4 *  COPYRIGHT (c) 1989-2007.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <rtems/system.h>
19#include <rtems/rtems/clock.h>
20
21#define TOD_SECONDS_AT_2100_03_01_00_00 4107538800UL
22
23/*
24 *  The following array contains the number of days in all months
25 *  up to the month indicated by the index of the second dimension.
26 *  The first dimension should be 1 for leap years, and 0 otherwise.
27 */
28const uint16_t   _TOD_Days_to_date[2][13] = {
29  { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 },
30  { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }
31};
32
33/*
34 *  The following array contains the number of days in the years
35 *  since the last leap year.  The index should be 0 for leap
36 *  years, and the number of years since the beginning of a leap
37 *  year otherwise.
38 */
39const uint16_t   _TOD_Days_since_last_leap_year[4] = { 0, 366, 731, 1096 };
40
41
42
43/*
44 *  _TOD_To_seconds
45 *
46 *  This routine returns the seconds from the epoch until the
47 *  current date and time.
48 *
49 *  Input parameters:
50 *    the_tod - pointer to the time and date structure
51 *
52 *  Output parameters:
53 *    returns    - seconds since epoch until the_tod
54 */
55
56uint32_t   _TOD_To_seconds(
57  const rtems_time_of_day *the_tod
58)
59{
60  uint32_t   time;
61  uint32_t   year_mod_4;
62
63  time = the_tod->day - 1;
64  year_mod_4 = the_tod->year & 3;
65
66  if ( year_mod_4 == 0 )
67    time += _TOD_Days_to_date[ 1 ][ the_tod->month ];
68  else
69    time += _TOD_Days_to_date[ 0 ][ the_tod->month ];
70
71  time += ( (the_tod->year - TOD_BASE_YEAR) / 4 ) *
72            ( (TOD_DAYS_PER_YEAR * 4) + 1);
73
74  time += _TOD_Days_since_last_leap_year[ year_mod_4 ];
75
76  time *= TOD_SECONDS_PER_DAY;
77
78  time += ((the_tod->hour * TOD_MINUTES_PER_HOUR) + the_tod->minute)
79             * TOD_SECONDS_PER_MINUTE;
80
81  time += the_tod->second;
82
83  /* The year 2100 is not a leap year */
84  if ( time
85      >= (TOD_SECONDS_AT_2100_03_01_00_00 - TOD_SECONDS_1970_THROUGH_1988)) {
86    time -= TOD_SECONDS_PER_DAY;
87  }
88
89  time += TOD_SECONDS_1970_THROUGH_1988;
90
91  return( time );
92}
Note: See TracBrowser for help on using the repository browser.