source: rtems/cpukit/rtems/src/tasks.c @ a29d2e7

4.104.114.84.95
Last change on this file since a29d2e7 was 1095ec1, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/18/05 at 09:03:45

Include config.h.

  • Property mode set to 100644
File size: 6.8 KB
Line 
1/*
2 *  RTEMS Task 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.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/rtems/status.h>
21#include <rtems/rtems/support.h>
22#include <rtems/rtems/modes.h>
23#include <rtems/score/object.h>
24#include <rtems/score/stack.h>
25#include <rtems/score/states.h>
26#include <rtems/rtems/tasks.h>
27#include <rtems/score/thread.h>
28#include <rtems/score/threadq.h>
29#include <rtems/score/tod.h>
30#include <rtems/score/userext.h>
31#include <rtems/score/wkspace.h>
32#include <rtems/score/apiext.h>
33#include <rtems/score/sysstate.h>
34
35/*PAGE
36 *
37 *  _RTEMS_tasks_Create_extension
38 *
39 *  This routine is an extension routine that is invoked as part
40 *  of creating any type of task or thread in the system.  If the
41 *  task is created via another API, then this routine is invoked
42 *  and this API given the opportunity to initialize its extension
43 *  area.
44 */
45
46boolean _RTEMS_tasks_Create_extension(
47  Thread_Control *executing,
48  Thread_Control *created
49)
50{
51  RTEMS_API_Control *api;
52  int                i;
53
54  api = _Workspace_Allocate( sizeof( RTEMS_API_Control ) );
55
56  if ( !api )
57    return FALSE;
58
59  created->API_Extensions[ THREAD_API_RTEMS ] = api;
60
61  api->pending_events = EVENT_SETS_NONE_PENDING;
62  _ASR_Initialize( &api->Signal );
63  created->task_variables = NULL;
64
65  for (i=0; i < RTEMS_NUMBER_NOTEPADS; i++)
66    api->Notepads[i] = 0;
67
68  return TRUE;
69}
70
71/*PAGE
72 *
73 *  _RTEMS_tasks_Start_extension
74 *
75 *  This extension routine is invoked when a task is started for the
76 *  first time.
77 */
78
79User_extensions_routine _RTEMS_tasks_Start_extension(
80  Thread_Control *executing,
81  Thread_Control *started
82)
83{
84  RTEMS_API_Control *api;
85
86  api = started->API_Extensions[ THREAD_API_RTEMS ];
87
88  api->pending_events = EVENT_SETS_NONE_PENDING;
89
90  _ASR_Initialize( &api->Signal );
91}
92
93/*PAGE
94 *
95 *  _RTEMS_tasks_Delete_extension
96 *
97 *  This extension routine is invoked when a task is deleted.
98 */
99
100User_extensions_routine _RTEMS_tasks_Delete_extension(
101  Thread_Control *executing,
102  Thread_Control *deleted
103)
104{
105  rtems_task_variable_t *tvp, *next;
106
107  /*
108   *  Free per task variable memory
109   */
110
111  tvp = deleted->task_variables;
112  deleted->task_variables = NULL;
113  while (tvp) {
114    next = tvp->next;
115    if  (tvp->dtor)
116        (*tvp->dtor)(*tvp->ptr);
117    if (_Thread_Is_executing(deleted))
118        *tvp->ptr = tvp->gval;
119    _Workspace_Free( tvp );
120    tvp = next;
121  }
122
123  /*
124   *  Free API specific memory
125   */
126
127  (void) _Workspace_Free( deleted->API_Extensions[ THREAD_API_RTEMS ] );
128  deleted->API_Extensions[ THREAD_API_RTEMS ] = NULL;
129}
130
131/*PAGE
132 *
133 *  _RTEMS_tasks_Switch_extension
134 *
135 *  This extension routine is invoked at each context switch.
136 */
137
138void _RTEMS_tasks_Switch_extension(
139  Thread_Control *executing,
140  Thread_Control *heir
141)
142{
143  rtems_task_variable_t *tvp;
144
145  /*
146   *  Per Task Variables
147   */
148
149  tvp = executing->task_variables;
150  while (tvp) {
151    tvp->tval = *tvp->ptr;
152    *tvp->ptr = tvp->gval;
153    tvp = tvp->next;
154  }
155
156  tvp = heir->task_variables;
157  while (tvp) {
158    tvp->gval = *tvp->ptr;
159    *tvp->ptr = tvp->tval;
160    tvp = tvp->next;
161  }
162}
163
164/*PAGE
165 *
166 *  _RTEMS_tasks_Post_switch_extension
167 *
168 *  This extension routine is invoked at each context switch.
169 */
170
171void _RTEMS_tasks_Post_switch_extension(
172  Thread_Control *executing
173)
174{
175  ISR_Level          level;
176  RTEMS_API_Control *api;
177  ASR_Information   *asr;
178  rtems_signal_set   signal_set;
179  Modes_Control      prev_mode;
180
181  api = executing->API_Extensions[ THREAD_API_RTEMS ];
182
183  /*
184   *  Signal Processing
185   */
186
187  asr = &api->Signal;
188
189  _ISR_Disable( level );
190    signal_set = asr->signals_posted;
191    asr->signals_posted = 0;
192  _ISR_Enable( level );
193
194
195  if ( !signal_set ) /* similar to _ASR_Are_signals_pending( asr ) */
196    return;
197
198  asr->nest_level += 1;
199  rtems_task_mode( asr->mode_set, RTEMS_ALL_MODE_MASKS, &prev_mode );
200
201  (*asr->handler)( signal_set );
202
203  asr->nest_level -= 1;
204  rtems_task_mode( prev_mode, RTEMS_ALL_MODE_MASKS, &prev_mode );
205
206}
207
208API_extensions_Control _RTEMS_tasks_API_extensions = {
209  { NULL, NULL },
210  NULL,                                     /* predriver */
211  _RTEMS_tasks_Initialize_user_tasks,       /* postdriver */
212  _RTEMS_tasks_Post_switch_extension        /* post switch */
213};
214
215User_extensions_Control _RTEMS_tasks_User_extensions = {
216  { NULL, NULL },
217  { { NULL, NULL }, _RTEMS_tasks_Switch_extension },
218  { _RTEMS_tasks_Create_extension,            /* create */
219    _RTEMS_tasks_Start_extension,             /* start */
220    _RTEMS_tasks_Start_extension,             /* restart */
221    _RTEMS_tasks_Delete_extension,            /* delete */
222    _RTEMS_tasks_Switch_extension,            /* switch */
223    NULL,                                     /* begin */
224    NULL,                                     /* exitted */
225    NULL                                      /* fatal */
226  }
227};
228
229/*PAGE
230 *
231 *  _RTEMS_tasks_Manager_initialization
232 *
233 *  This routine initializes all Task Manager related data structures.
234 *
235 *  Input parameters:
236 *    maximum_tasks       - number of tasks to initialize
237 *
238 *  Output parameters:  NONE
239 */
240
241void _RTEMS_tasks_Manager_initialization(
242  uint32_t                          maximum_tasks,
243  uint32_t                          number_of_initialization_tasks,
244  rtems_initialization_tasks_table *user_tasks
245)
246{
247
248  _RTEMS_tasks_Number_of_initialization_tasks = number_of_initialization_tasks;
249  _RTEMS_tasks_User_initialization_tasks = user_tasks;
250
251  /*
252   *  There may not be any RTEMS initialization tasks configured.
253   */
254
255#if 0
256  if ( user_tasks == NULL || number_of_initialization_tasks == 0 )
257    _Internal_error_Occurred( INTERNAL_ERROR_RTEMS_API, TRUE, RTEMS_TOO_MANY );
258#endif
259
260  _Objects_Initialize_information(
261    &_RTEMS_tasks_Information, /* object information table */
262    OBJECTS_CLASSIC_API,       /* object API */
263    OBJECTS_RTEMS_TASKS,       /* object class */
264    maximum_tasks,             /* maximum objects of this class */
265    sizeof( Thread_Control ),  /* size of this object's control block */
266    FALSE,                     /* TRUE if the name is a string */
267    RTEMS_MAXIMUM_NAME_LENGTH  /* maximum length of an object name */
268#if defined(RTEMS_MULTIPROCESSING)
269    ,
270    TRUE,                      /* TRUE if this is a global object class */
271    NULL                       /* Proxy extraction support callout */
272#endif
273  );
274
275  /*
276   *  Add all the extensions for this API
277   */
278
279  _User_extensions_Add_API_set( &_RTEMS_tasks_User_extensions );
280
281  _API_extensions_Add( &_RTEMS_tasks_API_extensions );
282
283  /*
284   *  Register the MP Process Packet routine.
285   */
286
287#if defined(RTEMS_MULTIPROCESSING)
288  _MPCI_Register_packet_processor(
289    MP_PACKET_TASKS,
290    _RTEMS_tasks_MP_Process_packet
291  );
292#endif
293
294}
Note: See TracBrowser for help on using the repository browser.