diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2007-04-02 18:23:59 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2007-04-02 18:23:59 +0000 |
commit | 812da546889eea0b6dea7eb2954f46a4c43d1314 (patch) | |
tree | 22fc95d921c3544de770454a2f9c604d5d0a27a2 /cpukit/score/src | |
parent | 2007-04-02 Joel Sherrill <joel@OARcorp.com> (diff) | |
download | rtems-812da546889eea0b6dea7eb2954f46a4c43d1314.tar.bz2 |
2007-04-02 Joel Sherrill <joel@OARcorp.com>
* itron/src/itrontime.c, libcsupport/src/__gettod.c,
posix/include/rtems/posix/time.h, posix/include/rtems/posix/timer.h,
posix/src/clockgettime.c, posix/src/clocksettime.c,
posix/src/nanosleep.c, posix/src/posixtimespecsubtract.c,
posix/src/posixtimespectointerval.c, posix/src/ptimer1.c,
posix/src/sleep.c, rtems/Makefile.am,
rtems/include/rtems/rtems/clock.h, rtems/include/rtems/rtems/timer.h,
rtems/include/rtems/rtems/types.h, rtems/src/clockget.c,
rtems/src/clockset.c, rtems/src/clocktodtoseconds.c,
rtems/src/clocktodvalidate.c, rtems/src/taskwakewhen.c,
score/Makefile.am, score/include/rtems/score/tod.h,
score/inline/rtems/score/tod.inl, score/src/coretod.c,
score/src/coretodset.c: Convert from Classic API style TOD_Control as
fundamental time structure to POSIX struct timespec. Add
clock_get_uptime().
* rtems/src/clockgetuptime.c, score/src/coretodget.c,
score/src/coretodgetuptime.c: New files.
* score/src/coretodtickle.c, score/src/coretodtoseconds.c,
score/src/coretodvalidate.c: Removed.
Diffstat (limited to 'cpukit/score/src')
-rw-r--r-- | cpukit/score/src/coretod.c | 21 | ||||
-rw-r--r-- | cpukit/score/src/coretodget.c | 53 | ||||
-rw-r--r-- | cpukit/score/src/coretodgetuptime.c | 52 | ||||
-rw-r--r-- | cpukit/score/src/coretodset.c | 28 | ||||
-rw-r--r-- | cpukit/score/src/coretodtickle.c | 71 | ||||
-rw-r--r-- | cpukit/score/src/coretodtoseconds.c | 67 | ||||
-rw-r--r-- | cpukit/score/src/coretodvalidate.c | 67 |
7 files changed, 128 insertions, 231 deletions
diff --git a/cpukit/score/src/coretod.c b/cpukit/score/src/coretod.c index 4824be2c36..142d8782bc 100644 --- a/cpukit/score/src/coretod.c +++ b/cpukit/score/src/coretod.c @@ -40,24 +40,25 @@ void _TOD_Handler_initialization( { _TOD_Microseconds_per_tick = microseconds_per_tick; - _TOD_Seconds_since_epoch = 0; + /* POSIX format TOD (timespec) */ + _TOD_Now.tv_sec = TOD_SECONDS_1970_THROUGH_1988; + _TOD_Now.tv_nsec = 0; + + /* Uptime (timespec) */ + _TOD_Uptime.tv_sec = 0; + _TOD_Uptime.tv_nsec = 0; - _TOD_Current.year = TOD_BASE_YEAR; - _TOD_Current.month = 1; - _TOD_Current.day = 1; - _TOD_Current.hour = 0; - _TOD_Current.minute = 0; - _TOD_Current.second = 0; - _TOD_Current.ticks = 0; + /* Seconds since RTEMS Epoch (1988) */ + _TOD_Seconds_since_epoch = 0; + /* Protect ourselves from a divide by zero fault */ if ( microseconds_per_tick == 0 ) _TOD_Ticks_per_second = 0; else _TOD_Ticks_per_second = TOD_MICROSECONDS_PER_SECOND / microseconds_per_tick; - _Watchdog_Initialize( &_TOD_Seconds_watchdog, _TOD_Tickle, 0, NULL ); - + /* TOD has not been set */ _TOD_Is_set = FALSE; _TOD_Activate( _TOD_Ticks_per_second ); } diff --git a/cpukit/score/src/coretodget.c b/cpukit/score/src/coretodget.c new file mode 100644 index 0000000000..96ae194f30 --- /dev/null +++ b/cpukit/score/src/coretodget.c @@ -0,0 +1,53 @@ +/* + * Time of Day (TOD) Handler - get TOD + * + * COPYRIGHT (c) 1989-2007. + * 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.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems/system.h> +#include <rtems/score/isr.h> +#include <rtems/score/tod.h> + +/* + * _TOD_Get + * + * This routine is used to obtain the current date and time. + * + * Input parameters: + * time - pointer to the time and date structure + * + * Output parameters: NONE + */ + +void _TOD_Get( + struct timespec *time +) +{ + ISR_Level level; + struct timespec offset; + + /* assume time checked by caller */ + + offset.tv_sec = 0; + offset.tv_nsec = 0; + + /* _TOD_Now is a proper POSIX time */ + _ISR_Disable( level ); + *time = _TOD_Now; + if ( _Watchdog_Nanoseconds_since_tick_handler ) + offset.tv_nsec = (*_Watchdog_Nanoseconds_since_tick_handler)(); + _ISR_Enable( level ); + + _TOD_Add_timespec( time, &offset ); +} diff --git a/cpukit/score/src/coretodgetuptime.c b/cpukit/score/src/coretodgetuptime.c new file mode 100644 index 0000000000..e420c0863d --- /dev/null +++ b/cpukit/score/src/coretodgetuptime.c @@ -0,0 +1,52 @@ +/* + * Time of Day (TOD) Handler - get uptime + * + * COPYRIGHT (c) 1989-2007. + * 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.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems/system.h> +#include <rtems/score/isr.h> +#include <rtems/score/tod.h> + +/* + * _TOD_Get_uptime + * + * This routine is used to obtain the system uptime + * + * Input parameters: + * time - pointer to the time and date structure + * + * Output parameters: NONE + */ + +void _TOD_Get_uptime( + struct timespec *uptime +) +{ + ISR_Level level; + struct timespec offset; + + /* assume uptime checked by caller */ + + offset.tv_sec = 0; + offset.tv_nsec = 0; + + _ISR_Disable( level ); + *uptime = _TOD_Uptime; + if ( _Watchdog_Nanoseconds_since_tick_handler ) + offset.tv_nsec = (*_Watchdog_Nanoseconds_since_tick_handler)(); + _ISR_Enable( level ); + + _TOD_Add_timespec( uptime, &offset ); +} diff --git a/cpukit/score/src/coretodset.c b/cpukit/score/src/coretodset.c index ae7ec65b30..21f77d8001 100644 --- a/cpukit/score/src/coretodset.c +++ b/cpukit/score/src/coretodset.c @@ -30,37 +30,33 @@ * new date and time structure. * * Input parameters: - * the_tod - pointer to the time and date structure - * seconds_since_epoch - seconds since system epoch + * time - pointer to the time and date structure * * Output parameters: NONE */ void _TOD_Set( - TOD_Control *the_tod, - Watchdog_Interval seconds_since_epoch + const struct timespec *time ) { - Watchdog_Interval ticks_until_next_second; - _Thread_Disable_dispatch(); _TOD_Deactivate(); - if ( seconds_since_epoch < _TOD_Seconds_since_epoch ) + if ( time->tv_sec < _TOD_Seconds_since_epoch ) _Watchdog_Adjust_seconds( WATCHDOG_BACKWARD, - _TOD_Seconds_since_epoch - seconds_since_epoch ); + _TOD_Seconds_since_epoch - time->tv_sec ); else _Watchdog_Adjust_seconds( WATCHDOG_FORWARD, - seconds_since_epoch - _TOD_Seconds_since_epoch ); - - ticks_until_next_second = _TOD_Ticks_per_second; - if ( ticks_until_next_second > the_tod->ticks ) - ticks_until_next_second -= the_tod->ticks; + time->tv_sec - _TOD_Seconds_since_epoch ); - _TOD_Current = *the_tod; - _TOD_Seconds_since_epoch = seconds_since_epoch; + _TOD_Seconds_since_epoch = time->tv_sec; _TOD_Is_set = TRUE; - _TOD_Activate( ticks_until_next_second ); + + /* POSIX format TOD (timespec) */ + _TOD_Now = *time; + _TOD_Now.tv_sec += TOD_SECONDS_1970_THROUGH_1988; + + _TOD_Activate( 0 ); _Thread_Enable_dispatch(); } diff --git a/cpukit/score/src/coretodtickle.c b/cpukit/score/src/coretodtickle.c deleted file mode 100644 index d2c0fe3d46..0000000000 --- a/cpukit/score/src/coretodtickle.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Time of Day (TOD) Handler - * - * - * COPYRIGHT (c) 1989-1999. - * 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.com/license/LICENSE. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include <rtems/system.h> -#include <rtems/score/object.h> -#include <rtems/score/thread.h> -#include <rtems/score/tod.h> -#include <rtems/score/watchdog.h> - -/*PAGE - * - * _TOD_Tickle - * - * This routine updates the calendar time and tickles the - * per second watchdog timer chain. - * - * Input parameters: - * ignored - this parameter is ignored - * - * Output parameters: NONE - * - * NOTE: This routine only works for leap-years through 2099. - */ - -void _TOD_Tickle( - Objects_Id id, - void *ignored -) -{ - uint32_t leap; - - _TOD_Current.ticks = 0; - ++_TOD_Seconds_since_epoch; - if ( ++_TOD_Current.second >= TOD_SECONDS_PER_MINUTE ) { - _TOD_Current.second = 0; - if ( ++_TOD_Current.minute >= TOD_MINUTES_PER_HOUR ) { - _TOD_Current.minute = 0; - if ( ++_TOD_Current.hour >= TOD_HOURS_PER_DAY ) { - _TOD_Current.hour = 0; - if ( _TOD_Current.year & 0x3 ) leap = 0; - else leap = 1; - if ( ++_TOD_Current.day > - _TOD_Days_per_month[ leap ][ _TOD_Current.month ]) { - _TOD_Current.day = 1; - if ( ++_TOD_Current.month > TOD_MONTHS_PER_YEAR ) { - _TOD_Current.month = 1; - _TOD_Current.year++; - } - } - } - } - } - - _Watchdog_Tickle_seconds(); - _Watchdog_Insert_ticks( &_TOD_Seconds_watchdog, _TOD_Ticks_per_second ); -} diff --git a/cpukit/score/src/coretodtoseconds.c b/cpukit/score/src/coretodtoseconds.c deleted file mode 100644 index 5bea09cc25..0000000000 --- a/cpukit/score/src/coretodtoseconds.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Time of Day (TOD) Handler - * - * - * COPYRIGHT (c) 1989-1999. - * 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.com/license/LICENSE. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include <rtems/system.h> -#include <rtems/score/object.h> -#include <rtems/score/thread.h> -#include <rtems/score/tod.h> -#include <rtems/score/watchdog.h> - -/*PAGE - * - * _TOD_To_seconds - * - * This routine returns the seconds from the epoch until the - * current date and time. - * - * Input parameters: - * the_tod - pointer to the time and date structure - * - * Output parameters: - * returns - seconds since epoch until the_tod - */ - -uint32_t _TOD_To_seconds( - TOD_Control *the_tod -) -{ - uint32_t time; - uint32_t year_mod_4; - - time = the_tod->day - 1; - year_mod_4 = the_tod->year & 3; - - if ( year_mod_4 == 0 ) - time += _TOD_Days_to_date[ 1 ][ the_tod->month ]; - else - time += _TOD_Days_to_date[ 0 ][ the_tod->month ]; - - time += ( (the_tod->year - TOD_BASE_YEAR) / 4 ) * - ( (TOD_DAYS_PER_YEAR * 4) + 1); - - time += _TOD_Days_since_last_leap_year[ year_mod_4 ]; - - time *= TOD_SECONDS_PER_DAY; - - time += ((the_tod->hour * TOD_MINUTES_PER_HOUR) + the_tod->minute) - * TOD_SECONDS_PER_MINUTE; - - time += the_tod->second; - - return( time ); -} diff --git a/cpukit/score/src/coretodvalidate.c b/cpukit/score/src/coretodvalidate.c deleted file mode 100644 index 6db0c9eb67..0000000000 --- a/cpukit/score/src/coretodvalidate.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Time of Day (TOD) Handler - * - * - * COPYRIGHT (c) 1989-1999. - * 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.com/license/LICENSE. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include <rtems/system.h> -#include <rtems/score/object.h> -#include <rtems/score/thread.h> -#include <rtems/score/tod.h> -#include <rtems/score/watchdog.h> - -/*PAGE - * - * _TOD_Validate - * - * This kernel routine checks the validity of a date and time structure. - * - * Input parameters: - * the_tod - pointer to a time and date structure - * - * Output parameters: - * TRUE - if the date, time, and tick are valid - * FALSE - if the the_tod is invalid - * - * NOTE: This routine only works for leap-years through 2099. - */ - -boolean _TOD_Validate( - TOD_Control *the_tod -) -{ - uint32_t days_in_month; - - if ((!the_tod) || - (the_tod->ticks >= _TOD_Ticks_per_second) || - (the_tod->second >= TOD_SECONDS_PER_MINUTE) || - (the_tod->minute >= TOD_MINUTES_PER_HOUR) || - (the_tod->hour >= TOD_HOURS_PER_DAY) || - (the_tod->month == 0) || - (the_tod->month > TOD_MONTHS_PER_YEAR) || - (the_tod->year < TOD_BASE_YEAR) || - (the_tod->day == 0) ) - return FALSE; - - if ( (the_tod->year % 4) == 0 ) - days_in_month = _TOD_Days_per_month[ 1 ][ the_tod->month ]; - else - days_in_month = _TOD_Days_per_month[ 0 ][ the_tod->month ]; - - if ( the_tod->day > days_in_month ) - return FALSE; - - return TRUE; -} |