1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2008. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.com/license/LICENSE. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #if HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <rtems/itron.h> |
---|
17 | |
---|
18 | #include <rtems/score/thread.h> |
---|
19 | #include <rtems/score/userext.h> |
---|
20 | #include <rtems/score/wkspace.h> |
---|
21 | #include <rtems/score/apiext.h> |
---|
22 | #include <rtems/score/sysstate.h> |
---|
23 | #include <rtems/score/apimutex.h> |
---|
24 | |
---|
25 | #include <rtems/itron/task.h> |
---|
26 | |
---|
27 | |
---|
28 | /* |
---|
29 | * cre_tsk - Create Task |
---|
30 | */ |
---|
31 | |
---|
32 | ER cre_tsk( |
---|
33 | ID tskid, |
---|
34 | T_CTSK *pk_ctsk |
---|
35 | ) |
---|
36 | { |
---|
37 | register Thread_Control *the_thread; |
---|
38 | bool status; |
---|
39 | Priority_Control core_priority; |
---|
40 | Objects_Name name; |
---|
41 | |
---|
42 | /* |
---|
43 | * Validate Parameters. |
---|
44 | */ |
---|
45 | |
---|
46 | if ( pk_ctsk == NULL ) |
---|
47 | return E_PAR; |
---|
48 | |
---|
49 | if ((pk_ctsk->tskatr != TA_ASM ) && |
---|
50 | (pk_ctsk->tskatr != TA_HLNG) && |
---|
51 | (pk_ctsk->tskatr != TA_COP0) && |
---|
52 | (pk_ctsk->tskatr != TA_COP1) && |
---|
53 | (pk_ctsk->tskatr != TA_COP2) && |
---|
54 | (pk_ctsk->tskatr != TA_COP3) && |
---|
55 | (pk_ctsk->tskatr != TA_COP4) && |
---|
56 | (pk_ctsk->tskatr != TA_COP5) && |
---|
57 | (pk_ctsk->tskatr != TA_COP6) && |
---|
58 | (pk_ctsk->tskatr != TA_COP7)) |
---|
59 | return E_RSATR; |
---|
60 | |
---|
61 | if (( pk_ctsk->itskpri <= 0 ) || ( pk_ctsk->itskpri >= 256 )) |
---|
62 | return E_PAR; |
---|
63 | if ( pk_ctsk->task == NULL ) |
---|
64 | return E_PAR; |
---|
65 | if ( pk_ctsk->stksz < 0 ) |
---|
66 | return E_PAR; |
---|
67 | |
---|
68 | /* |
---|
69 | * Lock the allocator mutex for protection |
---|
70 | */ |
---|
71 | _RTEMS_Lock_allocator(); |
---|
72 | |
---|
73 | /* |
---|
74 | * allocate the thread. |
---|
75 | */ |
---|
76 | |
---|
77 | the_thread = _ITRON_Task_Allocate( tskid ); |
---|
78 | if ( !the_thread ) { |
---|
79 | _RTEMS_Unlock_allocator(); |
---|
80 | return _ITRON_Task_Clarify_allocation_id_error( tskid ); |
---|
81 | } |
---|
82 | |
---|
83 | /* |
---|
84 | * Initialize the core thread for this task. |
---|
85 | */ |
---|
86 | |
---|
87 | name.name_u32 = 0; |
---|
88 | core_priority = _ITRON_Task_Priority_to_Core( pk_ctsk->itskpri ); |
---|
89 | status = _Thread_Initialize( |
---|
90 | &_ITRON_Task_Information, |
---|
91 | the_thread, |
---|
92 | NULL, |
---|
93 | pk_ctsk->stksz, |
---|
94 | #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) |
---|
95 | TRUE, /* XXX - All tasks FP (if the HW supports it) for now */ |
---|
96 | #else |
---|
97 | FALSE, |
---|
98 | #endif |
---|
99 | core_priority, |
---|
100 | TRUE, /* preemptible */ |
---|
101 | THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE, |
---|
102 | NULL, /* no budget algorithm callout */ |
---|
103 | 0, |
---|
104 | name |
---|
105 | ); |
---|
106 | |
---|
107 | if ( !status ) { |
---|
108 | _ITRON_Task_Free( the_thread ); |
---|
109 | _RTEMS_Unlock_allocator(); |
---|
110 | return E_NOMEM; |
---|
111 | } |
---|
112 | |
---|
113 | /* |
---|
114 | * This insures we evaluate the process-wide signals pending when we |
---|
115 | * first run. |
---|
116 | * |
---|
117 | * NOTE: Since the thread starts with all unblocked, this is necessary. |
---|
118 | */ |
---|
119 | |
---|
120 | the_thread->do_post_task_switch_extension = true; |
---|
121 | |
---|
122 | the_thread->Start.entry_point = (Thread_Entry) pk_ctsk->task; |
---|
123 | |
---|
124 | _RTEMS_Unlock_allocator(); |
---|
125 | return E_OK; |
---|
126 | } |
---|