1 | /* |
---|
2 | * RTEMS Task Manager |
---|
3 | * |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989-1999. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.OARcorp.com/rtems/license.html. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #include <rtems/system.h> |
---|
16 | #include <rtems/rtems/status.h> |
---|
17 | #include <rtems/rtems/support.h> |
---|
18 | #include <rtems/rtems/modes.h> |
---|
19 | #include <rtems/score/object.h> |
---|
20 | #include <rtems/score/stack.h> |
---|
21 | #include <rtems/score/states.h> |
---|
22 | #include <rtems/rtems/tasks.h> |
---|
23 | #include <rtems/score/thread.h> |
---|
24 | #include <rtems/score/threadq.h> |
---|
25 | #include <rtems/score/tod.h> |
---|
26 | #include <rtems/score/userext.h> |
---|
27 | #include <rtems/score/wkspace.h> |
---|
28 | #include <rtems/score/apiext.h> |
---|
29 | #include <rtems/score/sysstate.h> |
---|
30 | |
---|
31 | /*PAGE |
---|
32 | * |
---|
33 | * rtems_task_wake_when |
---|
34 | * |
---|
35 | * This directive blocks the requesting thread until the given date and |
---|
36 | * time is reached. |
---|
37 | * |
---|
38 | * Input parameters: |
---|
39 | * time_buffer - pointer to the time and date structure |
---|
40 | * |
---|
41 | * Output parameters: |
---|
42 | * RTEMS_SUCCESSFUL - if successful |
---|
43 | * error code - if unsuccessful |
---|
44 | */ |
---|
45 | |
---|
46 | rtems_status_code rtems_task_wake_when( |
---|
47 | rtems_time_of_day *time_buffer |
---|
48 | ) |
---|
49 | { |
---|
50 | Watchdog_Interval seconds; |
---|
51 | |
---|
52 | if ( !_TOD_Is_set ) |
---|
53 | return RTEMS_NOT_DEFINED; |
---|
54 | |
---|
55 | time_buffer->ticks = 0; |
---|
56 | |
---|
57 | if ( !_TOD_Validate( time_buffer ) ) |
---|
58 | return RTEMS_INVALID_CLOCK; |
---|
59 | |
---|
60 | seconds = _TOD_To_seconds( time_buffer ); |
---|
61 | |
---|
62 | if ( seconds <= _TOD_Seconds_since_epoch ) |
---|
63 | return RTEMS_INVALID_CLOCK; |
---|
64 | |
---|
65 | _Thread_Disable_dispatch(); |
---|
66 | _Thread_Set_state( _Thread_Executing, STATES_WAITING_FOR_TIME ); |
---|
67 | _Watchdog_Initialize( |
---|
68 | &_Thread_Executing->Timer, |
---|
69 | _Thread_Delay_ended, |
---|
70 | _Thread_Executing->Object.id, |
---|
71 | NULL |
---|
72 | ); |
---|
73 | _Watchdog_Insert_seconds( |
---|
74 | &_Thread_Executing->Timer, |
---|
75 | seconds - _TOD_Seconds_since_epoch |
---|
76 | ); |
---|
77 | _Thread_Enable_dispatch(); |
---|
78 | return RTEMS_SUCCESSFUL; |
---|
79 | } |
---|