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 | |
---|
24 | #include <rtems/itron/task.h> |
---|
25 | |
---|
26 | /* |
---|
27 | * _ITRON_Task_Create_extension |
---|
28 | * |
---|
29 | * This routine is an extension routine that is invoked as part |
---|
30 | * of creating any type of task or thread in the system. If the |
---|
31 | * task is created via another API, then this routine is invoked |
---|
32 | * and this API given the opportunity to initialize its extension |
---|
33 | * area. |
---|
34 | */ |
---|
35 | |
---|
36 | boolean _ITRON_Task_Create_extension( |
---|
37 | Thread_Control *executing, |
---|
38 | Thread_Control *created |
---|
39 | ) |
---|
40 | { |
---|
41 | ITRON_API_Control *api; |
---|
42 | |
---|
43 | api = _Workspace_Allocate( sizeof( ITRON_API_Control ) ); |
---|
44 | |
---|
45 | if ( !api ) |
---|
46 | return FALSE; |
---|
47 | |
---|
48 | created->API_Extensions[ THREAD_API_ITRON ] = api; |
---|
49 | |
---|
50 | /* |
---|
51 | * Initialize the ITRON API extension |
---|
52 | */ |
---|
53 | |
---|
54 | return TRUE; |
---|
55 | } |
---|
56 | |
---|
57 | /* |
---|
58 | * _ITRON_Task_Delete_extension |
---|
59 | * |
---|
60 | * This extension routine is invoked when a task is deleted. |
---|
61 | */ |
---|
62 | |
---|
63 | User_extensions_routine _ITRON_Task_Delete_extension( |
---|
64 | Thread_Control *executing, |
---|
65 | Thread_Control *deleted |
---|
66 | ) |
---|
67 | { |
---|
68 | (void) _Workspace_Free( deleted->API_Extensions[ THREAD_API_ITRON ] ); |
---|
69 | |
---|
70 | deleted->API_Extensions[ THREAD_API_ITRON ] = NULL; |
---|
71 | } |
---|
72 | |
---|
73 | /* |
---|
74 | * _ITRON_Task_Initialize_user_tasks |
---|
75 | * |
---|
76 | * This routine creates and starts all configured user |
---|
77 | * initialzation threads. |
---|
78 | */ |
---|
79 | |
---|
80 | void _ITRON_Task_Initialize_user_tasks( void ) |
---|
81 | { |
---|
82 | extern void (*_ITRON_Initialize_user_tasks_p)(void); |
---|
83 | if ( _ITRON_Initialize_user_tasks_p ) |
---|
84 | (*_ITRON_Initialize_user_tasks_p)(); |
---|
85 | } |
---|
86 | |
---|
87 | /*PAGE |
---|
88 | * |
---|
89 | * _ITRON_Delete_task |
---|
90 | */ |
---|
91 | |
---|
92 | ER _ITRON_Delete_task( |
---|
93 | Thread_Control *the_thread |
---|
94 | ) |
---|
95 | { |
---|
96 | Objects_Information *the_information; |
---|
97 | |
---|
98 | the_information = _Objects_Get_information_id( the_thread->Object.id ); |
---|
99 | if ( !the_information ) { |
---|
100 | return E_OBJ; /* XXX - should never happen */ |
---|
101 | } |
---|
102 | |
---|
103 | _Thread_Close( the_information, the_thread ); |
---|
104 | |
---|
105 | _ITRON_Task_Free( the_thread ); |
---|
106 | |
---|
107 | return E_OK; |
---|
108 | } |
---|
109 | |
---|
110 | /* |
---|
111 | * At this point in time, the ITRON API does not need any other |
---|
112 | * extensions. See the POSIX and RTEMS API extensions for |
---|
113 | * examples of how they can be used. |
---|
114 | */ |
---|
115 | |
---|
116 | /* |
---|
117 | * Extension Tables |
---|
118 | */ |
---|
119 | |
---|
120 | API_extensions_Control _ITRON_Task_API_extensions = { |
---|
121 | { NULL, NULL }, |
---|
122 | NULL, /* predriver */ |
---|
123 | _ITRON_Task_Initialize_user_tasks, /* postdriver */ |
---|
124 | NULL /* post switch */ |
---|
125 | }; |
---|
126 | |
---|
127 | User_extensions_Control _ITRON_Task_User_extensions = { |
---|
128 | { NULL, NULL }, |
---|
129 | { { NULL, NULL }, NULL }, |
---|
130 | { _ITRON_Task_Create_extension, /* create */ |
---|
131 | NULL, /* start */ |
---|
132 | NULL, /* restart */ |
---|
133 | _ITRON_Task_Delete_extension, /* delete */ |
---|
134 | NULL, /* switch */ |
---|
135 | NULL, /* begin */ |
---|
136 | NULL, /* exitted */ |
---|
137 | NULL /* fatal */ |
---|
138 | } |
---|
139 | }; |
---|
140 | |
---|
141 | /* |
---|
142 | * _ITRON_Task_Manager_initialization |
---|
143 | * |
---|
144 | * This routine initializes all Task Manager related data structures. |
---|
145 | * |
---|
146 | * Input parameters: |
---|
147 | * maximum_tasks - number of tasks to initialize |
---|
148 | * |
---|
149 | * Output parameters: NONE |
---|
150 | */ |
---|
151 | |
---|
152 | void _ITRON_Task_Manager_initialization( |
---|
153 | uint32_t maximum_tasks, |
---|
154 | uint32_t number_of_initialization_tasks, |
---|
155 | itron_initialization_tasks_table *user_tasks |
---|
156 | ) |
---|
157 | { |
---|
158 | |
---|
159 | _ITRON_Task_Number_of_initialization_tasks = number_of_initialization_tasks; |
---|
160 | _ITRON_Task_User_initialization_tasks = user_tasks; |
---|
161 | |
---|
162 | /* |
---|
163 | * There may not be any ITRON_initialization tasks configured. |
---|
164 | */ |
---|
165 | |
---|
166 | #if 0 |
---|
167 | if ( user_tasks == NULL || number_of_initialization_tasks == 0 ) |
---|
168 | _Internal_error_Occurred( INTERNAL_ERROR_ITRON_API, TRUE, -1 ); |
---|
169 | #endif |
---|
170 | |
---|
171 | _Objects_Initialize_information( |
---|
172 | &_ITRON_Task_Information, /* object information table */ |
---|
173 | OBJECTS_ITRON_API, /* object API */ |
---|
174 | OBJECTS_ITRON_TASKS, /* object class */ |
---|
175 | maximum_tasks, /* maximum objects of this class */ |
---|
176 | sizeof( Thread_Control ), /* size of this object's control block */ |
---|
177 | FALSE, /* TRUE if names for this object are strings */ |
---|
178 | ITRON_MAXIMUM_NAME_LENGTH /* maximum length of each object's name */ |
---|
179 | #if defined(RTEMS_MULTIPROCESSING) |
---|
180 | , |
---|
181 | FALSE, /* TRUE if this is a global object class */ |
---|
182 | NULL /* Proxy extraction support callout */ |
---|
183 | #endif |
---|
184 | ); |
---|
185 | |
---|
186 | /* |
---|
187 | * Add all the extensions for this API |
---|
188 | */ |
---|
189 | |
---|
190 | _User_extensions_Add_API_set( &_ITRON_Task_User_extensions ); |
---|
191 | |
---|
192 | _API_extensions_Add( &_ITRON_Task_API_extensions ); |
---|
193 | |
---|
194 | /* |
---|
195 | * XXX MP not supported |
---|
196 | * Register the MP Process Packet routine. |
---|
197 | */ |
---|
198 | |
---|
199 | } |
---|