diff options
Diffstat (limited to 'cpukit/include/rtems/score/todimpl.h')
-rw-r--r-- | cpukit/include/rtems/score/todimpl.h | 115 |
1 files changed, 77 insertions, 38 deletions
diff --git a/cpukit/include/rtems/score/todimpl.h b/cpukit/include/rtems/score/todimpl.h index 316a56ec74..565e047c7f 100644 --- a/cpukit/include/rtems/score/todimpl.h +++ b/cpukit/include/rtems/score/todimpl.h @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -12,9 +14,26 @@ * COPYRIGHT (c) 1989-2009. * On-Line Applications Research Corporation (OAR). * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ #ifndef _RTEMS_SCORE_TODIMPL_H @@ -24,6 +43,7 @@ #include <rtems/score/timestamp.h> #include <rtems/score/timecounterimpl.h> #include <rtems/score/watchdog.h> +#include <rtems/score/watchdogticks.h> #include <sys/time.h> #include <time.h> @@ -115,6 +135,15 @@ extern "C" { (4 * TOD_SECONDS_PER_DAY)) /** + * @brief Seconds from 1970-01-01T00:00:00Z to 2400-01-01T00:00:00Z. + * + * This is the latest time of day which should be set by _TOD_Set(). The year + * 2400 was chosen to guarantee a defined CLOCK_REALTIME within the range of a + * system uptime of about 114 years. + */ +#define TOD_SECONDS_1970_THROUGH_2400 13569465600 + +/** * @brief Earliest year to which an time of day can be initialized. * * The following constant define the earliest year to which an @@ -132,12 +161,16 @@ extern "C" { * 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 year 2099 was chosen because all years evenly divisible by 4 from 1988 + * to 2099 are leap years. In this time frame, years evenly divisible by 100 + * are no leap years unless they are evenly divisible by 400. Thus the year + * 2000 is a leap year. * - * The internal realtime clock can run centuries longer but in + * The internal CLOCK_REALTIME 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 +#define TOD_LATEST_YEAR 2099 /** * @addtogroup RTEMSScoreTOD @@ -166,6 +199,14 @@ typedef struct { extern TOD_Control _TOD; /** + * @brief This array contains the number of days in all months up to the month + * indicated by the index of the second dimension. + * + * The first dimension should be 0 for leap years, and 1 otherwise. + */ +extern const uint16_t _TOD_Days_to_date[ 2 ][ 13 ]; + +/** * @brief Locks the time of day mutex. */ void _TOD_Lock( void ); @@ -206,12 +247,39 @@ static inline void _TOD_Release( ISR_lock_Context *lock_context ) } /** + * @brief Maps the year to the leap year index. + * + * @param year is the year to map. + * + * @retval 0 The year is a leap year. + * + * @retval 1 The year is not a leap year. + */ +static inline size_t _TOD_Get_leap_year_index( uint32_t year ) +{ + _Assert( year % 4 != 0 || year % 100 != 0 || year % 400 == 0 ); + return ( ( year % 4 ) + 3 ) / 4; +} + +/** + * @brief Checks the time point is a valid new time of day for _TOD_Set(). + * + * @param tod the time of day to check. + * + * @retval STATUS_SUCCESSFUL The time of day is valid. + * + * @retval STATUS_INVALID_NUMBER The time of day is invalid. + */ +Status_Control _TOD_Is_valid_new_time_of_day( const struct timespec *tod ); + +/** * @brief Sets the time of day. * * The caller must be the owner of the TOD lock. * * @param tod The new time of day in timespec format representing - * the time since UNIX Epoch. + * the time since UNIX Epoch. The new time of day shall be valid according + * to _TOD_Is_valid_new_time_of_day(). * @param lock_context The ISR lock context used for the corresponding * _TOD_Acquire(). The caller must be the owner of the TOD lock. This * function will release the TOD lock. @@ -296,26 +364,9 @@ static inline uint32_t _TOD_Seconds_since_epoch( void ) } /** - * @brief Gets number of ticks in a second. - * - * This method returns the number of ticks in a second. - * - * @note If the clock tick value does not multiply evenly into a second - * then this number of ticks will be slightly shorter than a second. - * - * @return The number of ticks in a second. - */ -uint32_t TOD_TICKS_PER_SECOND_method(void); - -/** * @brief Gets number of ticks in a second. - * - * This method exists to hide the fact that TOD_TICKS_PER_SECOND can not - * be implemented as a macro in a .h file due to visibility issues. - * The Configuration Table is not available to SuperCore .h files but - * is available to their .c files. */ -#define TOD_TICKS_PER_SECOND TOD_TICKS_PER_SECOND_method() +#define TOD_TICKS_PER_SECOND _Watchdog_Ticks_per_second /** * @brief This routine returns a timeval based upon the internal timespec @@ -323,7 +374,7 @@ uint32_t TOD_TICKS_PER_SECOND_method(void); * * @param[out] time The timeval to be filled in by the method. */ -RTEMS_INLINE_ROUTINE void _TOD_Get_timeval( +static inline void _TOD_Get_timeval( struct timeval *time ) { @@ -331,24 +382,12 @@ RTEMS_INLINE_ROUTINE void _TOD_Get_timeval( } /** - * @brief Adjusts the Time of Time. - * - * This method is used to adjust the current time of day by the - * specified amount. - * - * @param delta is the amount to adjust. - */ -void _TOD_Adjust( - const struct timespec *delta -); - -/** * @brief Check if the TOD is Set * * @retval true The time is set. * @retval false The time is not set. */ -RTEMS_INLINE_ROUTINE bool _TOD_Is_set( void ) +static inline bool _TOD_Is_set( void ) { return _TOD.is_set; } |