Changeset 7cd2484 in rtems


Ignore:
Timestamp:
May 12, 2015, 12:32:47 PM (4 years ago)
Author:
Alexander Krutwig <alexander.krutwig@…>
Branches:
4.11, master
Children:
75acd9e
Parents:
31be416
git-author:
Alexander Krutwig <alexander.krutwig@…> (05/12/15 12:32:47)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/20/15 06:40:33)
Message:

timecounter: Use in RTEMS

Replace timestamp implementation with FreeBSD bintime and timecounters.

New test sptests/sptimecounter02.

Update #2271.

Files:
5 added
17 deleted
31 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libnetworking/rtems/rtems_bsdnet_internal.h

    r31be416 r7cd2484  
    1313#include <rtems.h>
    1414#include <rtems/fs.h>
     15#include <rtems/bsd.h>
    1516
    1617#ifdef __cplusplus
     
    6263#define suser(a,b)      0
    6364
    64 void microtime(struct timeval *tv);
     65#define microtime(tv) rtems_bsd_microtime(tv)
    6566
    6667#define hz rtems_bsdnet_ticks_per_second
  • cpukit/libnetworking/rtems/rtems_glue.c

    r31be416 r7cd2484  
    13401340}
    13411341
    1342 void microtime(struct timeval *tv)
    1343 {
    1344         rtems_clock_get_uptime_timeval(tv);
    1345 }
  • cpukit/posix/src/clockgettime.c

    r31be416 r7cd2484  
    3838
    3939  if ( clock_id == CLOCK_REALTIME ) {
    40     _TOD_Get(tp);
     40    _TOD_Get_as_timespec(tp);
    4141    return 0;
    4242  }
    4343#ifdef CLOCK_MONOTONIC
    4444  if ( clock_id == CLOCK_MONOTONIC ) {
    45     _TOD_Get_uptime_as_timespec( tp );
     45    _TOD_Get_zero_based_uptime_as_timespec( tp );
     46    --tp->tv_sec;
    4647    return 0;
    4748  }
     
    5051#ifdef _POSIX_CPUTIME
    5152  if ( clock_id == CLOCK_PROCESS_CPUTIME_ID ) {
    52     _TOD_Get_uptime_as_timespec( tp );
     53    _TOD_Get_zero_based_uptime_as_timespec( tp );
     54    --tp->tv_sec;
    5355    return 0;
    5456  }
  • cpukit/posix/src/posixtimespecabsolutetimeout.c

    r31be416 r7cd2484  
    5858   *  Is the absolute time in the past?
    5959   */
    60   _TOD_Get( &current_time );
     60  _TOD_Get_as_timespec( &current_time );
    6161
    6262  if ( _Timespec_Less_than( abstime, &current_time ) )
  • cpukit/posix/src/timergettime.c

    r31be416 r7cd2484  
    5050
    5151  /* Reads the current time */
    52   _TOD_Get( &current_time );
     52  _TOD_Get_as_timespec( &current_time );
    5353
    5454  ptimer = _POSIX_Timer_Get( timerid, &location );
  • cpukit/posix/src/timersettime.c

    r31be416 r7cd2484  
    6767  if (flags == TIMER_ABSTIME) {
    6868    struct timespec now;
    69     _TOD_Get( &now );
     69    _TOD_Get_as_timespec( &now );
    7070    /* Check for seconds in the past */
    7171    if ( _Timespec_Greater_than( &now, &normalize.it_value ) )
     
    126126       /* Indicate that the time is running */
    127127       ptimer->state = POSIX_TIMER_STATE_CREATE_RUN;
    128        _TOD_Get( &ptimer->time );
     128       _TOD_Get_as_timespec( &ptimer->time );
    129129      _Objects_Put( &ptimer->Object );
    130130       return 0;
  • cpukit/posix/src/timertsr.c

    r31be416 r7cd2484  
    5959
    6060    /* Store the time when the timer was started again */
    61     _TOD_Get( &ptimer->time );
     61    _TOD_Get_as_timespec( &ptimer->time );
    6262
    6363    /* The state really did not change but just to be safe */
  • cpukit/rtems/Makefile.am

    r31be416 r7cd2484  
    156156librtems_a_SOURCES += src/clockgetuptime.c
    157157librtems_a_SOURCES += src/clockgetuptimetimeval.c
    158 librtems_a_SOURCES += src/clockgetuptimeseconds.c
    159158librtems_a_SOURCES += src/clockgetuptimenanoseconds.c
    160159librtems_a_SOURCES += src/clockset.c
    161 librtems_a_SOURCES += src/clocksetnsecshandler.c
    162160librtems_a_SOURCES += src/clocktick.c
    163161librtems_a_SOURCES += src/clocktodtoseconds.c
  • cpukit/rtems/include/rtems/rtems/clock.h

    r31be416 r7cd2484  
    1515 * - set the current date and time
    1616 * - obtain the current date and time
    17  * - set the nanoseconds since last clock tick handler
    1817 * - announce a clock tick
    1918 * - obtain the system uptime
     
    3635#include <rtems/rtems/types.h>
    3736#include <rtems/config.h>
     37#include <rtems/score/timecounterimpl.h>
    3838
    3939#include <sys/time.h> /* struct timeval */
     
    7070
    7171/**
    72  *  Type for the nanoseconds since last tick BSP extension.
    73  */
    74 typedef TOD_Nanoseconds_since_last_tick_routine
    75   rtems_nanoseconds_extension_routine;
    76 
    77 /**
    7872 * @brief Obtain Current Time of Day
    7973 *
     
    280274
    281275/**
    282  * @brief Set the BSP specific Nanoseconds Extension
    283  *
    284  * Clock Manager
    285  *
    286  * This directive sets the BSP provided nanoseconds since last tick
    287  * extension.
    288  *
    289  * @param[in] routine is a pointer to the extension routine
    290  *
    291  * @return This method returns RTEMS_SUCCESSFUL if there was not an
    292  *         error. Otherwise, a status code is returned indicating the
    293  *         source of the error.
    294  */
    295 rtems_status_code rtems_clock_set_nanoseconds_extension(
    296   rtems_nanoseconds_extension_routine routine
    297 );
    298 
    299 /**
    300276 * @brief Obtain the System Uptime
    301277 *
     
    329305 * @retval The system uptime in seconds.
    330306 */
    331 time_t rtems_clock_get_uptime_seconds( void );
     307RTEMS_INLINE_ROUTINE time_t rtems_clock_get_uptime_seconds( void )
     308{
     309  return _Timecounter_Time_uptime - 1;
     310}
    332311
    333312/**
  • cpukit/rtems/src/clockgetuptime.c

    r31be416 r7cd2484  
    4343    return RTEMS_INVALID_ADDRESS;
    4444
    45   _TOD_Get_uptime_as_timespec( uptime );
     45  _TOD_Get_zero_based_uptime_as_timespec( uptime );
    4646  return RTEMS_SUCCESSFUL;
    4747}
  • cpukit/rtems/src/clockgetuptimenanoseconds.c

    r31be416 r7cd2484  
    2424{
    2525  Timestamp_Control  snapshot_as_timestamp;
    26   uint32_t           nanoseconds;
    27   ISR_lock_Context   lock_context;
    2826
    29   _TOD_Acquire( &_TOD, &lock_context );
    30     snapshot_as_timestamp = _TOD.uptime;
    31     nanoseconds = ( *_TOD.nanoseconds_since_last_tick )();
    32   _TOD_Release( &_TOD, &lock_context );
     27  _TOD_Get_zero_based_uptime(&snapshot_as_timestamp);
    3328
    34   return _Timestamp_Get_As_nanoseconds( &snapshot_as_timestamp, nanoseconds );
     29  return _Timestamp_Get_as_nanoseconds(&snapshot_as_timestamp);
    3530}
  • cpukit/rtems/src/clockgetuptimetimeval.c

    r31be416 r7cd2484  
    3131  Timestamp_Control snapshot_as_timestamp;
    3232
    33   _TOD_Get_uptime( &snapshot_as_timestamp );
     33  _TOD_Get_zero_based_uptime( &snapshot_as_timestamp );
    3434  _Timestamp_To_timeval( &snapshot_as_timestamp, uptime );
    3535}
  • cpukit/rtems/src/clocktick.c

    r31be416 r7cd2484  
    2020
    2121#include <rtems/rtems/clock.h>
    22 #include <rtems/score/schedulerimpl.h>
    23 #include <rtems/score/threadimpl.h>
    24 #include <rtems/score/todimpl.h>
    25 #include <rtems/score/watchdogimpl.h>
     22#include <rtems/score/timecounter.h>
    2623
    2724rtems_status_code rtems_clock_tick( void )
    2825{
    29   _TOD_Tickle_ticks();
    30 
    31   _Watchdog_Tickle_ticks();
    32 
    33   _Scheduler_Tick();
    34 
    35   if ( _Thread_Dispatch_is_enabled() )
    36     _Thread_Dispatch();
     26  _Timecounter_Tick_simple(
     27    rtems_configuration_get_microseconds_per_tick(),
     28    0
     29  );
    3730
    3831  return RTEMS_SUCCESSFUL;
  • cpukit/sapi/src/exinit.c

    r31be416 r7cd2484  
    4545#include <rtems/score/schedulerimpl.h>
    4646#include <rtems/score/smpimpl.h>
     47#include <rtems/score/timecounter.h>
    4748#include <rtems/score/threadimpl.h>
    4849#include <rtems/score/todimpl.h>
  • cpukit/score/Makefile.am

    r31be416 r7cd2484  
    9494include_rtems_score_HEADERS += include/rtems/score/timespec.h
    9595include_rtems_score_HEADERS += include/rtems/score/timestamp.h
    96 include_rtems_score_HEADERS += include/rtems/score/timestamp64.h
    9796include_rtems_score_HEADERS += include/rtems/score/timecounter.h
    9897include_rtems_score_HEADERS += include/rtems/score/timecounterimpl.h
     
    321320    src/timespecdividebyinteger.c src/timespecgetasnanoseconds.c
    322321
    323 ## TIMESTAMP_INT64_C_FILES
    324 libscore_a_SOURCES += src/ts64addto.c \
    325     src/ts64divide.c src/ts64equalto.c \
    326     src/ts64getnanoseconds.c src/ts64getseconds.c \
    327     src/ts64lessthan.c \
    328     src/ts64set.c src/ts64settozero.c src/ts64subtract.c \
    329     src/ts64totimespec.c src/ts64totimeval.c
    330 
    331322## TOD_C_FILES
    332 libscore_a_SOURCES += src/coretod.c src/coretodset.c src/coretodget.c \
    333     src/coretodgetuptimetimespec.c src/coretodtickle.c \
    334     src/coretodsecondssinceepoch.c src/coretodtickspersec.c \
     323libscore_a_SOURCES += src/coretod.c src/coretodset.c \
     324    src/coretodtickle.c \
     325    src/coretodtickspersec.c \
    335326    src/coretodadjust.c
    336327
     
    338329libscore_a_SOURCES += src/watchdog.c src/watchdogadjust.c \
    339330    src/watchdoginsert.c src/watchdogremove.c
     331libscore_a_SOURCES += src/watchdogtick.c
    340332libscore_a_SOURCES += src/watchdogtickssinceboot.c
    341333
  • cpukit/score/include/rtems/score/timespec.h

    r31be416 r7cd2484  
    9595 *
    9696 *  @param[in] time points to the timestamp.
    97  *  @param[in] nanoseconds the nanoseconds since the last tick.
    9897 *
    9998 *  @retval The time in nanoseconds.
    10099 */
    101 uint64_t _Timespec_Get_As_nanoseconds(
    102   const struct timespec *time,
    103   const uint32_t nanoseconds
     100uint64_t _Timespec_Get_as_nanoseconds(
     101  const struct timespec *time
    104102);
    105103
  • cpukit/score/include/rtems/score/timestamp.h

    r31be416 r7cd2484  
    4343#include <sys/time.h>
    4444
    45 #include <rtems/score/cpu.h>
     45#include <rtems/score/basedefs.h>
    4646#include <rtems/score/timespec.h>
    4747
     
    5050#endif
    5151
    52 #if ! ( ( CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE \
    53     && CPU_TIMESTAMP_USE_INT64 == FALSE \
    54     && CPU_TIMESTAMP_USE_INT64_INLINE == FALSE ) \
    55   || ( CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == FALSE \
    56     && CPU_TIMESTAMP_USE_INT64 == TRUE \
    57     && CPU_TIMESTAMP_USE_INT64_INLINE == FALSE ) \
    58   || ( CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == FALSE \
    59     && CPU_TIMESTAMP_USE_INT64 == FALSE \
    60     && CPU_TIMESTAMP_USE_INT64_INLINE == TRUE ) )
    61   #error "Invalid SuperCore Timestamp implementations selection."
    62 #endif
    63 
    64 #if CPU_TIMESTAMP_USE_INT64 == TRUE || CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
    65   #include <rtems/score/timestamp64.h>
    66 #endif
    67 
    6852/**
    6953 *   Define the Timestamp control type.
    7054 */
    71 #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
    72   typedef struct timespec Timestamp_Control;
    73 #else
    74   typedef Timestamp64_Control Timestamp_Control;
    75 #endif
     55typedef struct bintime Timestamp_Control;
    7656
    7757/**
     
    8565 *  @param[in] _nanoseconds is the nanoseconds portion of the timestamp
    8666 */
    87 #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
    88   #define _Timestamp_Set( _time, _seconds, _nanoseconds ) \
    89           _Timespec_Set( _time, _seconds, _nanoseconds )
    90 #else
    91   #define _Timestamp_Set( _time, _seconds, _nanoseconds ) \
    92           _Timestamp64_Set( _time, _seconds, _nanoseconds )
    93 #endif
     67RTEMS_INLINE_ROUTINE void _Timestamp_Set(
     68  Timestamp_Control *_time,
     69  time_t             _seconds,
     70  long               _nanoseconds
     71)
     72{
     73  struct timespec _ts;
     74
     75  _ts.tv_sec = _seconds;
     76  _ts.tv_nsec = _nanoseconds;
     77
     78  timespec2bintime( &_ts, _time );
     79}
    9480
    9581/**
     
    10187 *  @param[in] _time points to the timestamp instance to zero.
    10288 */
    103 #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
    104   #define _Timestamp_Set_to_zero( _time ) \
    105           _Timespec_Set_to_zero( _time )
    106 #else
    107   #define _Timestamp_Set_to_zero( _time ) \
    108           _Timestamp64_Set_to_zero( _time )
    109 #endif
     89
     90RTEMS_INLINE_ROUTINE void _Timestamp_Set_to_zero(
     91  Timestamp_Control *_time
     92)
     93{
     94  _time->sec = 0;
     95  _time->frac = 0;
     96}
    11097
    11198/**
     
    120107 *          false otherwise.
    121108 */
    122 #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
    123   #define _Timestamp_Less_than( _lhs, _rhs ) \
    124           _Timespec_Less_than( _lhs, _rhs )
    125 #else
    126   #define _Timestamp_Less_than( _lhs, _rhs ) \
    127           _Timestamp64_Less_than( _lhs, _rhs )
    128 #endif
     109
     110RTEMS_INLINE_ROUTINE bool _Timestamp_Less_than(
     111  const Timestamp_Control *_lhs,
     112  const Timestamp_Control *_rhs
     113)
     114{
     115  if ( _lhs->sec < _rhs->sec )
     116    return true;
     117
     118  if ( _lhs->sec > _rhs->sec )
     119    return false;
     120
     121  return _lhs->frac < _rhs->frac;
     122}
    129123
    130124/**
     
    139133 *          false otherwise.
    140134 */
    141 #define _Timestamp_Greater_than( _lhs, _rhs ) \
    142   _Timestamp_Less_than( _rhs, _lhs )
     135
     136RTEMS_INLINE_ROUTINE bool _Timestamp_Greater_than(
     137  const Timestamp_Control *_lhs,
     138  const Timestamp_Control *_rhs
     139)
     140{
     141  if ( _lhs->sec > _rhs->sec )
     142    return true;
     143
     144  if ( _lhs->sec < _rhs->sec )
     145    return false;
     146
     147  return _lhs->frac > _rhs->frac;
     148}
    143149
    144150/**
     
    153159 *          false otherwise.
    154160 */
    155 #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
    156   #define _Timestamp_Equal_to( _lhs, _rhs ) \
    157           _Timespec_Equal_to( _lhs, _rhs )
    158 #else
    159   #define _Timestamp_Equal_to( _lhs, _rhs ) \
    160           _Timestamp64_Equal_to( _lhs, _rhs )
    161 #endif
     161
     162RTEMS_INLINE_ROUTINE bool _Timestamp_Equal_to(
     163  const Timestamp_Control *_lhs,
     164  const Timestamp_Control *_rhs
     165)
     166{
     167  return _lhs->sec == _rhs->sec && _lhs->frac == _rhs->frac;
     168}
    162169
    163170/**
     
    172179 *  @retval This method returns the number of seconds @a time increased by.
    173180 */
    174 #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
    175   #define _Timestamp_Add_to( _time, _add ) \
    176           _Timespec_Add_to( _time, _add )
    177 #else
    178   #define _Timestamp_Add_to( _time, _add ) \
    179           _Timestamp64_Add_to( _time, _add )
    180 #endif
     181RTEMS_INLINE_ROUTINE time_t _Timestamp_Add_to(
     182  Timestamp_Control *_time,
     183  const Timestamp_Control *_add
     184)
     185{
     186  time_t seconds = _time->sec;
     187
     188  bintime_add( _time, _add );
     189
     190  return _time->sec - seconds;
     191}
    181192
    182193/**
     
    193204 *  @retval This method fills in @a _result.
    194205 */
    195 #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
    196   #define _Timestamp_Subtract( _start, _end, _result ) \
    197           _Timespec_Subtract( _start, _end, _result )
    198 #else
    199   #define _Timestamp_Subtract( _start, _end, _result ) \
    200           _Timestamp64_Subtract( _start, _end, _result )
    201 #endif
     206RTEMS_INLINE_ROUTINE void _Timestamp_Subtract(
     207  const Timestamp_Control *_start,
     208  const Timestamp_Control *_end,
     209  Timestamp_Control       *_result
     210)
     211{
     212  _result->sec = _end->sec;
     213  _result->frac = _end->frac;
     214
     215  bintime_sub( _result, _start );
     216}
    202217
    203218/**
     
    214229 *  @retval This method fills in @a result.
    215230 */
    216 #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
    217   #define _Timestamp_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage ) \
    218           _Timespec_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage )
    219 #else
    220   #define _Timestamp_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage ) \
    221           _Timestamp64_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage )
    222 #endif
     231RTEMS_INLINE_ROUTINE void _Timestamp_Divide(
     232  const Timestamp_Control *_lhs,
     233  const Timestamp_Control *_rhs,
     234  uint32_t                *_ival_percentage,
     235  uint32_t                *_fval_percentage
     236)
     237{
     238  struct timespec _ts_left;
     239  struct timespec _ts_right;
     240
     241  bintime2timespec( _lhs, &_ts_left );
     242  bintime2timespec( _rhs, &_ts_right );
     243
     244  _Timespec_Divide(
     245    &_ts_left,
     246    &_ts_right,
     247    _ival_percentage,
     248    _fval_percentage
     249  );
     250}
    223251
    224252/**
     
    231259 *  @retval The seconds portion of @a _time.
    232260 */
    233 #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
    234   #define _Timestamp_Get_seconds( _time ) \
    235           _Timespec_Get_seconds( _time )
    236 #else
    237   #define _Timestamp_Get_seconds( _time ) \
    238           _Timestamp64_Get_seconds( _time )
    239 #endif
     261RTEMS_INLINE_ROUTINE time_t _Timestamp_Get_seconds(
     262  const Timestamp_Control *_time
     263)
     264{
     265  return _time->sec;
     266}
    240267
    241268/**
     
    248275 *  @retval The nanoseconds portion of @a _time.
    249276 */
    250 #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
    251   #define _Timestamp_Get_nanoseconds( _time ) \
    252           _Timespec_Get_nanoseconds( _time )
    253 #else
    254   #define _Timestamp_Get_nanoseconds( _time ) \
    255           _Timestamp64_Get_nanoseconds( _time )
    256 #endif
     277RTEMS_INLINE_ROUTINE uint32_t _Timestamp_Get_nanoseconds(
     278  const Timestamp_Control *_time
     279)
     280{
     281  struct timespec _ts;
     282
     283  bintime2timespec( _time, &_ts );
     284
     285  return _ts.tv_nsec;
     286}
    257287
    258288/**
     
    265295 *  @retval The time in nanoseconds.
    266296 */
    267 #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
    268   #define _Timestamp_Get_As_nanoseconds( _timestamp, _nanoseconds ) \
    269           _Timespec_Get_As_nanoseconds( _timestamp, _nanoseconds )
    270 #else
    271   #define _Timestamp_Get_As_nanoseconds( _timestamp, _nanoseconds ) \
    272           _Timestamp64_Get_As_nanoseconds( _timestamp, _nanoseconds )
    273 #endif
     297RTEMS_INLINE_ROUTINE uint64_t _Timestamp_Get_as_nanoseconds(
     298  const Timestamp_Control *_time
     299)
     300{
     301  struct timespec _ts;
     302
     303  bintime2timespec( _time, &_ts );
     304
     305  return _Timespec_Get_as_nanoseconds( &_ts );
     306}
    274307
    275308/**
     
    281314 *  @param[in] _timespec points to the timespec
    282315 */
    283 #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
    284   /* in this case we know they are the same type so use simple assignment */
    285   #define _Timestamp_To_timespec( _timestamp, _timespec  ) \
    286           *(_timespec) = *(_timestamp)
    287 #else
    288   #define _Timestamp_To_timespec( _timestamp, _timespec  ) \
    289           _Timestamp64_To_timespec( _timestamp, _timespec  )
    290 #endif
     316RTEMS_INLINE_ROUTINE void _Timestamp_To_timespec(
     317  const Timestamp_Control *_timestamp,
     318  struct timespec         *_timespec
     319)
     320{
     321  bintime2timespec( _timestamp, _timespec );
     322}
    291323
    292324/**
     
    296328 *  @param[in] _timeval points to the timeval
    297329 */
    298 #if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
    299   #define _Timestamp_To_timeval( _timestamp, _timeval  ) \
    300     do { \
    301       (_timeval)->tv_sec = (_timestamp)->tv_sec; \
    302       (_timeval)->tv_usec = (_timestamp)->tv_nsec / 1000; \
    303     } while (0)
    304 #else
    305   #define _Timestamp_To_timeval( _timestamp, _timeval  ) \
    306           _Timestamp64_To_timeval( _timestamp, _timeval  )
    307 #endif
     330RTEMS_INLINE_ROUTINE void _Timestamp_To_timeval(
     331  const Timestamp_Control *_timestamp,
     332  struct timeval          *_timeval
     333)
     334{
     335  bintime2timeval( _timestamp, _timeval );
     336}
    308337
    309338#ifdef __cplusplus
  • cpukit/score/include/rtems/score/tod.h

    r31be416 r7cd2484  
    2525#endif
    2626
    27 /**
    28  * @brief Returns the nanoseconds since the last clock tick.
    29  *
    30  * @ingroup ScoreTOD
    31  *
    32  * @return The nanoseconds since the last clock tick.
    33  */
    34 typedef uint32_t ( *TOD_Nanoseconds_since_last_tick_routine )( void );
    35 
    3627#ifdef __cplusplus
    3728}
  • cpukit/score/include/rtems/score/todimpl.h

    r31be416 r7cd2484  
    2020
    2121#include <rtems/score/tod.h>
    22 #include <rtems/score/isrlock.h>
    2322#include <rtems/score/timestamp.h>
     23#include <rtems/score/timecounterimpl.h>
    2424
    2525#include <sys/time.h>
     
    131131 */
    132132typedef struct {
    133   /**
    134    * @brief Current time of day value.
    135    *
    136    * This field is protected by the lock.
    137    */
    138   Timestamp_Control now;
    139 
    140   /**
    141    * @brief System uptime.
    142    *
    143    * This field is protected by the lock.
    144    */
    145   Timestamp_Control uptime;
    146 
    147   /**
    148    * @brief Lock to protect the now and uptime fields.
    149    */
    150   ISR_lock_Control lock;
    151 
    152133  /**
    153134   * @brief Time of day seconds trigger.
     
    160141
    161142  /**
    162    * @brief The current nanoseconds since last tick handler.
    163    *
    164    * This field must not be NULL after initialization.
    165    */
    166   TOD_Nanoseconds_since_last_tick_routine nanoseconds_since_last_tick;
    167 
    168   /**
    169143   *  @brief Indicates if the time of day is set.
    170144   *
     
    177151SCORE_EXTERN TOD_Control _TOD;
    178152
    179 #define _TOD_Acquire( _tod, lock_context ) \
    180   _ISR_lock_ISR_disable_and_acquire( &( _tod )->lock, lock_context )
    181 
    182 #define _TOD_Release( _tod, lock_context ) \
    183   _ISR_lock_Release_and_ISR_enable( &( _tod )->lock, lock_context )
    184 
    185153/**
    186154 *  @brief Initializes the time of day handler.
     
    202170);
    203171
     172/**
     173 *  @brief Sets the time of day from timespec.
     174 *
     175 *  The @a tod_as_timestamp timestamp represents the time since UNIX epoch.
     176 *  The watchdog seconds chain will be adjusted.
     177 *
     178 *  In the process the input given as timespec will be transformed to FreeBSD
     179 *  bintime format to guarantee the right format for later setting it with a
     180 *  timestamp.
     181 *
     182 *  @param[in] tod_as_timespec is the constant of the time of day as a timespec
     183 */
    204184static inline void _TOD_Set(
    205185  const struct timespec *tod_as_timespec
     
    217197
    218198/**
    219  *  @brief Returns a snapshot of a clock.
    220  *
    221  *  This function invokes the nanoseconds extension.
    222  *
    223  *  @param[out] snapshot points to an area that will contain the current
    224  *              TOD plus the BSP nanoseconds since last tick adjustment
    225  *  @param[in] clock contains the current TOD
    226  *
    227  *  @retval @a snapshot
    228  */
    229 Timestamp_Control *_TOD_Get_with_nanoseconds(
    230   Timestamp_Control *snapshot,
    231   const Timestamp_Control *clock
    232 );
    233 
     199 *  @brief Gets the current time in the bintime format.
     200 *
     201 *  @param[out] time is the value gathered by the bintime request
     202 */
    234203static inline void _TOD_Get(
    235   struct timespec *tod_as_timespec
    236 )
    237 {
    238   Timestamp_Control  tod_as_timestamp;
    239   Timestamp_Control *tod_as_timestamp_ptr;
    240 
    241   tod_as_timestamp_ptr =
    242     _TOD_Get_with_nanoseconds( &tod_as_timestamp, &_TOD.now );
    243   _Timestamp_To_timespec( tod_as_timestamp_ptr, tod_as_timespec );
     204  Timestamp_Control *time
     205)
     206{
     207  _Timecounter_Bintime(time);
     208}
     209
     210/**
     211 *  @brief Gets the current time in the timespec format.
     212 *
     213 *  @param[out] time is the value gathered by the nanotime request
     214 */
     215static inline void _TOD_Get_as_timespec(
     216  struct timespec *time
     217)
     218{
     219  _Timecounter_Nanotime(time);
    244220}
    245221
     
    250226 *  to the nanosecond.
    251227 *
     228 *  The initial uptime value is undefined.
     229 *
    252230 *  @param[in] time is a pointer to the uptime to be returned
    253231 */
     
    256234)
    257235{
    258   _TOD_Get_with_nanoseconds( time, &_TOD.uptime );
     236  _Timecounter_Binuptime( time );
    259237}
    260238
    261239/**
    262240 *  @brief Gets the system uptime with potential accuracy to the nanosecond.
    263  *
    264  *  This routine returns the system uptime with potential accuracy
    265241 *  to the nanosecond.
    266242 *
     243 *  The initial uptime value is zero.
     244 *
    267245 *  @param[in] time is a pointer to the uptime to be returned
    268246 */
    269 void _TOD_Get_uptime_as_timespec(
     247static inline void _TOD_Get_zero_based_uptime(
     248  Timestamp_Control *time
     249)
     250{
     251  _Timecounter_Binuptime( time );
     252  --time->sec;
     253}
     254
     255/**
     256 *  @brief Gets the system uptime with potential accuracy to the nanosecond.
     257 *
     258 *  The initial uptime value is zero.
     259 *
     260 *  @param[in] time is a pointer to the uptime to be returned
     261 */
     262static inline void _TOD_Get_zero_based_uptime_as_timespec(
    270263  struct timespec *time
    271 );
     264)
     265{
     266  _Timecounter_Nanouptime( time );
     267  --time->tv_sec;
     268}
    272269
    273270/**
     
    277274 *  January 1, TOD_BASE_YEAR until the current time of day.
    278275 */
    279 uint32_t _TOD_Seconds_since_epoch( void );
     276static inline uint32_t _TOD_Seconds_since_epoch( void )
     277{
     278  return (uint32_t) _Timecounter_Time_second;
     279}
    280280
    281281/**
     
    315315)
    316316{
    317   Timestamp_Control  snapshot_as_timestamp;
    318   Timestamp_Control *snapshot_as_timestamp_ptr;
    319 
    320   snapshot_as_timestamp_ptr =
    321     _TOD_Get_with_nanoseconds( &snapshot_as_timestamp, &_TOD.now );
    322   _Timestamp_To_timeval( snapshot_as_timestamp_ptr, time );
     317  _Timecounter_Microtime( time );
    323318}
    324319
     
    336331
    337332/**
    338  * @brief Install the BSP's nanoseconds since clock tick handler
    339  *
    340  * @param[in] routine is the BSP's nanoseconds since clock tick method
    341  */
    342 RTEMS_INLINE_ROUTINE void _TOD_Set_nanoseconds_since_last_tick_handler(
    343   TOD_Nanoseconds_since_last_tick_routine routine
    344 )
    345 {
    346   _TOD.nanoseconds_since_last_tick = routine;
    347 }
    348 
    349 /**
    350333 * @brief Check if the TOD is Set
    351334 *
  • cpukit/score/include/rtems/score/watchdogimpl.h

    r31be416 r7cd2484  
    139139
    140140/**
     141 *  @brief Triggers a watchdog tick.
     142 *
     143 *  This routine executes TOD, watchdog and scheduler ticks.
     144 */
     145void _Watchdog_Tick( void );
     146
     147/**
    141148 *  @brief Removes @a the_watchdog from the watchdog chain.
    142149 *
  • cpukit/score/preinstall.am

    r31be416 r7cd2484  
    344344        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/timestamp.h
    345345PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/timestamp.h
    346 
    347 $(PROJECT_INCLUDE)/rtems/score/timestamp64.h: include/rtems/score/timestamp64.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
    348         $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/timestamp64.h
    349 PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/timestamp64.h
    350346
    351347$(PROJECT_INCLUDE)/rtems/score/timecounter.h: include/rtems/score/timecounter.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
  • cpukit/score/src/coretod.c

    r31be416 r7cd2484  
    2121#include <rtems/score/todimpl.h>
    2222
    23 static uint32_t _TOD_Nanoseconds_since_tick_default_handler( void )
    24 {
    25   return 0;
    26 }
    27 
    2823void _TOD_Handler_initialization(void)
    2924{
    30   TOD_Control *tod = &_TOD;
     25  struct timespec ts;
    3126
    32   _ISR_lock_Initialize( &tod->lock, "TOD" );
     27  _Timecounter_Initialize();
    3328
    34   _Timestamp_Set( &tod->now, TOD_SECONDS_1970_THROUGH_1988, 0 );
    35 
    36   _Timestamp_Set_to_zero( &tod->uptime );
    37 
    38   tod->nanoseconds_since_last_tick =
    39     _TOD_Nanoseconds_since_tick_default_handler;
     29  ts.tv_sec = TOD_SECONDS_1970_THROUGH_1988;
     30  ts.tv_nsec = 0;
     31  _Timecounter_Set_clock( &ts );
    4032
    4133  /* TOD has not been set */
    42   tod->is_set = false;
     34  _TOD.is_set = false;
    4335}
  • cpukit/score/src/coretodadjust.c

    r31be416 r7cd2484  
    2626)
    2727{
    28   Timestamp_Control  tod;
    29   Timestamp_Control *tod_ptr;
     28  Timestamp_Control tod;
    3029
    3130  /*
     
    4241  _Thread_Disable_dispatch();
    4342
    44     tod_ptr = _TOD_Get_with_nanoseconds( &tod, &_TOD.now );
     43    _TOD_Get( &tod );
    4544
    46     _Timestamp_Add_to( tod_ptr, &delta );
     45    _Timestamp_Add_to( &tod, &delta );
    4746
    48     _TOD_Set_with_timestamp( tod_ptr );
     47    _TOD_Set_with_timestamp( &tod );
    4948
    5049  _Thread_Enable_dispatch();
  • cpukit/score/src/coretodset.c

    r31be416 r7cd2484  
    2727)
    2828{
    29   TOD_Control *tod = &_TOD;
    30   uint32_t nanoseconds = _Timestamp_Get_nanoseconds( tod_as_timestamp );
    31   Watchdog_Interval seconds_next = _Timestamp_Get_seconds( tod_as_timestamp );
     29  struct timespec ts;
     30  uint32_t nanoseconds;
     31  Watchdog_Interval seconds_next;
    3232  Watchdog_Interval seconds_now;
    33   ISR_lock_Context lock_context;
    3433  Watchdog_Header *header;
     34
     35  _Timestamp_To_timespec( tod_as_timestamp, &ts );
     36  nanoseconds = ts.tv_nsec;
     37  seconds_next = ts.tv_sec;
    3538
    3639  _Thread_Disable_dispatch();
     
    3841  seconds_now = _TOD_Seconds_since_epoch();
    3942
    40   _TOD_Acquire( tod, &lock_context );
    41   tod->now = *tod_as_timestamp;
    42   _TOD_Release( tod, &lock_context );
     43  _Timecounter_Set_clock( &ts );
    4344
    4445  header = &_Watchdog_Seconds_header;
     
    4950    _Watchdog_Adjust_forward( header, seconds_next - seconds_now );
    5051
    51   tod->seconds_trigger = nanoseconds;
    52   tod->is_set = true;
     52  _TOD.seconds_trigger = nanoseconds;
     53  _TOD.is_set = true;
    5354
    5455  _Thread_Enable_dispatch();
  • cpukit/score/src/coretodtickle.c

    r31be416 r7cd2484  
    2525void _TOD_Tickle_ticks( void )
    2626{
    27   TOD_Control       *tod = &_TOD;
    28   ISR_lock_Context   lock_context;
    29   Timestamp_Control  tick;
    30   uint32_t           nanoseconds_per_tick;
    31 
    32   nanoseconds_per_tick = rtems_configuration_get_nanoseconds_per_tick();
    33 
    34   /* Convert the tick quantum to a timestamp */
    35   _Timestamp_Set( &tick, 0, nanoseconds_per_tick );
    36 
    3727  /* Update the counter of ticks since boot */
    3828  _Watchdog_Ticks_since_boot += 1;
    3929
    40   _TOD_Acquire( tod, &lock_context );
    41 
    42   /* Update the uptime */
    43   _Timestamp_Add_to( &tod->uptime, &tick );
    44 
    45   /* Update the current TOD */
    46   _Timestamp_Add_to( &tod->now, &tick );
    47 
    48   _TOD_Release( tod, &lock_context );
    49 
    50   _TOD.seconds_trigger += nanoseconds_per_tick;
     30  _TOD.seconds_trigger += rtems_configuration_get_nanoseconds_per_tick();
    5131  if ( _TOD.seconds_trigger >= 1000000000UL ) {
    5232    _TOD.seconds_trigger -= 1000000000UL;
  • cpukit/score/src/kern_tc.c

    r31be416 r7cd2484  
    3434#define time_uptime _Timecounter_Time_uptime
    3535#include <rtems/score/timecounterimpl.h>
     36#include <rtems/score/watchdogimpl.h>
    3637#endif /* __rtems__ */
    3738#include <sys/cdefs.h>
     
    18871888#endif /* __rtems__ */
    18881889        tc_windup();
     1890#ifdef __rtems__
     1891        _Watchdog_Tick();
     1892#endif /* __rtems__ */
    18891893}
    18901894#ifdef __rtems__
     
    19251929
    19261930        _ISR_lock_Release_and_ISR_enable(&_Timecounter_Lock, &lock_context);
     1931
     1932        _Watchdog_Tick();
    19271933}
    19281934#endif /* __rtems__ */
  • cpukit/score/src/timespecgetasnanoseconds.c

    r31be416 r7cd2484  
    2121#include <rtems/score/todimpl.h>
    2222
    23 uint64_t _Timespec_Get_As_nanoseconds(
    24   const struct timespec *time,
    25   const uint32_t nanoseconds
     23uint64_t _Timespec_Get_as_nanoseconds(
     24  const struct timespec *time
    2625)
    2726{
    28   return ( ((uint64_t) time->tv_sec) * 1000000000ULL ) + time->tv_nsec + nanoseconds;
     27  return ( ((uint64_t) time->tv_sec) * 1000000000ULL ) + time->tv_nsec;
    2928}
  • testsuites/sptests/Makefile.am

    r31be416 r7cd2484  
    4040_SUBDIRS += spintrcritical23
    4141_SUBDIRS += sptimecounter01
     42_SUBDIRS += sptimecounter02
    4243_SUBDIRS += spatomic01
    4344_SUBDIRS += spintrcritical22
  • testsuites/sptests/configure.ac

    r31be416 r7cd2484  
    4343spintrcritical23/Makefile
    4444sptimecounter01/Makefile
     45sptimecounter02/Makefile
    4546spatomic01/Makefile
    4647spglobalcon01/Makefile
  • testsuites/sptests/spclock_err01/init.c

    r31be416 r7cd2484  
    116116  }
    117117
    118   puts( "TA1 - rtems_clock_set_nanoseconds_extension - RTEMS_INVALID_ADDRESS" );
    119   status = rtems_clock_set_nanoseconds_extension( NULL );
    120   fatal_directive_status(
    121     status,
    122     RTEMS_INVALID_ADDRESS,
    123     "rtems_clock_set_nanoseconds_extension NULL param"
    124   );
    125 
    126118  /* NULL parameter */
    127119  status = rtems_clock_set( NULL );
  • testsuites/sptests/spsize/size.c

    r31be416 r7cd2484  
    390390
    391391/*timerimpl.h*/ (sizeof _Timer_Information)               +
    392 
    393 /*tod.h*/       (sizeof _TOD.now)                         +
    394                 (sizeof _TOD.uptime)                      +
    395392
    396393/*tqdata.h*/    0                                         +
Note: See TracChangeset for help on using the changeset viewer.