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