diff options
-rw-r--r-- | cpukit/include/rtems/score/todimpl.h | 16 | ||||
-rw-r--r-- | cpukit/rtems/src/clocktodtoseconds.c | 2 | ||||
-rw-r--r-- | cpukit/rtems/src/clocktodvalidate.c | 1 | ||||
-rw-r--r-- | testsuites/sptests/sp2038/init.c | 28 |
4 files changed, 36 insertions, 11 deletions
diff --git a/cpukit/include/rtems/score/todimpl.h b/cpukit/include/rtems/score/todimpl.h index 9805ec0dfd..316a56ec74 100644 --- a/cpukit/include/rtems/score/todimpl.h +++ b/cpukit/include/rtems/score/todimpl.h @@ -124,6 +124,22 @@ extern "C" { #define TOD_BASE_YEAR 1988 /** + * @brief Latest year to which a time of day can be initialized. + * + * The following constant defines the latest year to which an + * RTEMS time of day can be set using rtems_clock_set(). + * + * 32 bits can accept as latest point in time 2106-Feb-7 6:28:15 + * but to simplify the implementation, is was decided to only + * check that the year is not greater than the year of this constant. + * + * The internal realtime clock can run centuries longer but in + * contrast to the POSIX API, the RTEMS Classic API does not + * support this for efficiency reasons. + */ +#define TOD_LATEST_YEAR 2105 + +/** * @addtogroup RTEMSScoreTOD * * This handler encapsulates functionality used to manage time of day. diff --git a/cpukit/rtems/src/clocktodtoseconds.c b/cpukit/rtems/src/clocktodtoseconds.c index 49ae257243..86e89f86eb 100644 --- a/cpukit/rtems/src/clocktodtoseconds.c +++ b/cpukit/rtems/src/clocktodtoseconds.c @@ -23,7 +23,7 @@ #include <rtems/rtems/clockimpl.h> #include <rtems/score/todimpl.h> -#define TOD_SECONDS_AT_2100_03_01_00_00 4107538800UL +#define TOD_SECONDS_AT_2100_03_01_00_00 4107542400UL /* * The following array contains the number of days in all months diff --git a/cpukit/rtems/src/clocktodvalidate.c b/cpukit/rtems/src/clocktodvalidate.c index d8af275d04..2685bfd6e7 100644 --- a/cpukit/rtems/src/clocktodvalidate.c +++ b/cpukit/rtems/src/clocktodvalidate.c @@ -52,6 +52,7 @@ bool _TOD_Validate( (the_tod->month == 0) || (the_tod->month > TOD_MONTHS_PER_YEAR) || (the_tod->year < TOD_BASE_YEAR) || + (the_tod->year > TOD_LATEST_YEAR) || (the_tod->day == 0) ) return false; diff --git a/testsuites/sptests/sp2038/init.c b/testsuites/sptests/sp2038/init.c index a3f09d4156..10850d9c4d 100644 --- a/testsuites/sptests/sp2038/init.c +++ b/testsuites/sptests/sp2038/init.c @@ -149,8 +149,7 @@ static const uint32_t sample_seconds [] = { 4168736895UL, 4200272895UL, 4231808895UL, - 4263431295UL, - 4294967295UL + 4263431295UL }; static const rtems_time_of_day nearly_problem_2038 = { @@ -171,8 +170,8 @@ static const rtems_time_of_day problem_2038 = { .second = 8 }; -static const rtems_time_of_day nearly_problem_2106 = { - .year = 2106, +static const rtems_time_of_day tod_to_seconds_base = { + .year = 0, .month = 2, .day = 7, .hour = 6, @@ -180,13 +179,22 @@ static const rtems_time_of_day nearly_problem_2106 = { .second = 15 }; +static const rtems_time_of_day nearly_problem_2106 = { + .year = 2105, + .month = 12, + .day = 31, + .hour = 23, + .minute = 59, + .second = 59 +}; + static const rtems_time_of_day problem_2106 = { .year = 2106, - .month = 2, - .day = 7, - .hour = 6, - .minute = 28, - .second = 16 + .month = 1, + .day = 1, + .hour = 0, + .minute = 0, + .second = 0 }; static const rtems_time_of_day problem_2100 = { @@ -214,7 +222,7 @@ static void test_tod_to_seconds(void) size_t n = sizeof(sample_seconds) / sizeof(sample_seconds [0]); for (i = 0; i < n; ++i) { - rtems_time_of_day tod = nearly_problem_2106; + rtems_time_of_day tod = tod_to_seconds_base; uint32_t seconds = 0; rtems_interval seconds_as_interval = 0; |