source: rtems/cpukit/rtems/src/taskwakewhen.c @ 3246b0f8

4.115
Last change on this file since 3246b0f8 was 3246b0f8, checked in by Sebastian Huber <sebastian.huber@…>, on 06/13/12 at 09:29:53

score: New structure TOD_Control

Group the global TOD variables (_TOD_Now, _TOD_Uptime, and _TOD_Is_set)
in a structure to reduce address loads in _TOD_Tickle_ticks().

  • Property mode set to 100644
File size: 2.0 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/userext.h>
30#include <rtems/score/wkspace.h>
31#include <rtems/score/apiext.h>
32#include <rtems/score/sysstate.h>
33
34/*
35 *  rtems_task_wake_when
36 *
37 *  This directive blocks the requesting thread until the given date and
38 *  time is reached.
39 *
40 *  Input parameters:
41 *    time_buffer - pointer to the time and date structure
42 *
43 *  Output parameters:
44 *    RTEMS_SUCCESSFUL - if successful
45 *    error code       - if unsuccessful
46 */
47
48rtems_status_code rtems_task_wake_when(
49  rtems_time_of_day *time_buffer
50)
51{
52  Watchdog_Interval   seconds;
53
54  if ( !_TOD.is_set )
55    return RTEMS_NOT_DEFINED;
56
57  if ( !time_buffer )
58    return RTEMS_INVALID_ADDRESS;
59
60  time_buffer->ticks = 0;
61
62  if ( !_TOD_Validate( time_buffer ) )
63    return RTEMS_INVALID_CLOCK;
64
65  seconds = _TOD_To_seconds( time_buffer );
66
67  if ( seconds <= _TOD_Seconds_since_epoch() )
68    return RTEMS_INVALID_CLOCK;
69
70  _Thread_Disable_dispatch();
71    _Thread_Set_state( _Thread_Executing, STATES_WAITING_FOR_TIME );
72    _Watchdog_Initialize(
73      &_Thread_Executing->Timer,
74      _Thread_Delay_ended,
75      _Thread_Executing->Object.id,
76      NULL
77    );
78    _Watchdog_Insert_seconds(
79      &_Thread_Executing->Timer,
80      seconds - _TOD_Seconds_since_epoch()
81    );
82  _Thread_Enable_dispatch();
83  return RTEMS_SUCCESSFUL;
84}
Note: See TracBrowser for help on using the repository browser.