mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-05 15:15:44 +00:00
2007-04-05 Joel Sherrill <joel@OARcorp.com>
* posix/Makefile.am, posix/include/rtems/posix/time.h, posix/src/adjtime.c, posix/src/alarm.c, posix/src/clockgetres.c, posix/src/condtimedwait.c, posix/src/mqueuetimedreceive.c, posix/src/mqueuetimedsend.c, posix/src/mutextimedlock.c, posix/src/nanosleep.c, posix/src/posixtimespecabsolutetimeout.c, posix/src/pthread.c, posix/src/pthreadcreate.c, posix/src/pthreadsetschedparam.c, posix/src/ptimer1.c, posix/src/sched.c, posix/src/semtimedwait.c, posix/src/sigtimedwait.c, posix/src/ualarm.c, rtems/src/clocktodtoseconds.c, score/Makefile.am, score/preinstall.am, score/include/rtems/score/tod.h, score/inline/rtems/score/tod.inl, score/src/coretod.c, score/src/coretodget.c, score/src/coretodgetuptime.c, score/src/coretodset.c, score/src/coretodtickle.c: Provide timespec manipulation routines in the SuperCore. Use them everywhere possible. This lead to significant cleanup in the API routines and eliminated some of the same code from the POSIX API. At this point, the SuperCore keeps time in POSIX timespec format properly from 1970. You just cannot set it before 1988 in keeping with RTEMS traditional behavior. * score/include/rtems/score/timespec.h, score/src/timespecaddto.c, score/src/timespecfromticks.c, score/src/timespecisvalid.c, score/src/timespeclessthan.c, score/src/timespecsubtract.c, score/src/timespectoticks.c: New files. * posix/src/posixintervaltotimespec.c, posix/src/posixtimespecsubtract.c, posix/src/posixtimespectointerval.c: Removed.
This commit is contained in:
@@ -1,3 +1,33 @@
|
||||
2007-04-05 Joel Sherrill <joel@OARcorp.com>
|
||||
|
||||
* posix/Makefile.am, posix/include/rtems/posix/time.h,
|
||||
posix/src/adjtime.c, posix/src/alarm.c, posix/src/clockgetres.c,
|
||||
posix/src/condtimedwait.c, posix/src/mqueuetimedreceive.c,
|
||||
posix/src/mqueuetimedsend.c, posix/src/mutextimedlock.c,
|
||||
posix/src/nanosleep.c, posix/src/posixtimespecabsolutetimeout.c,
|
||||
posix/src/pthread.c, posix/src/pthreadcreate.c,
|
||||
posix/src/pthreadsetschedparam.c, posix/src/ptimer1.c,
|
||||
posix/src/sched.c, posix/src/semtimedwait.c,
|
||||
posix/src/sigtimedwait.c, posix/src/ualarm.c,
|
||||
rtems/src/clocktodtoseconds.c, score/Makefile.am,
|
||||
score/preinstall.am, score/include/rtems/score/tod.h,
|
||||
score/inline/rtems/score/tod.inl, score/src/coretod.c,
|
||||
score/src/coretodget.c, score/src/coretodgetuptime.c,
|
||||
score/src/coretodset.c, score/src/coretodtickle.c: Provide timespec
|
||||
manipulation routines in the SuperCore. Use them everywhere possible.
|
||||
This lead to significant cleanup in the API routines and eliminated
|
||||
some of the same code from the POSIX API. At this point, the
|
||||
SuperCore keeps time in POSIX timespec format properly from 1970. You
|
||||
just cannot set it before 1988 in keeping with RTEMS traditional
|
||||
behavior.
|
||||
* score/include/rtems/score/timespec.h, score/src/timespecaddto.c,
|
||||
score/src/timespecfromticks.c, score/src/timespecisvalid.c,
|
||||
score/src/timespeclessthan.c, score/src/timespecsubtract.c,
|
||||
score/src/timespectoticks.c: New files.
|
||||
* posix/src/posixintervaltotimespec.c,
|
||||
posix/src/posixtimespecsubtract.c,
|
||||
posix/src/posixtimespectointerval.c: Removed.
|
||||
|
||||
2007-04-04 Joel Sherrill <joel@OARcorp.com>
|
||||
|
||||
* score/Makefile.am, score/include/rtems/score/tod.h,
|
||||
|
||||
@@ -144,8 +144,7 @@ libposix_a_SOURCES += src/pspin.c src/pspindestroy.c src/pspininit.c \
|
||||
src/pspinunlock.c
|
||||
|
||||
## TIME_C_FILES
|
||||
libposix_a_SOURCES += src/adjtime.c src/posixtimespecsubtract.c \
|
||||
src/posixtimespectointerval.c src/posixintervaltotimespec.c \
|
||||
libposix_a_SOURCES += src/adjtime.c \
|
||||
src/posixtimespecabsolutetimeout.c src/clockgetcpuclockid.c \
|
||||
src/clockgetenableattr.c src/clockgetres.c src/clockgettime.c \
|
||||
src/clocksetenableattr.c src/clocksettime.c src/nanosleep.c src/sleep.c \
|
||||
|
||||
@@ -3,7 +3,12 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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$
|
||||
*/
|
||||
@@ -11,43 +16,7 @@
|
||||
#ifndef _RTEMS_POSIX_TIME_H
|
||||
#define _RTEMS_POSIX_TIME_H
|
||||
|
||||
#include <rtems/score/tod.h>
|
||||
|
||||
/*
|
||||
* Seconds from January 1, 1970 to January 1, 1988. Used to account for
|
||||
* differences between POSIX API and RTEMS core.
|
||||
*
|
||||
* XXX probably able to be removed once core switches completely to timespec
|
||||
* XXX for current TOD.
|
||||
*/
|
||||
#define POSIX_TIME_SECONDS_1970_THROUGH_1988 TOD_SECONDS_1970_THROUGH_1988
|
||||
|
||||
/*
|
||||
* _POSIX_Timespec_subtract
|
||||
*/
|
||||
|
||||
void _POSIX_Timespec_subtract(
|
||||
const struct timespec *the_start,
|
||||
const struct timespec *end,
|
||||
struct timespec *result
|
||||
);
|
||||
|
||||
/*
|
||||
* _POSIX_Timespec_to_interval
|
||||
*/
|
||||
|
||||
Watchdog_Interval _POSIX_Timespec_to_interval(
|
||||
const struct timespec *time
|
||||
);
|
||||
|
||||
/*
|
||||
* _POSIX_Interval_to_timespec
|
||||
*/
|
||||
|
||||
void _POSIX_Interval_to_timespec(
|
||||
Watchdog_Interval ticks,
|
||||
struct timespec *time
|
||||
);
|
||||
#include <rtems/score/timespec.h>
|
||||
|
||||
/*
|
||||
* _POSIX_Absolute_timeout_to_ticks
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
/*
|
||||
* adjustime() function - required by NTP
|
||||
* adjime() function - required by NTP
|
||||
*
|
||||
* I am unaware of the history behind the definition of this service
|
||||
* and don't know if its behavior is covered by any standard. --joel
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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$
|
||||
*/
|
||||
@@ -32,16 +41,19 @@ int adjtime ( struct timeval *delta, struct timeval *olddelta )
|
||||
if ( !delta )
|
||||
return -1;
|
||||
|
||||
__adjustment = (delta->tv_sec * TOD_MICROSECONDS_PER_SECOND) + delta->tv_usec;
|
||||
/* convert delta to microseconds */
|
||||
__adjustment = (delta->tv_sec * TOD_MICROSECONDS_PER_SECOND);
|
||||
__adjustment += delta->tv_usec;
|
||||
|
||||
/* too small to account for */
|
||||
if ( __adjustment < _TOD_Microseconds_per_tick )
|
||||
return 0;
|
||||
|
||||
clock_gettime( CLOCK_REALTIME, &ts );
|
||||
/* Grab the current TOD */
|
||||
_TOD_Get( &ts );
|
||||
|
||||
ts.tv_sec += (__adjustment / TOD_MICROSECONDS_PER_SECOND);
|
||||
ts.tv_nsec += (__adjustment % TOD_MICROSECONDS_PER_SECOND) *
|
||||
TOD_NANOSECONDS_PER_MICROSECOND;
|
||||
ts.tv_sec += delta->tv_sec;
|
||||
ts.tv_nsec += delta->tv_usec * TOD_NANOSECONDS_PER_MICROSECOND;
|
||||
|
||||
/* if adjustment is too much positive */
|
||||
while ( ts.tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) {
|
||||
@@ -55,6 +67,6 @@ int adjtime ( struct timeval *delta, struct timeval *olddelta )
|
||||
ts.tv_sec--;
|
||||
}
|
||||
|
||||
clock_settime( CLOCK_REALTIME, &ts );
|
||||
_TOD_Set( &ts );
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/*
|
||||
* 3.4.1 Schedule Alarm, P1003.1b-1993, p. 79
|
||||
*
|
||||
* COPYRIGHT (c) 1989-1999.
|
||||
*/
|
||||
|
||||
/* COPYRIGHT (c) 1989-2007.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
@@ -16,7 +17,6 @@
|
||||
#endif
|
||||
|
||||
#include <pthread.h>
|
||||
/* #include <errno.h> */
|
||||
|
||||
#include <rtems/system.h>
|
||||
#include <rtems/posix/pthread.h>
|
||||
@@ -69,12 +69,9 @@ unsigned int alarm(
|
||||
* this.
|
||||
*/
|
||||
|
||||
remaining = the_timer->initial;
|
||||
remaining -= (the_timer->stop_time - the_timer->start_time);
|
||||
|
||||
/* remaining is now in ticks */
|
||||
remaining *= _TOD_Microseconds_per_tick;
|
||||
remaining /= TOD_MICROSECONDS_PER_SECOND;
|
||||
remaining = the_timer->initial -
|
||||
((the_timer->stop_time - the_timer->start_time) /
|
||||
TOD_TICKS_PER_SECOND);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,17 @@
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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
|
||||
@@ -42,7 +53,7 @@ int clock_getres(
|
||||
if ( res ) {
|
||||
res->tv_sec = _TOD_Microseconds_per_tick / 1000000;
|
||||
res->tv_nsec = _TOD_Microseconds_per_tick * 1000;
|
||||
/* _POSIX_Interval_to_timespec( _TOD_Microseconds_per_tick, res ); */
|
||||
/* _TOD_From_ticks( _TOD_Microseconds_per_tick, res ); */
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -2,6 +2,17 @@
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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
|
||||
@@ -33,24 +44,27 @@ int pthread_cond_timedwait(
|
||||
struct timespec difference;
|
||||
boolean already_timedout = FALSE;
|
||||
|
||||
if ( !abstime )
|
||||
if ( !_Timespec_Is_valid(abstime) )
|
||||
return EINVAL;
|
||||
|
||||
/*
|
||||
* The abstime is a walltime. We turn it into an interval.
|
||||
*/
|
||||
|
||||
(void) clock_gettime( CLOCK_REALTIME, ¤t_time );
|
||||
_TOD_Get( ¤t_time );
|
||||
|
||||
/* XXX probably some error checking should go here */
|
||||
|
||||
_POSIX_Timespec_subtract( ¤t_time, abstime, &difference );
|
||||
|
||||
if ( ( difference.tv_sec < 0 ) || ( ( difference.tv_sec == 0 ) &&
|
||||
( difference.tv_nsec < 0 ) ) )
|
||||
/*
|
||||
* Make sure the timeout is in the future
|
||||
*/
|
||||
if ( _Timespec_Less_than( abstime, ¤t_time ) ) {
|
||||
already_timedout = TRUE;
|
||||
|
||||
timeout = _POSIX_Timespec_to_interval( &difference );
|
||||
difference.tv_sec = 0;
|
||||
difference.tv_nsec = 0;
|
||||
timeout = 0;
|
||||
} else {
|
||||
_Timespec_Subtract( ¤t_time, abstime, &difference );
|
||||
timeout = _Timespec_To_ticks( &difference );
|
||||
}
|
||||
|
||||
return _POSIX_Condition_variables_Wait_support(
|
||||
cond,
|
||||
|
||||
@@ -10,6 +10,15 @@
|
||||
*
|
||||
* This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
|
||||
* time.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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$
|
||||
*/
|
||||
@@ -52,6 +61,6 @@ ssize_t mq_timedreceive(
|
||||
msg_ptr,
|
||||
msg_len,
|
||||
msg_prio,
|
||||
_POSIX_Timespec_to_interval( timeout )
|
||||
_Timespec_To_ticks( timeout )
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,15 @@
|
||||
*
|
||||
* This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
|
||||
* time.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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$
|
||||
*/
|
||||
@@ -52,6 +61,6 @@ int mq_timedsend(
|
||||
msg_ptr,
|
||||
msg_len,
|
||||
msg_prio,
|
||||
_POSIX_Timespec_to_interval( timeout )
|
||||
_Timespec_To_ticks( timeout )
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
/*
|
||||
* Mutex Timed Lock
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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$
|
||||
*/
|
||||
|
||||
@@ -31,9 +42,10 @@ int pthread_mutex_timedlock(
|
||||
const struct timespec *timeout
|
||||
)
|
||||
{
|
||||
/* XXX does timeout need to be based on CLOCK_REALTIME and be TOD? */
|
||||
return _POSIX_Mutex_Lock_support(
|
||||
mutex,
|
||||
TRUE,
|
||||
_POSIX_Timespec_to_interval( timeout )
|
||||
_Timespec_To_ticks( timeout )
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
/*
|
||||
* 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$
|
||||
*/
|
||||
|
||||
@@ -28,41 +35,25 @@ int nanosleep(
|
||||
)
|
||||
{
|
||||
Watchdog_Interval ticks;
|
||||
struct timespec *the_rqtp;
|
||||
|
||||
if ( !rqtp )
|
||||
if ( !_Timespec_Is_valid( rqtp ) )
|
||||
rtems_set_errno_and_return_minus_one( EINVAL );
|
||||
|
||||
the_rqtp = (struct timespec *)rqtp;
|
||||
|
||||
/*
|
||||
* Return EAGAIN if the delay interval is negative.
|
||||
* Return EINVAL if the delay interval is negative.
|
||||
*
|
||||
* NOTE: This behavior is beyond the POSIX specification.
|
||||
* FSU pthreads shares this behavior.
|
||||
* FSU and GNU/Linux pthreads shares this behavior.
|
||||
*/
|
||||
|
||||
if ( the_rqtp->tv_sec < 0 )
|
||||
the_rqtp->tv_sec = 0;
|
||||
|
||||
if ( /* the_rqtp->tv_sec < 0 || */ the_rqtp->tv_nsec < 0 )
|
||||
rtems_set_errno_and_return_minus_one( EAGAIN );
|
||||
|
||||
if ( the_rqtp->tv_nsec >= TOD_NANOSECONDS_PER_SECOND )
|
||||
if ( rqtp->tv_sec < 0 || rqtp->tv_nsec < 0 )
|
||||
rtems_set_errno_and_return_minus_one( EINVAL );
|
||||
|
||||
ticks = _POSIX_Timespec_to_interval( the_rqtp );
|
||||
|
||||
/*
|
||||
* Bump the ticks by one so the delay is at least the number of
|
||||
* ticks requested
|
||||
*/
|
||||
ticks++;
|
||||
ticks = _Timespec_To_ticks( rqtp );
|
||||
|
||||
/*
|
||||
* A nanosleep for zero time is implemented as a yield.
|
||||
* This behavior is also beyond the POSIX specification but is
|
||||
* consistent with the RTEMS api and yields desirable behavior.
|
||||
* consistent with the RTEMS API and yields desirable behavior.
|
||||
*/
|
||||
|
||||
if ( !ticks ) {
|
||||
@@ -99,7 +90,7 @@ int nanosleep(
|
||||
ticks -=
|
||||
_Thread_Executing->Timer.stop_time - _Thread_Executing->Timer.start_time;
|
||||
|
||||
_POSIX_Interval_to_timespec( ticks, rmtp );
|
||||
_Timespec_From_ticks( ticks, rmtp );
|
||||
|
||||
/*
|
||||
* If there is time remaining, then we were interrupted by a signal.
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
/*
|
||||
* Convert abstime timeout to ticks
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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$
|
||||
*/
|
||||
@@ -33,36 +42,20 @@ int _POSIX_Absolute_timeout_to_ticks(
|
||||
struct timespec current_time;
|
||||
struct timespec difference;
|
||||
|
||||
if ( !abstime )
|
||||
if ( !_Timespec_Is_valid(abstime) )
|
||||
return EINVAL;
|
||||
|
||||
/*
|
||||
* Error check the absolute time to timeout
|
||||
*/
|
||||
#if 0
|
||||
/* they are unsigned so this is impossible */
|
||||
if ( abstime->tv_sec < 0 || abstime->tv_nsec < 0 )
|
||||
return EINVAL;
|
||||
#endif
|
||||
|
||||
if ( abstime->tv_nsec >= TOD_NANOSECONDS_PER_SECOND )
|
||||
return EINVAL;
|
||||
|
||||
(void) clock_gettime( CLOCK_REALTIME, ¤t_time );
|
||||
_TOD_Get( ¤t_time );
|
||||
|
||||
/*
|
||||
* Make sure the abstime is in the future
|
||||
*/
|
||||
if ( abstime->tv_sec < current_time.tv_sec )
|
||||
if ( _Timespec_Less_than( abstime, ¤t_time ) )
|
||||
return EINVAL;
|
||||
|
||||
if ( (abstime->tv_sec == current_time.tv_sec) &&
|
||||
(abstime->tv_nsec <= current_time.tv_nsec) )
|
||||
return EINVAL;
|
||||
_Timespec_Subtract( ¤t_time, abstime, &difference );
|
||||
|
||||
_POSIX_Timespec_subtract( ¤t_time, abstime, &difference );
|
||||
|
||||
*ticks_out = _POSIX_Timespec_to_interval( &difference );
|
||||
*ticks_out = _Timespec_To_ticks( &difference );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <rtems/system.h>
|
||||
#include <rtems/score/isr.h>
|
||||
#include <rtems/score/thread.h>
|
||||
#include <rtems/score/tod.h>
|
||||
|
||||
#include <rtems/seterr.h>
|
||||
#include <rtems/posix/time.h>
|
||||
|
||||
/*PAGE
|
||||
*
|
||||
* _POSIX_Timespec_subtract
|
||||
*/
|
||||
|
||||
void _POSIX_Timespec_subtract(
|
||||
const struct timespec *start,
|
||||
const struct timespec *end,
|
||||
struct timespec *result
|
||||
)
|
||||
{
|
||||
#if 0
|
||||
struct timespec start_struct = *the_start;
|
||||
struct timespec *start = &start_struct;
|
||||
uint32_t nsecs_per_sec = TOD_NANOSECONDS_PER_SECOND;
|
||||
|
||||
if (end->tv_nsec < start->tv_nsec) {
|
||||
int seconds = (start->tv_nsec - end->tv_nsec) / nsecs_per_sec + 1;
|
||||
start->tv_nsec -= nsecs_per_sec * seconds;
|
||||
start->tv_sec += seconds;
|
||||
}
|
||||
|
||||
if (end->tv_nsec - start->tv_nsec > nsecs_per_sec) {
|
||||
int seconds = (start->tv_nsec - end->tv_nsec) / nsecs_per_sec;
|
||||
start->tv_nsec += nsecs_per_sec * seconds;
|
||||
start->tv_sec -= seconds;
|
||||
}
|
||||
#else
|
||||
|
||||
#endif
|
||||
|
||||
if (end->tv_nsec < start->tv_nsec) {
|
||||
result->tv_sec = end->tv_sec - start->tv_sec - 1;
|
||||
result->tv_nsec = (TOD_NANOSECONDS_PER_SECOND - start->tv_nsec) + end->tv_nsec;
|
||||
} else {
|
||||
result->tv_sec = end->tv_sec - start->tv_sec;
|
||||
result->tv_nsec = end->tv_nsec - start->tv_nsec;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <rtems/system.h>
|
||||
#include <rtems/score/isr.h>
|
||||
#include <rtems/score/thread.h>
|
||||
#include <rtems/score/tod.h>
|
||||
|
||||
#include <rtems/seterr.h>
|
||||
#include <rtems/posix/time.h>
|
||||
|
||||
/*PAGE
|
||||
*
|
||||
* _POSIX_Timespec_to_interval
|
||||
*/
|
||||
|
||||
Watchdog_Interval _POSIX_Timespec_to_interval(
|
||||
const struct timespec *time
|
||||
)
|
||||
{
|
||||
Watchdog_Interval ticks;
|
||||
|
||||
ticks = time->tv_sec *
|
||||
(TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick);
|
||||
|
||||
ticks += (time->tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND) /
|
||||
_TOD_Microseconds_per_tick;
|
||||
|
||||
if (ticks)
|
||||
return ticks;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -1,4 +1,11 @@
|
||||
/*
|
||||
* 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$
|
||||
*/
|
||||
|
||||
@@ -70,7 +77,7 @@ void _POSIX_Threads_Sporadic_budget_TSR(
|
||||
|
||||
api = the_thread->API_Extensions[ THREAD_API_POSIX ];
|
||||
|
||||
ticks = _POSIX_Timespec_to_interval( &api->schedparam.ss_initial_budget );
|
||||
ticks = _Timespec_To_ticks( &api->schedparam.ss_initial_budget );
|
||||
|
||||
if ( !ticks )
|
||||
ticks = 1;
|
||||
@@ -84,7 +91,7 @@ void _POSIX_Threads_Sporadic_budget_TSR(
|
||||
the_thread->current_priority > new_priority )
|
||||
_Thread_Change_priority( the_thread, new_priority, TRUE );
|
||||
|
||||
ticks = _POSIX_Timespec_to_interval( &api->schedparam.ss_replenish_period );
|
||||
ticks = _Timespec_To_ticks( &api->schedparam.ss_replenish_period );
|
||||
|
||||
if ( !ticks )
|
||||
ticks = 1;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/*
|
||||
* 16.1.2 Thread Creation, P1003.1c/Draft 10, p. 144
|
||||
*
|
||||
* COPYRIGHT (c) 1989-1999.
|
||||
*/
|
||||
|
||||
/* COPYRIGHT (c) 1989-2007.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
@@ -126,8 +127,8 @@ int pthread_create(
|
||||
budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT;
|
||||
budget_callout = _POSIX_Threads_Sporadic_budget_callout;
|
||||
|
||||
if ( _POSIX_Timespec_to_interval( &schedparam.ss_replenish_period ) <
|
||||
_POSIX_Timespec_to_interval( &schedparam.ss_initial_budget ) )
|
||||
if ( _Timespec_To_ticks( &schedparam.ss_replenish_period ) <
|
||||
_Timespec_To_ticks( &schedparam.ss_initial_budget ) )
|
||||
return EINVAL;
|
||||
|
||||
if ( !_POSIX_Priority_Is_valid( schedparam.ss_low_priority ) )
|
||||
@@ -230,7 +231,7 @@ int pthread_create(
|
||||
if ( schedpolicy == SCHED_SPORADIC ) {
|
||||
_Watchdog_Insert_ticks(
|
||||
&api->Sporadic_timer,
|
||||
_POSIX_Timespec_to_interval( &api->schedparam.ss_replenish_period )
|
||||
_Timespec_To_ticks( &api->schedparam.ss_replenish_period )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
/*
|
||||
* 13.5.2 Dynamic Thread Scheduling Parameters Access,
|
||||
* P1003.1c/Draft 10, p. 124
|
||||
*
|
||||
* COPYRIGHT (c) 1989-1999.
|
||||
*/
|
||||
|
||||
/* COPYRIGHT (c) 1989-2007.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
@@ -66,8 +67,8 @@ int pthread_setschedparam(
|
||||
budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT;
|
||||
budget_callout = _POSIX_Threads_Sporadic_budget_callout;
|
||||
|
||||
if ( _POSIX_Timespec_to_interval( ¶m->ss_replenish_period ) <
|
||||
_POSIX_Timespec_to_interval( ¶m->ss_initial_budget ) )
|
||||
if ( _Timespec_To_ticks( ¶m->ss_replenish_period ) <
|
||||
_Timespec_To_ticks( ¶m->ss_initial_budget ) )
|
||||
return EINVAL;
|
||||
|
||||
if ( !_POSIX_Priority_Is_valid( param->ss_low_priority ) )
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
/*
|
||||
* ptimer.c,v 1.1 1996/06/03 16:29:58 joel Exp
|
||||
* 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
|
||||
@@ -344,7 +351,7 @@ int timer_settime(
|
||||
/* The fire time is relative: use "rtems_time_fire_after" */
|
||||
case POSIX_TIMER_RELATIVE:
|
||||
/* First, convert from seconds and nanoseconds to ticks */
|
||||
ptimer->ticks = _POSIX_Timespec_to_interval( &value->it_value );
|
||||
ptimer->ticks = _Timespec_To_ticks( &value->it_value );
|
||||
|
||||
activated = _Watchdog_Insert_ticks_helper(
|
||||
&ptimer->Timer,
|
||||
@@ -422,11 +429,13 @@ int timer_gettime(
|
||||
|
||||
/* Calculates the time left before the timer finishes */
|
||||
|
||||
_POSIX_Timespec_subtract(
|
||||
&ptimer->timer_data.it_value, ¤t_time, &value->it_value);
|
||||
_Timespec_Subtract(
|
||||
&ptimer->timer_data.it_value,
|
||||
¤t_time,
|
||||
&value->it_value
|
||||
);
|
||||
|
||||
value->it_interval.tv_sec = ptimer->timer_data.it_interval.tv_sec;
|
||||
value->it_interval.tv_nsec = ptimer->timer_data.it_interval.tv_nsec;
|
||||
value->it_interval = ptimer->timer_data.it_interval;
|
||||
|
||||
_Thread_Enable_dispatch();
|
||||
return 0;
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
/*
|
||||
* 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$
|
||||
*/
|
||||
|
||||
@@ -126,8 +133,6 @@ int sched_rr_get_interval(
|
||||
struct timespec *interval
|
||||
)
|
||||
{
|
||||
/* XXX do we need to support different time quantums per thread */
|
||||
|
||||
/*
|
||||
* Only supported for the "calling process" (i.e. this node).
|
||||
*/
|
||||
@@ -138,7 +143,7 @@ int sched_rr_get_interval(
|
||||
if ( !interval )
|
||||
rtems_set_errno_and_return_minus_one( EINVAL );
|
||||
|
||||
_POSIX_Interval_to_timespec( _Thread_Ticks_per_timeslice, interval );
|
||||
_Timespec_From_ticks( _Thread_Ticks_per_timeslice, interval );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
/*
|
||||
* 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$
|
||||
*/
|
||||
|
||||
@@ -43,26 +50,18 @@ int sem_timedwait(
|
||||
/*
|
||||
* Error check the absolute time to timeout
|
||||
*/
|
||||
#if 0
|
||||
if ( /* abstime->tv_sec < 0 || */ abstime->tv_nsec ) /* tv_sec is unsigned */
|
||||
if ( !_Timespec_Is_valid( abstime ) ) {
|
||||
blocking = CORE_SEMAPHORE_BAD_TIMEOUT_VALUE;
|
||||
else
|
||||
#endif
|
||||
if ( abstime->tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) {
|
||||
blocking = CORE_SEMAPHORE_BAD_TIMEOUT;
|
||||
} else {
|
||||
clock_gettime( CLOCK_REALTIME, ¤t_time );
|
||||
_TOD_Get( ¤t_time );
|
||||
/*
|
||||
* Make sure the abstime is in the future
|
||||
*/
|
||||
if ( abstime->tv_sec < current_time.tv_sec )
|
||||
if ( _Timespec_Less_than( abstime, ¤t_time ) ) {
|
||||
blocking = CORE_SEMAPHORE_BAD_TIMEOUT;
|
||||
else if ( (abstime->tv_sec == current_time.tv_sec) &&
|
||||
(abstime->tv_nsec <= current_time.tv_nsec) )
|
||||
blocking = CORE_SEMAPHORE_BAD_TIMEOUT;
|
||||
else {
|
||||
_POSIX_Timespec_subtract( ¤t_time, abstime, &difference );
|
||||
ticks = _POSIX_Timespec_to_interval( &difference );
|
||||
} else {
|
||||
_Timespec_Subtract( ¤t_time, abstime, &difference );
|
||||
ticks = _Timespec_To_ticks( &difference );
|
||||
blocking = CORE_SEMAPHORE_BLOCK_WITH_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* 3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76
|
||||
*
|
||||
* COPYRIGHT (c) 1989-1999.
|
||||
* COPYRIGHT (c) 1989-2007.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
@@ -68,12 +68,11 @@ int sigtimedwait(
|
||||
interval = 0;
|
||||
if ( timeout ) {
|
||||
|
||||
if ( timeout->tv_nsec < 0 ||
|
||||
timeout->tv_nsec >= TOD_NANOSECONDS_PER_SECOND) {
|
||||
if ( !_Timespec_Is_valid( timeout ) ) {
|
||||
rtems_set_errno_and_return_minus_one( EINVAL );
|
||||
}
|
||||
|
||||
interval = _POSIX_Timespec_to_interval( timeout );
|
||||
interval = _Timespec_To_ticks( timeout );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -96,7 +95,13 @@ int sigtimedwait(
|
||||
if ( *set & api->signals_pending ) {
|
||||
/* XXX real info later */
|
||||
the_info->si_signo = _POSIX_signals_Get_highest( api->signals_pending );
|
||||
_POSIX_signals_Clear_signals( api, the_info->si_signo, the_info, FALSE, FALSE );
|
||||
_POSIX_signals_Clear_signals(
|
||||
api,
|
||||
the_info->si_signo,
|
||||
the_info,
|
||||
FALSE,
|
||||
FALSE
|
||||
);
|
||||
_ISR_Enable( level );
|
||||
|
||||
the_info->si_code = SI_USER;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* XXX 3.4.1 Schedule Alarm, P1003.1b-1993, p. 79
|
||||
* 3.4.1 Schedule Alarm, P1003.1b-1993, p. 79
|
||||
*
|
||||
* COPYRIGHT (c) 1989-2003.
|
||||
* COPYRIGHT (c) 1989-2007.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
@@ -75,12 +75,9 @@ useconds_t ualarm(
|
||||
|
||||
ticks = the_timer->initial;
|
||||
ticks -= (the_timer->stop_time - the_timer->start_time);
|
||||
|
||||
/* remaining is now in ticks */
|
||||
ticks *= _TOD_Microseconds_per_tick;
|
||||
ticks /= TOD_MICROSECONDS_PER_SECOND;
|
||||
|
||||
_POSIX_Interval_to_timespec( ticks, &tp );
|
||||
_Timespec_From_ticks( ticks, &tp );
|
||||
remaining = tp.tv_sec * TOD_MICROSECONDS_PER_SECOND;
|
||||
remaining += tp.tv_nsec / 1000;
|
||||
break;
|
||||
@@ -89,8 +86,7 @@ useconds_t ualarm(
|
||||
|
||||
tp.tv_sec = useconds / TOD_MICROSECONDS_PER_SECOND;
|
||||
tp.tv_nsec = (useconds % TOD_MICROSECONDS_PER_SECOND) * 1000;
|
||||
ticks = _POSIX_Timespec_to_interval( &tp );
|
||||
_Watchdog_Insert_ticks( the_timer, ticks );
|
||||
_Watchdog_Insert_ticks( the_timer, _Timespec_To_ticks( &tp ) );
|
||||
|
||||
return remaining;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* Time of Day (TOD) Handler - Classic TOD to Seconds
|
||||
*
|
||||
*
|
||||
* COPYRIGHT (c) 1989-2007.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
@@ -80,5 +79,7 @@ uint32_t _TOD_To_seconds(
|
||||
|
||||
time += the_tod->second;
|
||||
|
||||
time += TOD_SECONDS_1970_THROUGH_1988;
|
||||
|
||||
return( time );
|
||||
}
|
||||
|
||||
@@ -28,10 +28,10 @@ include_rtems_score_HEADERS = include/rtems/score/address.h \
|
||||
include/rtems/score/object.h include/rtems/score/priority.h \
|
||||
include/rtems/score/stack.h include/rtems/score/states.h \
|
||||
include/rtems/score/sysstate.h include/rtems/score/thread.h \
|
||||
include/rtems/score/threadq.h include/rtems/score/tod.h \
|
||||
include/rtems/score/tqdata.h include/rtems/score/userext.h \
|
||||
include/rtems/score/watchdog.h include/rtems/score/wkspace.h \
|
||||
include/rtems/score/cpuopts.h
|
||||
include/rtems/score/threadq.h include/rtems/score/timespec.h \
|
||||
include/rtems/score/tod.h include/rtems/score/tqdata.h \
|
||||
include/rtems/score/userext.h include/rtems/score/watchdog.h \
|
||||
include/rtems/score/wkspace.h include/rtems/score/cpuopts.h
|
||||
|
||||
if HAS_MP
|
||||
# We only build multiprocessing related files if HAS_MP was defined
|
||||
@@ -140,7 +140,9 @@ libscore_a_SOURCES += src/threadq.c src/threadqdequeue.c \
|
||||
src/threadqtimeout.c
|
||||
|
||||
## TIMESPEC_C_FILES
|
||||
## libscore_a_SOURCES +=
|
||||
libscore_a_SOURCES += src/timespecaddto.c src/timespecfromticks.c \
|
||||
src/timespecisvalid.c src/timespeclessthan.c src/timespecsubtract.c \
|
||||
src/timespectoticks.c
|
||||
|
||||
## TOD_C_FILES
|
||||
libscore_a_SOURCES += src/coretod.c src/coretodset.c src/coretodget.c \
|
||||
|
||||
130
cpukit/score/include/rtems/score/timespec.h
Normal file
130
cpukit/score/include/rtems/score/timespec.h
Normal file
@@ -0,0 +1,130 @@
|
||||
/**
|
||||
* @file rtems/score/timespec.h
|
||||
*
|
||||
* This include file contains helpers for manipulating timespecs.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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$
|
||||
*/
|
||||
|
||||
#ifndef _RTEMS_SCORE_TIMESPEC_H
|
||||
#define _RTEMS_SCORE_TIMESPEC_H
|
||||
|
||||
/**
|
||||
* @defgroup Timespec Helpers
|
||||
*
|
||||
* This handler encapsulates functionality related to manipulating
|
||||
* POSIX struct timespecs.
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <rtems/score/tod.h>
|
||||
#include <rtems/score/watchdog.h>
|
||||
|
||||
/** @brief Is Timespec Valid
|
||||
*
|
||||
* This method determines the validatity of a timespec.
|
||||
*
|
||||
* @param[in] time is the timespec instance to validate.
|
||||
*
|
||||
* @return This method returns true if @a time is valid and
|
||||
* false otherwise.
|
||||
*/
|
||||
boolean _Timespec_Is_valid(
|
||||
const struct timespec *time
|
||||
);
|
||||
|
||||
/** @brief Timespec Less Than Operator
|
||||
*
|
||||
* This method is the less than operator for timespecs.
|
||||
*
|
||||
* @param[in] lhs is the left hand side timespec
|
||||
* @param[in] rhs is the left hand side timespec
|
||||
*
|
||||
* @return This method returns true if @a lhs is less than the @a rhs and
|
||||
* false otherwise.
|
||||
*/
|
||||
boolean _Timespec_Less_than(
|
||||
const struct timespec *lhs,
|
||||
const struct timespec *rhs
|
||||
);
|
||||
|
||||
/** @brief Add to a Timespec
|
||||
*
|
||||
* This routine adds two timespecs. The second argument is added
|
||||
* to the first.
|
||||
*
|
||||
* @param[in] time is the base time to be added to
|
||||
* @param[in] add is the timespec to add to the first argument
|
||||
*
|
||||
* @return This method returns the number of seconds @a time increased by.
|
||||
*/
|
||||
uint32_t _Timespec_Add_to(
|
||||
struct timespec *time,
|
||||
const struct timespec *add
|
||||
);
|
||||
|
||||
/** @brief Convert Timespec to Number of Ticks
|
||||
*
|
||||
* This routine convert the @a time timespec to the corresponding number
|
||||
* of clock ticks.
|
||||
*
|
||||
* @param[in] time is the time to be converted
|
||||
*
|
||||
* @return This method returns the number of ticks computed.
|
||||
*/
|
||||
uint32_t _Timespec_To_ticks(
|
||||
const struct timespec *time
|
||||
);
|
||||
|
||||
/** @brief Convert Ticks to Timespec
|
||||
*
|
||||
* This routine converts the @a ticks value to the corresponding
|
||||
* timespec format @a time.
|
||||
*
|
||||
* @param[in] time is the timespec format time result
|
||||
* @param[in] ticks is the number of ticks to convert
|
||||
*/
|
||||
void _Timespec_From_ticks(
|
||||
uint32_t ticks,
|
||||
struct timespec *time
|
||||
);
|
||||
|
||||
/** @brief Subtract Two Timespec
|
||||
*
|
||||
* This routine subtracts two timespecs. @a result is set to
|
||||
* @a end - @a start.
|
||||
*
|
||||
* @param[in] start is the starting time
|
||||
* @param[in] end is the ending time
|
||||
* @param[in] result is the difference between starting and ending time.
|
||||
*
|
||||
* @return This method fills in @a result.
|
||||
*/
|
||||
void _Timespec_Subtract(
|
||||
const struct timespec *start,
|
||||
const struct timespec *end,
|
||||
struct timespec *result
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**@}*/
|
||||
|
||||
#endif
|
||||
/* end of include file */
|
||||
@@ -137,7 +137,7 @@ SCORE_EXTERN struct timespec _TOD_Uptime;
|
||||
* The following contains the number of seconds from 00:00:00
|
||||
* January 1, TOD_BASE_YEAR until the current time of day.
|
||||
*/
|
||||
SCORE_EXTERN Watchdog_Interval _TOD_Seconds_since_epoch;
|
||||
#define _TOD_Seconds_since_epoch (_TOD_Now.tv_sec)
|
||||
|
||||
/** @brief Microseconds per Clock Tick
|
||||
*
|
||||
@@ -217,6 +217,17 @@ void _TOD_Tickle_ticks( void );
|
||||
#define TOD_MILLISECONDS_TO_TICKS(_ms) \
|
||||
(TOD_MILLISECONDS_TO_MICROSECONDS(_ms) / _TOD_Microseconds_per_tick)
|
||||
|
||||
|
||||
/** @brief How many ticks in a second?
|
||||
*
|
||||
* This macro 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.
|
||||
*/
|
||||
#define TOD_TICKS_PER_SECOND \
|
||||
(TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick)
|
||||
|
||||
#ifndef __RTEMS_APPLICATION__
|
||||
#include <rtems/score/tod.inl>
|
||||
#endif
|
||||
|
||||
@@ -26,34 +26,6 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* This routines adds two timespecs. The second argument is added
|
||||
* to the first.
|
||||
*/
|
||||
|
||||
RTEMS_INLINE_ROUTINE uint32_t _TOD_Add_timespec(
|
||||
struct timespec *time,
|
||||
struct timespec *add
|
||||
)
|
||||
{
|
||||
uint32_t seconds = 0;
|
||||
|
||||
|
||||
/* Add the basics */
|
||||
time->tv_sec += add->tv_sec;
|
||||
time->tv_nsec += add->tv_nsec;
|
||||
|
||||
/* Now adjust it so nanoseconds is in range */
|
||||
while ( time->tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) {
|
||||
time->tv_nsec -= TOD_NANOSECONDS_PER_SECOND;
|
||||
time->tv_sec++;
|
||||
seconds++;
|
||||
}
|
||||
|
||||
return seconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine deactivates updating of the current time of day.
|
||||
*/
|
||||
|
||||
@@ -127,6 +127,10 @@ $(PROJECT_INCLUDE)/rtems/score/threadq.h: include/rtems/score/threadq.h $(PROJEC
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/threadq.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/threadq.h
|
||||
|
||||
$(PROJECT_INCLUDE)/rtems/score/timespec.h: include/rtems/score/timespec.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/timespec.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/timespec.h
|
||||
|
||||
$(PROJECT_INCLUDE)/rtems/score/tod.h: include/rtems/score/tod.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/tod.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/tod.h
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Time of Day (TOD) Handler
|
||||
*
|
||||
*
|
||||
* COPYRIGHT (c) 1989-1999.
|
||||
*/
|
||||
|
||||
/* COPYRIGHT (c) 1989-2007.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
@@ -48,9 +48,6 @@ void _TOD_Handler_initialization(
|
||||
_TOD_Uptime.tv_sec = 0;
|
||||
_TOD_Uptime.tv_nsec = 0;
|
||||
|
||||
/* Seconds since RTEMS Epoch (1988) */
|
||||
_TOD_Seconds_since_epoch = 0;
|
||||
|
||||
/* TOD has not been set */
|
||||
_TOD_Is_set = FALSE;
|
||||
_TOD_Activate();
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <rtems/system.h>
|
||||
#include <rtems/score/isr.h>
|
||||
#include <rtems/score/timespec.h>
|
||||
#include <rtems/score/tod.h>
|
||||
|
||||
/*
|
||||
@@ -49,5 +50,5 @@ void _TOD_Get(
|
||||
offset.tv_nsec = (*_Watchdog_Nanoseconds_since_tick_handler)();
|
||||
_ISR_Enable( level );
|
||||
|
||||
_TOD_Add_timespec( time, &offset );
|
||||
_Timespec_Add_to( time, &offset );
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/*
|
||||
* Time of Day (TOD) Handler - get uptime
|
||||
*
|
||||
* COPYRIGHT (c) 1989-2007.
|
||||
*/
|
||||
|
||||
/* COPYRIGHT (c) 1989-2007.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
@@ -17,6 +18,7 @@
|
||||
|
||||
#include <rtems/system.h>
|
||||
#include <rtems/score/isr.h>
|
||||
#include <rtems/score/timespec.h>
|
||||
#include <rtems/score/tod.h>
|
||||
|
||||
/*
|
||||
@@ -48,5 +50,5 @@ void _TOD_Get_uptime(
|
||||
offset.tv_nsec = (*_Watchdog_Nanoseconds_since_tick_handler)();
|
||||
_ISR_Enable( level );
|
||||
|
||||
_TOD_Add_timespec( uptime, &offset );
|
||||
_Timespec_Add_to( uptime, &offset );
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Time of Day (TOD) Handler
|
||||
*
|
||||
*
|
||||
* COPYRIGHT (c) 1989-1999.
|
||||
* Time of Day (TOD) Handler -- Set Time
|
||||
*/
|
||||
|
||||
/* COPYRIGHT (c) 1989-2007.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
@@ -49,12 +49,9 @@ void _TOD_Set(
|
||||
_Watchdog_Adjust_seconds( WATCHDOG_FORWARD,
|
||||
time->tv_sec - _TOD_Seconds_since_epoch );
|
||||
|
||||
_TOD_Seconds_since_epoch = time->tv_sec;
|
||||
_TOD_Is_set = TRUE;
|
||||
|
||||
/* POSIX format TOD (timespec) */
|
||||
_TOD_Now = *time;
|
||||
_TOD_Now.tv_sec += TOD_SECONDS_1970_THROUGH_1988;
|
||||
_TOD_Is_set = TRUE;
|
||||
|
||||
_TOD_Activate( 0 );
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
/*
|
||||
* Time of Day (TOD) Handler -- Tickle Ticks
|
||||
*
|
||||
* COPYRIGHT (c) 1989-2007.
|
||||
*/
|
||||
|
||||
/* COPYRIGHT (c) 1989-2007.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <rtems/system.h>
|
||||
#include <rtems/score/object.h>
|
||||
#include <rtems/score/thread.h>
|
||||
#include <rtems/score/timespec.h>
|
||||
#include <rtems/score/tod.h>
|
||||
#include <rtems/score/watchdog.h>
|
||||
|
||||
@@ -46,11 +47,11 @@ void _TOD_Tickle_ticks( void )
|
||||
_Watchdog_Ticks_since_boot += 1;
|
||||
|
||||
/* Update the timespec format uptime */
|
||||
(void) _TOD_Add_timespec( &_TOD_Uptime, &tick );
|
||||
(void) _Timespec_Add_to( &_TOD_Uptime, &tick );
|
||||
/* we do not care how much the uptime changed */
|
||||
|
||||
/* Update the timespec format TOD */
|
||||
seconds = _TOD_Add_timespec( &_TOD_Now, &tick );
|
||||
seconds = _Timespec_Add_to( &_TOD_Now, &tick );
|
||||
while ( seconds ) {
|
||||
_Watchdog_Tickle_seconds();
|
||||
seconds--;
|
||||
|
||||
51
cpukit/score/src/timespecaddto.c
Normal file
51
cpukit/score/src/timespecaddto.c
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* @file score/src//timespecaddto.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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 <sys/types.h>
|
||||
#include <rtems/score/timespec.h>
|
||||
#include <rtems/score/tod.h>
|
||||
#include <rtems/score/watchdog.h>
|
||||
|
||||
/**
|
||||
*
|
||||
* This routines adds two timespecs. The second argument is added
|
||||
* to the first.
|
||||
*/
|
||||
|
||||
uint32_t _Timespec_Add_to(
|
||||
struct timespec *time,
|
||||
const struct timespec *add
|
||||
)
|
||||
{
|
||||
uint32_t seconds = add->tv_sec;
|
||||
|
||||
/* Add the basics */
|
||||
time->tv_sec += add->tv_sec;
|
||||
time->tv_nsec += add->tv_nsec;
|
||||
|
||||
/* Now adjust it so nanoseconds is in range */
|
||||
while ( time->tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) {
|
||||
time->tv_nsec -= TOD_NANOSECONDS_PER_SECOND;
|
||||
time->tv_sec++;
|
||||
seconds++;
|
||||
}
|
||||
|
||||
return seconds;
|
||||
}
|
||||
@@ -1,4 +1,11 @@
|
||||
/*
|
||||
* 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$
|
||||
*/
|
||||
|
||||
@@ -7,23 +14,13 @@
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <rtems/system.h>
|
||||
#include <rtems/score/isr.h>
|
||||
#include <rtems/score/thread.h>
|
||||
#include <rtems/score/timespec.h>
|
||||
#include <rtems/score/tod.h>
|
||||
|
||||
#include <rtems/seterr.h>
|
||||
#include <rtems/posix/time.h>
|
||||
|
||||
/*PAGE
|
||||
*
|
||||
* _POSIX_Interval_to_timespec
|
||||
*/
|
||||
|
||||
void _POSIX_Interval_to_timespec(
|
||||
Watchdog_Interval ticks,
|
||||
void _Timespec_From_ticks(
|
||||
uint32_t ticks,
|
||||
struct timespec *time
|
||||
)
|
||||
{
|
||||
43
cpukit/score/src/timespecisvalid.c
Normal file
43
cpukit/score/src/timespecisvalid.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* @file score/src/timespecisvalid.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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 <sys/types.h>
|
||||
|
||||
#include <rtems/system.h>
|
||||
#include <rtems/score/timespec.h>
|
||||
#include <rtems/score/tod.h>
|
||||
|
||||
boolean _Timespec_Is_valid(
|
||||
const struct timespec *time
|
||||
)
|
||||
{
|
||||
if ( !time )
|
||||
return FALSE;
|
||||
|
||||
if ( time->tv_sec < 0 )
|
||||
return FALSE;
|
||||
|
||||
if ( time->tv_nsec < 0 )
|
||||
return FALSE;
|
||||
|
||||
if ( time->tv_nsec >= TOD_NANOSECONDS_PER_SECOND )
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
42
cpukit/score/src/timespeclessthan.c
Normal file
42
cpukit/score/src/timespeclessthan.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @file score/src/timespeclessthan.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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 <sys/types.h>
|
||||
|
||||
#include <rtems/system.h>
|
||||
#include <rtems/score/timespec.h>
|
||||
#include <rtems/score/tod.h>
|
||||
|
||||
boolean _Timespec_Less_than(
|
||||
const struct timespec *lhs,
|
||||
const struct timespec *rhs
|
||||
)
|
||||
{
|
||||
if ( lhs->tv_sec < rhs->tv_sec )
|
||||
return TRUE;
|
||||
|
||||
if ( lhs->tv_sec > rhs->tv_sec )
|
||||
return FALSE;
|
||||
|
||||
/* ASSERT: lhs->tv_sec == rhs->tv_sec */
|
||||
if ( lhs->tv_nsec < rhs->tv_nsec )
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
41
cpukit/score/src/timespecsubtract.c
Normal file
41
cpukit/score/src/timespecsubtract.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @file score/src/timespecsubtract.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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 <sys/types.h>
|
||||
#include <rtems/score/timespec.h>
|
||||
#include <rtems/score/tod.h>
|
||||
#include <rtems/score/watchdog.h>
|
||||
|
||||
void _Timespec_Subtract(
|
||||
const struct timespec *start,
|
||||
const struct timespec *end,
|
||||
struct timespec *result
|
||||
)
|
||||
{
|
||||
|
||||
if (end->tv_nsec < start->tv_nsec) {
|
||||
result->tv_sec = end->tv_sec - start->tv_sec - 1;
|
||||
result->tv_nsec =
|
||||
(TOD_NANOSECONDS_PER_SECOND - start->tv_nsec) + end->tv_nsec;
|
||||
} else {
|
||||
result->tv_sec = end->tv_sec - start->tv_sec;
|
||||
result->tv_nsec = end->tv_nsec - start->tv_nsec;
|
||||
}
|
||||
}
|
||||
49
cpukit/score/src/timespectoticks.c
Normal file
49
cpukit/score/src/timespectoticks.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* @file score/src/timespectoticks.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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/timespec.h>
|
||||
#include <sys/types.h>
|
||||
#include <rtems/score/tod.h>
|
||||
#include <rtems/score/watchdog.h>
|
||||
|
||||
/**
|
||||
*
|
||||
* This routines converts a timespec to the corresponding number of ticks.
|
||||
*/
|
||||
|
||||
uint32_t _Timespec_To_ticks(
|
||||
const struct timespec *time
|
||||
)
|
||||
{
|
||||
uint32_t ticks;
|
||||
|
||||
if ( (time->tv_sec == 0) && (time->tv_nsec == 0) )
|
||||
return 0;
|
||||
|
||||
ticks = time->tv_sec * TOD_TICKS_PER_SECOND;
|
||||
|
||||
ticks += (time->tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND) /
|
||||
_TOD_Microseconds_per_tick;
|
||||
|
||||
if (ticks)
|
||||
return ticks;
|
||||
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user