1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Task API Extensions |
---|
5 | * @ingroup ClassicTasks |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2009. |
---|
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.com/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/system.h> |
---|
22 | #include <rtems/config.h> |
---|
23 | #include <rtems/rtems/asrimpl.h> |
---|
24 | #include <rtems/rtems/eventimpl.h> |
---|
25 | #include <rtems/rtems/status.h> |
---|
26 | #include <rtems/rtems/support.h> |
---|
27 | #include <rtems/rtems/modes.h> |
---|
28 | #include <rtems/score/stack.h> |
---|
29 | #include <rtems/rtems/tasksimpl.h> |
---|
30 | #include <rtems/score/thread.h> |
---|
31 | #include <rtems/score/userextimpl.h> |
---|
32 | #include <rtems/score/wkspace.h> |
---|
33 | #include <rtems/score/apiext.h> |
---|
34 | |
---|
35 | /* |
---|
36 | * _RTEMS_tasks_Create_extension |
---|
37 | * |
---|
38 | * This routine is an extension routine that is invoked as part |
---|
39 | * of creating any type of task or thread in the system. If the |
---|
40 | * task is created via another API, then this routine is invoked |
---|
41 | * and this API given the opportunity to initialize its extension |
---|
42 | * area. |
---|
43 | */ |
---|
44 | |
---|
45 | static bool _RTEMS_tasks_Create_extension( |
---|
46 | Thread_Control *executing, |
---|
47 | Thread_Control *created |
---|
48 | ) |
---|
49 | { |
---|
50 | RTEMS_API_Control *api; |
---|
51 | int i; |
---|
52 | size_t to_allocate; |
---|
53 | |
---|
54 | /* |
---|
55 | * Notepads must be the last entry in the structure and they |
---|
56 | * can be left off if disabled in the configuration. |
---|
57 | */ |
---|
58 | to_allocate = sizeof( RTEMS_API_Control ); |
---|
59 | if ( !rtems_configuration_get_notepads_enabled() ) |
---|
60 | to_allocate -= (RTEMS_NUMBER_NOTEPADS * sizeof(uint32_t)); |
---|
61 | |
---|
62 | api = _Workspace_Allocate( to_allocate ); |
---|
63 | |
---|
64 | if ( !api ) |
---|
65 | return false; |
---|
66 | |
---|
67 | created->API_Extensions[ THREAD_API_RTEMS ] = api; |
---|
68 | |
---|
69 | _Event_Initialize( &api->Event ); |
---|
70 | _Event_Initialize( &api->System_event ); |
---|
71 | _ASR_Initialize( &api->Signal ); |
---|
72 | created->task_variables = NULL; |
---|
73 | |
---|
74 | if ( rtems_configuration_get_notepads_enabled() ) { |
---|
75 | for (i=0; i < RTEMS_NUMBER_NOTEPADS; i++) |
---|
76 | api->Notepads[i] = 0; |
---|
77 | } |
---|
78 | |
---|
79 | return true; |
---|
80 | } |
---|
81 | |
---|
82 | /* |
---|
83 | * _RTEMS_tasks_Start_extension |
---|
84 | * |
---|
85 | * This extension routine is invoked when a task is started for the |
---|
86 | * first time. |
---|
87 | */ |
---|
88 | |
---|
89 | static void _RTEMS_tasks_Start_extension( |
---|
90 | Thread_Control *executing, |
---|
91 | Thread_Control *started |
---|
92 | ) |
---|
93 | { |
---|
94 | RTEMS_API_Control *api; |
---|
95 | |
---|
96 | api = started->API_Extensions[ THREAD_API_RTEMS ]; |
---|
97 | |
---|
98 | _Event_Initialize( &api->Event ); |
---|
99 | _Event_Initialize( &api->System_event ); |
---|
100 | } |
---|
101 | |
---|
102 | /* |
---|
103 | * _RTEMS_tasks_Delete_extension |
---|
104 | * |
---|
105 | * This extension routine is invoked when a task is deleted. |
---|
106 | */ |
---|
107 | |
---|
108 | static void _RTEMS_tasks_Delete_extension( |
---|
109 | Thread_Control *executing, |
---|
110 | Thread_Control *deleted |
---|
111 | ) |
---|
112 | { |
---|
113 | rtems_task_variable_t *tvp, *next; |
---|
114 | |
---|
115 | /* |
---|
116 | * Free per task variable memory |
---|
117 | */ |
---|
118 | |
---|
119 | tvp = deleted->task_variables; |
---|
120 | deleted->task_variables = NULL; |
---|
121 | while (tvp) { |
---|
122 | next = (rtems_task_variable_t *)tvp->next; |
---|
123 | _RTEMS_Tasks_Invoke_task_variable_dtor( deleted, tvp ); |
---|
124 | tvp = next; |
---|
125 | } |
---|
126 | |
---|
127 | /* |
---|
128 | * Free API specific memory |
---|
129 | */ |
---|
130 | |
---|
131 | (void) _Workspace_Free( deleted->API_Extensions[ THREAD_API_RTEMS ] ); |
---|
132 | deleted->API_Extensions[ THREAD_API_RTEMS ] = NULL; |
---|
133 | } |
---|
134 | |
---|
135 | /* |
---|
136 | * _RTEMS_tasks_Switch_extension |
---|
137 | * |
---|
138 | * This extension routine is invoked at each context switch. |
---|
139 | */ |
---|
140 | |
---|
141 | static void _RTEMS_tasks_Switch_extension( |
---|
142 | Thread_Control *executing, |
---|
143 | Thread_Control *heir |
---|
144 | ) |
---|
145 | { |
---|
146 | rtems_task_variable_t *tvp; |
---|
147 | |
---|
148 | /* |
---|
149 | * Per Task Variables |
---|
150 | */ |
---|
151 | |
---|
152 | tvp = executing->task_variables; |
---|
153 | while (tvp) { |
---|
154 | tvp->tval = *tvp->ptr; |
---|
155 | *tvp->ptr = tvp->gval; |
---|
156 | tvp = (rtems_task_variable_t *)tvp->next; |
---|
157 | } |
---|
158 | |
---|
159 | tvp = heir->task_variables; |
---|
160 | while (tvp) { |
---|
161 | tvp->gval = *tvp->ptr; |
---|
162 | *tvp->ptr = tvp->tval; |
---|
163 | tvp = (rtems_task_variable_t *)tvp->next; |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | API_extensions_Control _RTEMS_tasks_API_extensions = { |
---|
168 | #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API) |
---|
169 | .predriver_hook = NULL, |
---|
170 | #endif |
---|
171 | .postdriver_hook = _RTEMS_tasks_Initialize_user_tasks |
---|
172 | }; |
---|
173 | |
---|
174 | User_extensions_Control _RTEMS_tasks_User_extensions = { |
---|
175 | { NULL, NULL }, |
---|
176 | { { NULL, NULL }, _RTEMS_tasks_Switch_extension }, |
---|
177 | { _RTEMS_tasks_Create_extension, /* create */ |
---|
178 | _RTEMS_tasks_Start_extension, /* start */ |
---|
179 | _RTEMS_tasks_Start_extension, /* restart */ |
---|
180 | _RTEMS_tasks_Delete_extension, /* delete */ |
---|
181 | _RTEMS_tasks_Switch_extension, /* switch */ |
---|
182 | NULL, /* begin */ |
---|
183 | NULL, /* exitted */ |
---|
184 | NULL /* fatal */ |
---|
185 | } |
---|
186 | }; |
---|
187 | |
---|
188 | void _RTEMS_tasks_Manager_initialization(void) |
---|
189 | { |
---|
190 | _Objects_Initialize_information( |
---|
191 | &_RTEMS_tasks_Information, /* object information table */ |
---|
192 | OBJECTS_CLASSIC_API, /* object API */ |
---|
193 | OBJECTS_RTEMS_TASKS, /* object class */ |
---|
194 | Configuration_RTEMS_API.maximum_tasks, |
---|
195 | /* maximum objects of this class */ |
---|
196 | sizeof( Thread_Control ), /* size of this object's control block */ |
---|
197 | false, /* true if the name is a string */ |
---|
198 | RTEMS_MAXIMUM_NAME_LENGTH /* maximum length of an object name */ |
---|
199 | #if defined(RTEMS_MULTIPROCESSING) |
---|
200 | , |
---|
201 | true, /* true if this is a global object class */ |
---|
202 | NULL /* Proxy extraction support callout */ |
---|
203 | #endif |
---|
204 | ); |
---|
205 | |
---|
206 | /* |
---|
207 | * Add all the extensions for this API |
---|
208 | */ |
---|
209 | |
---|
210 | _User_extensions_Add_API_set( &_RTEMS_tasks_User_extensions ); |
---|
211 | |
---|
212 | _API_extensions_Add( &_RTEMS_tasks_API_extensions ); |
---|
213 | |
---|
214 | /* |
---|
215 | * Register the MP Process Packet routine. |
---|
216 | */ |
---|
217 | |
---|
218 | #if defined(RTEMS_MULTIPROCESSING) |
---|
219 | _MPCI_Register_packet_processor( |
---|
220 | MP_PACKET_TASKS, |
---|
221 | _RTEMS_tasks_MP_Process_packet |
---|
222 | ); |
---|
223 | #endif |
---|
224 | |
---|
225 | } |
---|
226 | |
---|
227 | void _RTEMS_tasks_Initialize_user_tasks( void ) |
---|
228 | { |
---|
229 | if ( _RTEMS_tasks_Initialize_user_tasks_p ) |
---|
230 | (*_RTEMS_tasks_Initialize_user_tasks_p)(); |
---|
231 | } |
---|