source: rtems/cpukit/rtems/src/taskwakewhen.c @ 3be0c9a

4.115
Last change on this file since 3be0c9a was 3be0c9a, checked in by Sebastian Huber <sebastian.huber@…>, on 11/22/12 at 13:51:25

score: Add and use <rtems/score/userextimpl.h>

This file contains the parts of <rtems/score/userext.h> that are only
necessary for the RTEMS implementation.

  • Property mode set to 100644
File size: 1.9 KB
Line 
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.rtems.com/license/LICENSE.
11 */
12
13#if HAVE_CONFIG_H
14#include "config.h"
15#endif
16
17#include <rtems/system.h>
18#include <rtems/rtems/status.h>
19#include <rtems/rtems/support.h>
20#include <rtems/rtems/modes.h>
21#include <rtems/rtems/clock.h>
22#include <rtems/score/object.h>
23#include <rtems/score/stack.h>
24#include <rtems/score/states.h>
25#include <rtems/rtems/tasks.h>
26#include <rtems/score/thread.h>
27#include <rtems/score/threadq.h>
28#include <rtems/score/tod.h>
29#include <rtems/score/wkspace.h>
30#include <rtems/score/apiext.h>
31#include <rtems/score/sysstate.h>
32
33/*
34 *  rtems_task_wake_when
35 *
36 *  This directive blocks the requesting thread until the given date and
37 *  time is reached.
38 *
39 *  Input parameters:
40 *    time_buffer - pointer to the time and date structure
41 *
42 *  Output parameters:
43 *    RTEMS_SUCCESSFUL - if successful
44 *    error code       - if unsuccessful
45 */
46
47rtems_status_code rtems_task_wake_when(
48  rtems_time_of_day *time_buffer
49)
50{
51  Watchdog_Interval   seconds;
52
53  if ( !_TOD.is_set )
54    return RTEMS_NOT_DEFINED;
55
56  if ( !time_buffer )
57    return RTEMS_INVALID_ADDRESS;
58
59  time_buffer->ticks = 0;
60
61  if ( !_TOD_Validate( time_buffer ) )
62    return RTEMS_INVALID_CLOCK;
63
64  seconds = _TOD_To_seconds( time_buffer );
65
66  if ( seconds <= _TOD_Seconds_since_epoch() )
67    return RTEMS_INVALID_CLOCK;
68
69  _Thread_Disable_dispatch();
70    _Thread_Set_state( _Thread_Executing, STATES_WAITING_FOR_TIME );
71    _Watchdog_Initialize(
72      &_Thread_Executing->Timer,
73      _Thread_Delay_ended,
74      _Thread_Executing->Object.id,
75      NULL
76    );
77    _Watchdog_Insert_seconds(
78      &_Thread_Executing->Timer,
79      seconds - _TOD_Seconds_since_epoch()
80    );
81  _Thread_Enable_dispatch();
82  return RTEMS_SUCCESSFUL;
83}
Note: See TracBrowser for help on using the repository browser.