source: rtems/cpukit/rtems/src/clocktodtoseconds.c @ 66cb142

Last change on this file since 66cb142 was 10e4000, checked in by Gedare Bloom <gedare@…>, on Jun 23, 2016 at 6:40:43 PM

cpukit/rtems: fix return type mismatch for _TOD_To_seconds

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief TOD to Seconds
5 *  @ingroup ClassicClock
6 */
7
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#if 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 */
31const 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 */
42const uint16_t   _TOD_Days_since_last_leap_year[4] = { 0, 366, 731, 1096 };
43
44
45Watchdog_Interval   _TOD_To_seconds(
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)
68             * TOD_SECONDS_PER_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
78  time += TOD_SECONDS_1970_THROUGH_1988;
79
80  return( time );
81}
Note: See TracBrowser for help on using the repository browser.