From 812da546889eea0b6dea7eb2954f46a4c43d1314 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Mon, 2 Apr 2007 18:23:59 +0000 Subject: 2007-04-02 Joel Sherrill * 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. --- cpukit/rtems/src/clockget.c | 44 +++++++++++++++++++------------ cpukit/rtems/src/clockgetuptime.c | 50 ++++++++++++++++++++++++++++++++++++ cpukit/rtems/src/clockset.c | 9 ++++--- cpukit/rtems/src/clocktodtoseconds.c | 31 +++++++++++++++++----- cpukit/rtems/src/clocktodvalidate.c | 22 +++++++++++----- cpukit/rtems/src/taskwakewhen.c | 1 + 6 files changed, 123 insertions(+), 34 deletions(-) create mode 100644 cpukit/rtems/src/clockgetuptime.c (limited to 'cpukit/rtems/src') diff --git a/cpukit/rtems/src/clockget.c b/cpukit/rtems/src/clockget.c index d8f808ce8e..f5948bcffd 100644 --- a/cpukit/rtems/src/clockget.c +++ b/cpukit/rtems/src/clockget.c @@ -46,20 +46,35 @@ rtems_status_code rtems_clock_get( void *time_buffer ) { - ISR_Level level; - rtems_interval tmp; - - if ( !time_buffer ) - return RTEMS_INVALID_ADDRESS; + if ( !time_buffer ) + return RTEMS_INVALID_ADDRESS; switch ( option ) { - case RTEMS_CLOCK_GET_TOD: + case RTEMS_CLOCK_GET_TOD: { + struct tm time; + struct timeval now; + rtems_time_of_day *tmbuf = (rtems_time_of_day *)time_buffer; + if ( !_TOD_Is_set ) return RTEMS_NOT_DEFINED; - *(rtems_time_of_day *)time_buffer = _TOD_Current; + /* Obtain the current time */ + _TOD_Get_timeval( &now ); + + /* Split it into a closer format */ + gmtime_r( &now.tv_sec, &time ); + + /* Now adjust it to the RTEMS format */ + tmbuf->year = time.tm_year + 1900; + tmbuf->month = time.tm_mon + 1; + tmbuf->day = time.tm_mday; + tmbuf->hour = time.tm_hour; + tmbuf->minute = time.tm_min; + tmbuf->second = time.tm_sec; + tmbuf->ticks = now.tv_usec / _TOD_Microseconds_per_tick; + return RTEMS_SUCCESSFUL; - + } case RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH: if ( !_TOD_Is_set ) return RTEMS_NOT_DEFINED; @@ -75,20 +90,15 @@ rtems_status_code rtems_clock_get( *(rtems_interval *)time_buffer = _TOD_Ticks_per_second; return RTEMS_SUCCESSFUL; - case RTEMS_CLOCK_GET_TIME_VALUE: + case RTEMS_CLOCK_GET_TIME_VALUE: { + struct timeval *time = (struct timeval *)time_buffer; if ( !_TOD_Is_set ) return RTEMS_NOT_DEFINED; - _ISR_Disable( level ); - ((rtems_clock_time_value *)time_buffer)->seconds = - _TOD_Seconds_since_epoch; - tmp = _TOD_Current.ticks; - _ISR_Enable( level ); - - tmp *= _TOD_Microseconds_per_tick; - ((rtems_clock_time_value *)time_buffer)->microseconds = tmp; + _TOD_Get_timeval( time ); return RTEMS_SUCCESSFUL; + } } return RTEMS_INTERNAL_ERROR; /* should never get here */ diff --git a/cpukit/rtems/src/clockgetuptime.c b/cpukit/rtems/src/clockgetuptime.c new file mode 100644 index 0000000000..9fa88ef74b --- /dev/null +++ b/cpukit/rtems/src/clockgetuptime.c @@ -0,0 +1,50 @@ +/* + * Clock Manager - 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 +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * rtems_clock_get_uptime + * + * This directive obtains the system uptime. A timestamp is the seconds + * and nanoseconds since boot. + * + * Input parameters: + * timestamp - pointer to the timestamp + * + * Output parameters: + * *uptime - filled in + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ +rtems_status_code rtems_clock_get_uptime( + struct timespec *uptime +) +{ + if ( !uptime ) + return RTEMS_INVALID_ADDRESS; + + _TOD_Get_uptime( uptime ); + return RTEMS_SUCCESSFUL; +} diff --git a/cpukit/rtems/src/clockset.c b/cpukit/rtems/src/clockset.c index befdc5339b..1b1bbe8b04 100644 --- a/cpukit/rtems/src/clockset.c +++ b/cpukit/rtems/src/clockset.c @@ -41,15 +41,18 @@ rtems_status_code rtems_clock_set( rtems_time_of_day *time_buffer ) { - rtems_interval seconds; + struct timespec newtime; if ( !time_buffer ) return RTEMS_INVALID_ADDRESS; if ( _TOD_Validate( time_buffer ) ) { - seconds = _TOD_To_seconds( time_buffer ); + newtime.tv_sec = _TOD_To_seconds( time_buffer ); + newtime.tv_nsec = time_buffer->ticks * + (_TOD_Microseconds_per_tick * TOD_NANOSECONDS_PER_MICROSECOND); + _Thread_Disable_dispatch(); - _TOD_Set( time_buffer, seconds ); + _TOD_Set( &newtime ); _Thread_Enable_dispatch(); return RTEMS_SUCCESSFUL; } diff --git a/cpukit/rtems/src/clocktodtoseconds.c b/cpukit/rtems/src/clocktodtoseconds.c index 5bea09cc25..0caac50214 100644 --- a/cpukit/rtems/src/clocktodtoseconds.c +++ b/cpukit/rtems/src/clocktodtoseconds.c @@ -1,8 +1,8 @@ /* - * Time of Day (TOD) Handler + * Time of Day (TOD) Handler - Classic TOD to Seconds * * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2007. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -17,10 +17,27 @@ #endif #include -#include -#include -#include -#include +#include + +/* + * The following 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 1 for leap years, and 0 otherwise. + */ +const uint16_t _TOD_Days_to_date[2][13] = { + { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }, + { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 } +}; + +/* + * The following array contains the number of days in the years + * since the last leap year. The index should be 0 for leap + * years, and the number of years since the beginning of a leap + * year otherwise. + */ +const uint16_t _TOD_Days_since_last_leap_year[4] = { 0, 366, 731, 1096 }; + + /*PAGE * @@ -37,7 +54,7 @@ */ uint32_t _TOD_To_seconds( - TOD_Control *the_tod + rtems_time_of_day *the_tod ) { uint32_t time; diff --git a/cpukit/rtems/src/clocktodvalidate.c b/cpukit/rtems/src/clocktodvalidate.c index 6db0c9eb67..09cb5b4092 100644 --- a/cpukit/rtems/src/clocktodvalidate.c +++ b/cpukit/rtems/src/clocktodvalidate.c @@ -1,8 +1,8 @@ /* - * Time of Day (TOD) Handler + * Time of Day (TOD) Handler -- Validate Classic TOD * * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2007. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -17,10 +17,18 @@ #endif #include -#include -#include -#include -#include +#include + +/* + * The following array contains the number of days in all months. + * The first dimension should be 1 for leap years, and 0 otherwise. + * The second dimension should range from 1 to 12 for January to + * February, respectively. + */ +const uint32_t _TOD_Days_per_month[ 2 ][ 13 ] = { + { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, + { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } +}; /*PAGE * @@ -39,7 +47,7 @@ */ boolean _TOD_Validate( - TOD_Control *the_tod + rtems_time_of_day *the_tod ) { uint32_t days_in_month; diff --git a/cpukit/rtems/src/taskwakewhen.c b/cpukit/rtems/src/taskwakewhen.c index 363234fa08..96f7db2618 100644 --- a/cpukit/rtems/src/taskwakewhen.c +++ b/cpukit/rtems/src/taskwakewhen.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include -- cgit v1.2.3