[ac7d5ef0] | 1 | /* |
---|
| 2 | * RTEMS Task Manager |
---|
| 3 | * |
---|
| 4 | * |
---|
[60b791ad] | 5 | * COPYRIGHT (c) 1989-1998. |
---|
[ac7d5ef0] | 6 | * On-Line Applications Research Corporation (OAR). |
---|
[84ff7c23] | 7 | * Copyright assigned to U.S. Government, 1994. |
---|
[ac7d5ef0] | 8 | * |
---|
[98e4ebf5] | 9 | * The license and distribution terms for this file may be |
---|
| 10 | * found in the file LICENSE in this distribution or at |
---|
[84ff7c23] | 11 | * http://www.OARcorp.com/rtems/license.html. |
---|
[ac7d5ef0] | 12 | * |
---|
| 13 | * $Id$ |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #include <rtems/system.h> |
---|
[3a4ae6c] | 17 | #include <rtems/rtems/status.h> |
---|
| 18 | #include <rtems/rtems/support.h> |
---|
| 19 | #include <rtems/rtems/modes.h> |
---|
[5e9b32b] | 20 | #include <rtems/score/object.h> |
---|
| 21 | #include <rtems/score/stack.h> |
---|
| 22 | #include <rtems/score/states.h> |
---|
[3a4ae6c] | 23 | #include <rtems/rtems/tasks.h> |
---|
[5e9b32b] | 24 | #include <rtems/score/thread.h> |
---|
| 25 | #include <rtems/score/threadq.h> |
---|
| 26 | #include <rtems/score/tod.h> |
---|
| 27 | #include <rtems/score/userext.h> |
---|
| 28 | #include <rtems/score/wkspace.h> |
---|
| 29 | #include <rtems/score/apiext.h> |
---|
| 30 | #include <rtems/score/sysstate.h> |
---|
[3a4ae6c] | 31 | |
---|
| 32 | /*PAGE |
---|
| 33 | * |
---|
| 34 | * _RTEMS_tasks_Create_extension |
---|
| 35 | * |
---|
| 36 | * XXX |
---|
| 37 | */ |
---|
| 38 | |
---|
| 39 | boolean _RTEMS_tasks_Create_extension( |
---|
| 40 | Thread_Control *executing, |
---|
| 41 | Thread_Control *created |
---|
| 42 | ) |
---|
| 43 | { |
---|
| 44 | RTEMS_API_Control *api; |
---|
| 45 | |
---|
| 46 | api = _Workspace_Allocate( sizeof( RTEMS_API_Control ) ); |
---|
| 47 | |
---|
| 48 | if ( !api ) |
---|
| 49 | return FALSE; |
---|
| 50 | |
---|
| 51 | created->API_Extensions[ THREAD_API_RTEMS ] = api; |
---|
| 52 | |
---|
| 53 | api->pending_events = EVENT_SETS_NONE_PENDING; |
---|
| 54 | _ASR_Initialize( &api->Signal ); |
---|
| 55 | return TRUE; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | /*PAGE |
---|
| 59 | * |
---|
| 60 | * _RTEMS_tasks_Start_extension |
---|
| 61 | * |
---|
| 62 | * XXX |
---|
| 63 | */ |
---|
| 64 | |
---|
| 65 | User_extensions_routine _RTEMS_tasks_Start_extension( |
---|
| 66 | Thread_Control *executing, |
---|
| 67 | Thread_Control *started |
---|
| 68 | ) |
---|
| 69 | { |
---|
| 70 | RTEMS_API_Control *api; |
---|
| 71 | |
---|
| 72 | api = started->API_Extensions[ THREAD_API_RTEMS ]; |
---|
| 73 | |
---|
| 74 | api->pending_events = EVENT_SETS_NONE_PENDING; |
---|
| 75 | |
---|
| 76 | _ASR_Initialize( &api->Signal ); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | /*PAGE |
---|
| 80 | * |
---|
| 81 | * _RTEMS_tasks_Delete_extension |
---|
| 82 | * |
---|
| 83 | * XXX |
---|
| 84 | */ |
---|
| 85 | |
---|
| 86 | User_extensions_routine _RTEMS_tasks_Delete_extension( |
---|
| 87 | Thread_Control *executing, |
---|
| 88 | Thread_Control *deleted |
---|
| 89 | ) |
---|
| 90 | { |
---|
| 91 | (void) _Workspace_Free( deleted->API_Extensions[ THREAD_API_RTEMS ] ); |
---|
| 92 | |
---|
| 93 | deleted->API_Extensions[ THREAD_API_RTEMS ] = NULL; |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | /*PAGE |
---|
| 97 | * |
---|
| 98 | * _RTEMS_tasks_Switch_extension |
---|
| 99 | * |
---|
| 100 | * XXX |
---|
| 101 | */ |
---|
| 102 | |
---|
[94b3ec59] | 103 | void _RTEMS_tasks_Switch_extension( |
---|
[3a4ae6c] | 104 | Thread_Control *executing |
---|
| 105 | ) |
---|
| 106 | { |
---|
| 107 | ISR_Level level; |
---|
| 108 | RTEMS_API_Control *api; |
---|
| 109 | ASR_Information *asr; |
---|
| 110 | rtems_signal_set signal_set; |
---|
| 111 | Modes_Control prev_mode; |
---|
| 112 | |
---|
| 113 | api = executing->API_Extensions[ THREAD_API_RTEMS ]; |
---|
| 114 | asr = &api->Signal; |
---|
| 115 | |
---|
| 116 | _ISR_Disable( level ); |
---|
[3652ad35] | 117 | signal_set = asr->signals_posted; |
---|
[3a4ae6c] | 118 | asr->signals_posted = 0; |
---|
[3652ad35] | 119 | _ISR_Enable( level ); |
---|
[3a4ae6c] | 120 | |
---|
| 121 | |
---|
[3652ad35] | 122 | if ( !signal_set ) /* similar to _ASR_Are_signals_pending( asr ) */ |
---|
| 123 | return; |
---|
[3a4ae6c] | 124 | |
---|
[3652ad35] | 125 | asr->nest_level += 1; |
---|
| 126 | rtems_task_mode( asr->mode_set, RTEMS_ALL_MODE_MASKS, &prev_mode ); |
---|
| 127 | |
---|
| 128 | (*asr->handler)( signal_set ); |
---|
| 129 | |
---|
| 130 | asr->nest_level -= 1; |
---|
| 131 | rtems_task_mode( prev_mode, RTEMS_ALL_MODE_MASKS, &prev_mode ); |
---|
[3a4ae6c] | 132 | |
---|
| 133 | } |
---|
| 134 | |
---|
[7af35da5] | 135 | API_extensions_Control _RTEMS_tasks_API_extensions = { |
---|
[3a4ae6c] | 136 | { NULL, NULL }, |
---|
| 137 | NULL, /* predriver */ |
---|
[94b3ec59] | 138 | _RTEMS_tasks_Initialize_user_tasks, /* postdriver */ |
---|
| 139 | _RTEMS_tasks_Switch_extension /* post switch */ |
---|
[3a4ae6c] | 140 | }; |
---|
| 141 | |
---|
[7af35da5] | 142 | User_extensions_Control _RTEMS_tasks_User_extensions = { |
---|
[3a4ae6c] | 143 | { NULL, NULL }, |
---|
| 144 | { _RTEMS_tasks_Create_extension, /* create */ |
---|
| 145 | _RTEMS_tasks_Start_extension, /* start */ |
---|
| 146 | _RTEMS_tasks_Start_extension, /* restart */ |
---|
| 147 | _RTEMS_tasks_Delete_extension, /* delete */ |
---|
| 148 | NULL, /* switch */ |
---|
| 149 | NULL, /* begin */ |
---|
| 150 | NULL, /* exitted */ |
---|
| 151 | NULL /* fatal */ |
---|
| 152 | } |
---|
| 153 | }; |
---|
[ac7d5ef0] | 154 | |
---|
[5250ff39] | 155 | /*PAGE |
---|
| 156 | * |
---|
| 157 | * _RTEMS_tasks_Manager_initialization |
---|
| 158 | * |
---|
| 159 | * This routine initializes all Task Manager related data structures. |
---|
| 160 | * |
---|
| 161 | * Input parameters: |
---|
| 162 | * maximum_tasks - number of tasks to initialize |
---|
| 163 | * |
---|
| 164 | * Output parameters: NONE |
---|
| 165 | */ |
---|
| 166 | |
---|
| 167 | void _RTEMS_tasks_Manager_initialization( |
---|
[3a4ae6c] | 168 | unsigned32 maximum_tasks, |
---|
| 169 | unsigned32 number_of_initialization_tasks, |
---|
| 170 | rtems_initialization_tasks_table *user_tasks |
---|
[5250ff39] | 171 | ) |
---|
| 172 | { |
---|
[3a4ae6c] | 173 | |
---|
| 174 | _RTEMS_tasks_Number_of_initialization_tasks = number_of_initialization_tasks; |
---|
| 175 | _RTEMS_tasks_User_initialization_tasks = user_tasks; |
---|
| 176 | |
---|
[019bce7] | 177 | /* |
---|
| 178 | * There may not be any RTEMS initialization tasks configured. |
---|
| 179 | */ |
---|
| 180 | |
---|
| 181 | #if 0 |
---|
[3a4ae6c] | 182 | if ( user_tasks == NULL || number_of_initialization_tasks == 0 ) |
---|
| 183 | _Internal_error_Occurred( INTERNAL_ERROR_RTEMS_API, TRUE, RTEMS_TOO_MANY ); |
---|
[019bce7] | 184 | #endif |
---|
[3a4ae6c] | 185 | |
---|
[5250ff39] | 186 | _Objects_Initialize_information( |
---|
| 187 | &_RTEMS_tasks_Information, |
---|
| 188 | OBJECTS_RTEMS_TASKS, |
---|
| 189 | TRUE, |
---|
| 190 | maximum_tasks, |
---|
| 191 | sizeof( Thread_Control ), |
---|
| 192 | FALSE, |
---|
| 193 | RTEMS_MAXIMUM_NAME_LENGTH, |
---|
| 194 | TRUE |
---|
| 195 | ); |
---|
[3a4ae6c] | 196 | |
---|
| 197 | /* |
---|
| 198 | * Add all the extensions for this API |
---|
| 199 | */ |
---|
| 200 | |
---|
[7af35da5] | 201 | _User_extensions_Add_API_set( &_RTEMS_tasks_User_extensions ); |
---|
[3a4ae6c] | 202 | |
---|
[7af35da5] | 203 | _API_extensions_Add( &_RTEMS_tasks_API_extensions ); |
---|
[3a4ae6c] | 204 | |
---|
| 205 | /* |
---|
| 206 | * Register the MP Process Packet routine. |
---|
| 207 | */ |
---|
| 208 | |
---|
[97e2729d] | 209 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3a4ae6c] | 210 | _MPCI_Register_packet_processor( |
---|
| 211 | MP_PACKET_TASKS, |
---|
| 212 | _RTEMS_tasks_MP_Process_packet |
---|
| 213 | ); |
---|
[97e2729d] | 214 | #endif |
---|
[3a4ae6c] | 215 | |
---|
[5250ff39] | 216 | } |
---|
| 217 | |
---|
[ac7d5ef0] | 218 | /*PAGE |
---|
| 219 | * |
---|
| 220 | * rtems_task_create |
---|
| 221 | * |
---|
| 222 | * This directive creates a thread by allocating and initializing a |
---|
| 223 | * thread control block and a stack. The newly created thread is |
---|
| 224 | * placed in the dormant state. |
---|
| 225 | * |
---|
| 226 | * Input parameters: |
---|
| 227 | * name - user defined thread name |
---|
| 228 | * initial_priority - thread priority |
---|
| 229 | * stack_size - stack size in bytes |
---|
| 230 | * initial_modes - initial thread mode |
---|
| 231 | * attribute_set - thread attributes |
---|
| 232 | * id - pointer to thread id |
---|
| 233 | * |
---|
| 234 | * Output parameters: |
---|
| 235 | * id - thread id |
---|
| 236 | * RTEMS_SUCCESSFUL - if successful |
---|
| 237 | * error code - if unsuccessful |
---|
| 238 | */ |
---|
| 239 | |
---|
| 240 | rtems_status_code rtems_task_create( |
---|
[3235ad9] | 241 | rtems_name name, |
---|
[ac7d5ef0] | 242 | rtems_task_priority initial_priority, |
---|
| 243 | unsigned32 stack_size, |
---|
| 244 | rtems_mode initial_modes, |
---|
| 245 | rtems_attribute attribute_set, |
---|
| 246 | Objects_Id *id |
---|
| 247 | ) |
---|
| 248 | { |
---|
| 249 | register Thread_Control *the_thread; |
---|
[7f6a24ab] | 250 | boolean is_fp; |
---|
[97e2729d] | 251 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 252 | Objects_MP_Control *the_global_object = NULL; |
---|
[7f6a24ab] | 253 | boolean is_global; |
---|
[97e2729d] | 254 | #endif |
---|
[3a4ae6c] | 255 | boolean status; |
---|
[ac7d5ef0] | 256 | rtems_attribute the_attribute_set; |
---|
[7f6a24ab] | 257 | Priority_Control core_priority; |
---|
[3a4ae6c] | 258 | RTEMS_API_Control *api; |
---|
| 259 | ASR_Information *asr; |
---|
[7f6a24ab] | 260 | |
---|
[ac7d5ef0] | 261 | |
---|
[3235ad9] | 262 | if ( !rtems_is_name_valid( name ) ) |
---|
[3a4ae6c] | 263 | return RTEMS_INVALID_NAME; |
---|
[ac7d5ef0] | 264 | |
---|
[7f6a24ab] | 265 | /* |
---|
| 266 | * Core Thread Initialize insures we get the minimum amount of |
---|
| 267 | * stack space. |
---|
| 268 | */ |
---|
| 269 | |
---|
[ac7d5ef0] | 270 | #if 0 |
---|
| 271 | if ( !_Stack_Is_enough( stack_size ) ) |
---|
[3a4ae6c] | 272 | return RTEMS_INVALID_SIZE; |
---|
[ac7d5ef0] | 273 | #endif |
---|
| 274 | |
---|
| 275 | /* |
---|
| 276 | * Fix the attribute set to match the attributes which |
---|
| 277 | * this processor (1) requires and (2) is able to support. |
---|
| 278 | * First add in the required flags for attribute_set |
---|
| 279 | * Typically this might include FP if the platform |
---|
| 280 | * or application required all tasks to be fp aware. |
---|
| 281 | * Then turn off the requested bits which are not supported. |
---|
| 282 | */ |
---|
| 283 | |
---|
| 284 | the_attribute_set = _Attributes_Set( attribute_set, ATTRIBUTES_REQUIRED ); |
---|
| 285 | the_attribute_set = |
---|
| 286 | _Attributes_Clear( the_attribute_set, ATTRIBUTES_NOT_SUPPORTED ); |
---|
| 287 | |
---|
[7f6a24ab] | 288 | if ( _Attributes_Is_floating_point( the_attribute_set ) ) |
---|
| 289 | is_fp = TRUE; |
---|
| 290 | else |
---|
| 291 | is_fp = FALSE; |
---|
| 292 | |
---|
[7a035ebc] | 293 | /* |
---|
| 294 | * Validate the RTEMS API priority and convert it to the core priority range. |
---|
| 295 | */ |
---|
| 296 | |
---|
| 297 | if ( !_Attributes_Is_system_task( the_attribute_set ) ) { |
---|
| 298 | if ( !_RTEMS_tasks_Priority_is_valid( initial_priority ) ) |
---|
| 299 | return RTEMS_INVALID_PRIORITY; |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | core_priority = _RTEMS_tasks_Priority_to_Core( initial_priority ); |
---|
| 303 | |
---|
[97e2729d] | 304 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[7f6a24ab] | 305 | if ( _Attributes_Is_global( the_attribute_set ) ) { |
---|
| 306 | |
---|
| 307 | is_global = TRUE; |
---|
| 308 | |
---|
[3a4ae6c] | 309 | if ( !_System_state_Is_multiprocessing ) |
---|
| 310 | return RTEMS_MP_NOT_CONFIGURED; |
---|
[ac7d5ef0] | 311 | |
---|
[7f6a24ab] | 312 | } else |
---|
| 313 | is_global = FALSE; |
---|
[97e2729d] | 314 | #endif |
---|
[7f6a24ab] | 315 | |
---|
| 316 | /* |
---|
| 317 | * Make sure system is MP if this task is global |
---|
| 318 | */ |
---|
| 319 | |
---|
| 320 | /* |
---|
| 321 | * Disable dispatch for protection |
---|
| 322 | */ |
---|
| 323 | |
---|
| 324 | _Thread_Disable_dispatch(); |
---|
| 325 | |
---|
| 326 | /* |
---|
| 327 | * Allocate the thread control block and -- if the task is global -- |
---|
| 328 | * allocate a global object control block. |
---|
| 329 | * |
---|
| 330 | * NOTE: This routine does not use the combined allocate and open |
---|
| 331 | * global object routine because this results in a lack of |
---|
| 332 | * control over when memory is allocated and can be freed in |
---|
| 333 | * the event of an error. |
---|
| 334 | */ |
---|
[ac7d5ef0] | 335 | |
---|
| 336 | the_thread = _RTEMS_tasks_Allocate(); |
---|
| 337 | |
---|
| 338 | if ( !the_thread ) { |
---|
| 339 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 340 | return RTEMS_TOO_MANY; |
---|
[ac7d5ef0] | 341 | } |
---|
| 342 | |
---|
[97e2729d] | 343 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[7f6a24ab] | 344 | if ( is_global ) { |
---|
| 345 | the_global_object = _Objects_MP_Allocate_global_object(); |
---|
[ac7d5ef0] | 346 | |
---|
[7f6a24ab] | 347 | if ( _Objects_MP_Is_null_global_object( the_global_object ) ) { |
---|
| 348 | _RTEMS_tasks_Free( the_thread ); |
---|
| 349 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 350 | return RTEMS_TOO_MANY; |
---|
[7f6a24ab] | 351 | } |
---|
| 352 | } |
---|
[97e2729d] | 353 | #endif |
---|
[ac7d5ef0] | 354 | |
---|
| 355 | /* |
---|
[7f6a24ab] | 356 | * Initialize the core thread for this task. |
---|
[ac7d5ef0] | 357 | */ |
---|
| 358 | |
---|
[3a4ae6c] | 359 | status = _Thread_Initialize( |
---|
| 360 | &_RTEMS_tasks_Information, |
---|
| 361 | the_thread, |
---|
| 362 | NULL, |
---|
| 363 | stack_size, |
---|
| 364 | is_fp, |
---|
| 365 | core_priority, |
---|
| 366 | _Modes_Is_preempt(initial_modes) ? TRUE : FALSE, |
---|
[ebd40c0] | 367 | _Modes_Is_timeslice(initial_modes) ? |
---|
| 368 | THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE : |
---|
| 369 | THREAD_CPU_BUDGET_ALGORITHM_NONE, |
---|
| 370 | NULL, /* no budget algorithm callout */ |
---|
[3a4ae6c] | 371 | _Modes_Get_interrupt_level(initial_modes), |
---|
| 372 | &name |
---|
| 373 | ); |
---|
[ac7d5ef0] | 374 | |
---|
[3a4ae6c] | 375 | if ( !status ) { |
---|
[97e2729d] | 376 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[7f6a24ab] | 377 | if ( is_global ) |
---|
| 378 | _Objects_MP_Free_global_object( the_global_object ); |
---|
[97e2729d] | 379 | #endif |
---|
[ac7d5ef0] | 380 | _RTEMS_tasks_Free( the_thread ); |
---|
| 381 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 382 | return RTEMS_UNSATISFIED; |
---|
[ac7d5ef0] | 383 | } |
---|
| 384 | |
---|
[3a4ae6c] | 385 | api = the_thread->API_Extensions[ THREAD_API_RTEMS ]; |
---|
| 386 | asr = &api->Signal; |
---|
| 387 | |
---|
| 388 | asr->is_enabled = _Modes_Is_asr_disabled(initial_modes) ? FALSE : TRUE; |
---|
| 389 | |
---|
[7f6a24ab] | 390 | *id = the_thread->Object.id; |
---|
[ac7d5ef0] | 391 | |
---|
[97e2729d] | 392 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[7f6a24ab] | 393 | if ( is_global ) { |
---|
[ac7d5ef0] | 394 | |
---|
[3a4ae6c] | 395 | the_thread->is_global = TRUE; |
---|
[ac7d5ef0] | 396 | |
---|
[7f6a24ab] | 397 | _Objects_MP_Open( |
---|
| 398 | &_RTEMS_tasks_Information, |
---|
| 399 | the_global_object, |
---|
| 400 | name, |
---|
| 401 | the_thread->Object.id |
---|
| 402 | ); |
---|
[ac7d5ef0] | 403 | |
---|
| 404 | _RTEMS_tasks_MP_Send_process_packet( |
---|
| 405 | RTEMS_TASKS_MP_ANNOUNCE_CREATE, |
---|
| 406 | the_thread->Object.id, |
---|
| 407 | name |
---|
| 408 | ); |
---|
| 409 | |
---|
[7f6a24ab] | 410 | } |
---|
[97e2729d] | 411 | #endif |
---|
[7f6a24ab] | 412 | |
---|
[ac7d5ef0] | 413 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 414 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 415 | } |
---|
| 416 | |
---|
| 417 | /*PAGE |
---|
| 418 | * |
---|
| 419 | * rtems_task_ident |
---|
| 420 | * |
---|
| 421 | * This directive returns the system ID associated with |
---|
| 422 | * the thread name. |
---|
| 423 | * |
---|
| 424 | * Input parameters: |
---|
| 425 | * name - user defined thread name |
---|
| 426 | * node - node(s) to be searched |
---|
| 427 | * id - pointer to thread id |
---|
| 428 | * |
---|
| 429 | * Output parameters: |
---|
| 430 | * *id - thread id |
---|
| 431 | * RTEMS_SUCCESSFUL - if successful |
---|
| 432 | * error code - if unsuccessful |
---|
| 433 | */ |
---|
| 434 | |
---|
| 435 | rtems_status_code rtems_task_ident( |
---|
[3235ad9] | 436 | rtems_name name, |
---|
[ac7d5ef0] | 437 | unsigned32 node, |
---|
| 438 | Objects_Id *id |
---|
| 439 | ) |
---|
| 440 | { |
---|
[3a4ae6c] | 441 | Objects_Name_to_id_errors status; |
---|
| 442 | |
---|
| 443 | if ( name == OBJECTS_ID_OF_SELF ) { |
---|
| 444 | *id = _Thread_Executing->Object.id; |
---|
| 445 | return RTEMS_SUCCESSFUL; |
---|
| 446 | } |
---|
| 447 | |
---|
| 448 | status = _Objects_Name_to_id( &_RTEMS_tasks_Information, &name, node, id ); |
---|
[ac7d5ef0] | 449 | |
---|
[3a4ae6c] | 450 | return _Status_Object_name_errors_to_status[ status ]; |
---|
[ac7d5ef0] | 451 | } |
---|
| 452 | |
---|
| 453 | /*PAGE |
---|
| 454 | * |
---|
| 455 | * rtems_task_start |
---|
| 456 | * |
---|
| 457 | * This directive readies the thread identified by the "id" |
---|
| 458 | * based on its current priorty, to await execution. A thread |
---|
| 459 | * can be started only from the dormant state. |
---|
| 460 | * |
---|
| 461 | * Input parameters: |
---|
| 462 | * id - thread id |
---|
| 463 | * entry_point - start execution address of thread |
---|
| 464 | * argument - thread argument |
---|
| 465 | * |
---|
| 466 | * Output parameters: |
---|
| 467 | * RTEMS_SUCCESSFUL - if successful |
---|
| 468 | * error code - if unsuccessful |
---|
| 469 | */ |
---|
| 470 | |
---|
| 471 | rtems_status_code rtems_task_start( |
---|
[7f6a24ab] | 472 | rtems_id id, |
---|
[ac7d5ef0] | 473 | rtems_task_entry entry_point, |
---|
[7f6a24ab] | 474 | unsigned32 argument |
---|
[ac7d5ef0] | 475 | ) |
---|
| 476 | { |
---|
| 477 | register Thread_Control *the_thread; |
---|
| 478 | Objects_Locations location; |
---|
| 479 | |
---|
| 480 | if ( entry_point == NULL ) |
---|
[3a4ae6c] | 481 | return RTEMS_INVALID_ADDRESS; |
---|
[ac7d5ef0] | 482 | |
---|
| 483 | the_thread = _Thread_Get( id, &location ); |
---|
| 484 | switch ( location ) { |
---|
[97e2729d] | 485 | |
---|
[ac7d5ef0] | 486 | case OBJECTS_REMOTE: |
---|
[97e2729d] | 487 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[ac7d5ef0] | 488 | _Thread_Dispatch(); |
---|
[3a4ae6c] | 489 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
[97e2729d] | 490 | #endif |
---|
| 491 | |
---|
| 492 | case OBJECTS_ERROR: |
---|
| 493 | return RTEMS_INVALID_ID; |
---|
| 494 | |
---|
[ac7d5ef0] | 495 | case OBJECTS_LOCAL: |
---|
[7f6a24ab] | 496 | if ( _Thread_Start( |
---|
| 497 | the_thread, THREAD_START_NUMERIC, entry_point, NULL, argument ) ) { |
---|
[ac7d5ef0] | 498 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 499 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 500 | } |
---|
| 501 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 502 | return RTEMS_INCORRECT_STATE; |
---|
[ac7d5ef0] | 503 | } |
---|
| 504 | |
---|
[3a4ae6c] | 505 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
[ac7d5ef0] | 506 | } |
---|
| 507 | |
---|
| 508 | /*PAGE |
---|
| 509 | * |
---|
| 510 | * rtems_task_restart |
---|
| 511 | * |
---|
| 512 | * This directive readies the specified thread. It restores |
---|
| 513 | * the thread environment to the original values established |
---|
| 514 | * at thread creation and start time. A thread can be restarted |
---|
| 515 | * from any state except the dormant state. |
---|
| 516 | * |
---|
| 517 | * Input parameters: |
---|
| 518 | * id - thread id |
---|
| 519 | * argument - thread argument |
---|
| 520 | * |
---|
| 521 | * Output parameters: |
---|
| 522 | * RTEMS_SUCCESSFUL - if successful |
---|
| 523 | * error code - if unsuccessful |
---|
| 524 | */ |
---|
| 525 | |
---|
| 526 | rtems_status_code rtems_task_restart( |
---|
| 527 | Objects_Id id, |
---|
| 528 | unsigned32 argument |
---|
| 529 | ) |
---|
| 530 | { |
---|
| 531 | register Thread_Control *the_thread; |
---|
[7f6a24ab] | 532 | Objects_Locations location; |
---|
[ac7d5ef0] | 533 | |
---|
| 534 | the_thread = _Thread_Get( id, &location ); |
---|
| 535 | switch ( location ) { |
---|
[97e2729d] | 536 | |
---|
[ac7d5ef0] | 537 | case OBJECTS_REMOTE: |
---|
[97e2729d] | 538 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[ac7d5ef0] | 539 | _Thread_Dispatch(); |
---|
[3a4ae6c] | 540 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
[97e2729d] | 541 | #endif |
---|
| 542 | |
---|
| 543 | case OBJECTS_ERROR: |
---|
| 544 | return RTEMS_INVALID_ID; |
---|
| 545 | |
---|
[ac7d5ef0] | 546 | case OBJECTS_LOCAL: |
---|
[7f6a24ab] | 547 | if ( _Thread_Restart( the_thread, NULL, argument ) ) { |
---|
[ac7d5ef0] | 548 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 549 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 550 | } |
---|
| 551 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 552 | return RTEMS_INCORRECT_STATE; |
---|
[ac7d5ef0] | 553 | } |
---|
| 554 | |
---|
[3a4ae6c] | 555 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
[ac7d5ef0] | 556 | } |
---|
| 557 | |
---|
| 558 | /*PAGE |
---|
| 559 | * |
---|
| 560 | * rtems_task_delete |
---|
| 561 | * |
---|
| 562 | * This directive allows a thread to delete itself or the thread |
---|
| 563 | * identified in the id field. The executive halts execution |
---|
| 564 | * of the thread and frees the thread control block. |
---|
| 565 | * |
---|
| 566 | * Input parameters: |
---|
| 567 | * id - thread id |
---|
| 568 | * |
---|
| 569 | * Output parameters: |
---|
| 570 | * nothing - if id is the requesting thread (always succeeds) |
---|
| 571 | * RTEMS_SUCCESSFUL - if successful and id is |
---|
| 572 | * not the requesting thread |
---|
| 573 | * error code - if unsuccessful |
---|
| 574 | */ |
---|
| 575 | |
---|
| 576 | rtems_status_code rtems_task_delete( |
---|
| 577 | Objects_Id id |
---|
| 578 | ) |
---|
| 579 | { |
---|
| 580 | register Thread_Control *the_thread; |
---|
| 581 | Objects_Locations location; |
---|
[cb1b853d] | 582 | Objects_Information *the_information; |
---|
[ac7d5ef0] | 583 | |
---|
| 584 | the_thread = _Thread_Get( id, &location ); |
---|
| 585 | switch ( location ) { |
---|
[97e2729d] | 586 | |
---|
[ac7d5ef0] | 587 | case OBJECTS_REMOTE: |
---|
[97e2729d] | 588 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[ac7d5ef0] | 589 | _Thread_Dispatch(); |
---|
[3a4ae6c] | 590 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
[97e2729d] | 591 | #endif |
---|
| 592 | |
---|
| 593 | case OBJECTS_ERROR: |
---|
| 594 | return RTEMS_INVALID_ID; |
---|
| 595 | |
---|
[ac7d5ef0] | 596 | case OBJECTS_LOCAL: |
---|
[cb1b853d] | 597 | the_information = _Objects_Get_information( the_thread->Object.id ); |
---|
| 598 | |
---|
| 599 | if ( !the_information ) { |
---|
| 600 | _Thread_Enable_dispatch(); |
---|
| 601 | return RTEMS_INVALID_ID; |
---|
| 602 | /* This should never happen if _Thread_Get() works right */ |
---|
| 603 | } |
---|
| 604 | |
---|
| 605 | _Thread_Close( the_information, the_thread ); |
---|
[ac7d5ef0] | 606 | |
---|
| 607 | _RTEMS_tasks_Free( the_thread ); |
---|
| 608 | |
---|
[97e2729d] | 609 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3a4ae6c] | 610 | if ( the_thread->is_global ) { |
---|
[ac7d5ef0] | 611 | |
---|
[5250ff39] | 612 | _Objects_MP_Close( &_RTEMS_tasks_Information, the_thread->Object.id ); |
---|
[ac7d5ef0] | 613 | |
---|
| 614 | _RTEMS_tasks_MP_Send_process_packet( |
---|
| 615 | RTEMS_TASKS_MP_ANNOUNCE_DELETE, |
---|
| 616 | the_thread->Object.id, |
---|
| 617 | 0 /* Not used */ |
---|
| 618 | ); |
---|
| 619 | } |
---|
[97e2729d] | 620 | #endif |
---|
[ac7d5ef0] | 621 | |
---|
| 622 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 623 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 624 | } |
---|
| 625 | |
---|
[3a4ae6c] | 626 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
[ac7d5ef0] | 627 | } |
---|
| 628 | |
---|
| 629 | /*PAGE |
---|
| 630 | * |
---|
| 631 | * rtems_task_suspend |
---|
| 632 | * |
---|
| 633 | * This directive will place the specified thread in the "suspended" |
---|
| 634 | * state. Note that the suspended state can be in addition to |
---|
| 635 | * other waiting states. |
---|
| 636 | * |
---|
| 637 | * Input parameters: |
---|
| 638 | * id - thread id |
---|
| 639 | * |
---|
| 640 | * Output parameters: |
---|
| 641 | * RTEMS_SUCCESSFUL - if successful |
---|
| 642 | * error code - if unsuccessful |
---|
| 643 | */ |
---|
| 644 | |
---|
| 645 | rtems_status_code rtems_task_suspend( |
---|
| 646 | Objects_Id id |
---|
| 647 | ) |
---|
| 648 | { |
---|
| 649 | register Thread_Control *the_thread; |
---|
| 650 | Objects_Locations location; |
---|
| 651 | |
---|
| 652 | the_thread = _Thread_Get( id, &location ); |
---|
| 653 | switch ( location ) { |
---|
[97e2729d] | 654 | |
---|
[ac7d5ef0] | 655 | case OBJECTS_REMOTE: |
---|
[97e2729d] | 656 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[3a4ae6c] | 657 | return _RTEMS_tasks_MP_Send_request_packet( |
---|
| 658 | RTEMS_TASKS_MP_SUSPEND_REQUEST, |
---|
| 659 | id, |
---|
| 660 | 0, /* Not used */ |
---|
| 661 | 0, /* Not used */ |
---|
| 662 | 0 /* Not used */ |
---|
[ac7d5ef0] | 663 | ); |
---|
[97e2729d] | 664 | #endif |
---|
| 665 | |
---|
| 666 | case OBJECTS_ERROR: |
---|
| 667 | return RTEMS_INVALID_ID; |
---|
| 668 | |
---|
[ac7d5ef0] | 669 | case OBJECTS_LOCAL: |
---|
| 670 | if ( !_States_Is_suspended( the_thread->current_state ) ) { |
---|
| 671 | _Thread_Set_state( the_thread, STATES_SUSPENDED ); |
---|
| 672 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 673 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 674 | } |
---|
| 675 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 676 | return RTEMS_ALREADY_SUSPENDED; |
---|
[ac7d5ef0] | 677 | } |
---|
| 678 | |
---|
[3a4ae6c] | 679 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
[ac7d5ef0] | 680 | } |
---|
| 681 | |
---|
| 682 | /*PAGE |
---|
| 683 | * |
---|
| 684 | * rtems_task_resume |
---|
| 685 | * |
---|
| 686 | * This directive will remove the specified thread |
---|
| 687 | * from the suspended state. |
---|
| 688 | * |
---|
| 689 | * Input parameters: |
---|
| 690 | * id - thread id |
---|
| 691 | * |
---|
| 692 | * Output parameters: |
---|
| 693 | * RTEMS_SUCCESSFUL - if successful |
---|
| 694 | * error code - if unsuccessful |
---|
| 695 | */ |
---|
| 696 | |
---|
| 697 | rtems_status_code rtems_task_resume( |
---|
| 698 | Objects_Id id |
---|
| 699 | ) |
---|
| 700 | { |
---|
| 701 | register Thread_Control *the_thread; |
---|
| 702 | Objects_Locations location; |
---|
| 703 | |
---|
| 704 | the_thread = _Thread_Get( id, &location ); |
---|
| 705 | switch ( location ) { |
---|
[97e2729d] | 706 | |
---|
[ac7d5ef0] | 707 | case OBJECTS_REMOTE: |
---|
[97e2729d] | 708 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 709 | return _RTEMS_tasks_MP_Send_request_packet( |
---|
[ac7d5ef0] | 710 | RTEMS_TASKS_MP_RESUME_REQUEST, |
---|
| 711 | id, |
---|
| 712 | 0, /* Not used */ |
---|
| 713 | 0, /* Not used */ |
---|
| 714 | 0 /* Not used */ |
---|
[97e2729d] | 715 | ); |
---|
| 716 | #endif |
---|
| 717 | |
---|
| 718 | case OBJECTS_ERROR: |
---|
| 719 | return RTEMS_INVALID_ID; |
---|
| 720 | |
---|
[ac7d5ef0] | 721 | case OBJECTS_LOCAL: |
---|
| 722 | if ( _States_Is_suspended( the_thread->current_state ) ) { |
---|
| 723 | _Thread_Resume( the_thread ); |
---|
| 724 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 725 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 726 | } |
---|
| 727 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 728 | return RTEMS_INCORRECT_STATE; |
---|
[ac7d5ef0] | 729 | } |
---|
| 730 | |
---|
[3a4ae6c] | 731 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
[ac7d5ef0] | 732 | } |
---|
| 733 | |
---|
| 734 | /*PAGE |
---|
| 735 | * |
---|
| 736 | * rtems_task_set_priority |
---|
| 737 | * |
---|
| 738 | * This directive changes the priority of the specified thread. |
---|
| 739 | * The specified thread can be any thread in the system including |
---|
| 740 | * the requesting thread. |
---|
| 741 | * |
---|
| 742 | * Input parameters: |
---|
| 743 | * id - thread id (0 indicates requesting thread) |
---|
| 744 | * new_priority - thread priority (0 indicates current priority) |
---|
| 745 | * old_priority - pointer to previous priority |
---|
| 746 | * |
---|
| 747 | * Output parameters: |
---|
| 748 | * old_priority - previous priority |
---|
| 749 | * RTEMS_SUCCESSFUL - if successful |
---|
| 750 | * error code - if unsuccessful |
---|
| 751 | */ |
---|
| 752 | |
---|
| 753 | rtems_status_code rtems_task_set_priority( |
---|
[7f6a24ab] | 754 | Objects_Id id, |
---|
[ac7d5ef0] | 755 | rtems_task_priority new_priority, |
---|
| 756 | rtems_task_priority *old_priority |
---|
| 757 | ) |
---|
| 758 | { |
---|
| 759 | register Thread_Control *the_thread; |
---|
| 760 | Objects_Locations location; |
---|
| 761 | |
---|
| 762 | if ( new_priority != RTEMS_CURRENT_PRIORITY && |
---|
[3a4ae6c] | 763 | !_RTEMS_tasks_Priority_is_valid( new_priority ) ) |
---|
| 764 | return RTEMS_INVALID_PRIORITY; |
---|
[ac7d5ef0] | 765 | |
---|
| 766 | the_thread = _Thread_Get( id, &location ); |
---|
| 767 | switch ( location ) { |
---|
[97e2729d] | 768 | |
---|
[ac7d5ef0] | 769 | case OBJECTS_REMOTE: |
---|
[97e2729d] | 770 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[ac7d5ef0] | 771 | _Thread_Executing->Wait.return_argument = old_priority; |
---|
[97e2729d] | 772 | return _RTEMS_tasks_MP_Send_request_packet( |
---|
[ac7d5ef0] | 773 | RTEMS_TASKS_MP_SET_PRIORITY_REQUEST, |
---|
| 774 | id, |
---|
| 775 | new_priority, |
---|
| 776 | 0, /* Not used */ |
---|
| 777 | 0 /* Not used */ |
---|
| 778 | ); |
---|
[97e2729d] | 779 | #endif |
---|
| 780 | |
---|
| 781 | case OBJECTS_ERROR: |
---|
| 782 | return RTEMS_INVALID_ID; |
---|
| 783 | |
---|
[ac7d5ef0] | 784 | case OBJECTS_LOCAL: |
---|
| 785 | *old_priority = the_thread->current_priority; |
---|
| 786 | if ( new_priority != RTEMS_CURRENT_PRIORITY ) { |
---|
| 787 | the_thread->real_priority = new_priority; |
---|
| 788 | if ( the_thread->resource_count == 0 || |
---|
| 789 | the_thread->current_priority > new_priority ) |
---|
[dab057a] | 790 | _Thread_Change_priority( the_thread, new_priority, FALSE ); |
---|
[ac7d5ef0] | 791 | } |
---|
| 792 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 793 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 794 | } |
---|
| 795 | |
---|
[3a4ae6c] | 796 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
[ac7d5ef0] | 797 | } |
---|
| 798 | |
---|
| 799 | /*PAGE |
---|
| 800 | * |
---|
| 801 | * rtems_task_mode |
---|
| 802 | * |
---|
| 803 | * This directive enables and disables several modes of |
---|
| 804 | * execution for the requesting thread. |
---|
| 805 | * |
---|
| 806 | * Input parameters: |
---|
| 807 | * mode_set - new mode |
---|
| 808 | * mask - mask |
---|
| 809 | * previous_mode_set - address of previous mode set |
---|
| 810 | * |
---|
| 811 | * Output: |
---|
| 812 | * *previous_mode_set - previous mode set |
---|
[3a4ae6c] | 813 | * always return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 814 | */ |
---|
| 815 | |
---|
| 816 | rtems_status_code rtems_task_mode( |
---|
| 817 | rtems_mode mode_set, |
---|
| 818 | rtems_mode mask, |
---|
| 819 | rtems_mode *previous_mode_set |
---|
| 820 | ) |
---|
| 821 | { |
---|
[3a4ae6c] | 822 | Thread_Control *executing; |
---|
| 823 | RTEMS_API_Control *api; |
---|
| 824 | ASR_Information *asr; |
---|
| 825 | boolean is_asr_enabled = FALSE; |
---|
| 826 | boolean needs_asr_dispatching = FALSE; |
---|
| 827 | rtems_mode old_mode; |
---|
| 828 | |
---|
| 829 | executing = _Thread_Executing; |
---|
| 830 | api = executing->API_Extensions[ THREAD_API_RTEMS ]; |
---|
| 831 | asr = &api->Signal; |
---|
| 832 | |
---|
| 833 | old_mode = (executing->is_preemptible) ? RTEMS_PREEMPT : RTEMS_NO_PREEMPT; |
---|
[ebd40c0] | 834 | |
---|
| 835 | if ( executing->budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_NONE ) |
---|
| 836 | old_mode |= RTEMS_NO_TIMESLICE; |
---|
| 837 | else |
---|
| 838 | old_mode |= RTEMS_TIMESLICE; |
---|
| 839 | |
---|
[3a4ae6c] | 840 | old_mode |= (asr->is_enabled) ? RTEMS_ASR : RTEMS_NO_ASR; |
---|
| 841 | old_mode |= _ISR_Get_level(); |
---|
| 842 | |
---|
| 843 | *previous_mode_set = old_mode; |
---|
| 844 | |
---|
| 845 | /* |
---|
| 846 | * These are generic thread scheduling characteristics. |
---|
| 847 | */ |
---|
| 848 | |
---|
| 849 | if ( mask & RTEMS_PREEMPT_MASK ) |
---|
| 850 | executing->is_preemptible = _Modes_Is_preempt(mode_set) ? TRUE : FALSE; |
---|
| 851 | |
---|
[ebd40c0] | 852 | if ( mask & RTEMS_TIMESLICE_MASK ) { |
---|
| 853 | if ( _Modes_Is_timeslice(mode_set) ) |
---|
| 854 | executing->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE; |
---|
| 855 | else |
---|
| 856 | executing->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE; |
---|
| 857 | } |
---|
[3a4ae6c] | 858 | |
---|
| 859 | /* |
---|
| 860 | * Set the new interrupt level |
---|
| 861 | */ |
---|
| 862 | |
---|
| 863 | if ( mask & RTEMS_INTERRUPT_MASK ) |
---|
| 864 | _Modes_Set_interrupt_level( mode_set ); |
---|
| 865 | |
---|
| 866 | /* |
---|
| 867 | * This is specific to the RTEMS API |
---|
| 868 | */ |
---|
| 869 | |
---|
| 870 | is_asr_enabled = FALSE; |
---|
| 871 | needs_asr_dispatching = FALSE; |
---|
| 872 | |
---|
| 873 | if ( mask & RTEMS_ASR_MASK ) { |
---|
| 874 | is_asr_enabled = _Modes_Is_asr_disabled( mode_set ) ? FALSE : TRUE; |
---|
| 875 | if ( is_asr_enabled != asr->is_enabled ) { |
---|
| 876 | asr->is_enabled = is_asr_enabled; |
---|
| 877 | _ASR_Swap_signals( asr ); |
---|
[94b3ec59] | 878 | if ( _ASR_Are_signals_pending( asr ) ) { |
---|
[3a4ae6c] | 879 | needs_asr_dispatching = TRUE; |
---|
[94b3ec59] | 880 | executing->do_post_task_switch_extension = TRUE; |
---|
| 881 | } |
---|
[3a4ae6c] | 882 | } |
---|
| 883 | } |
---|
| 884 | |
---|
| 885 | if ( _Thread_Evaluate_mode() || needs_asr_dispatching ) |
---|
[ac7d5ef0] | 886 | _Thread_Dispatch(); |
---|
[3a4ae6c] | 887 | |
---|
| 888 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 889 | } |
---|
| 890 | |
---|
| 891 | /*PAGE |
---|
| 892 | * |
---|
| 893 | * rtems_task_get_note |
---|
| 894 | * |
---|
| 895 | * This directive obtains the note from the specified notepad |
---|
| 896 | * of the specified thread. |
---|
| 897 | * |
---|
| 898 | * Input parameters: |
---|
| 899 | * id - thread id |
---|
| 900 | * notepad - notepad number |
---|
| 901 | * note - pointer to note |
---|
| 902 | * |
---|
| 903 | * Output parameters: |
---|
| 904 | * note - filled in if successful |
---|
| 905 | * RTEMS_SUCCESSFUL - if successful |
---|
| 906 | * error code - if unsuccessful |
---|
| 907 | */ |
---|
| 908 | |
---|
| 909 | rtems_status_code rtems_task_get_note( |
---|
| 910 | Objects_Id id, |
---|
| 911 | unsigned32 notepad, |
---|
| 912 | unsigned32 *note |
---|
| 913 | ) |
---|
| 914 | { |
---|
| 915 | register Thread_Control *the_thread; |
---|
| 916 | Objects_Locations location; |
---|
[3a4ae6c] | 917 | RTEMS_API_Control *api; |
---|
[ac7d5ef0] | 918 | |
---|
| 919 | /* |
---|
| 920 | * NOTE: There is no check for < RTEMS_NOTEPAD_FIRST because that would |
---|
| 921 | * be checking an unsigned number for being negative. |
---|
| 922 | */ |
---|
| 923 | |
---|
| 924 | if ( notepad > RTEMS_NOTEPAD_LAST ) |
---|
[3a4ae6c] | 925 | return RTEMS_INVALID_NUMBER; |
---|
[ac7d5ef0] | 926 | |
---|
| 927 | /* |
---|
| 928 | * Optimize the most likely case to avoid the Thread_Dispatch. |
---|
| 929 | */ |
---|
| 930 | |
---|
| 931 | if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) || |
---|
| 932 | _Objects_Are_ids_equal( id, _Thread_Executing->Object.id ) ) { |
---|
[3a4ae6c] | 933 | api = _Thread_Executing->API_Extensions[ THREAD_API_RTEMS ]; |
---|
| 934 | *note = api->Notepads[ notepad ]; |
---|
| 935 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 936 | } |
---|
| 937 | |
---|
| 938 | the_thread = _Thread_Get( id, &location ); |
---|
| 939 | switch ( location ) { |
---|
[97e2729d] | 940 | |
---|
[ac7d5ef0] | 941 | case OBJECTS_REMOTE: |
---|
[97e2729d] | 942 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[ac7d5ef0] | 943 | _Thread_Executing->Wait.return_argument = note; |
---|
| 944 | |
---|
| 945 | return _RTEMS_tasks_MP_Send_request_packet( |
---|
| 946 | RTEMS_TASKS_MP_GET_NOTE_REQUEST, |
---|
| 947 | id, |
---|
| 948 | 0, /* Not used */ |
---|
| 949 | notepad, |
---|
| 950 | 0 /* Not used */ |
---|
| 951 | ); |
---|
[97e2729d] | 952 | #endif |
---|
| 953 | |
---|
| 954 | case OBJECTS_ERROR: |
---|
| 955 | return RTEMS_INVALID_ID; |
---|
| 956 | |
---|
[ac7d5ef0] | 957 | case OBJECTS_LOCAL: |
---|
[3a4ae6c] | 958 | api = the_thread->API_Extensions[ THREAD_API_RTEMS ]; |
---|
| 959 | *note = api->Notepads[ notepad ]; |
---|
[ac7d5ef0] | 960 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 961 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 962 | } |
---|
| 963 | |
---|
[3a4ae6c] | 964 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
[ac7d5ef0] | 965 | } |
---|
| 966 | |
---|
| 967 | /*PAGE |
---|
| 968 | * |
---|
| 969 | * rtems_task_set_note |
---|
| 970 | * |
---|
| 971 | * This directive sets the specified notepad contents to the given |
---|
| 972 | * note. |
---|
| 973 | * |
---|
| 974 | * Input parameters: |
---|
| 975 | * id - thread id |
---|
| 976 | * notepad - notepad number |
---|
| 977 | * note - note value |
---|
| 978 | * |
---|
| 979 | * Output parameters: |
---|
| 980 | * RTEMS_SUCCESSFUL - if successful |
---|
| 981 | * error code - if unsuccessful |
---|
| 982 | */ |
---|
| 983 | |
---|
| 984 | rtems_status_code rtems_task_set_note( |
---|
| 985 | Objects_Id id, |
---|
| 986 | unsigned32 notepad, |
---|
| 987 | unsigned32 note |
---|
| 988 | ) |
---|
| 989 | { |
---|
| 990 | register Thread_Control *the_thread; |
---|
| 991 | Objects_Locations location; |
---|
[3a4ae6c] | 992 | RTEMS_API_Control *api; |
---|
[ac7d5ef0] | 993 | |
---|
| 994 | /* |
---|
| 995 | * NOTE: There is no check for < RTEMS_NOTEPAD_FIRST because that would |
---|
| 996 | * be checking an unsigned number for being negative. |
---|
| 997 | */ |
---|
| 998 | |
---|
| 999 | if ( notepad > RTEMS_NOTEPAD_LAST ) |
---|
[3a4ae6c] | 1000 | return RTEMS_INVALID_NUMBER; |
---|
[ac7d5ef0] | 1001 | |
---|
| 1002 | /* |
---|
| 1003 | * Optimize the most likely case to avoid the Thread_Dispatch. |
---|
| 1004 | */ |
---|
| 1005 | |
---|
| 1006 | if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) || |
---|
| 1007 | _Objects_Are_ids_equal( id, _Thread_Executing->Object.id ) ) { |
---|
[3a4ae6c] | 1008 | api = _Thread_Executing->API_Extensions[ THREAD_API_RTEMS ]; |
---|
| 1009 | api->Notepads[ notepad ] = note; |
---|
| 1010 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 1011 | } |
---|
| 1012 | |
---|
| 1013 | the_thread = _Thread_Get( id, &location ); |
---|
| 1014 | switch ( location ) { |
---|
[97e2729d] | 1015 | |
---|
[ac7d5ef0] | 1016 | case OBJECTS_REMOTE: |
---|
[97e2729d] | 1017 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[ac7d5ef0] | 1018 | return _RTEMS_tasks_MP_Send_request_packet( |
---|
| 1019 | RTEMS_TASKS_MP_SET_NOTE_REQUEST, |
---|
| 1020 | id, |
---|
| 1021 | 0, /* Not used */ |
---|
| 1022 | notepad, |
---|
| 1023 | note |
---|
| 1024 | ); |
---|
[97e2729d] | 1025 | #endif |
---|
| 1026 | |
---|
| 1027 | case OBJECTS_ERROR: |
---|
| 1028 | return RTEMS_INVALID_ID; |
---|
[ac7d5ef0] | 1029 | |
---|
| 1030 | case OBJECTS_LOCAL: |
---|
[3a4ae6c] | 1031 | api = the_thread->API_Extensions[ THREAD_API_RTEMS ]; |
---|
| 1032 | api->Notepads[ notepad ] = note; |
---|
[ac7d5ef0] | 1033 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 1034 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 1035 | } |
---|
| 1036 | |
---|
[3a4ae6c] | 1037 | return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ |
---|
[ac7d5ef0] | 1038 | } |
---|
| 1039 | |
---|
| 1040 | /*PAGE |
---|
| 1041 | * |
---|
| 1042 | * rtems_task_wake_after |
---|
| 1043 | * |
---|
| 1044 | * This directive suspends the requesting thread for the given amount |
---|
| 1045 | * of ticks. |
---|
| 1046 | * |
---|
| 1047 | * Input parameters: |
---|
| 1048 | * ticks - number of ticks to wait |
---|
| 1049 | * |
---|
| 1050 | * Output parameters: |
---|
| 1051 | * RTEMS_SUCCESSFUL - always successful |
---|
| 1052 | */ |
---|
| 1053 | |
---|
| 1054 | rtems_status_code rtems_task_wake_after( |
---|
| 1055 | rtems_interval ticks |
---|
| 1056 | ) |
---|
| 1057 | { |
---|
[5a909149] | 1058 | _Thread_Disable_dispatch(); |
---|
| 1059 | if ( ticks == 0 ) { |
---|
| 1060 | _Thread_Yield_processor(); |
---|
| 1061 | } else { |
---|
[ac7d5ef0] | 1062 | _Thread_Set_state( _Thread_Executing, STATES_DELAYING ); |
---|
| 1063 | _Watchdog_Initialize( |
---|
| 1064 | &_Thread_Executing->Timer, |
---|
| 1065 | _Thread_Delay_ended, |
---|
| 1066 | _Thread_Executing->Object.id, |
---|
| 1067 | NULL |
---|
| 1068 | ); |
---|
[8d0b7d96] | 1069 | _Watchdog_Insert_ticks( &_Thread_Executing->Timer, ticks ); |
---|
[5a909149] | 1070 | } |
---|
| 1071 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 1072 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 1073 | } |
---|
| 1074 | |
---|
| 1075 | /*PAGE |
---|
| 1076 | * |
---|
| 1077 | * rtems_task_wake_when |
---|
| 1078 | * |
---|
| 1079 | * This directive blocks the requesting thread until the given date and |
---|
| 1080 | * time is reached. |
---|
| 1081 | * |
---|
| 1082 | * Input parameters: |
---|
| 1083 | * time_buffer - pointer to the time and date structure |
---|
| 1084 | * |
---|
| 1085 | * Output parameters: |
---|
| 1086 | * RTEMS_SUCCESSFUL - if successful |
---|
| 1087 | * error code - if unsuccessful |
---|
| 1088 | */ |
---|
| 1089 | |
---|
| 1090 | rtems_status_code rtems_task_wake_when( |
---|
| 1091 | rtems_time_of_day *time_buffer |
---|
| 1092 | ) |
---|
| 1093 | { |
---|
[3a4ae6c] | 1094 | Watchdog_Interval seconds; |
---|
[ac7d5ef0] | 1095 | |
---|
[7fea679b] | 1096 | if ( !_TOD_Is_set ) |
---|
[3a4ae6c] | 1097 | return RTEMS_NOT_DEFINED; |
---|
[ac7d5ef0] | 1098 | |
---|
| 1099 | time_buffer->ticks = 0; |
---|
| 1100 | |
---|
[3a4ae6c] | 1101 | if ( !_TOD_Validate( time_buffer ) ) |
---|
| 1102 | return RTEMS_INVALID_CLOCK; |
---|
[ac7d5ef0] | 1103 | |
---|
| 1104 | seconds = _TOD_To_seconds( time_buffer ); |
---|
| 1105 | |
---|
| 1106 | if ( seconds <= _TOD_Seconds_since_epoch ) |
---|
[3a4ae6c] | 1107 | return RTEMS_INVALID_CLOCK; |
---|
[ac7d5ef0] | 1108 | |
---|
| 1109 | _Thread_Disable_dispatch(); |
---|
| 1110 | _Thread_Set_state( _Thread_Executing, STATES_WAITING_FOR_TIME ); |
---|
| 1111 | _Watchdog_Initialize( |
---|
| 1112 | &_Thread_Executing->Timer, |
---|
| 1113 | _Thread_Delay_ended, |
---|
| 1114 | _Thread_Executing->Object.id, |
---|
| 1115 | NULL |
---|
| 1116 | ); |
---|
[8d0b7d96] | 1117 | _Watchdog_Insert_seconds( |
---|
| 1118 | &_Thread_Executing->Timer, |
---|
| 1119 | seconds - _TOD_Seconds_since_epoch |
---|
| 1120 | ); |
---|
[ac7d5ef0] | 1121 | _Thread_Enable_dispatch(); |
---|
[3a4ae6c] | 1122 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 1123 | } |
---|
[3a4ae6c] | 1124 | |
---|
| 1125 | /*PAGE |
---|
| 1126 | * |
---|
| 1127 | * _RTEMS_tasks_Initialize_user_tasks |
---|
| 1128 | * |
---|
| 1129 | * This routine creates and starts all configured user |
---|
| 1130 | * initialzation threads. |
---|
| 1131 | * |
---|
| 1132 | * Input parameters: NONE |
---|
| 1133 | * |
---|
| 1134 | * Output parameters: NONE |
---|
| 1135 | */ |
---|
| 1136 | |
---|
| 1137 | void _RTEMS_tasks_Initialize_user_tasks( void ) |
---|
| 1138 | { |
---|
| 1139 | unsigned32 index; |
---|
| 1140 | unsigned32 maximum; |
---|
| 1141 | rtems_id id; |
---|
| 1142 | rtems_status_code return_value; |
---|
| 1143 | rtems_initialization_tasks_table *user_tasks; |
---|
| 1144 | |
---|
| 1145 | /* |
---|
| 1146 | * NOTE: This is slightly different from the Ada implementation. |
---|
| 1147 | */ |
---|
| 1148 | |
---|
| 1149 | user_tasks = _RTEMS_tasks_User_initialization_tasks; |
---|
| 1150 | maximum = _RTEMS_tasks_Number_of_initialization_tasks; |
---|
| 1151 | |
---|
[98849f44] | 1152 | if ( !user_tasks || maximum == 0 ) |
---|
| 1153 | return; |
---|
| 1154 | |
---|
[3a4ae6c] | 1155 | for ( index=0 ; index < maximum ; index++ ) { |
---|
| 1156 | return_value = rtems_task_create( |
---|
| 1157 | user_tasks[ index ].name, |
---|
| 1158 | user_tasks[ index ].initial_priority, |
---|
| 1159 | user_tasks[ index ].stack_size, |
---|
| 1160 | user_tasks[ index ].mode_set, |
---|
| 1161 | user_tasks[ index ].attribute_set, |
---|
| 1162 | &id |
---|
| 1163 | ); |
---|
| 1164 | |
---|
| 1165 | if ( !rtems_is_status_successful( return_value ) ) |
---|
| 1166 | _Internal_error_Occurred( INTERNAL_ERROR_RTEMS_API, TRUE, return_value ); |
---|
| 1167 | |
---|
| 1168 | return_value = rtems_task_start( |
---|
| 1169 | id, |
---|
| 1170 | user_tasks[ index ].entry_point, |
---|
| 1171 | user_tasks[ index ].argument |
---|
| 1172 | ); |
---|
| 1173 | |
---|
| 1174 | if ( !rtems_is_status_successful( return_value ) ) |
---|
| 1175 | _Internal_error_Occurred( INTERNAL_ERROR_RTEMS_API, TRUE, return_value ); |
---|
| 1176 | } |
---|
| 1177 | } |
---|
| 1178 | |
---|