OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

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

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

Line No. Rev Author Line
1 30 unneback
/*
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
 *  $Id: ratemonperiod.c,v 1.2 2001-09-27 11:59:19 chris 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
 
99
          _Watchdog_Insert_ticks( &the_period->Timer, length );
100
          _Thread_Enable_dispatch();
101
          return RTEMS_SUCCESSFUL;
102
 
103
        case RATE_MONOTONIC_ACTIVE:
104
          /*
105
           *  This tells the _Rate_monotonic_Timeout that this task is
106
           *  in the process of blocking on the period.
107
           */
108
 
109
          the_period->state = RATE_MONOTONIC_OWNER_IS_BLOCKING;
110
          _ISR_Enable( level );
111
 
112
          _Thread_Executing->Wait.id = the_period->Object.id;
113
          _Thread_Set_state( _Thread_Executing, STATES_WAITING_FOR_PERIOD );
114
 
115
          /*
116
           *  Did the watchdog timer expire while we were actually blocking
117
           *  on it?
118
           */
119
 
120
          _ISR_Disable( level );
121
            local_state = the_period->state;
122
            the_period->state = RATE_MONOTONIC_ACTIVE;
123
          _ISR_Enable( level );
124
 
125
          /*
126
           *  If it did, then we want to unblock ourself and continue as
127
           *  if nothing happen.  The period was reset in the timeout routine.
128
           */
129
 
130
          if ( local_state == RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING )
131
            _Thread_Clear_state( _Thread_Executing, STATES_WAITING_FOR_PERIOD );
132
 
133
          _Thread_Enable_dispatch();
134
          return RTEMS_SUCCESSFUL;
135
          break;
136
 
137
        case RATE_MONOTONIC_EXPIRED:
138
          _ISR_Enable( level );
139
          the_period->state = RATE_MONOTONIC_ACTIVE;
140
          the_period->owner_ticks_executed_at_period =
141
            _Thread_Executing->ticks_executed;
142
          the_period->time_at_period = _Watchdog_Ticks_since_boot;
143
 
144
          _Watchdog_Insert_ticks( &the_period->Timer, length );
145
          _Thread_Enable_dispatch();
146
          return RTEMS_TIMEOUT;
147
 
148
        case RATE_MONOTONIC_OWNER_IS_BLOCKING:
149
        case RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING:
150
          /*
151
           *  These should never happen.
152
           */
153
          break;
154
      }
155
  }
156
 
157
  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
158
}

powered by: WebSVN 2.1.0

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