1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Function Fetches State of POSIX Per-Process Timers |
---|
5 | * @ingroup POSIXAPI |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * 14.2.4 Per-Process Timers, P1003.1b-1993, p. 267 |
---|
10 | * |
---|
11 | * COPYRIGHT (c) 1989-2008. |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #if HAVE_CONFIG_H |
---|
20 | #include "config.h" |
---|
21 | #endif |
---|
22 | |
---|
23 | #include <time.h> |
---|
24 | #include <errno.h> |
---|
25 | |
---|
26 | #include <rtems/posix/timerimpl.h> |
---|
27 | #include <rtems/score/todimpl.h> |
---|
28 | #include <rtems/score/watchdogimpl.h> |
---|
29 | #include <rtems/seterr.h> |
---|
30 | |
---|
31 | /* |
---|
32 | * - When a timer is initialized, the value of the time in |
---|
33 | * that moment is stored. |
---|
34 | * - When this function is called, it returns the difference |
---|
35 | * between the current time and the initialization time. |
---|
36 | */ |
---|
37 | |
---|
38 | int timer_gettime( |
---|
39 | timer_t timerid, |
---|
40 | struct itimerspec *value |
---|
41 | ) |
---|
42 | { |
---|
43 | POSIX_Timer_Control *ptimer; |
---|
44 | Objects_Locations location; |
---|
45 | struct timespec current_time; |
---|
46 | Watchdog_Interval left; |
---|
47 | |
---|
48 | if ( !value ) |
---|
49 | rtems_set_errno_and_return_minus_one( EINVAL ); |
---|
50 | |
---|
51 | /* Reads the current time */ |
---|
52 | _TOD_Get( ¤t_time ); |
---|
53 | |
---|
54 | ptimer = _POSIX_Timer_Get( timerid, &location ); |
---|
55 | switch ( location ) { |
---|
56 | |
---|
57 | case OBJECTS_LOCAL: |
---|
58 | |
---|
59 | /* Calculates the time left before the timer finishes */ |
---|
60 | |
---|
61 | left = |
---|
62 | (ptimer->Timer.start_time + ptimer->Timer.initial) - /* expire */ |
---|
63 | _Watchdog_Ticks_since_boot; /* now */ |
---|
64 | |
---|
65 | _Timespec_From_ticks( left, &value->it_value ); |
---|
66 | |
---|
67 | value->it_interval = ptimer->timer_data.it_interval; |
---|
68 | |
---|
69 | _Objects_Put( &ptimer->Object ); |
---|
70 | return 0; |
---|
71 | |
---|
72 | #if defined(RTEMS_MULTIPROCESSING) |
---|
73 | case OBJECTS_REMOTE: |
---|
74 | #endif |
---|
75 | case OBJECTS_ERROR: |
---|
76 | break; |
---|
77 | } |
---|
78 | |
---|
79 | rtems_set_errno_and_return_minus_one( EINVAL ); |
---|
80 | } |
---|