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/] [taskcreate.c] - Blame information for rev 314

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

Line No. Rev Author Line
1 30 unneback
/*
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.OARcorp.com/rtems/license.html.
11
 *
12
 *  $Id: taskcreate.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/rtems/modes.h>
19
#include <rtems/score/object.h>
20
#include <rtems/score/stack.h>
21
#include <rtems/score/states.h>
22
#include <rtems/rtems/tasks.h>
23
#include <rtems/score/thread.h>
24
#include <rtems/score/threadq.h>
25
#include <rtems/score/tod.h>
26
#include <rtems/score/userext.h>
27
#include <rtems/score/wkspace.h>
28
#include <rtems/score/apiext.h>
29
#include <rtems/score/sysstate.h>
30
 
31
/*PAGE
32
 *
33
 *  rtems_task_create
34
 *
35
 *  This directive creates a thread by allocating and initializing a
36
 *  thread control block and a stack.  The newly created thread is
37
 *  placed in the dormant state.
38
 *
39
 *  Input parameters:
40
 *    name             - user defined thread name
41
 *    initial_priority - thread priority
42
 *    stack_size       - stack size in bytes
43
 *    initial_modes    - initial thread mode
44
 *    attribute_set    - thread attributes
45
 *    id               - pointer to thread id
46
 *
47
 *  Output parameters:
48
 *    id                - thread id
49
 *    RTEMS_SUCCESSFUL - if successful
50
 *    error code        - if unsuccessful
51
 */
52
 
53
rtems_status_code rtems_task_create(
54
  rtems_name           name,
55
  rtems_task_priority  initial_priority,
56
  unsigned32           stack_size,
57
  rtems_mode           initial_modes,
58
  rtems_attribute      attribute_set,
59
  Objects_Id          *id
60
)
61
{
62
  register Thread_Control *the_thread;
63
  boolean                  is_fp;
64
#if defined(RTEMS_MULTIPROCESSING)
65
  Objects_MP_Control      *the_global_object = NULL;
66
  boolean                  is_global;
67
#endif
68
  boolean                  status;
69
  rtems_attribute          the_attribute_set;
70
  Priority_Control         core_priority;
71
  RTEMS_API_Control       *api;
72
  ASR_Information         *asr;
73
 
74
 
75
  if ( !rtems_is_name_valid( name ) )
76
    return RTEMS_INVALID_NAME;
77
 
78
  /*
79
   *  Core Thread Initialize insures we get the minimum amount of
80
   *  stack space.
81
   */
82
 
83
#if 0
84
  if ( !_Stack_Is_enough( stack_size ) )
85
    return RTEMS_INVALID_SIZE;
86
#endif
87
 
88
  /*
89
   *  Fix the attribute set to match the attributes which
90
   *  this processor (1) requires and (2) is able to support.
91
   *  First add in the required flags for attribute_set
92
   *  Typically this might include FP if the platform
93
   *  or application required all tasks to be fp aware.
94
   *  Then turn off the requested bits which are not supported.
95
   */
96
 
97
  the_attribute_set = _Attributes_Set( attribute_set, ATTRIBUTES_REQUIRED );
98
  the_attribute_set =
99
    _Attributes_Clear( the_attribute_set, ATTRIBUTES_NOT_SUPPORTED );
100
 
101
  if ( _Attributes_Is_floating_point( the_attribute_set ) )
102
    is_fp = TRUE;
103
  else
104
    is_fp = FALSE;
105
 
106
  /*
107
   *  Validate the RTEMS API priority and convert it to the core priority range.
108
   */
109
 
110
  if ( !_Attributes_Is_system_task( the_attribute_set ) ) {
111
    if ( !_RTEMS_tasks_Priority_is_valid( initial_priority ) )
112
      return RTEMS_INVALID_PRIORITY;
113
  }
114
 
115
  core_priority = _RTEMS_tasks_Priority_to_Core( initial_priority );
116
 
117
#if defined(RTEMS_MULTIPROCESSING)
118
  if ( _Attributes_Is_global( the_attribute_set ) ) {
119
 
120
    is_global = TRUE;
121
 
122
    if ( !_System_state_Is_multiprocessing )
123
      return RTEMS_MP_NOT_CONFIGURED;
124
 
125
  } else
126
    is_global = FALSE;
127
#endif
128
 
129
  /*
130
   *  Make sure system is MP if this task is global
131
   */
132
 
133
  /*
134
   *  Disable dispatch for protection
135
   */
136
 
137
  _Thread_Disable_dispatch();
138
 
139
  /*
140
   *  Allocate the thread control block and -- if the task is global --
141
   *  allocate a global object control block.
142
   *
143
   *  NOTE:  This routine does not use the combined allocate and open
144
   *         global object routine because this results in a lack of
145
   *         control over when memory is allocated and can be freed in
146
   *         the event of an error.
147
   */
148
 
149
  the_thread = _RTEMS_tasks_Allocate();
150
 
151
  if ( !the_thread ) {
152
    _Thread_Enable_dispatch();
153
    return RTEMS_TOO_MANY;
154
  }
155
 
156
#if defined(RTEMS_MULTIPROCESSING)
157
  if ( is_global ) {
158
    the_global_object = _Objects_MP_Allocate_global_object();
159
 
160
    if ( _Objects_MP_Is_null_global_object( the_global_object ) ) {
161
      _RTEMS_tasks_Free( the_thread );
162
      _Thread_Enable_dispatch();
163
      return RTEMS_TOO_MANY;
164
    }
165
  }
166
#endif
167
 
168
  /*
169
   *  Initialize the core thread for this task.
170
   */
171
 
172
  status = _Thread_Initialize(
173
    &_RTEMS_tasks_Information,
174
    the_thread,
175
    NULL,
176
    stack_size,
177
    is_fp,
178
    core_priority,
179
    _Modes_Is_preempt(initial_modes)   ? TRUE : FALSE,
180
    _Modes_Is_timeslice(initial_modes) ?
181
      THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE :
182
      THREAD_CPU_BUDGET_ALGORITHM_NONE,
183
    NULL,        /* no budget algorithm callout */
184
    _Modes_Get_interrupt_level(initial_modes),
185
    &name
186
  );
187
 
188
  if ( !status ) {
189
#if defined(RTEMS_MULTIPROCESSING)
190
    if ( is_global )
191
      _Objects_MP_Free_global_object( the_global_object );
192
#endif
193
    _RTEMS_tasks_Free( the_thread );
194
    _Thread_Enable_dispatch();
195
    return RTEMS_UNSATISFIED;
196
  }
197
 
198
  api = the_thread->API_Extensions[ THREAD_API_RTEMS ];
199
  asr = &api->Signal;
200
 
201
  asr->is_enabled = _Modes_Is_asr_disabled(initial_modes) ? FALSE : TRUE;
202
 
203
  *id = the_thread->Object.id;
204
 
205
#if defined(RTEMS_MULTIPROCESSING)
206
  if ( is_global ) {
207
 
208
    the_thread->is_global = TRUE;
209
 
210
    _Objects_MP_Open(
211
      &_RTEMS_tasks_Information,
212
      the_global_object,
213
      name,
214
      the_thread->Object.id
215
    );
216
 
217
    _RTEMS_tasks_MP_Send_process_packet(
218
      RTEMS_TASKS_MP_ANNOUNCE_CREATE,
219
      the_thread->Object.id,
220
      name
221
    );
222
 
223
   }
224
#endif
225
 
226
  _Thread_Enable_dispatch();
227
  return RTEMS_SUCCESSFUL;
228
}

powered by: WebSVN 2.1.0

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