Changeset 812da54 in rtems


Ignore:
Timestamp:
Apr 2, 2007, 6:23:59 PM (13 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, master
Children:
23a0105a
Parents:
bf4d016
Message:

2007-04-02 Joel Sherrill <joel@…>

  • 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.
Location:
cpukit
Files:
3 added
3 deleted
26 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    rbf4d016 r812da54  
     12007-04-02      Joel Sherrill <joel@OARcorp.com>
     2
     3        * itron/src/itrontime.c, libcsupport/src/__gettod.c,
     4        posix/include/rtems/posix/time.h, posix/include/rtems/posix/timer.h,
     5        posix/src/clockgettime.c, posix/src/clocksettime.c,
     6        posix/src/nanosleep.c, posix/src/posixtimespecsubtract.c,
     7        posix/src/posixtimespectointerval.c, posix/src/ptimer1.c,
     8        posix/src/sleep.c, rtems/Makefile.am,
     9        rtems/include/rtems/rtems/clock.h, rtems/include/rtems/rtems/timer.h,
     10        rtems/include/rtems/rtems/types.h, rtems/src/clockget.c,
     11        rtems/src/clockset.c, rtems/src/clocktodtoseconds.c,
     12        rtems/src/clocktodvalidate.c, rtems/src/taskwakewhen.c,
     13        score/Makefile.am, score/include/rtems/score/tod.h,
     14        score/inline/rtems/score/tod.inl, score/src/coretod.c,
     15        score/src/coretodset.c: Convert from Classic API style TOD_Control as
     16        fundamental time structure to POSIX struct timespec. Add
     17        clock_get_uptime().
     18        * rtems/src/clockgetuptime.c, score/src/coretodget.c,
     19        score/src/coretodgetuptime.c: New files.
     20        * score/src/coretodtickle.c, score/src/coretodtoseconds.c,
     21        score/src/coretodvalidate.c: Removed.
     22
    1232007-04-02      Joel Sherrill <joel@OARcorp.com>
    224
  • cpukit/itron/src/itrontime.c

    rbf4d016 r812da54  
    2525 */
    2626
    27 void converTime(SYSTIME ms, TOD_Control *time)
    28 {
    29   int millisecond;
    30 
    31 /* XXX need to dereference structure */
    32 #if 0
    33   milisecond = ms % 1000;
    34   tempSecond = ms / 1000;
    35 #else
    36    millisecond = 0;
    37 #endif
    38 }
    39 
    40 
    41 /*
    42  *  set_tim - Set System Clock
    43  */
    44 
    4527ER set_tim(
    4628  SYSTIME *pk_tim
    4729)
    4830{
    49  Watchdog_Interval temp; /* an integer in seconds after conversion from SYSTIME */
    50  TOD_Control the_tod;
     31#if 0
     32 struct timespec   time;
    5133
    5234/* convert *pk_tim which is 48 bits integer in binary into an ordinary
     
    5638  if(temp > 0) {
    5739    _Thread_Disable_dispatch();
    58       _TOD_Set(&the_tod, temp);
     40      _TOD_Set(&the_tod);
    5941    _Thread_Enable_dispatch();
    60       if(_TOD_Validate(&the_tod)){
    61       return E_OK;
    62       }
     42    return E_OK;
    6343  }
     44#endif
    6445  return E_SYS;
    6546}
  • cpukit/libcsupport/src/__gettod.c

    rbf4d016 r812da54  
    2929
    3030#include <errno.h>
    31 #include <assert.h>
    32 
    33 /*
    34  *  Seconds from January 1, 1970 to January 1, 1988.  Used to account for
    35  *  differences between POSIX API and RTEMS core.
    36  */
    37 
    38 #define POSIX_TIME_SECONDS_1970_THROUGH_1988 \
    39   (((1987 - 1970 + 1)  * TOD_SECONDS_PER_NON_LEAP_YEAR) + \
    40   (4 * TOD_SECONDS_PER_DAY))
    4131
    4232/*
     
    4939)
    5040{
    51   rtems_interrupt_level level;
    52   uint32_t        seconds;
    53   uint32_t        microseconds;
    54 
    5541  if ( !tp ) {
    5642    errno = EFAULT;
     
    6147   *  POSIX does not seem to allow for not having a TOD so we just
    6248   *  grab the time of day.
    63    *
    64    *  NOTE: XXX this routine should really be in the executive proper.
    6549   */
    6650
    67   rtems_interrupt_disable(level);
    68     seconds      = _TOD_Seconds_since_epoch;
    69     microseconds = _TOD_Current.ticks;
    70   rtems_interrupt_enable(level);
    71 
    72   tp->tv_sec  = seconds + POSIX_TIME_SECONDS_1970_THROUGH_1988;
    73   tp->tv_usec = microseconds * _TOD_Microseconds_per_tick;
     51  _TOD_Get_timeval( tp );
    7452
    7553  /*
  • cpukit/posix/include/rtems/posix/time.h

    rbf4d016 r812da54  
    1717 *  Seconds from January 1, 1970 to January 1, 1988.  Used to account for
    1818 *  differences between POSIX API and RTEMS core.
     19 *
     20 *  XXX probably able to be removed once core switches completely to timespec
     21 *  XXX for current TOD.
    1922 */
    20 
    21 #define POSIX_TIME_SECONDS_1970_THROUGH_1988 \
    22   (((1987 - 1970 + 1)  * TOD_SECONDS_PER_NON_LEAP_YEAR) + \
    23   (4 * TOD_SECONDS_PER_DAY))
     23#define POSIX_TIME_SECONDS_1970_THROUGH_1988 TOD_SECONDS_1970_THROUGH_1988
    2424
    2525/*
  • cpukit/posix/include/rtems/posix/timer.h

    rbf4d016 r812da54  
    4848  uint32_t          ticks;      /* Number of ticks of the initialization */
    4949  uint32_t          overrun;    /* Number of expirations of the timer    */
    50   TOD_Control       time;       /* Time in which the timer was started   */
     50  struct timespec   time;       /* Time in which the timer was started   */
    5151} POSIX_Timer_Control;
    5252
  • cpukit/posix/src/clockgettime.c

    rbf4d016 r812da54  
    2828)
    2929{
    30   ISR_Level      level;
    31   time_t         seconds;
    32   long           ticks;
    33 
    3430  if ( !tp )
    3531    rtems_set_errno_and_return_minus_one( EINVAL );
     
    3834
    3935    case CLOCK_REALTIME:
     36      _TOD_Get(tp);
     37      break;
    4038
    41       _ISR_Disable( level );
    42         seconds = _TOD_Seconds_since_epoch;
    43         ticks   = _TOD_Current.ticks;
    44       _ISR_Enable( level );
    45 
    46       tp->tv_sec  = seconds + POSIX_TIME_SECONDS_1970_THROUGH_1988;
    47       tp->tv_nsec = ticks * _TOD_Microseconds_per_tick *
    48                       TOD_NANOSECONDS_PER_MICROSECOND;
     39#if 0
     40    case CLOCK_MONOTONIC:
     41      _TOD_Get_uptime(tp);
    4942      break;
     43#endif
    5044
    5145#ifdef _POSIX_CPUTIME
    5246    case CLOCK_PROCESS_CPUTIME:
    53       /* don't base this on _Watchdog_Ticks_since_boot--duration is too short*/
    54       return POSIX_NOT_IMPLEMENTED();
     47      _TOD_Get_uptime(tp);
    5548      break;
    5649#endif
  • cpukit/posix/src/clocksettime.c

    rbf4d016 r812da54  
    77#endif
    88
    9 #include <assert.h>
    109#include <time.h>
    1110#include <errno.h>
     
    2928)
    3029{
    31   struct tm         split_time;
    32   TOD_Control       tod;
    33   Watchdog_Interval seconds;
    34 
    35   assert( tp );
     30  if ( !tp )
     31    rtems_set_errno_and_return_minus_one( EINVAL );
    3632
    3733  switch ( clock_id ) {
    3834
    3935    case CLOCK_REALTIME:
    40       (void) gmtime_r( &tp->tv_sec, &split_time );
    41 
    42       /*
    43        *  Convert the tm structure format to that used by the TOD Handler
    44        *
    45        *  NOTE: TOD Handler does not honor leap seconds.
    46        */
    47 
    48       tod.year   = split_time.tm_year + 1900;  /* RHS is years since 1900 */
    49       tod.month  = split_time.tm_mon + 1;      /* RHS uses 0-11 */
    50       tod.day    = split_time.tm_mday;
    51       tod.hour   = split_time.tm_hour;
    52       tod.minute = split_time.tm_min;
    53       tod.second = split_time.tm_sec;  /* RHS allows 0-61 for leap seconds */
    54 
    55       tod.ticks  = (tp->tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND) /
    56                       _TOD_Microseconds_per_tick;
    57 
    58       if ( !_TOD_Validate( &tod ) )
     36      if ( tp->tv_sec < TOD_SECONDS_1970_THROUGH_1988 )
    5937        rtems_set_errno_and_return_minus_one( EINVAL );
    6038
    61       /*
    62        *  We can't use the tp->tv_sec field because it is based on
    63        *  a different EPOCH.
    64        */
    65 
    66       seconds = _TOD_To_seconds( &tod );
    6739      _Thread_Disable_dispatch();
    68         _TOD_Set( &tod, seconds );
     40        _TOD_Set( tp );
    6941      _Thread_Enable_dispatch();
    7042      break;
  • cpukit/posix/src/nanosleep.c

    rbf4d016 r812da54  
    5555
    5656  /*
     57   * Bump the ticks by one so the delay is at least the number of
     58   * ticks requested
     59   */
     60  ticks++;
     61
     62  /*
     63   *  A nanosleep for zero time is implemented as a yield.
    5764   *  This behavior is also beyond the POSIX specification but is
    5865   *  consistent with the RTEMS api and yields desirable behavior.
     
    7077  }
    7178
     79  /*
     80   *  Block for the desired amount of time
     81   */
    7282  _Thread_Disable_dispatch();
    7383    _Thread_Set_state(
  • cpukit/posix/src/posixtimespecsubtract.c

    rbf4d016 r812da54  
    2424
    2525void _POSIX_Timespec_subtract(
    26   const struct timespec *the_start,
     26  const struct timespec *start,
    2727  const struct timespec *end,
    2828  struct timespec *result
    2929)
    3030{
     31#if 0
    3132  struct timespec  start_struct = *the_start;
    3233  struct timespec *start = &start_struct;
     
    4445    start->tv_sec -= seconds;
    4546  }
     47#else
    4648
    47   result->tv_sec  = end->tv_sec - start->tv_sec;
    48   result->tv_nsec = end->tv_nsec - start->tv_nsec;
     49#endif
     50
     51  if (end->tv_nsec < start->tv_nsec) {
     52    result->tv_sec  = end->tv_sec - start->tv_sec - 1;
     53    result->tv_nsec = (TOD_NANOSECONDS_PER_SECOND - start->tv_nsec) + end->tv_nsec;
     54  } else {
     55    result->tv_sec  = end->tv_sec - start->tv_sec;
     56    result->tv_nsec = end->tv_nsec - start->tv_nsec;
     57  }
    4958}
  • cpukit/posix/src/posixtimespectointerval.c

    rbf4d016 r812da54  
    2929  Watchdog_Interval  ticks;
    3030
    31   ticks  = (time->tv_sec * TOD_MICROSECONDS_PER_SECOND) /
    32              _TOD_Microseconds_per_tick;
    33 
     31  ticks  = (time->tv_sec * _TOD_Ticks_per_second);
    3432  ticks += (time->tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND) /
    3533             _TOD_Microseconds_per_tick;
  • cpukit/posix/src/ptimer1.c

    rbf4d016 r812da54  
    144144
    145145    /* Store the time when the timer was started again */
    146     ptimer->time = _TOD_Current;
     146    _TOD_Get( &ptimer->time );
    147147
    148148    /* The state really did not change but just to be safe */
     
    384384
    385385           /* Stores the time in which the timer was started again */
    386            ptimer->time = _TOD_Current;
     386           _TOD_Get( &ptimer->time );
    387387           _Thread_Enable_dispatch();
    388388           return 0;
     
    417417           /* Indicate that the time is running */
    418418           ptimer->state = STATE_CREATE_RUN_C;
    419            ptimer->time = _TOD_Current;
     419           _TOD_Get( &ptimer->time );
    420420            _Thread_Enable_dispatch();
    421421           return 0;
     
    455455  POSIX_Timer_Control *ptimer;
    456456  Objects_Locations    location;
    457   rtems_time_of_day    current_time;
    458   uint32_t             hours;
    459   uint32_t             minutes;
    460   uint32_t             seconds;
    461   uint32_t             ticks;
    462   uint32_t             nanosec;
     457  struct timespec      current_time;
    463458
    464459  /* Reads the current time */
    465   current_time = _TOD_Current;
     460  _TOD_Get( &current_time );
    466461
    467462  ptimer = _POSIX_Timer_Get( timerid, &location );
     
    477472
    478473    case OBJECTS_LOCAL:
    479       /* Calculates the difference between the start time of the timer and
    480        * the current one */
    481 
    482       hours    = current_time.hour - ptimer->time.hour;
    483 
    484       if ( current_time.minute < ptimer->time.minute ) {
    485         minutes = 60 - ptimer->time.minute + current_time.minute;
    486         hours--;
    487       } else {
    488         minutes = current_time.minute - ptimer->time.minute;
    489       }
    490 
    491       if ( current_time.second < ptimer->time.second ) {
    492         seconds = 60 - ptimer->time.second + current_time.second;
    493         minutes--;
    494       } else {
    495         seconds = current_time.second - ptimer->time.second;
    496       }
    497 
    498       if ( current_time.ticks < ptimer->time.ticks ) {
    499         ticks = 100 - ptimer->time.ticks + current_time.ticks;
    500         seconds--;
    501       } else {
    502         ticks = current_time.ticks - ptimer->time.ticks;
    503       }
    504 
    505       /* The time that the timer is running is calculated */
    506       seconds = hours   * 60 * 60 +
    507                 minutes * 60      +
    508                 seconds;
    509 
    510       nanosec  = ticks * 10 *  /* msec     */
    511                  1000  *       /* microsec */
    512                  1000;         /* nanosec  */
    513 
    514474
    515475      /* Calculates the time left before the timer finishes */
    516476
    517       value->it_value.tv_sec  = ptimer->timer_data.it_value.tv_sec - seconds;
    518       value->it_value.tv_nsec = ptimer->timer_data.it_value.tv_nsec - nanosec;
     477      _POSIX_Timespec_subtract(&ptimer->timer_data.it_value, &current_time, &value->it_value);
    519478
    520479      value->it_interval.tv_sec  = ptimer->timer_data.it_interval.tv_sec;
  • cpukit/posix/src/sleep.c

    rbf4d016 r812da54  
    1919)
    2020{
    21   /* XXX can we get away with this implementation? */
    2221  struct timespec tp;
    2322  struct timespec tm;
  • cpukit/rtems/Makefile.am

    rbf4d016 r812da54  
    7878## CLOCK_C_FILES
    7979librtems_a_SOURCES += src/rtclock.c src/clockget.c src/clockset.c \
    80     src/clocktick.c src/clocksetnsecshandler.c
     80    src/clocktick.c src/clocksetnsecshandler.c src/clockgetuptime.c \
     81    src/clocktodtoseconds.c src/clocktodvalidate.c
    8182
    8283## TIMER_C_FILES
  • cpukit/rtems/include/rtems/rtems/clock.h

    rbf4d016 r812da54  
    3333
    3434#include <rtems/score/tod.h>
     35#include <rtems/score/watchdog.h>
     36#include <rtems/rtems/status.h>
    3537#include <rtems/rtems/types.h>
    3638
     
    123125);
    124126
     127/*
     128 *  rtems_clock_get_uptime
     129 *
     130 *  DESCRIPTION:
     131 *
     132 *  This directive returns the system uptime.
     133 *
     134 *  Input parameters:
     135 *    routine - pointer to the time structure
     136 *
     137 *  Output parameters:
     138 *    RTEMS_SUCCESSFUL - if successful
     139 *    error code        - if unsuccessful
     140 */
     141rtems_status_code rtems_clock_get_uptime(
     142  struct timespec *uptime
     143);
     144
     145/** @brief _TOD_Validate
     146 *
     147 *  This function returns TRUE if THE_TOD contains
     148 *  a valid time of day, and FALSE otherwise.
     149 */
     150boolean _TOD_Validate(
     151  rtems_time_of_day *the_tod
     152);
     153
     154/** @brief _TOD_To_seconds
     155 *
     156 *  This function returns the number seconds between the epoch and THE_TOD.
     157 */
     158Watchdog_Interval _TOD_To_seconds(
     159  rtems_time_of_day *the_tod
     160);
     161
    125162#ifdef __cplusplus
    126163}
  • cpukit/rtems/include/rtems/rtems/timer.h

    rbf4d016 r812da54  
    4242
    4343#include <rtems/score/object.h>
    44 #include <rtems/score/tod.h>
    4544#include <rtems/score/watchdog.h>
     45#include <rtems/rtems/clock.h>
    4646#include <rtems/rtems/attr.h>
    4747
  • cpukit/rtems/include/rtems/rtems/types.h

    rbf4d016 r812da54  
    6262
    6363typedef Watchdog_Interval rtems_interval;
    64 typedef TOD_Control       rtems_time_of_day;
     64
     65
     66/**
     67 *  The following record defines the time of control block.  This
     68 *  control block is used to maintain the current time of day.
     69 *
     70 *  @note This is an RTEID style time/date.
     71 */
     72typedef struct {
     73  /** This field is the year, A.D. */
     74  uint32_t   year;
     75  /** This field is the month, 1 -> 12 */
     76  uint32_t   month;
     77  /** This field is the day, 1 -> 31 */
     78  uint32_t   day;
     79  /** This field is the hour, 0 -> 23 */
     80  uint32_t   hour;
     81  /** This field is the minute, 0 -> 59 */
     82  uint32_t   minute;
     83  /** This field is the second, 0 -> 59 */
     84  uint32_t   second;
     85  /** This field is the elapsed ticks between secs */
     86  uint32_t   ticks;
     87}   rtems_time_of_day;
    6588
    6689/*
  • cpukit/rtems/src/clockget.c

    rbf4d016 r812da54  
    4747)
    4848{
    49   ISR_Level      level;
    50   rtems_interval tmp;
    51 
    52    if ( !time_buffer )
    53      return RTEMS_INVALID_ADDRESS;
     49  if ( !time_buffer )
     50    return RTEMS_INVALID_ADDRESS;
    5451
    5552  switch ( option ) {
    56     case RTEMS_CLOCK_GET_TOD:
     53    case RTEMS_CLOCK_GET_TOD: {
     54      struct tm time;
     55      struct timeval now;
     56      rtems_time_of_day *tmbuf = (rtems_time_of_day *)time_buffer;
     57
    5758      if ( !_TOD_Is_set )
    5859        return RTEMS_NOT_DEFINED;
    5960
    60       *(rtems_time_of_day *)time_buffer = _TOD_Current;
     61      /* Obtain the current time */
     62      _TOD_Get_timeval( &now );
     63
     64      /* Split it into a closer format */
     65      gmtime_r( &now.tv_sec, &time );
     66
     67      /* Now adjust it to the RTEMS format */
     68      tmbuf->year   = time.tm_year + 1900;
     69      tmbuf->month  = time.tm_mon + 1;
     70      tmbuf->day    = time.tm_mday;
     71      tmbuf->hour   = time.tm_hour;
     72      tmbuf->minute = time.tm_min;
     73      tmbuf->second = time.tm_sec;
     74      tmbuf->ticks  = now.tv_usec / _TOD_Microseconds_per_tick;
     75     
    6176      return RTEMS_SUCCESSFUL;
    62 
     77    }
    6378    case RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH:
    6479      if ( !_TOD_Is_set )
     
    7691      return RTEMS_SUCCESSFUL;
    7792
    78     case RTEMS_CLOCK_GET_TIME_VALUE:
     93    case RTEMS_CLOCK_GET_TIME_VALUE: {
     94      struct timeval *time = (struct timeval *)time_buffer;
    7995      if ( !_TOD_Is_set )
    8096        return RTEMS_NOT_DEFINED;
    8197
    82       _ISR_Disable( level );
    83         ((rtems_clock_time_value *)time_buffer)->seconds =
    84           _TOD_Seconds_since_epoch;
    85         tmp = _TOD_Current.ticks;
    86       _ISR_Enable( level );
    87 
    88       tmp *= _TOD_Microseconds_per_tick;
    89       ((rtems_clock_time_value *)time_buffer)->microseconds = tmp;
     98      _TOD_Get_timeval( time );
    9099
    91100      return RTEMS_SUCCESSFUL;
     101    }
    92102  }
    93103
  • cpukit/rtems/src/clockset.c

    rbf4d016 r812da54  
    4242)
    4343{
    44   rtems_interval     seconds;
     44  struct timespec  newtime;
    4545
    4646  if ( !time_buffer )
     
    4848
    4949  if ( _TOD_Validate( time_buffer ) ) {
    50     seconds = _TOD_To_seconds( time_buffer );
     50    newtime.tv_sec = _TOD_To_seconds( time_buffer );
     51    newtime.tv_nsec = time_buffer->ticks *
     52                 (_TOD_Microseconds_per_tick * TOD_NANOSECONDS_PER_MICROSECOND);
     53
    5154    _Thread_Disable_dispatch();
    52       _TOD_Set( time_buffer, seconds );
     55      _TOD_Set( &newtime );
    5356    _Thread_Enable_dispatch();
    5457    return RTEMS_SUCCESSFUL;
  • cpukit/rtems/src/clocktodtoseconds.c

    rbf4d016 r812da54  
    11/*
    2  *  Time of Day (TOD) Handler
     2 *  Time of Day (TOD) Handler - Classic TOD to Seconds
    33 *
    44 *
    5  *  COPYRIGHT (c) 1989-1999.
     5 *  COPYRIGHT (c) 1989-2007.
    66 *  On-Line Applications Research Corporation (OAR).
    77 *
     
    1818
    1919#include <rtems/system.h>
    20 #include <rtems/score/object.h>
    21 #include <rtems/score/thread.h>
    22 #include <rtems/score/tod.h>
    23 #include <rtems/score/watchdog.h>
     20#include <rtems/rtems/clock.h>
     21
     22/*
     23 *  The following array contains the number of days in all months
     24 *  up to the month indicated by the index of the second dimension.
     25 *  The first dimension should be 1 for leap years, and 0 otherwise.
     26 */
     27const uint16_t   _TOD_Days_to_date[2][13] = {
     28  { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 },
     29  { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }
     30};
     31
     32/*
     33 *  The following array contains the number of days in the years
     34 *  since the last leap year.  The index should be 0 for leap
     35 *  years, and the number of years since the beginning of a leap
     36 *  year otherwise.
     37 */
     38const uint16_t   _TOD_Days_since_last_leap_year[4] = { 0, 366, 731, 1096 };
     39
     40
    2441
    2542/*PAGE
     
    3855
    3956uint32_t   _TOD_To_seconds(
    40   TOD_Control *the_tod
     57  rtems_time_of_day *the_tod
    4158)
    4259{
  • cpukit/rtems/src/clocktodvalidate.c

    rbf4d016 r812da54  
    11/*
    2  *  Time of Day (TOD) Handler
     2 *  Time of Day (TOD) Handler -- Validate Classic TOD
    33 *
    44 *
    5  *  COPYRIGHT (c) 1989-1999.
     5 *  COPYRIGHT (c) 1989-2007.
    66 *  On-Line Applications Research Corporation (OAR).
    77 *
     
    1818
    1919#include <rtems/system.h>
    20 #include <rtems/score/object.h>
    21 #include <rtems/score/thread.h>
    22 #include <rtems/score/tod.h>
    23 #include <rtems/score/watchdog.h>
     20#include <rtems/rtems/clock.h>
     21
     22/*
     23 *  The following array contains the number of days in all months.
     24 *  The first dimension should be 1 for leap years, and 0 otherwise.
     25 *  The second dimension should range from 1 to 12 for January to
     26 *  February, respectively.
     27 */
     28const uint32_t   _TOD_Days_per_month[ 2 ][ 13 ] = {
     29  { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
     30  { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
     31};
    2432
    2533/*PAGE
     
    4048
    4149boolean _TOD_Validate(
    42   TOD_Control *the_tod
     50  rtems_time_of_day *the_tod
    4351)
    4452{
  • cpukit/rtems/src/taskwakewhen.c

    rbf4d016 r812da54  
    2121#include <rtems/rtems/support.h>
    2222#include <rtems/rtems/modes.h>
     23#include <rtems/rtems/clock.h>
    2324#include <rtems/score/object.h>
    2425#include <rtems/score/stack.h>
  • cpukit/score/Makefile.am

    rbf4d016 r812da54  
    141141
    142142## TOD_C_FILES
    143 libscore_a_SOURCES += src/coretod.c src/coretodset.c src/coretodtickle.c \
    144     src/coretodtoseconds.c src/coretodvalidate.c
     143libscore_a_SOURCES += src/coretod.c src/coretodset.c src/coretodget.c \
     144    src/coretodgetuptime.c
    145145
    146146## WATCHDOG_C_FILES
    147 libscore_a_SOURCES += src/watchdog.c src/watchdogadjust.c src/watchdoginsert.c \
    148     src/watchdogremove.c src/watchdogtickle.c
     147libscore_a_SOURCES += src/watchdog.c src/watchdogadjust.c \
     148    src/watchdoginsert.c src/watchdogremove.c src/watchdogtickle.c
    149149
    150150## STD_C_FILES
  • cpukit/score/include/rtems/score/tod.h

    rbf4d016 r812da54  
    77
    88/*
    9  *  COPYRIGHT (c) 1989-2006.
     9 *  COPYRIGHT (c) 1989-2007.
    1010 *  On-Line Applications Research Corporation (OAR).
    1111 *
     
    3333#include <rtems/score/object.h>
    3434#include <rtems/score/watchdog.h>
     35#include <time.h>
    3536
    3637/** @defgroup ScoreTODConstants TOD Constants
     
    9798#define TOD_NANOSECONDS_PER_MICROSECOND (uint32_t)1000
    9899
     100/*
     101 *  Seconds from January 1, 1970 to January 1, 1988.  Used to account for
     102 *  differences between POSIX API and RTEMS core. The timespec format time
     103 *  is kept in POSIX compliant form.
     104 */
     105#define TOD_SECONDS_1970_THROUGH_1988 \
     106  (((1987 - 1970 + 1)  * TOD_SECONDS_PER_NON_LEAP_YEAR) + \
     107  (4 * TOD_SECONDS_PER_DAY))
     108
    99109/**@}*/
    100110
     
    107117#define TOD_BASE_YEAR 1988
    108118
    109 /**
    110  *  The following record defines the time of control block.  This
    111  *  control block is used to maintain the current time of day.
    112  *
    113  *  @note This is an RTEID style time/date.
    114  */
    115 typedef struct {
    116   /** This field is the year, A.D. */
    117   uint32_t   year;
    118   /** This field is the month, 1 -> 12 */
    119   uint32_t   month;
    120   /** This field is the day, 1 -> 31 */
    121   uint32_t   day;
    122   /** This field is the hour, 0 -> 23 */
    123   uint32_t   hour;
    124   /** This field is the minute, 0 -> 59 */
    125   uint32_t   minute;
    126   /** This field is the second, 0 -> 59 */
    127   uint32_t   second;
    128   /** This field is the elapsed ticks between secs */
    129   uint32_t   ticks;
    130 }   TOD_Control;
    131 
    132119/** @brief Is the Time Of Day Set
    133120 *
     
    137124SCORE_EXTERN boolean _TOD_Is_set;
    138125
    139 /** @brief Current Time of Day
     126/** @brief Current Time of Day (Timespec)
    140127 *  The following contains the current time of day.
    141128 */
    142 SCORE_EXTERN TOD_Control _TOD_Current;
     129SCORE_EXTERN struct timespec _TOD_Now;
     130
     131/** @brief Current Time of Day (Timespec)
     132 *  The following contains the running uptime.
     133 */
     134SCORE_EXTERN struct timespec _TOD_Uptime;
    143135
    144136/** @brief Seconds Since RTEMS Epoch
     
    165157SCORE_EXTERN uint32_t   _TOD_Ticks_per_second;
    166158
    167 /** @brief Watchdog Set Managed by Seconds
    168  *
    169  *  This is the control structure for the watchdog timer which
    170  *  fires to service the seconds chain.
    171  */
    172 SCORE_EXTERN Watchdog_Control _TOD_Seconds_watchdog;
    173 
    174 #ifdef SCORE_INIT
    175 
    176 /*
    177  *  The following array contains the number of days in all months.
    178  *  The first dimension should be 1 for leap years, and 0 otherwise.
    179  *  The second dimension should range from 1 to 12 for January to
    180  *  February, respectively.
    181  */
    182 const uint32_t   _TOD_Days_per_month[ 2 ][ 13 ] = {
    183   { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
    184   { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
    185 };
    186 
    187 /*
    188  *  The following array contains the number of days in all months
    189  *  up to the month indicated by the index of the second dimension.
    190  *  The first dimension should be 1 for leap years, and 0 otherwise.
    191  */
    192 const uint16_t   _TOD_Days_to_date[2][13] = {
    193   { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 },
    194   { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }
    195 };
    196 
    197 /*
    198  *  The following array contains the number of days in the years
    199  *  since the last leap year.  The index should be 0 for leap
    200  *  years, and the number of years since the beginning of a leap
    201  *  year otherwise.
    202  */
    203 const uint16_t   _TOD_Days_since_last_leap_year[4] = { 0, 366, 731, 1096 };
    204 
    205 #else
    206 
    207 /** @brief Convert Month to Julian Days
    208  *
    209  *  This is a prototype for a table which assists in converting the
    210  *  current day into the Julian days since the first of the year.
    211  */
    212 extern const uint16_t   _TOD_Days_to_date[2][13]; /* Julian days */
    213 
    214 /** @brief Days since Beginning of Last Leap Year
    215  *
    216  *  This is a prototype for a table which assists in calculating the
    217  *  number of days since the beginning of the last leap year.
    218  */
    219 extern const uint16_t   _TOD_Days_since_last_leap_year[4];
    220 
    221 /** @brief Days Per Month Table
    222  *
    223  *  This is a prototype for a table which holds the number of days
    224  *  per month for a leap year and non-leap year.
    225  */
    226 extern const uint32_t   _TOD_Days_per_month[2][13];
    227 
    228 #endif
    229 
    230159/** @brief _TOD_Handler_initialization
    231160 *
     
    238167/** @brief _TOD_Set
    239168 *
    240  *  This routine sets the current time of day to THE_TOD and
     169 *  This routine sets the current time of day to @a time and
    241170 *  the equivalent SECONDS_SINCE_EPOCH.
    242171 */
    243172void _TOD_Set(
    244   TOD_Control       *the_tod,
    245   Watchdog_Interval  seconds_since_epoch
    246 );
    247 
    248 /** @brief _TOD_Validate
    249  *
    250  *  This function returns TRUE if THE_TOD contains
    251  *  a valid time of day, and FALSE otherwise.
    252  */
    253 boolean _TOD_Validate(
    254   TOD_Control *the_tod
    255 );
    256 
    257 /** @brief _TOD_To_seconds
    258  *
    259  *  This function returns the number seconds between the epoch and THE_TOD.
    260  */
    261 Watchdog_Interval _TOD_To_seconds(
    262   TOD_Control *the_tod
    263 );
    264 
    265 /** @brief _TOD_Tickle
    266  *
    267  *  This routine is scheduled as a watchdog function and is invoked at
    268  *  each second boundary.  It updates the current time of day to indicate
    269  *  that a second has passed and processes the seconds watchdog chain.
    270  */
    271 void _TOD_Tickle(
    272   Objects_Id  id,
    273   void       *ignored
     173  const struct timespec *time
     174);
     175
     176/** @brief _TOD_Get
     177 *
     178 *  This routine returns the current time of day with potential accuracy
     179 *  to the nanosecond. 
     180 *
     181 *  @param[in] time is a pointer to the time to be returned
     182 */
     183void _TOD_Get(
     184  struct timespec *time
     185);
     186
     187/** @brief _TOD_Get_uptime
     188 *
     189 *  This routine returns the system uptime with potential accuracy
     190 *  to the nanosecond. 
     191 *
     192 *  @param[in] time is a pointer to the uptime to be returned
     193 */
     194void _TOD_Get_uptime(
     195  struct timespec *time
    274196);
    275197
  • cpukit/score/inline/rtems/score/tod.inl

    rbf4d016 r812da54  
    77
    88/*
    9  *  COPYRIGHT (c) 1989-2004.
     9 *  COPYRIGHT (c) 1989-2007.
    1010 *  On-Line Applications Research Corporation (OAR).
    1111 *
     
    2020#define _RTEMS_SCORE_TOD_INL
    2121
     22#include <rtems/score/isr.h>
     23
    2224/**
    2325 *  @addtogroup ScoreTOD
    2426 *  @{
    2527 */
     28
     29/**
     30 *
     31 *  This routines adds two timespecs.  The second argument is added
     32 *  to the first.
     33 */
     34
     35RTEMS_INLINE_ROUTINE uint32_t _TOD_Add_timespec(
     36  struct timespec *time,
     37  struct timespec *add
     38)
     39{
     40  uint32_t seconds = 0;
     41
     42 
     43  /* Add the basics */
     44  time->tv_sec += add->tv_sec;
     45  time->tv_nsec += add->tv_nsec;
     46
     47  /* Now adjust it so nanoseconds is in range */
     48  while ( time->tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) {
     49    time->tv_nsec -= TOD_NANOSECONDS_PER_SECOND;
     50    time->tv_sec++;
     51    seconds++;
     52  }
     53
     54  return seconds;
     55}
    2656
    2757/**
     
    3262RTEMS_INLINE_ROUTINE void _TOD_Tickle_ticks( void )
    3363{
    34   _TOD_Current.ticks += 1;
     64  struct timespec tick;
     65  uint32_t        seconds;
     66
     67  /* Convert the tick quantum to a timespec */
     68  tick.tv_nsec = _TOD_Microseconds_per_tick * 1000;
     69  tick.tv_sec  = 0;
     70
     71  /* Update the counter of ticks since boot */
    3572  _Watchdog_Ticks_since_boot += 1;
     73
     74  /* Update the timespec format uptime */
     75  (void) _TOD_Add_timespec( &_TOD_Uptime, &tick );
     76  /* we do not care how much the uptime changed */
     77
     78  /* Update the timespec format TOD */
     79  seconds = _TOD_Add_timespec( &_TOD_Now, &tick );
     80  while ( seconds ) {
     81    _Watchdog_Tickle_seconds();
     82    seconds--;
     83  }
    3684}
    3785
     
    4290RTEMS_INLINE_ROUTINE void _TOD_Deactivate( void )
    4391{
    44   _Watchdog_Remove( &_TOD_Seconds_watchdog );
     92  /* XXX do we need something now that we are using timespec for TOD */
    4593}
    4694
     
    53101)
    54102{
    55   _Watchdog_Insert_ticks( &_TOD_Seconds_watchdog, ticks );
     103  /* XXX do we need something now that we are using timespec for TOD */
     104}
     105
     106/**
     107 *  This routine returns a timeval based upon the internal timespec format TOD.
     108 */
     109
     110RTEMS_INLINE_ROUTINE void _TOD_Get_timeval(
     111  struct timeval *time
     112)
     113{
     114  ISR_Level level;
     115  struct timespec now;
     116
     117  _ISR_Disable(level);
     118    _TOD_Get( &now );
     119  _ISR_Enable(level);
     120
     121  time->tv_sec  = now.tv_sec;
     122  time->tv_usec = now.tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND;
    56123}
    57124
  • cpukit/score/src/coretod.c

    rbf4d016 r812da54  
    4141  _TOD_Microseconds_per_tick = microseconds_per_tick;
    4242
     43  /* POSIX format TOD (timespec) */
     44  _TOD_Now.tv_sec  = TOD_SECONDS_1970_THROUGH_1988;
     45  _TOD_Now.tv_nsec = 0;
     46
     47  /* Uptime (timespec) */
     48  _TOD_Uptime.tv_sec  = 0;
     49  _TOD_Uptime.tv_nsec = 0;
     50
     51  /* Seconds since RTEMS Epoch (1988) */
    4352  _TOD_Seconds_since_epoch = 0;
    4453
    45   _TOD_Current.year   = TOD_BASE_YEAR;
    46   _TOD_Current.month  = 1;
    47   _TOD_Current.day    = 1;
    48   _TOD_Current.hour   = 0;
    49   _TOD_Current.minute = 0;
    50   _TOD_Current.second = 0;
    51   _TOD_Current.ticks  = 0;
    52 
     54  /* Protect ourselves from a divide by zero fault */
    5355  if ( microseconds_per_tick == 0 )
    5456    _TOD_Ticks_per_second = 0;
     
    5759       TOD_MICROSECONDS_PER_SECOND / microseconds_per_tick;
    5860
    59   _Watchdog_Initialize( &_TOD_Seconds_watchdog, _TOD_Tickle, 0, NULL );
    60 
     61  /* TOD has not been set */
    6162  _TOD_Is_set = FALSE;
    6263  _TOD_Activate( _TOD_Ticks_per_second );
  • cpukit/score/src/coretodset.c

    rbf4d016 r812da54  
    3131 *
    3232 *  Input parameters:
    33  *    the_tod             - pointer to the time and date structure
    34  *    seconds_since_epoch - seconds since system epoch
     33 *    time                - pointer to the time and date structure
    3534 *
    3635 *  Output parameters: NONE
     
    3837
    3938void _TOD_Set(
    40   TOD_Control *the_tod,
    41   Watchdog_Interval  seconds_since_epoch
     39  const struct timespec *time
    4240)
    4341{
    44   Watchdog_Interval ticks_until_next_second;
    45 
    4642  _Thread_Disable_dispatch();
    4743  _TOD_Deactivate();
    4844
    49   if ( seconds_since_epoch < _TOD_Seconds_since_epoch )
     45  if ( time->tv_sec < _TOD_Seconds_since_epoch )
    5046    _Watchdog_Adjust_seconds( WATCHDOG_BACKWARD,
    51        _TOD_Seconds_since_epoch - seconds_since_epoch );
     47       _TOD_Seconds_since_epoch - time->tv_sec );
    5248  else
    5349    _Watchdog_Adjust_seconds( WATCHDOG_FORWARD,
    54        seconds_since_epoch - _TOD_Seconds_since_epoch );
     50       time->tv_sec - _TOD_Seconds_since_epoch );
    5551
    56   ticks_until_next_second = _TOD_Ticks_per_second;
    57   if ( ticks_until_next_second > the_tod->ticks )
    58     ticks_until_next_second -= the_tod->ticks;
     52  _TOD_Seconds_since_epoch = time->tv_sec;
     53  _TOD_Is_set              = TRUE;
    5954
    60   _TOD_Current             = *the_tod;
    61   _TOD_Seconds_since_epoch = seconds_since_epoch;
    62   _TOD_Is_set              = TRUE;
    63   _TOD_Activate( ticks_until_next_second );
     55  /* POSIX format TOD (timespec) */
     56  _TOD_Now         = *time;
     57  _TOD_Now.tv_sec += TOD_SECONDS_1970_THROUGH_1988;
     58
     59  _TOD_Activate( 0 );
    6460
    6561  _Thread_Enable_dispatch();
Note: See TracChangeset for help on using the changeset viewer.