source: rtems/cpukit/score/src/coretodabsolutetimeout.c @ 2256946

5
Last change on this file since 2256946 was 2256946, checked in by Sebastian Huber <sebastian.huber@…>, on 10/06/17 at 13:30:47

score: Use struct timespec for TOD

Use the timestamps only for uptime based values. Use struct timespec
for the absolute time values (TOD).

Update #2740.

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[a0e6c73]1/**
2 * @file
3 *
4 * @brief Convert Absolute Timeout to Ticks
[21789a21]5 * @ingroup ScoreTOD
[412dbff6]6 */
7
8/*
[6a0898b]9 *  COPYRIGHT (c) 1989-2008.
[412dbff6]10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
[c499856]14 *  http://www.rtems.org/license/LICENSE.
[ba16717]15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
[f031df0e]21#include <rtems/score/todimpl.h>
[ba16717]22
23/*
24 *  The abstime is a walltime.  We turn it into an interval.
25 */
[21789a21]26TOD_Absolute_timeout_conversion_results _TOD_Absolute_timeout_to_ticks(
[ba16717]27  const struct timespec *abstime,
[b5bfaaf9]28  clockid_t              clock,
[ba16717]29  Watchdog_Interval     *ticks_out
30)
31{
[412dbff6]32  struct timespec current_time;
33  struct timespec difference;
[ba16717]34
[6a0898b]35  /*
36   *  Make sure there is always a value returned.
37   */
38  *ticks_out = 0;
[ba16717]39
[6a0898b]40  /*
41   *  Is the absolute time even valid?
42   */
43  if ( !_Timespec_Is_valid(abstime) )
[21789a21]44    return TOD_ABSOLUTE_TIMEOUT_INVALID;
[ba16717]45
46  /*
[6a0898b]47   *  Is the absolute time in the past?
[ba16717]48   */
[b5bfaaf9]49  if ( clock == CLOCK_REALTIME ) {
[2256946]50    _TOD_Get( &current_time );
[b5bfaaf9]51  } else {
52    _Assert( clock == CLOCK_MONOTONIC );
53    _TOD_Get_zero_based_uptime_as_timespec( &current_time );
54  }
[6a0898b]55
[412dbff6]56  if ( _Timespec_Less_than( abstime, &current_time ) )
[21789a21]57    return TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST;
[ba16717]58
[6a0898b]59  /*
60   *  How long until the requested absolute time?
61   */
[412dbff6]62  _Timespec_Subtract( &current_time, abstime, &difference );
[ba16717]63
[6a0898b]64  /*
65   *  Internally the SuperCore uses ticks, so convert to them.
66   */
[412dbff6]67  *ticks_out = _Timespec_To_ticks( &difference );
[ba16717]68
[6a0898b]69  /*
70   *  If the difference was 0, then the future is now.  It is so bright
71   *  we better wear shades.
72   */
73  if ( !*ticks_out )
[21789a21]74    return TOD_ABSOLUTE_TIMEOUT_IS_NOW;
[6a0898b]75
76  /*
77   *  This is the case we were expecting and it took this long to
78   *  get here.
79   */
[21789a21]80  return TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE;
[ba16717]81}
82
Note: See TracBrowser for help on using the repository browser.