source: rtems/cpukit/rtems/src/ratemonperiod.c @ 811804fe

4.104.114.84.95
Last change on this file since 811804fe was 5f9b3db, checked in by Joel Sherrill <joel.sherrill@…>, on 05/17/99 at 23:03:07

Split Rate Monotonic Manager into one routine per file.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 *  Rate Monotonic Manager
3 *
4 *
5 *  COPYRIGHT (c) 1989-1998.
6 *  On-Line Applications Research Corporation (OAR).
7 *  Copyright assigned to U.S. Government, 1994.
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.OARcorp.com/rtems/license.html.
12 *
13 *  $Id$
14 */
15
16#include <rtems/system.h>
17#include <rtems/rtems/status.h>
18#include <rtems/rtems/support.h>
19#include <rtems/score/isr.h>
20#include <rtems/score/object.h>
21#include <rtems/rtems/ratemon.h>
22#include <rtems/score/thread.h>
23
24/*PAGE
25 *
26 *  rtems_rate_monotonic_period
27 *
28 *  This directive allows a thread to manipulate a rate monotonic timer.
29 *
30 *  Input parameters:
31 *    id     - rate monotonic id
32 *    length - length of period (in ticks)
33 *
34 *  Output parameters:
35 *    RTEMS_SUCCESSFUL - if successful
36 *    error code        - if unsuccessful
37 */
38
39rtems_status_code rtems_rate_monotonic_period(
40  Objects_Id        id,
41  rtems_interval    length
42)
43{
44  Rate_monotonic_Control              *the_period;
45  Objects_Locations                    location;
46  rtems_status_code                    return_value;
47  rtems_rate_monotonic_period_states   local_state;
48  ISR_Level                            level;
49
50  the_period = _Rate_monotonic_Get( id, &location );
51  switch ( location ) {
52    case OBJECTS_REMOTE:            /* should never return this */
53      return RTEMS_INTERNAL_ERROR;
54
55    case OBJECTS_ERROR:
56      return RTEMS_INVALID_ID;
57
58    case OBJECTS_LOCAL:
59      if ( !_Thread_Is_executing( the_period->owner ) ) {
60        _Thread_Enable_dispatch();
61        return RTEMS_NOT_OWNER_OF_RESOURCE;
62      }
63
64      if ( length == RTEMS_PERIOD_STATUS ) {
65        switch ( the_period->state ) {
66          case RATE_MONOTONIC_INACTIVE:
67            return_value = RTEMS_NOT_DEFINED;
68            break;
69          case RATE_MONOTONIC_ACTIVE:
70            return_value = RTEMS_SUCCESSFUL;
71            break;
72          case RATE_MONOTONIC_EXPIRED:
73            return_value = RTEMS_TIMEOUT;
74            break;
75          default:              /* unreached -- only to remove warnings */
76            return_value = RTEMS_INTERNAL_ERROR;
77            break;
78        }
79        _Thread_Enable_dispatch();
80        return( return_value );
81      }
82
83      _ISR_Disable( level );
84      switch ( the_period->state ) {
85        case RATE_MONOTONIC_INACTIVE:
86          _ISR_Enable( level );
87          the_period->state = RATE_MONOTONIC_ACTIVE;
88          _Watchdog_Initialize(
89            &the_period->Timer,
90            _Rate_monotonic_Timeout,
91            id,
92            NULL
93          );
94
95          the_period->owner_ticks_executed_at_period =
96            _Thread_Executing->ticks_executed;
97
98          the_period->time_at_period = _Watchdog_Ticks_since_boot;
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.
108           */
109
110          the_period->state = RATE_MONOTONIC_OWNER_IS_BLOCKING;
111          _ISR_Enable( level );
112
113          _Thread_Executing->Wait.id = the_period->Object.id;
114          _Thread_Set_state( _Thread_Executing, STATES_WAITING_FOR_PERIOD );
115         
116          /*
117           *  Did the watchdog timer expire while we were actually blocking
118           *  on it?
119           */
120
121          _ISR_Disable( level );
122            local_state = the_period->state;
123            the_period->state = RATE_MONOTONIC_ACTIVE;
124          _ISR_Enable( level );
125
126          /*
127           *  If it did, then we want to unblock ourself and continue as
128           *  if nothing happen.  The period was reset in the timeout routine.
129           */
130
131          if ( local_state == RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING )
132            _Thread_Clear_state( _Thread_Executing, STATES_WAITING_FOR_PERIOD );
133
134          _Thread_Enable_dispatch();
135          return RTEMS_SUCCESSFUL;
136          break;
137
138        case RATE_MONOTONIC_EXPIRED:
139          _ISR_Enable( level );
140          the_period->state = RATE_MONOTONIC_ACTIVE;
141          the_period->owner_ticks_executed_at_period =
142            _Thread_Executing->ticks_executed;
143          the_period->time_at_period = _Watchdog_Ticks_since_boot;
144
145          _Watchdog_Insert_ticks( &the_period->Timer, length );
146          _Thread_Enable_dispatch();
147          return RTEMS_TIMEOUT;
148
149        case RATE_MONOTONIC_OWNER_IS_BLOCKING:
150        case RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING:
151          /*
152           *  These should never happen.
153           */
154          break;
155      }
156  }
157
158  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
159}
Note: See TracBrowser for help on using the repository browser.