Changeset 8d7aea0d in rtems


Ignore:
Timestamp:
Sep 29, 2011, 9:55:54 AM (8 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
7cb170b3
Parents:
fe7cc1ea
Message:

2011-09-29 Sebastian Huber <sebastian.huber@…>

  • score/include/rtems/score/tod.h: Declare _TOD_Set_with_timestamp() and _TOD_Get_as_timestamp().
  • score/src/coretodset.c: Define _TOD_Set_with_timestamp().
  • score/src/coretodget.c: Define _TOD_Get_as_timestamp().
  • rtems/src/clockset.c: Use _TOD_Set_with_timestamp().
  • score/include/rtems/score/timestamp64.h, score/src/ts64set.c: Changed parameter types of _Timestamp64_Set().
  • rtems/src/clocktodtoseconds.c: Year 2100 is not a leap year.
Location:
cpukit
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    rfe7cc1ea r8d7aea0d  
     12011-09-29      Sebastian Huber <sebastian.huber@embedded-brains.de>
     2
     3        * score/include/rtems/score/tod.h: Declare _TOD_Set_with_timestamp()
     4        and _TOD_Get_as_timestamp().
     5        * score/src/coretodset.c: Define _TOD_Set_with_timestamp().
     6        * score/src/coretodget.c: Define _TOD_Get_as_timestamp().
     7        * rtems/src/clockset.c: Use _TOD_Set_with_timestamp().
     8        * score/include/rtems/score/timestamp64.h, score/src/ts64set.c:
     9        Changed parameter types of _Timestamp64_Set().
     10        * rtems/src/clocktodtoseconds.c: Year 2100 is not a leap year.
     11
    1122011-09-28      Sebastian Huber <sebastian.huber@embedded-brains.de>
    213
  • cpukit/rtems/src/clockset.c

    rfe7cc1ea r8d7aea0d  
    3131 *
    3232 *  Input parameters:
    33  *    time_buffer - pointer to the time and date structure
     33 *    tod - pointer to the time and date structure
    3434 *
    3535 *  Output parameters:
     
    3939
    4040rtems_status_code rtems_clock_set(
    41   const rtems_time_of_day *time_buffer
     41  const rtems_time_of_day *tod
    4242)
    4343{
    44   struct timespec  newtime;
    45 
    46   if ( !time_buffer )
     44  if ( !tod )
    4745    return RTEMS_INVALID_ADDRESS;
    4846
    49   if ( _TOD_Validate( time_buffer ) ) {
    50     newtime.tv_sec = _TOD_To_seconds( time_buffer );
    51     newtime.tv_nsec = time_buffer->ticks *
    52       rtems_configuration_get_nanoseconds_per_tick();
     47  if ( _TOD_Validate( tod ) ) {
     48    Timestamp_Control tod_as_timestamp;
     49    uint32_t seconds = _TOD_To_seconds( tod );
     50    uint32_t nanoseconds = tod->ticks
     51      * rtems_configuration_get_nanoseconds_per_tick();
     52
     53    _Timestamp_Set( &tod_as_timestamp, seconds, nanoseconds );
    5354
    5455    _Thread_Disable_dispatch();
    55       _TOD_Set( &newtime );
     56      _TOD_Set_with_timestamp( &tod_as_timestamp );
    5657    _Thread_Enable_dispatch();
     58
    5759    return RTEMS_SUCCESSFUL;
    5860  }
     61
    5962  return RTEMS_INVALID_CLOCK;
    6063}
  • cpukit/rtems/src/clocktodtoseconds.c

    rfe7cc1ea r8d7aea0d  
    1818#include <rtems/system.h>
    1919#include <rtems/rtems/clock.h>
     20
     21#define TOD_SECONDS_AT_2100_03_01_00_00 4107538800UL
    2022
    2123/*
     
    7981  time += the_tod->second;
    8082
     83  /* The year 2100 is not a leap year */
     84  if ( time
     85      >= (TOD_SECONDS_AT_2100_03_01_00_00 - TOD_SECONDS_1970_THROUGH_1988)) {
     86    time -= TOD_SECONDS_PER_DAY;
     87  }
     88
    8189  time += TOD_SECONDS_1970_THROUGH_1988;
    8290
  • cpukit/score/include/rtems/score/timestamp64.h

    rfe7cc1ea r8d7aea0d  
    5656static inline void _Timestamp64_implementation_Set(
    5757  Timestamp64_Control *_time,
    58   long                 _seconds,
    59   long                 _nanoseconds
    60 )
    61 {
    62   Timestamp64_Control _seconds64 = _seconds;
    63   Timestamp64_Control _nanoseconds64 = _nanoseconds;
    64 
    65   *_time = _seconds64 * 1000000000L + _nanoseconds64;
     58  Timestamp64_Control  _seconds,
     59  Timestamp64_Control  _nanoseconds
     60)
     61{
     62  *_time = _seconds * 1000000000L + _nanoseconds;
    6663}
    6764
     
    8279  void _Timestamp64_Set(
    8380    Timestamp64_Control *_time,
    84     long                _seconds,
    85     long                _nanoseconds
     81    Timestamp64_Control  _seconds,
     82    Timestamp64_Control  _nanoseconds
    8683  );
    8784#endif
     
    407404)
    408405{
    409   _timespec->tv_sec = *_timestamp / 1000000000L;
    410   _timespec->tv_nsec = *_timestamp % 1000000000L;
     406  _timespec->tv_sec = (time_t) (*_timestamp / 1000000000L);
     407  _timespec->tv_nsec = (long) (*_timestamp % 1000000000L);
    411408}
    412409
  • cpukit/score/include/rtems/score/tod.h

    rfe7cc1ea r8d7aea0d  
    164164
    165165/**
    166  *  @brief _TOD_Set
    167  *
    168  *  This routine sets the current time of day to @a time and
    169  *  the equivalent SECONDS_SINCE_EPOCH.
    170  */
    171 void _TOD_Set(
    172   const struct timespec *time
    173 );
    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  */
    183 void _TOD_Get(
    184   struct timespec *time
    185 );
     166 *  @brief Sets the time of day according to @a tod_as_timestamp.
     167 *
     168 *  The @a tod_as_timestamp timestamp represents the time since UNIX epoch.  The watchdog
     169 *  seconds chain will be adjusted.
     170 */
     171void _TOD_Set_with_timestamp(
     172  const Timestamp_Control *tod_as_timestamp
     173);
     174
     175static inline void _TOD_Set(
     176  const struct timespec *tod_as_timespec
     177)
     178{
     179  Timestamp_Control tod_as_timestamp;
     180
     181  _Timestamp_Set(
     182    &tod_as_timestamp,
     183    tod_as_timespec->tv_sec,
     184    tod_as_timespec->tv_nsec
     185  );
     186  _TOD_Set_with_timestamp( &tod_as_timestamp );
     187}
     188
     189/**
     190 *  @brief Returns the time of day in @a tod_as_timestamp.
     191 *
     192 *  The @a tod_as_timestamp timestamp represents the time since UNIX epoch.
     193 */
     194void _TOD_Get_as_timestamp(
     195  Timestamp_Control *tod_as_timestamp
     196);
     197
     198static inline void _TOD_Get(
     199  struct timespec *tod_as_timespec
     200)
     201{
     202  Timestamp_Control tod_as_timestamp;
     203
     204  _TOD_Get_as_timestamp( &tod_as_timestamp );
     205  _Timestamp_To_timespec( &tod_as_timestamp, tod_as_timespec );
     206}
    186207
    187208/**
  • cpukit/score/src/coretodget.c

    rfe7cc1ea r8d7aea0d  
    2323#include <rtems/score/watchdog.h>
    2424
    25 /*
    26  *  _TOD_Get
    27  *
    28  *  This routine is used to obtain the current date and time.
    29  *
    30  *  Input parameters:
    31  *    time  - pointer to the time and date structure
    32  *
    33  *  Output parameters: NONE
    34  */
    35 
    36 void _TOD_Get(
    37   struct timespec *time
     25void _TOD_Get_as_timestamp(
     26  Timestamp_Control *tod
    3827)
    3928{
     
    5342  _Timestamp_Set( &offset, 0, nanoseconds );
    5443  _Timestamp_Add_to( &now, &offset );
    55   _Timestamp_To_timespec( &now, time );
     44
     45  *tod = now;
    5646}
  • cpukit/score/src/coretodset.c

    rfe7cc1ea r8d7aea0d  
    2424#include <rtems/score/watchdog.h>
    2525
    26 /*
    27  *  _TOD_Set
    28  *
    29  *  This rountine sets the current date and time with the specified
    30  *  new date and time structure.
    31  *
    32  *  Input parameters:
    33  *    time                - pointer to the time and date structure
    34  *
    35  *  Output parameters: NONE
    36  */
    37 
    38 void _TOD_Set(
    39   const struct timespec *time
     26void _TOD_Set_with_timestamp(
     27  const Timestamp_Control *tod
    4028)
    4129{
    42   long seconds;
     30  Watchdog_Interval seconds_next = _Timestamp_Get_seconds( tod );
     31  Watchdog_Interval seconds_now;
    4332
    4433  _Thread_Disable_dispatch();
    4534  _TOD_Deactivate();
    4635
    47   seconds = _TOD_Seconds_since_epoch();
     36  seconds_now = _TOD_Seconds_since_epoch();
    4837
    49   if ( time->tv_sec < seconds )
    50     _Watchdog_Adjust_seconds( WATCHDOG_BACKWARD, seconds - time->tv_sec );
     38  if ( seconds_next < seconds_now )
     39    _Watchdog_Adjust_seconds( WATCHDOG_BACKWARD, seconds_now - seconds_next );
    5140  else
    52     _Watchdog_Adjust_seconds( WATCHDOG_FORWARD, time->tv_sec - seconds );
     41    _Watchdog_Adjust_seconds( WATCHDOG_FORWARD, seconds_next - seconds_now );
    5342
    54   /* POSIX format TOD (timespec) */
    55   _Timestamp_Set( &_TOD_Now, time->tv_sec, time->tv_nsec );
     43  _TOD_Now = *tod;
    5644  _TOD_Is_set = true;
    5745
    5846  _TOD_Activate();
    59 
    6047  _Thread_Enable_dispatch();
    6148}
  • cpukit/score/src/ts64set.c

    rfe7cc1ea r8d7aea0d  
    2323void _Timestamp64_Set(
    2424  Timestamp64_Control *_time,
    25   long                 _seconds,
    26   long                 _nanoseconds
     25  Timestamp64_Control  _seconds,
     26  Timestamp64_Control  _nanoseconds
    2727)
    2828{
Note: See TracChangeset for help on using the changeset viewer.