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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [librtems++/] [src/] [rtemsTask.cc] - Blame information for rev 757

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

Line No. Rev Author Line
1 30 unneback
/*
2
  ------------------------------------------------------------------------
3
  $Id: rtemsTask.cc,v 1.2 2001-09-27 12:02:05 chris Exp $
4
  ------------------------------------------------------------------------
5
 
6
  COPYRIGHT (c) 1997
7
  Objective Design Systems Ltd Pty (ODS)
8
  All rights reserved (R) Objective Design Systems Ltd Pty
9
 
10
  The license and distribution terms for this file may be found in the
11
  file LICENSE in this distribution or at
12
  http://www.OARcorp.com/rtems/license.html.
13
 
14
  ------------------------------------------------------------------------
15
 
16
  See header file.
17
 
18
  ------------------------------------------------------------------------
19
*/
20
 
21
#include <string.h>
22
#include <rtems++/rtemsTask.h>
23
// include to allow it to be compiled
24
#include <rtems++/rtemsTaskMode.h>
25
 
26
/* ----
27
    rtemsTask
28
*/
29
 
30
rtemsTask::rtemsTask(const char* tname,
31
                     const rtems_task_priority initial_priority,
32
                     const rtems_unsigned32 stack_size,
33
                     const rtems_mode preemption,
34
                     const rtems_mode timeslice,
35
                     const rtems_mode asr,
36
                     const rtems_interrupt_level interrupt_level,
37
                     const FloatingPoint floating_point,
38
                     const Scope scope)
39
  : name(rtems_build_name('S', 'E', 'L', 'F')),
40
    owner(true),
41
    id(RTEMS_SELF),
42
    argument(0)
43
{
44
  strcpy(name_str, "SELF");
45
  create(tname,
46
         initial_priority,
47
         stack_size,
48
         preemption,
49
         timeslice,
50
         asr,
51
         interrupt_level,
52
         floating_point,
53
         scope);
54
}
55
 
56
rtemsTask::rtemsTask(const char *tname, rtems_unsigned32 node)
57
  : name(rtems_build_name('S', 'E', 'L', 'F')),
58
    owner(false),
59
    id(RTEMS_SELF),
60
    argument(0)
61
{
62
  strcpy(name_str, "SELF");
63
  connect(tname, node);
64
}
65
 
66
rtemsTask::rtemsTask(const rtemsTask& task)
67
  : name(rtems_build_name('S', 'E', 'L', 'F')),
68
    owner(false),
69
    id(RTEMS_SELF),
70
    argument(0)
71
{
72
  name = task.name;
73
  strcpy(name_str, task.name_str);
74
  argument = task.argument;
75
  id = task.id;
76
}
77
 
78
rtemsTask::rtemsTask()
79
  : name(rtems_build_name('S', 'E', 'L', 'F')),
80
    owner(false),
81
    id(RTEMS_SELF),
82
    argument(0)
83
{
84
  strcpy(name_str, "SELF");
85
}
86
 
87
rtemsTask::~rtemsTask()
88
{
89
  destroy();
90
}
91
 
92
void rtemsTask::make_self()
93
{
94
  strcpy(name_str, "SELF");
95
  name = rtems_build_name('S', 'E', 'L', 'F');
96
  id = RTEMS_SELF;
97
  owner = false;
98
}
99
 
100
const rtems_status_code rtemsTask::create(const char* tname,
101
                                          const rtems_task_priority initial_priority,
102
                                          const rtems_unsigned32 stack_size,
103
                                          const rtems_mode preemption,
104
                                          const rtems_mode timeslice,
105
                                          const rtems_mode asr,
106
                                          const rtems_interrupt_level interrupt_level,
107
                                          const FloatingPoint floating_point,
108
                                          const Scope scope)
109
{
110
  if (id)
111
    return set_status_code(RTEMS_ILLEGAL_ON_SELF);
112
 
113
  owner = true;
114
 
115
  strcpy(name_str, "    ");
116
  for (int c = 0; (c < 4) && (tname[c] != '\0'); c++)
117
    name_str[c] = tname[c];
118
  name = rtems_build_name(name_str[0],
119
                          name_str[1],
120
                          name_str[2],
121
                          name_str[3]);
122
 
123
  // protect the values that be set as the parameters are not enums
124
  set_status_code(rtems_task_create(name,
125
                                    initial_priority,
126
                                    stack_size,
127
                                    (preemption & RTEMS_PREEMPT_MASK) |
128
                                    (timeslice & RTEMS_TIMESLICE_MASK) |
129
                                    (asr & RTEMS_ASR_MASK) |
130
                                    (interrupt_level & RTEMS_INTERRUPT_MASK),
131
                                    floating_point | scope,
132
                                    &id));
133
 
134
  if (unsuccessful())
135
  {
136
    make_self();
137
  }
138
 
139
  return last_status_code();
140
}
141
 
