Index: cpukit/ChangeLog
===================================================================
--- cpukit/ChangeLog	(revision a6ec37212798aedefb9a9f74536075f8b70b6a05)
+++ cpukit/ChangeLog	(revision f6e09342eea83a34edeb71a140c988a818053a32)
@@ -1,2 +1,11 @@
+2007-04-02	Joel Sherrill <joel@OARcorp.com>
+
+	* posix/include/rtems/posix/timer.h, posix/src/alarm.c,
+	posix/src/posixtimespectointerval.c, posix/src/ptimer1.c,
+	posix/src/sysconf.c, posix/src/ualarm.c, rtems/src/clockget.c,
+	rtems/src/clocktodvalidate.c, score/include/rtems/score/tod.h,
+	score/inline/rtems/score/tod.inl, score/src/coretod.c: Eliminate
+	TOD_Ticks_per_second variable.
+
 2007-04-02	Joel Sherrill <joel@OARcorp.com>
 
Index: cpukit/posix/include/rtems/posix/timer.h
===================================================================
--- cpukit/posix/include/rtems/posix/timer.h	(revision a6ec37212798aedefb9a9f74536075f8b70b6a05)
+++ cpukit/posix/include/rtems/posix/timer.h	(revision f6e09342eea83a34edeb71a140c988a818053a32)
@@ -11,26 +11,28 @@
 
 #include <rtems/posix/config.h>
+
+/* Timer is free */
+#define POSIX_TIMER_STATE_FREE        0x01
+                                                                
+/* Created timer but not running          */
+#define POSIX_TIMER_STATE_CREATE_NEW  0x02
+
+/* Created timer and running              */
+#define POSIX_TIMER_STATE_CREATE_RUN  0x03
+
+/* Created, ran and stopped timer         */
+#define POSIX_TIMER_STATE_CREATE_STOP 0x04
+
+/* Indicates that the fire time is relative to the current one */
+#define POSIX_TIMER_RELATIVE       0
+
 /*
- * Constants
- */ 
-
-#define STATE_FREE_C        0x01 /* Free position of the table of timers   */
-#define STATE_CREATE_NEW_C  0x02 /* Created timer but not running          */
-#define STATE_CREATE_RUN_C  0x03 /* Created timer and running              */
-#define STATE_CREATE_STOP_C 0x04 /* Created, ran and stopped timer         */
-/* Maximum number of nsec allowed         */
-#define MAX_NSEC_C    (uint32_t  )1000000000
-#define MIN_NSEC_C             0 /* Minimum number of nsec allowew         */
-#define TIMER_RELATIVE_C       0 /* Indicates that the fire time is
-                                  * relative to the current one            */
-#define SEC_TO_TICKS_C _TOD_Ticks_per_second /* Number of ticks in a second*/
-/* Nanoseconds in a second               */
-#define NSEC_PER_SEC_C (uint32_t  )1000000000
-
-#define SECONDS_PER_YEAR_C    (uint32_t  )(360 * 24) * (uint32_t  )(60 * 60)
-#define SECONDS_PER_MONTH_C   (uint32_t  )( 30 * 24) * (uint32_t  )(60 * 60)
-#define SECONDS_PER_DAY_C     (uint32_t  )( 24 * 60) * (uint32_t  )(60)
-#define SECONDS_PER_HOUR_C               (uint32_t  )( 60 * 60 )
-#define SECONDS_PER_MINUTE_C                  (uint32_t  )( 60 )
+ * POSIX defines TIMER_ABSTIME but no constant for relative.  So
+ * we have one internally but we need to be careful it has a different
+ * value.
+ */
+#if (POSIX_TIMER_RELATIVE == TIMER_ABSTIME)
+#error "POSIX_TIMER_RELATIVE == TIMER_ABSTIME"
+#endif
 
 
@@ -38,5 +40,4 @@
  * Data for a timer
  */
-
 typedef struct {
   Objects_Control   Object;
@@ -58,5 +59,4 @@
  *  This routine performs the initialization necessary for this manager.
  */
-
 void _POSIX_Timer_Manager_initialization ( int max_timers );
 
@@ -65,5 +65,4 @@
  *  this class of objects.
  */
-
 POSIX_EXTERN Objects_Information  _POSIX_Timer_Information;
 
Index: cpukit/posix/src/alarm.c
===================================================================
--- cpukit/posix/src/alarm.c	(revision a6ec37212798aedefb9a9f74536075f8b70b6a05)
+++ cpukit/posix/src/alarm.c	(revision f6e09342eea83a34edeb71a140c988a818053a32)
@@ -70,7 +70,10 @@
          */
 
-        remaining = the_timer->initial -
-         ((the_timer->stop_time - the_timer->start_time) /
-	   _TOD_Ticks_per_second);
+        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;
         break;
     }
