OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [exec/] [rtems/] [src/] [eventseize.c] - Blame information for rev 373

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 *  Event Manager
3
 *
4
 *  COPYRIGHT (c) 1989-1999.
5
 *  On-Line Applications Research Corporation (OAR).
6
 *
7
 *  The license and distribution terms for this file may be
8
 *  found in the file LICENSE in this distribution or at
9
 *  http://www.OARcorp.com/rtems/license.html.
10
 *
11
 *  $Id: eventseize.c,v 1.2 2001-09-27 11:59:19 chris Exp $
12
 */
13
 
14
#include <rtems/system.h>
15
#include <rtems/rtems/status.h>
16
#include <rtems/rtems/event.h>
17
#include <rtems/score/isr.h>
18
#include <rtems/score/object.h>
19
#include <rtems/rtems/options.h>
20
#include <rtems/score/states.h>
21
#include <rtems/score/thread.h>
22
#include <rtems/rtems/tasks.h>
23
 
24
/*PAGE
25
 *
26
 *  _Event_Seize
27
 *
28
 *  This routine attempts to satisfy the requested event condition
29
 *  for the running thread.
30
 *
31
 *  Input parameters:
32
 *    event_in   - the event condition to satisfy
33
 *    option_set - acquire event options
34
 *    ticks      - interval to wait
35
 *    event_out  - pointer to event set output area
36
 *
37
 *  Output parameters: NONE
38
 *    *event_out - event set output area filled in
39
 *
40
 *  INTERRUPT LATENCY:
41
 *    available
42
 *    wait
43
 *    check sync
44
 */
45
 
46
void _Event_Seize(
47
  rtems_event_set  event_in,
48
  rtems_option     option_set,
49
  rtems_interval   ticks,
50
  rtems_event_set *event_out
51
)
52
{
53
  Thread_Control    *executing;
54
  rtems_event_set    seized_events;
55
  rtems_event_set    pending_events;
56
  ISR_Level          level;
57
  RTEMS_API_Control  *api;
58
  Event_Sync_states   sync_state;
59
 
60
  executing = _Thread_Executing;
61
  executing->Wait.return_code = RTEMS_SUCCESSFUL;
62
 
63
  api = executing->API_Extensions[ THREAD_API_RTEMS ];
64
 
65
  _ISR_Disable( level );
66
  pending_events = api->pending_events;
67
  seized_events  = _Event_sets_Get( pending_events, event_in );
68
 
69
  if ( !_Event_sets_Is_empty( seized_events ) &&
70
       (seized_events == event_in || _Options_Is_any( option_set )) ) {
71
    api->pending_events =
72
      _Event_sets_Clear( pending_events, seized_events );
73
    _ISR_Enable( level );
74
    *event_out = seized_events;
75
    return;
76
  }
77
 
78
  if ( _Options_Is_no_wait( option_set ) ) {
79
    _ISR_Enable( level );
80
    executing->Wait.return_code = RTEMS_UNSATISFIED;
81
    *event_out = seized_events;
82
    return;
83
  }
84
 
85
  _Event_Sync_state = EVENT_SYNC_NOTHING_HAPPENED;
86
 
87
  executing->Wait.option            = (unsigned32) option_set;
88
  executing->Wait.count             = (unsigned32) event_in;
89
  executing->Wait.return_argument   = event_out;
90
 
91
  _ISR_Enable( level );
92
 
93
  if ( ticks ) {
94
    _Watchdog_Initialize(
95
      &executing->Timer,
96
      _Event_Timeout,
97
      executing->Object.id,
98
      NULL
99
    );
100
    _Watchdog_Insert_ticks( &executing->Timer, ticks );
101
  }
102
 
103
  _Thread_Set_state( executing, STATES_WAITING_FOR_EVENT );
104
 
105
  _ISR_Disable( level );
106
 
107
  sync_state = _Event_Sync_state;
108
  _Event_Sync_state = EVENT_SYNC_SYNCHRONIZED;
109
 
110
  switch ( sync_state ) {
111
    case EVENT_SYNC_SYNCHRONIZED:
112
      /*
113
       *  This cannot happen.  It indicates that this routine did not
114
       *  enter the synchronization states above.
115
       */
116
      return;
117
 
118
    case EVENT_SYNC_NOTHING_HAPPENED:
119
      _ISR_Enable( level );
120
      return;
121
 
122
    case EVENT_SYNC_TIMEOUT:
123
      executing->Wait.return_code = RTEMS_TIMEOUT;
124
      _ISR_Enable( level );
125
      _Thread_Unblock( executing );
126
      return;
127
 
128
    case EVENT_SYNC_SATISFIED:
129
      if ( _Watchdog_Is_active( &executing->Timer ) ) {
130
        _Watchdog_Deactivate( &executing->Timer );
131
        _ISR_Enable( level );
132
        (void) _Watchdog_Remove( &executing->Timer );
133
      } else
134
        _ISR_Enable( level );
135
      _Thread_Unblock( executing );
136
      return;
137
  }
138
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.