Changeset adaf5c23 in rtems


Ignore:
Timestamp:
Oct 19, 2017, 11:38:48 AM (17 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
d16d07f
Parents:
ecef3698
git-author:
Sebastian Huber <sebastian.huber@…> (10/19/17 11:38:48)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/24/17 07:37:27)
Message:

score: _Watchdog_Is_far_future_realtime_timespec()

Update #3117.
Update #3182.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/include/rtems/score/watchdogimpl.h

    recef3698 radaf5c23  
    285285}
    286286
    287 /**
    288  * @brief The bits necessary to store 1000000000 nanoseconds.
     287#define WATCHDOG_NANOSECONDS_PER_SECOND 1000000000
     288
     289/**
     290 * @brief The bits necessary to store 1000000000
     291 * (= WATCHDOG_NANOSECONDS_PER_SECOND) nanoseconds.
    289292 *
    290293 * The expiration time is an unsigned 64-bit integer.  To store absolute
     
    294297#define WATCHDOG_BITS_FOR_1E9_NANOSECONDS 30
    295298
     299/**
     300 * @brief The maximum number of seconds representable in the realtime watchdog
     301 * format.
     302 *
     303 * We have 2**34 bits for the seconds part.
     304 */
     305#define WATCHDOG_REALTIME_MAX_SECONDS 0x3ffffffff
     306
     307RTEMS_INLINE_ROUTINE bool _Watchdog_Is_valid_timespec(
     308  const struct timespec *ts
     309)
     310{
     311  return ts != NULL
     312    && (unsigned long) ts->tv_nsec < WATCHDOG_NANOSECONDS_PER_SECOND;
     313}
     314
     315RTEMS_INLINE_ROUTINE bool _Watchdog_Is_far_future_realtime_timespec(
     316  const struct timespec *ts
     317)
     318{
     319  return ts->tv_sec > WATCHDOG_REALTIME_MAX_SECONDS;
     320}
     321
    296322RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Realtime_from_seconds(
    297323  uint32_t seconds
     
    309335)
    310336{
    311   /*
    312    * The seconds are in time_t which is a signed integer.  Thus this cast is
    313    * subject to the year 2038 problem in case time_t is a 32-bit integer.
    314    */
    315   uint64_t ticks = (uint64_t) ts->tv_sec;
    316 
    317   _Assert( ticks < 0x400000000 );
    318   _Assert( ts->tv_nsec >= 0 );
    319   _Assert( ts->tv_nsec < 1000000000 );
    320 
     337  uint64_t ticks;
     338
     339  _Assert( _Watchdog_Is_valid_timespec( ts ) );
     340  _Assert( ts->tv_sec >= 0 );
     341  _Assert( !_Watchdog_Is_far_future_realtime_timespec( ts ) );
     342
     343  ticks = (uint64_t) ts->tv_sec;
    321344  ticks <<= WATCHDOG_BITS_FOR_1E9_NANOSECONDS;
    322345  ticks |= (uint32_t) ts->tv_nsec;
Note: See TracChangeset for help on using the changeset viewer.