Index: cpukit/posix/src/posixtimespectointerval.c
===================================================================
--- cpukit/posix/src/posixtimespectointerval.c	(revision a6ec37212798aedefb9a9f74536075f8b70b6a05)
+++ cpukit/posix/src/posixtimespectointerval.c	(revision f6e09342eea83a34edeb71a140c988a818053a32)
@@ -29,5 +29,7 @@
   Watchdog_Interval  ticks;
 
-  ticks  = (time->tv_sec * _TOD_Ticks_per_second);
+  ticks  = time->tv_sec *
+           (TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick);
+
   ticks += (time->tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND) /
              _TOD_Microseconds_per_tick;
Index: cpukit/posix/src/ptimer1.c
===================================================================
--- cpukit/posix/src/ptimer1.c	(revision a6ec37212798aedefb9a9f74536075f8b70b6a05)
+++ cpukit/posix/src/ptimer1.c	(revision f6e09342eea83a34edeb71a140c988a818053a32)
@@ -68,46 +68,4 @@
 /* #define DEBUG_MESSAGES */
 
-/*
- * ITIMERSPEC_TO_RTEMS_TIME_OF_DAY_S
- *
- *  Description: This function converts the data of a structure itimerspec
- *               into structure rtems_time_of_day
-  */
-
-void ITIMERSPEC_TO_RTEMS_TIME_OF_DAY_S(
-  const struct itimerspec *itimer,
-  rtems_time_of_day *rtems_time
-)
-{
-   unsigned long int seconds;
-
-   /* The leap years and the months with 28, 29 or 31 days have not been
-    * considered. It will be made in the future */
-
-   seconds            = itimer->it_value.tv_sec;
-
-   rtems_time->year   = seconds / SECONDS_PER_YEAR_C;
-   seconds            = seconds % SECONDS_PER_YEAR_C;
-
-   rtems_time->month  = seconds / SECONDS_PER_MONTH_C;
-   seconds            = seconds % SECONDS_PER_MONTH_C;
-
-   rtems_time->day    = seconds / SECONDS_PER_DAY_C;
-   seconds            = seconds % SECONDS_PER_DAY_C;
-
-   rtems_time->hour   = seconds / SECONDS_PER_HOUR_C;
-   seconds            = seconds % SECONDS_PER_HOUR_C;
-
-   rtems_time->minute = seconds / SECONDS_PER_MINUTE_C;
-   seconds            = seconds % SECONDS_PER_MINUTE_C;
-
-   rtems_time->second = seconds;
-
-   rtems_time->ticks  = itimer->it_value.tv_nsec/
-                        (NSEC_PER_SEC_C / SEC_TO_TICKS_C);
-
-}
-
-
 /* ***************************************************************************
  * _POSIX_Timer_TSR
@@ -147,8 +105,8 @@
 
     /* The state really did not change but just to be safe */
-    ptimer->state = STATE_CREATE_RUN_C;
+    ptimer->state = POSIX_TIMER_STATE_CREATE_RUN;
   } else {
    /* Indicates that the timer is stopped */
-   ptimer->state = STATE_CREATE_STOP_C;
+   ptimer->state = POSIX_TIMER_STATE_CREATE_STOP;
   }
 
@@ -220,5 +178,5 @@
   /* The data of the created timer are stored to use them later */
 
-  ptimer->state     = STATE_CREATE_NEW_C;
+  ptimer->state     = POSIX_TIMER_STATE_CREATE_NEW;
   ptimer->thread_id = _Thread_Executing->Object.id;
 
@@ -275,5 +233,5 @@
     case OBJECTS_LOCAL:
       _Objects_Close( &_POSIX_Timer_Information, &ptimer->Object );
-      ptimer->state = STATE_FREE_C;
+      ptimer->state = POSIX_TIMER_STATE_FREE;
       (void) _Watchdog_Remove( &ptimer->Timer );
       _POSIX_Timer_Free( ptimer );
@@ -309,6 +267,6 @@
 
   /* First, it verifies if the structure "value" is correct */
