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