1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Task Wake When |
---|
5 | * @ingroup ClassicTasks |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-1999. |
---|
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 |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/rtems/tasks.h> |
---|
22 | #include <rtems/rtems/clock.h> |
---|
23 | #include <rtems/score/threadimpl.h> |
---|
24 | #include <rtems/score/watchdogimpl.h> |
---|
25 | |
---|
26 | rtems_status_code rtems_task_wake_when( |
---|
27 | rtems_time_of_day *time_buffer |
---|
28 | ) |
---|
29 | { |
---|
30 | Watchdog_Interval seconds; |
---|
31 | |
---|
32 | if ( !_TOD.is_set ) |
---|
33 | return RTEMS_NOT_DEFINED; |
---|
34 | |
---|
35 | if ( !time_buffer ) |
---|
36 | return RTEMS_INVALID_ADDRESS; |
---|
37 | |
---|
38 | time_buffer->ticks = 0; |
---|
39 | |
---|
40 | if ( !_TOD_Validate( time_buffer ) ) |
---|
41 | return RTEMS_INVALID_CLOCK; |
---|
42 | |
---|
43 | seconds = _TOD_To_seconds( time_buffer ); |
---|
44 | |
---|
45 | if ( seconds <= _TOD_Seconds_since_epoch() ) |
---|
46 | return RTEMS_INVALID_CLOCK; |
---|
47 | |
---|
48 | _Thread_Disable_dispatch(); |
---|
49 | _Thread_Set_state( _Thread_Executing, STATES_WAITING_FOR_TIME ); |
---|
50 | _Watchdog_Initialize( |
---|
51 | &_Thread_Executing->Timer, |
---|
52 | _Thread_Delay_ended, |
---|
53 | _Thread_Executing->Object.id, |
---|
54 | NULL |
---|
55 | ); |
---|
56 | _Watchdog_Insert_seconds( |
---|
57 | &_Thread_Executing->Timer, |
---|
58 | seconds - _TOD_Seconds_since_epoch() |
---|
59 | ); |
---|
60 | _Thread_Enable_dispatch(); |
---|
61 | return RTEMS_SUCCESSFUL; |
---|
62 | } |
---|