-  if ( ( value->it_value.tv_nsec > MAX_NSEC_C ) ||
-       ( value->it_value.tv_nsec < MIN_NSEC_C ) ) {
+  if ( ( value->it_value.tv_nsec > TOD_NANOSECONDS_PER_SECOND ) ||
+       ( value->it_value.tv_nsec < 0 ) ) {
     /* The number of nanoseconds is not correct */
     rtems_set_errno_and_return_minus_one( EINVAL );
@@ -317,5 +275,5 @@
   /* XXX check for seconds in the past */
 
-  if ( flags != TIMER_ABSTIME && flags != TIMER_RELATIVE_C ) {
+  if ( flags != TIMER_ABSTIME && flags != POSIX_TIMER_RELATIVE ) {
     rtems_set_errno_and_return_minus_one( EINVAL );
   }
@@ -349,5 +307,5 @@
          ptimer->timer_data = *value;
          /* Indicates that the timer is created and stopped */
-         ptimer->state = STATE_CREATE_STOP_C;
+         ptimer->state = POSIX_TIMER_STATE_CREATE_STOP;
          /* Returns with success */
         _Thread_Enable_dispatch();
@@ -362,9 +320,4 @@
            /* First, it converts from struct itimerspec to rtems_time_of_day */
 
-#if 0
-           ITIMERSPEC_TO_RTEMS_TIME_OF_DAY_S( value, &tod );
-           status = rtems_timer_fire_when(
-             ptimer->timer_id, &tod, _POSIX_Timer_TSR, ptimer);
-#endif
            _Watchdog_Initialize(
              &ptimer->Timer, _POSIX_Timer_TSR, ptimer->Object.id, ptimer );
@@ -381,5 +334,5 @@
 
            /* Indicate that the time is running */
-           ptimer->state = STATE_CREATE_RUN_C;
+           ptimer->state = POSIX_TIMER_STATE_CREATE_RUN;
 
            /* Stores the time in which the timer was started again */
@@ -390,13 +343,8 @@
 
          /* The fire time is relative: use "rtems_time_fire_after" */
-         case TIMER_RELATIVE_C:
+         case POSIX_TIMER_RELATIVE:
            /* First, convert from seconds and nanoseconds to ticks */
-           ptimer->ticks = ( SEC_TO_TICKS_C * value->it_value.tv_sec ) +
-                ( value->it_value.tv_nsec / (NSEC_PER_SEC_C / SEC_TO_TICKS_C));
-
-#if 0
-           status = rtems_timer_fire_after(
-             ptimer->timer_id, ptimer->ticks, _POSIX_Timer_TSR, ptimer );
-#endif
+           ptimer->ticks = _POSIX_Timespec_to_interval( &value->it_value );
+
            activated = _Watchdog_Insert_ticks_helper(
              &ptimer->Timer,
@@ -416,5 +364,5 @@
 
            /* Indicate that the time is running */
-           ptimer->state = STATE_CREATE_RUN_C;
+           ptimer->state = POSIX_TIMER_STATE_CREATE_RUN;
            _TOD_Get( &ptimer->time );
             _Thread_Enable_dispatch();
@@ -475,5 +423,6 @@
       /* Calculates the time left before the timer finishes */
 
-      _POSIX_Timespec_subtract(&ptimer->timer_data.it_value, &current_time, &value->it_value);
+      _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;
Index: cpukit/posix/src/sysconf.c
===================================================================
--- cpukit/posix/src/sysconf.c	(revision a6ec37212798aedefb9a9f74536075f8b70b6a05)
+++ cpukit/posix/src/sysconf.c	(revision f6e09342eea83a34edeb71a140c988a818053a32)
@@ -28,5 +28,5 @@
   switch (name) {
     case _SC_CLK_TCK:
-      return _TOD_Ticks_per_second;
+      return (TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick);
 
     case _SC_OPEN_MAX: {
Index: cpukit/posix/src/ualarm.c
===================================================================
--- cpukit/posix/src/ualarm.c	(revision a6ec37212798aedefb9a9f74536075f8b70b6a05)
+++ cpukit/posix/src/ualarm.c	(revision f6e09342eea83a34edeb71a140c988a818053a32)
@@ -74,8 +74,10 @@
          */
 
-
-        ticks = the_timer->initial -
-         ((the_timer->stop_time - the_timer->start_time) /
-	   _TOD_Ticks_per_second);
+        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 );
Index: cpukit/rtems/src/clockget.c
===================================================================
--- cpukit/rtems/src/clockget.c	(revision a6ec37212798aedefb9a9f74536075f8b70b6a05)
+++ cpukit/rtems/src/clockget.c	(revision f6e09342eea83a34edeb71a140c988a818053a32)
@@ -76,21 +76,31 @@
       return RTEMS_SUCCESSFUL;
     }
-    case RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH:
+    case RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH: {
+      rtems_interval *interval = (rtems_interval *)time_buffer;
+
       if ( !_TOD_Is_set )
         return RTEMS_NOT_DEFINED;
 
-      *(rtems_interval *)time_buffer = _TOD_Seconds_since_epoch;
+      *interval = _TOD_Seconds_since_epoch;
       return RTEMS_SUCCESSFUL;
+    }
 
-    case RTEMS_CLOCK_GET_TICKS_SINCE_BOOT:
-      *(rtems_interval *)time_buffer = _Watchdog_Ticks_since_boot;
+    case RTEMS_CLOCK_GET_TICKS_SINCE_BOOT: {
+      rtems_interval *interval = (rtems_interval *)time_buffer;
+
+      *interval = _Watchdog_Ticks_since_boot;
       return RTEMS_SUCCESSFUL;
+    }
 
-    case RTEMS_CLOCK_GET_TICKS_PER_SECOND:
-      *(rtems_interval *)time_buffer = _TOD_Ticks_per_second;
+    case RTEMS_CLOCK_GET_TICKS_PER_SECOND: {
+      rtems_interval *interval = (rtems_interval *)time_buffer;
+
+      *interval = TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick;
       return RTEMS_SUCCESSFUL;
+    }
 
     case RTEMS_CLOCK_GET_TIME_VALUE: {
       struct timeval *time = (struct timeval *)time_buffer;
+
       if ( !_TOD_Is_set )
         return RTEMS_NOT_DEFINED;
Index: cpukit/rtems/src/clocktodvalidate.c
===================================================================
--- cpukit/rtems/src/clocktodvalidate.c	(revision a6ec37212798aedefb9a9f74536075f8b70b6a05)
+++ cpukit/rtems/src/clocktodvalidate.c	(revision f6e09342eea83a34edeb71a140c988a818053a32)
@@ -54,5 +54,6 @@
 
   if ((!the_tod)                                  ||
-      (the_tod->ticks  >= _TOD_Ticks_per_second)  ||
+      (the_tod->ticks  >=
+          (TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick))  ||
       (the_tod->second >= TOD_SECONDS_PER_MINUTE) ||
       (the_tod->minute >= TOD_MINUTES_PER_HOUR)   ||
Index: cpukit/score/include/rtems/score/tod.h
===================================================================
--- cpukit/score/include/rtems/score/tod.h	(revision a6ec37212798aedefb9a9f74536075f8b70b6a05)
+++ cpukit/score/include/rtems/score/tod.h	(revision f6e09342eea83a34edeb71a140c988a818053a32)
@@ -146,15 +146,4 @@
 SCORE_EXTERN uint32_t   _TOD_Microseconds_per_tick;
 
-/** @brief Clock Ticks per Second
- *
- *  The following contains the number of clock ticks per second.
- *
- *  @note If one second is NOT evenly divisible by the number of microseconds
- *  per clock tick, this value will contain only the integer portion
- *  of the division.  This means that the interval between clock ticks
- *  can be a source of error in the current time of day.
- */
-SCORE_EXTERN uint32_t   _TOD_Ticks_per_second;
-
 /** @brief _TOD_Handler_initialization
  *
Index: cpukit/score/inline/rtems/score/tod.inl
===================================================================
--- cpukit/score/inline/rtems/score/tod.inl	(revision a6ec37212798aedefb9a9f74536075f8b70b6a05)
+++ cpukit/score/inline/rtems/score/tod.inl	(revision f6e09342eea83a34edeb71a140c988a818053a32)
@@ -97,7 +97,5 @@
  */
 
-RTEMS_INLINE_ROUTINE void _TOD_Activate(
-  Watchdog_Interval ticks
-)
+RTEMS_INLINE_ROUTINE void _TOD_Activate()
 {
   /* XXX do we need something now that we are using timespec for TOD */
Index: cpukit/score/src/coretod.c
===================================================================
--- cpukit/score/src/coretod.c	(revision a6ec37212798aedefb9a9f74536075f8b70b6a05)
+++ cpukit/score/src/coretod.c	(revision f6e09342eea83a34edeb71a140c988a818053a32)
@@ -52,13 +52,6 @@
   _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;
-
   /* TOD has not been set */
   _TOD_Is_set = FALSE;
-  _TOD_Activate( _TOD_Ticks_per_second );
+  _TOD_Activate();
 }
