1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Start Task |
---|
5 | * @ingroup ClassicTasks Tasks |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2014. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/rtems/tasks.h> |
---|
22 | #include <rtems/score/threadimpl.h> |
---|
23 | |
---|
24 | /* |
---|
25 | * rtems_task_start |
---|
26 | * |
---|
27 | * This directive readies the thread identified by the "id" |
---|
28 | * based on its current priorty, to await execution. A thread |
---|
29 | * can be started only from the dormant state. |
---|
30 | * |
---|
31 | * Input parameters: |
---|
32 | * id - thread id |
---|
33 | * entry_point - start execution address of thread |
---|
34 | * argument - thread argument |
---|
35 | * |
---|
36 | * Output parameters: |
---|
37 | * RTEMS_SUCCESSFUL - if successful |
---|
38 | * error code - if unsuccessful |
---|
39 | */ |
---|
40 | |
---|
41 | rtems_status_code rtems_task_start( |
---|
42 | rtems_id id, |
---|
43 | rtems_task_entry entry_point, |
---|
44 | rtems_task_argument argument |
---|
45 | ) |
---|
46 | { |
---|
47 | Thread_Entry_information entry = { |
---|
48 | .adaptor = _Thread_Entry_adaptor_numeric, |
---|
49 | .Kinds = { |
---|
50 | .Numeric = { |
---|
51 | .entry = entry_point, |
---|
52 | .argument = argument |
---|
53 | } |
---|
54 | } |
---|
55 | }; |
---|
56 | Thread_Control *the_thread; |
---|
57 | Objects_Locations location; |
---|
58 | bool successfully_started; |
---|
59 | |
---|
60 | if ( entry_point == NULL ) |
---|
61 | return RTEMS_INVALID_ADDRESS; |
---|
62 | |
---|
63 | the_thread = _Thread_Get( id, &location ); |
---|
64 | switch ( location ) { |
---|
65 | |
---|
66 | case OBJECTS_LOCAL: |
---|
67 | successfully_started = _Thread_Start( the_thread, &entry, NULL ); |
---|
68 | |
---|
69 | _Objects_Put( &the_thread->Object ); |
---|
70 | |
---|
71 | if ( successfully_started ) { |
---|
72 | return RTEMS_SUCCESSFUL; |
---|
73 | } else { |
---|
74 | return RTEMS_INCORRECT_STATE; |
---|
75 | } |
---|
76 | |
---|
77 | #if defined(RTEMS_MULTIPROCESSING) |
---|
78 | case OBJECTS_REMOTE: |
---|
79 | _Thread_Dispatch(); |
---|
80 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
81 | #endif |
---|
82 | |
---|
83 | case OBJECTS_ERROR: |
---|
84 | break; |
---|
85 | } |
---|
86 | |
---|
87 | return RTEMS_INVALID_ID; |
---|
88 | } |
---|