142
const rtems_status_code rtemsTask::destroy()
143
{
144
  if (id && owner)
145
  {
146
    set_status_code(rtems_task_delete(id));
147
    make_self();
148
  }
149
  else
150
    set_status_code(RTEMS_NOT_OWNER_OF_RESOURCE);
151
 
152
  return last_status_code();
153
}
154
 
155
const rtemsTask& rtemsTask::operator=(const rtemsTask& task)
156
{
157
  if (!owner)
158
  {
159
    name = task.name;
160
    strcpy(name_str, task.name_str);
161
    argument = task.argument;
162
    id = task.id;
163
  }
164
  return *this;
165
}
166
 
167
const rtems_status_code rtemsTask::connect(const char *sname,
168
                                           const rtems_unsigned32 node)
169
{
170
  if (id && owner)
171
    return set_status_code(RTEMS_UNSATISFIED);
172
 
173
  // change state to not owner
174
  owner = false;
175
 
176
  strcpy(name_str, "    ");
177
  for (int c = 0; (c < 4) && (sname[c] != '\0'); c++)
178
    name_str[c] = sname[c];
179
  name = rtems_build_name(name_str[0],
180
                          name_str[1],
181
                          name_str[2],
182
                          name_str[3]);
183
 
184
  set_status_code(rtems_task_ident(name, node, &id));
185
 
186
  if (unsuccessful())
187
  {
188
    make_self();
189
  }
190
 
191
  return last_status_code();
192
}
193
 
194
const rtems_status_code rtemsTask::start(const rtems_task_argument arg)
195
{
196
  if (owner)
197
  {
198
    argument = arg;
199
    // pass the this pointer as the argument
200
    set_status_code(rtems_task_start(id,
201
                                     origin,
202
                                     (rtems_task_argument) this));
203
  }
204
  else
205
    set_status_code(RTEMS_NOT_OWNER_OF_RESOURCE);
206
  return last_status_code();
207
}
208
 
209
const rtems_status_code rtemsTask::restart(const rtems_task_argument arg)
210
{
211
  if (owner)
212
  {
213
    argument = arg;
214
    set_status_code(rtems_task_restart(id, (rtems_task_argument) this));
215
  }
216
  else
217
    set_status_code(RTEMS_NOT_OWNER_OF_RESOURCE);
218
 
219
  return last_status_code();
220
}
221
 
222
const rtems_status_code rtemsTask::suspend()
223
{
224
  return set_status_code(rtems_task_suspend(id));
225
}
226
 
227
const rtems_status_code rtemsTask::resume()
228
{
229
  return set_status_code(rtems_task_resume(id));
230
}
231
 
232
const rtems_status_code rtemsTask::wake_after(const rtems_interval micro_secs)
233
{
234
  rtems_interval usecs =
235
    micro_secs && (micro_secs < _TOD_Microseconds_per_tick) ?
236
    _TOD_Microseconds_per_tick : micro_secs;
237
  return set_status_code(rtems_task_wake_after(TOD_MICROSECONDS_TO_TICKS(usecs)));
238
}
239
 
240
const rtems_status_code rtemsTask::wake_when(const rtems_time_of_day& tod)
241
{
242
  return set_status_code(rtems_task_wake_when((rtems_time_of_day*) &tod));
243
}
244
 
245
const rtems_status_code rtemsTask::get_priority(rtems_task_priority& priority)
246
{
247
  return set_status_code(rtems_task_set_priority(id,
248
                                                 RTEMS_CURRENT_PRIORITY,
249
                                                 &priority));
250
}
251
 
252
const rtems_status_code rtemsTask::set_priority(const rtems_task_priority priority)
253
{
254
  rtems_task_priority old_priority;
255
  return set_status_code(rtems_task_set_priority(id,
256
                                                 priority,
257
                                                 &old_priority));
258
}
259
 
260
const rtems_status_code rtemsTask::set_priority(const rtems_task_priority priority,
261
                                                rtems_task_priority& old_priority)
262
{
263
  return set_status_code(rtems_task_set_priority(id,
264
                                                 priority,
265
                                                 &old_priority));
266
}
267
 
268
const rtems_status_code rtemsTask::get_note(const rtems_unsigned32 notepad,
269
                                            rtems_unsigned32& note)
270
{
271
  return set_status_code(rtems_task_get_note(id, notepad, &note));
272
}
273
 
274
const rtems_status_code rtemsTask::set_note(const rtems_unsigned32 notepad,
275
                                            const rtems_unsigned32 note)
276
{
277
  return set_status_code(rtems_task_set_note(id, notepad, note));
278
}
279
 
280
void rtemsTask::body(rtems_task_argument )
281
{
282
}
283
 
284
rtems_task rtemsTask::origin(rtems_task_argument argument)
285
{
286
  rtemsTask *task = (rtemsTask*) argument;
287
  task->body(task->argument);
288
}

powered by: WebSVN 2.1.0

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