summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2007-04-02 18:23:59 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2007-04-02 18:23:59 +0000
commit812da546889eea0b6dea7eb2954f46a4c43d1314 (patch)
tree22fc95d921c3544de770454a2f9c604d5d0a27a2 /cpukit/posix/src
parent2007-04-02 Joel Sherrill <joel@OARcorp.com> (diff)
downloadrtems-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/posix/src')
-rw-r--r--cpukit/posix/src/clockgettime.c21
-rw-r--r--cpukit/posix/src/clocksettime.c36
-rw-r--r--cpukit/posix/src/nanosleep.c10
-rw-r--r--cpukit/posix/src/posixtimespecsubtract.c15
-rw-r--r--cpukit/posix/src/posixtimespectointerval.c4
-rw-r--r--cpukit/posix/src/ptimer1.c53
-rw-r--r--cpukit/posix/src/sleep.c1
7 files changed, 40 insertions, 100 deletions
diff --git a/cpukit/posix/src/clockgettime.c b/cpukit/posix/src/clockgettime.c
index 5a39bba210..d5752359c0 100644
--- a/cpukit/posix/src/clockgettime.c
+++ b/cpukit/posix/src/clockgettime.c
@@ -27,31 +27,24 @@ int clock_gettime(
struct timespec *tp
)
{
- ISR_Level level;
- time_t seconds;
- long ticks;
-
if ( !tp )
rtems_set_errno_and_return_minus_one( EINVAL );
switch ( clock_id ) {
case CLOCK_REALTIME:
+ _TOD_Get(tp);
+ break;
- _ISR_Disable( level );
- seconds = _TOD_Seconds_since_epoch;
- ticks = _TOD_Current.ticks;
- _ISR_Enable( level );
-
- tp->tv_sec = seconds + POSIX_TIME_SECONDS_1970_THROUGH_1988;
- tp->tv_nsec = ticks * _TOD_Microseconds_per_tick *
- TOD_NANOSECONDS_PER_MICROSECOND;
+#if 0
+ case CLOCK_MONOTONIC:
+ _TOD_Get_uptime(tp);
break;
+#endif
#ifdef _POSIX_CPUTIME
case CLOCK_PROCESS_CPUTIME:
- /* don't base this on _Watchdog_Ticks_since_boot--duration is too short*/
- return POSIX_NOT_IMPLEMENTED();
+ _TOD_Get_uptime(tp);
break;
#endif
diff --git a/cpukit/posix/src/clocksettime.c b/cpukit/posix/src/clocksettime.c
index c85e90de61..ed8035bba3 100644
--- a/cpukit/posix/src/clocksettime.c
+++ b/cpukit/posix/src/clocksettime.c
@@ -6,7 +6,6 @@
#include "config.h"
#endif
-#include <assert.h>
#include <time.h>
#include <errno.h>
@@ -28,44 +27,17 @@ int clock_settime(
const struct timespec *tp
)
{
- struct tm split_time;
- TOD_Control tod;
- Watchdog_Interval seconds;
-
- assert( tp );
+ if ( !tp )
+ rtems_set_errno_and_return_minus_one( EINVAL );
switch ( clock_id ) {
case CLOCK_REALTIME:
- (void) gmtime_r( &tp->tv_sec, &split_time );
-
- /*
- * Convert the tm structure format to that used by the TOD Handler
- *
- * NOTE: TOD Handler does not honor leap seconds.
- */
-
- tod.year = split_time.tm_year + 1900; /* RHS is years since 1900 */
- tod.month = split_time.tm_mon + 1; /* RHS uses 0-11 */
- tod.day = split_time.tm_mday;
- tod.hour = split_time.tm_hour;
- tod.minute = split_time.tm_min;
- tod.second = split_time.tm_sec; /* RHS allows 0-61 for leap seconds */
-
- tod.ticks = (tp->tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND) /
- _TOD_Microseconds_per_tick;
-
- if ( !_TOD_Validate( &tod ) )
+ if ( tp->tv_sec < TOD_SECONDS_1970_THROUGH_1988 )
rtems_set_errno_and_return_minus_one( EINVAL );
- /*
- * We can't use the tp->tv_sec field because it is based on
- * a different EPOCH.
- */
-
- seconds = _TOD_To_seconds( &tod );
_Thread_Disable_dispatch();
- _TOD_Set( &tod, seconds );
+ _TOD_Set( tp );
_Thread_Enable_dispatch();
break;
diff --git a/cpukit/posix/src/nanosleep.c b/cpukit/posix/src/nanosleep.c
index a7fc8d6e97..47f7cbad0e 100644
--- a/cpukit/posix/src/nanosleep.c
+++ b/cpukit/posix/src/nanosleep.c
@@ -54,6 +54,13 @@ int nanosleep(
ticks = _POSIX_Timespec_to_interval( the_rqtp );
/*
+ * Bump the ticks by one so the delay is at least the number of
+ * ticks requested
+ */
+ ticks++;
+
+ /*
+ * 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.
*/
@@ -69,6 +76,9 @@ int nanosleep(
return 0;
}
+ /*
+ * Block for the desired amount of time
+ */
_Thread_Disable_dispatch();
_Thread_Set_state(
_Thread_Executing,
diff --git a/cpukit/posix/src/posixtimespecsubtract.c b/cpukit/posix/src/posixtimespecsubtract.c
index 52b3c79fec..a2cce2a332 100644
--- a/cpukit/posix/src/posixtimespecsubtract.c
+++ b/cpukit/posix/src/posixtimespecsubtract.c
@@ -23,11 +23,12 @@
*/
void _POSIX_Timespec_subtract(
- const struct timespec *the_start,
+ 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;
@@ -43,7 +44,15 @@ void _POSIX_Timespec_subtract(
start->tv_nsec += nsecs_per_sec * seconds;
start->tv_sec -= seconds;
}
+#else
- result->tv_sec = end->tv_sec - start->tv_sec;
- result->tv_nsec = end->tv_nsec - start->tv_nsec;
+#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;
+ }
}
diff --git a/cpukit/posix/src/posixtimespectointerval.c b/cpukit/posix/src/posixtimespectointerval.c
index 3edebc7060..024dfe679c 100644
--- a/cpukit/posix/src/posixtimespectointerval.c
+++ b/cpukit/posix/src/posixtimespectointerval.c
@@ -28,9 +28,7 @@ Watchdog_Interval _POSIX_Timespec_to_interval(
{
Watchdog_Interval ticks;
- ticks = (time->tv_sec * TOD_MICROSECONDS_PER_SECOND) /
- _TOD_Microseconds_per_tick;
-
+ ticks = (time->tv_sec * _TOD_Ticks_per_second);
ticks += (time->tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND) /
_TOD_Microseconds_per_tick;
diff --git a/cpukit/posix/src/ptimer1.c b/cpukit/posix/src/ptimer1.c
index c1a8f77d06..c8a97b3644 100644
--- a/cpukit/posix/src/ptimer1.c
+++ b/cpukit/posix/src/ptimer1.c
@@ -143,7 +143,7 @@ void _POSIX_Timer_TSR(Objects_Id timer, void *data)
return;
/* Store the time when the timer was started again */
- ptimer->time = _TOD_Current;
+ _TOD_Get( &ptimer->time );
/* The state really did not change but just to be safe */
ptimer->state = STATE_CREATE_RUN_C;
@@ -383,7 +383,7 @@ int timer_settime(
ptimer->state = STATE_CREATE_RUN_C;
/* Stores the time in which the timer was started again */
- ptimer->time = _TOD_Current;
+ _TOD_Get( &ptimer->time );
_Thread_Enable_dispatch();
return 0;
break;
@@ -416,7 +416,7 @@ int timer_settime(
/* Indicate that the time is running */
ptimer->state = STATE_CREATE_RUN_C;
- ptimer->time = _TOD_Current;
+ _TOD_Get( &ptimer->time );
_Thread_Enable_dispatch();
return 0;
}
@@ -454,15 +454,10 @@ int timer_gettime(
POSIX_Timer_Control *ptimer;
Objects_Locations location;
- rtems_time_of_day current_time;
- uint32_t hours;
- uint32_t minutes;
- uint32_t seconds;
- uint32_t ticks;
- uint32_t nanosec;
+ struct timespec current_time;
/* Reads the current time */
- current_time = _TOD_Current;
+ _TOD_Get( &current_time );
ptimer = _POSIX_Timer_Get( timerid, &location );
switch ( location ) {
@@ -476,46 +471,10 @@ int timer_gettime(
rtems_set_errno_and_return_minus_one( EINVAL );
case OBJECTS_LOCAL:
- /* Calculates the difference between the start time of the timer and
- * the current one */
-
- hours = current_time.hour - ptimer->time.hour;
-
- if ( current_time.minute < ptimer->time.minute ) {
- minutes = 60 - ptimer->time.minute + current_time.minute;
- hours--;
- } else {
- minutes = current_time.minute - ptimer->time.minute;
- }
-
- if ( current_time.second < ptimer->time.second ) {
- seconds = 60 - ptimer->time.second + current_time.second;
- minutes--;
- } else {
- seconds = current_time.second - ptimer->time.second;
- }
-
- if ( current_time.ticks < ptimer->time.ticks ) {
- ticks = 100 - ptimer->time.ticks + current_time.ticks;
- seconds--;
- } else {
- ticks = current_time.ticks - ptimer->time.ticks;
- }
-
- /* The time that the timer is running is calculated */
- seconds = hours * 60 * 60 +
- minutes * 60 +
- seconds;
-
- nanosec = ticks * 10 * /* msec */
- 1000 * /* microsec */
- 1000; /* nanosec */
-
/* Calculates the time left before the timer finishes */
- value->it_value.tv_sec = ptimer->timer_data.it_value.tv_sec - seconds;
- value->it_value.tv_nsec = ptimer->timer_data.it_value.tv_nsec - nanosec;
+ _POSIX_Timespec_subtract(&ptimer->timer_data.it_value, &current_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;
diff --git a/cpukit/posix/src/sleep.c b/cpukit/posix/src/sleep.c
index 501fe5770f..b4670a96ce 100644
--- a/cpukit/posix/src/sleep.c
+++ b/cpukit/posix/src/sleep.c
@@ -18,7 +18,6 @@ unsigned int sleep(
unsigned int seconds
)
{
- /* XXX can we get away with this implementation? */
struct timespec tp;
struct timespec tm;