source: rtems/cpukit/rtems/src/clocktodtoseconds.c @ 9d06996

4.104.115
Last change on this file since 9d06996 was 9d06996, checked in by Joel Sherrill <joel.sherrill@…>, on 05/04/09 at 11:09:05

2009-05-04 Joel Sherrill <joel.sherrill@…>

  • rtems/include/rtems/rtems/clock.h, rtems/src/clocktodtoseconds.c, rtems/src/clocktodvalidate.c: Add const to parameter.
  • Property mode set to 100644
File size: 2.0 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/*
22 *  The following array contains the number of days in all months
23 *  up to the month indicated by the index of the second dimension.
24 *  The first dimension should be 1 for leap years, and 0 otherwise.
25 */
26const uint16_t   _TOD_Days_to_date[2][13] = {
27  { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 },
28  { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }
29};
30
31/*
32 *  The following array contains the number of days in the years
33 *  since the last leap year.  The index should be 0 for leap
34 *  years, and the number of years since the beginning of a leap
35 *  year otherwise.
36 */
37const uint16_t   _TOD_Days_since_last_leap_year[4] = { 0, 366, 731, 1096 };
38
39
40
41/*PAGE
42 *
43 *  _TOD_To_seconds
44 *
45 *  This routine returns the seconds from the epoch until the
46 *  current date and time.
47 *
48 *  Input parameters:
49 *    the_tod - pointer to the time and date structure
50 *
51 *  Output parameters:
52 *    returns    - seconds since epoch until the_tod
53 */
54
55uint32_t   _TOD_To_seconds(
56  const rtems_time_of_day *the_tod
57)
58{
59  uint32_t   time;
60  uint32_t   year_mod_4;
61
62  time = the_tod->day - 1;
63  year_mod_4 = the_tod->year & 3;
64
65  if ( year_mod_4 == 0 )
66    time += _TOD_Days_to_date[ 1 ][ the_tod->month ];
67  else
68    time += _TOD_Days_to_date[ 0 ][ the_tod->month ];
69
70  time += ( (the_tod->year - TOD_BASE_YEAR) / 4 ) *
71            ( (TOD_DAYS_PER_YEAR * 4) + 1);
72
73  time += _TOD_Days_since_last_leap_year[ year_mod_4 ];
74
75  time *= TOD_SECONDS_PER_DAY;
76
77  time += ((the_tod->hour * TOD_MINUTES_PER_HOUR) + the_tod->minute)
78             * TOD_SECONDS_PER_MINUTE;
79
80  time += the_tod->second;
81
82  time += TOD_SECONDS_1970_THROUGH_1988;
83
84  return( time );
85}
Note: See TracBrowser for help on using the repository browser.