1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2008. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.com/license/LICENSE. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #if HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <rtems/itron.h> |
---|
17 | |
---|
18 | #include <rtems/itron/semaphore.h> |
---|
19 | #include <rtems/itron/task.h> |
---|
20 | #include <rtems/score/tod.h> |
---|
21 | |
---|
22 | /* |
---|
23 | * twai_sem - Wait on Semaphore with Timeout |
---|
24 | * |
---|
25 | * This function implements the ITRON 3.0 twai_sem() service. |
---|
26 | */ |
---|
27 | |
---|
28 | ER twai_sem( |
---|
29 | ID semid, |
---|
30 | TMO tmout |
---|
31 | ) |
---|
32 | { |
---|
33 | ITRON_Semaphore_Control *the_semaphore; |
---|
34 | Objects_Locations location; |
---|
35 | Watchdog_Interval interval; |
---|
36 | bool blocking; |
---|
37 | |
---|
38 | interval = 0; |
---|
39 | if ( tmout == TMO_POL ) { |
---|
40 | blocking = false; |
---|
41 | } else { |
---|
42 | blocking = true; |
---|
43 | |
---|
44 | if ( tmout != TMO_FEVR ) |
---|
45 | interval = TOD_MILLISECONDS_TO_TICKS(tmout); |
---|
46 | |
---|
47 | if ( _ITRON_Is_in_non_task_state() ) |
---|
48 | return E_CTX; |
---|
49 | } |
---|
50 | |
---|
51 | the_semaphore = _ITRON_Semaphore_Get( semid, &location ); |
---|
52 | switch ( location ) { |
---|
53 | #if defined(RTEMS_MULTIPROCESSING) |
---|
54 | case OBJECTS_REMOTE: /* Multiprocessing not supported */ |
---|
55 | #endif |
---|
56 | case OBJECTS_ERROR: |
---|
57 | return _ITRON_Semaphore_Clarify_get_id_error( semid ); |
---|
58 | |
---|
59 | case OBJECTS_LOCAL: |
---|
60 | _CORE_semaphore_Seize( |
---|
61 | &the_semaphore->semaphore, |
---|
62 | the_semaphore->Object.id, |
---|
63 | blocking, /* wait for a timeout */ |
---|
64 | interval /* timeout value */ |
---|
65 | ); |
---|
66 | _Thread_Enable_dispatch(); |
---|
67 | return _ITRON_Semaphore_Translate_core_semaphore_return_code( |
---|
68 | _Thread_Executing->Wait.return_code |
---|
69 | ); |
---|
70 | } |
---|
71 | return E_OK; |
---|
72 | } |
---|