1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Convert Absolute Timeout to Ticks |
---|
5 | * @ingroup ScoreTOD |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2008. |
---|
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 |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/score/todimpl.h> |
---|
22 | |
---|
23 | /* |
---|
24 | * The abstime is a walltime. We turn it into an interval. |
---|
25 | */ |
---|
26 | TOD_Absolute_timeout_conversion_results _TOD_Absolute_timeout_to_ticks( |
---|
27 | const struct timespec *abstime, |
---|
28 | clockid_t clock, |
---|
29 | Watchdog_Interval *ticks_out |
---|
30 | ) |
---|
31 | { |
---|
32 | struct timespec current_time; |
---|
33 | struct timespec difference; |
---|
34 | |
---|
35 | /* |
---|
36 | * Make sure there is always a value returned. |
---|
37 | */ |
---|
38 | *ticks_out = 0; |
---|
39 | |
---|
40 | /* |
---|
41 | * Is the absolute time even valid? |
---|
42 | */ |
---|
43 | if ( !_Timespec_Is_valid(abstime) ) |
---|
44 | return TOD_ABSOLUTE_TIMEOUT_INVALID; |
---|
45 | |
---|
46 | /* |
---|
47 | * Is the absolute time in the past? |
---|
48 | */ |
---|
49 | if ( clock == CLOCK_REALTIME ) { |
---|
50 | _TOD_Get_as_timespec( ¤t_time ); |
---|
51 | } else { |
---|
52 | _Assert( clock == CLOCK_MONOTONIC ); |
---|
53 | _TOD_Get_zero_based_uptime_as_timespec( ¤t_time ); |
---|
54 | } |
---|
55 | |
---|
56 | if ( _Timespec_Less_than( abstime, ¤t_time ) ) |
---|
57 | return TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST; |
---|
58 | |
---|
59 | /* |
---|
60 | * How long until the requested absolute time? |
---|
61 | */ |
---|
62 | _Timespec_Subtract( ¤t_time, abstime, &difference ); |
---|
63 | |
---|
64 | /* |
---|
65 | * Internally the SuperCore uses ticks, so convert to them. |
---|
66 | */ |
---|
67 | *ticks_out = _Timespec_To_ticks( &difference ); |
---|
68 | |
---|
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 ) |
---|
74 | return TOD_ABSOLUTE_TIMEOUT_IS_NOW; |
---|
75 | |
---|
76 | /* |
---|
77 | * This is the case we were expecting and it took this long to |
---|
78 | * get here. |
---|
79 | */ |
---|
80 | return TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE; |
---|
81 | } |
---|
82 | |
---|