[52adc808] | 1 | /** |
---|
| 2 | * @file |
---|
[c4d69e2] | 3 | * |
---|
[52adc808] | 4 | * @brief RTEMS Task Wake When |
---|
| 5 | * @ingroup ClassicTasks |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | /* |
---|
[08311cc3] | 9 | * COPYRIGHT (c) 1989-1999. |
---|
[c4d69e2] | 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 |
---|
[c499856] | 14 | * http://www.rtems.org/license/LICENSE. |
---|
[c4d69e2] | 15 | */ |
---|
| 16 | |
---|
[1095ec1] | 17 | #if HAVE_CONFIG_H |
---|
| 18 | #include "config.h" |
---|
| 19 | #endif |
---|
| 20 | |
---|
[5618c37a] | 21 | #include <rtems/rtems/tasks.h> |
---|
[812da54] | 22 | #include <rtems/rtems/clock.h> |
---|
[5618c37a] | 23 | #include <rtems/score/threadimpl.h> |
---|
[f031df0e] | 24 | #include <rtems/score/todimpl.h> |
---|
[4b48ece0] | 25 | #include <rtems/score/watchdogimpl.h> |
---|
[c4d69e2] | 26 | |
---|
| 27 | rtems_status_code rtems_task_wake_when( |
---|
[e980b219] | 28 | rtems_time_of_day *time_buffer |
---|
[c4d69e2] | 29 | ) |
---|
| 30 | { |
---|
[03b900d] | 31 | uint32_t seconds; |
---|
| 32 | Thread_Control *executing; |
---|
| 33 | Per_CPU_Control *cpu_self; |
---|
[c4d69e2] | 34 | |
---|
[b915762] | 35 | if ( !_TOD_Is_set() ) |
---|
[c4d69e2] | 36 | return RTEMS_NOT_DEFINED; |
---|
| 37 | |
---|
[e980b219] | 38 | if ( !time_buffer ) |
---|
| 39 | return RTEMS_INVALID_ADDRESS; |
---|
| 40 | |
---|
[c4d69e2] | 41 | time_buffer->ticks = 0; |
---|
| 42 | |
---|
| 43 | if ( !_TOD_Validate( time_buffer ) ) |
---|
| 44 | return RTEMS_INVALID_CLOCK; |
---|
| 45 | |
---|
| 46 | seconds = _TOD_To_seconds( time_buffer ); |
---|
| 47 | |
---|
[c16bcc0] | 48 | if ( seconds <= _TOD_Seconds_since_epoch() ) |
---|
[c4d69e2] | 49 | return RTEMS_INVALID_CLOCK; |
---|
| 50 | |
---|
[aa05cfbb] | 51 | cpu_self = _Thread_Dispatch_disable(); |
---|
[a49dfb1] | 52 | executing = _Per_CPU_Get_executing( cpu_self ); |
---|
[f6b7b7ba] | 53 | _Thread_Set_state( executing, STATES_WAITING_FOR_TIME ); |
---|
[aa05cfbb] | 54 | _Thread_Wait_flags_set( executing, THREAD_WAIT_STATE_BLOCKED ); |
---|
[bf2a53d2] | 55 | _Thread_Timer_insert_realtime( |
---|
[03b900d] | 56 | executing, |
---|
| 57 | cpu_self, |
---|
[aa05cfbb] | 58 | _Thread_Timeout, |
---|
[3a4e044] | 59 | _Watchdog_Ticks_from_seconds( seconds ) |
---|
[c4d69e2] | 60 | ); |
---|
[ed24ed4e] | 61 | _Thread_Dispatch_direct( cpu_self ); |
---|
[c4d69e2] | 62 | return RTEMS_SUCCESSFUL; |
---|
| 63 | } |
---|