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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [rtems/] [src/] [ratemonperiod.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
2
 *  Rate Monotonic 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
 *  ratemonperiod.c,v 1.3 2000/09/29 14:48:17 joel Exp
13
 */
14
 
15
#include <rtems/system.h>
16
#include <rtems/rtems/status.h>
17
#include <rtems/rtems/support.h>
18
#include <rtems/score/isr.h>
19
#include <rtems/score/object.h>
20
#include <rtems/rtems/ratemon.h>
21
#include <rtems/score/thread.h>
22
 
23
/*PAGE
24
 *
25
 *  rtems_rate_monotonic_period
26
 *
27
 *  This directive allows a thread to manipulate a rate monotonic timer.
28
 *
29
 *  Input parameters:
30
 *    id     - rate monotonic id
31
 *    length - length of period (in ticks)
32
 *
33
 *  Output parameters:
34
 *    RTEMS_SUCCESSFUL - if successful
35
 *    error code        - if unsuccessful
36
 */
37
 
38
rtems_status_code rtems_rate_monotonic_period(
39
  Objects_Id        id,
40
  rtems_interval    length
41
)
42
{
43
  Rate_monotonic_Control              *the_period;
44
  Objects_Locations                    location;
45
  rtems_status_code                    return_value;
46
  rtems_rate_monotonic_period_states   local_state;
47
  ISR_Level                            level;
48
 
49
  the_period = _Rate_monotonic_Get( id, &location );
50
  switch ( location ) {
51
    case OBJECTS_REMOTE:            /* should never return this */
52
      return RTEMS_INTERNAL_ERROR;
53
 
54
    case OBJECTS_ERROR:
55
      return RTEMS_INVALID_ID;
56
 
57
    case OBJECTS_LOCAL:
58
      if ( !_Thread_Is_executing( the_period->owner ) ) {
59
        _Thread_Enable_dispatch();
60
        return RTEMS_NOT_OWNER_OF_RESOURCE;
61
      }
62
 
63
      if ( length == RTEMS_PERIOD_STATUS ) {
64
        switch ( the_period->state ) {
65
          case RATE_MONOTONIC_INACTIVE:
66
            return_value = RTEMS_NOT_DEFINED;
67
            break;
68
          case RATE_MONOTONIC_ACTIVE:
69
            return_value = RTEMS_SUCCESSFUL;
70
            break;
71
          case RATE_MONOTONIC_EXPIRED:
72
            return_value = RTEMS_TIMEOUT;
73
            break;
74
          default:              /* unreached -- only to remove warnings */
75
            return_value = RTEMS_INTERNAL_ERROR;
76
            break;
77
        }
78
        _Thread_Enable_dispatch();
79
        return( return_value );
80
      }
81
 
82
      _ISR_Disable( level );
83
      switch ( the_period->state ) {
84
        case RATE_MONOTONIC_INACTIVE:
85
          _ISR_Enable( level );
86
          the_period->state = RATE_MONOTONIC_ACTIVE;
87
          _Watchdog_Initialize(
88
            &the_period->Timer,
89
            _Rate_monotonic_Timeout,
90
            id,
91
            NULL
92
          );
93
 
94
          the_period->owner_ticks_executed_at_period =
95
            _Thread_Executing->ticks_executed;
96
 
97
          the_period->time_at_period = _Watchdog_Ticks_since_boot;
98
          the_period->next_length = length;
99
 
100
          _Watchdog_Insert_ticks( &the_period->Timer, length );
101
          _Thread_Enable_dispatch();
102
          return RTEMS_SUCCESSFUL;
103
 
104
        case RATE_MONOTONIC_ACTIVE:
105
          /*
106
           *  This tells the _Rate_monotonic_Timeout that this task is
107
           *  in the process of blocking on the period and that we
108
           *  may be changing the length of the next period.
109
           */
110
 
111
          the_period->state = RATE_MONOTONIC_OWNER_IS_BLOCKING;
112
          the_period->next_length = length;
113
 
114
          _ISR_Enable( level );
115
 
116
          _Thread_Executing->Wait.id = the_period->Object.id;
117
          _Thread_Set_state( _Thread_Executing, STATES_WAITING_FOR_PERIOD );
118
 
119
          /*
120
           *  Did the watchdog timer expire while we were actually blocking
121
           *  on it?
122
           */
123
 
124
          _ISR_Disable( level );
125
            local_state = the_period->state;
126
            the_period->state = RATE_MONOTONIC_ACTIVE;
127
          _ISR_Enable( level );
128
 
129
          /*
130
           *  If it did, then we want to unblock ourself and continue as
131
           *  if nothing happen.  The period was reset in the timeout routine.
132
           */
133
 
134
          if ( local_state == RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING )
135
            _Thread_Clear_state( _Thread_Executing, STATES_WAITING_FOR_PERIOD );
136
 
137
          _Thread_Enable_dispatch();
138
          return RTEMS_SUCCESSFUL;
139
          break;
140
 
141
        case RATE_MONOTONIC_EXPIRED:
142
          _ISR_Enable( level );
143
          the_period->state = RATE_MONOTONIC_ACTIVE;
144
          the_period->owner_ticks_executed_at_period =
145
            _Thread_Executing->ticks_executed;
146
          the_period->time_at_period = _Watchdog_Ticks_since_boot;
147
          the_period->next_length = length;
148
 
149
          _Watchdog_Insert_ticks( &the_period->Timer, length );
150
          _Thread_Enable_dispatch();
151
          return RTEMS_TIMEOUT;
152
 
153
        case RATE_MONOTONIC_OWNER_IS_BLOCKING:
154
        case RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING:
155
          /*
156
           *  These should never happen.
157
           */
158
          break;
159
      }
160
  }
161
 
162
  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
163
}

powered by: WebSVN 2.1.0

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