source: rtems/cpukit/itron/src/task.c @ eb02f47

4.104.114.84.95
Last change on this file since eb02f47 was eb02f47, checked in by Joel Sherrill <joel.sherrill@…>, on 11/10/99 at 13:48:27

Committed modifications from ITRON Task and Task Dependendent Synchronization
Working Group. Included are tests.

  • Property mode set to 100644
File size: 5.4 KB
Line 
1/*
2 *  The license and distribution terms for this file may be
3 *  found in the file LICENSE in this distribution or at
4 *  http://www.OARcorp.com/rtems/license.html.
5 *
6 *  $Id$
7 */
8
9#include <itron.h>
10
11#include <rtems/score/thread.h>
12#include <rtems/score/userext.h>
13#include <rtems/score/wkspace.h>
14#include <rtems/score/apiext.h>
15#include <rtems/score/sysstate.h>
16
17#include <rtems/itron/task.h>
18
19/*
20 *  _ITRON_Task_Create_extension
21 *
22 *  This routine is an extension routine that is invoked as part
23 *  of creating any type of task or thread in the system.  If the
24 *  task is created via another API, then this routine is invoked
25 *  and this API given the opportunity to initialize its extension
26 *  area.
27 */
28
29boolean _ITRON_Task_Create_extension(
30  Thread_Control *executing,
31  Thread_Control *created
32)
33{
34  ITRON_API_Control *api;
35
36  api = _Workspace_Allocate( sizeof( ITRON_API_Control ) );
37
38  if ( !api )
39    return FALSE;
40
41  created->API_Extensions[ THREAD_API_ITRON ] = api;
42
43  /*
44   *  Initialize the ITRON API extension
45   */
46
47  return TRUE;
48}
49
50/*
51 *  _ITRON_Task_Delete_extension
52 *
53 *  This extension routine is invoked when a task is deleted.
54 */
55
56User_extensions_routine _ITRON_Task_Delete_extension(
57  Thread_Control *executing,
58  Thread_Control *deleted
59)
60{
61  (void) _Workspace_Free( deleted->API_Extensions[ THREAD_API_ITRON ] );
62 
63  deleted->API_Extensions[ THREAD_API_ITRON ] = NULL;
64}
65
66/*
67 *  _ITRON_Task_Initialize_user_tasks
68 *
69 *  This routine creates and starts all configured user
70 *  initialzation threads.
71 */
72
73void _ITRON_Task_Initialize_user_tasks( void )
74{
75  unsigned32                        index;
76  unsigned32                        maximum;
77  ER                                return_value;
78  itron_initialization_tasks_table *user_tasks;
79
80  /*
81   *  NOTE:  This is slightly different from the Ada implementation.
82   */
83
84  user_tasks = _ITRON_Task_User_initialization_tasks;
85  maximum    = _ITRON_Task_Number_of_initialization_tasks;
86
87  if ( !user_tasks || maximum == 0 )
88    return;
89
90  for ( index=0 ; index < maximum ; index++ ) {
91   
92    return_value = cre_tsk(
93       user_tasks[ index ].id,
94       &user_tasks[ index ].attributes
95    );
96
97    if ( return_value != E_OK )
98      _Internal_error_Occurred( INTERNAL_ERROR_ITRON_API, TRUE, return_value );
99
100    return_value = sta_tsk( user_tasks[ index ].id, 0 );
101
102    if ( return_value != E_OK )
103      _Internal_error_Occurred( INTERNAL_ERROR_ITRON_API, TRUE, return_value );
104
105  }
106}
107
108/*PAGE
109 *
110 *  _ITRON_Delete_task
111 */
112
113ER _ITRON_Delete_task(
114  Thread_Control *the_thread
115)
116{
117  Objects_Information     *the_information;
118
119  the_information = _Objects_Get_information( the_thread->Object.id );
120  if ( !the_information ) {
121    return E_OBJ;             /* XXX - should never happen */
122  }
123
124  _Thread_Close( the_information, the_thread );
125
126  _ITRON_Task_Free( the_thread );
127
128  return E_OK;
129}
130
131/*
132 *  At this point in time, the ITRON API does not need any other
133 *  extensions.  See the POSIX and RTEMS API extensions for
134 *  examples of how they can be used.
135 */
136
137/*
138 *  Extension Tables
139 */
140
141API_extensions_Control _ITRON_Task_API_extensions = {
142  { NULL, NULL },
143  NULL,                                     /* predriver */
144  _ITRON_Task_Initialize_user_tasks,       /* postdriver */
145  NULL                                      /* post switch */
146};
147
148User_extensions_Control _ITRON_Task_User_extensions = {
149  { NULL, NULL },
150  { _ITRON_Task_Create_extension,             /* create */
151    NULL,                                     /* start */
152    NULL,                                     /* restart */
153    _ITRON_Task_Delete_extension,             /* delete */
154    NULL,                                     /* switch */
155    NULL,                                     /* begin */
156    NULL,                                     /* exitted */
157    NULL                                      /* fatal */
158  }
159};
160
161/*
162 *  _ITRON_Task_Manager_initialization
163 *
164 *  This routine initializes all Task Manager related data structures.
165 *
166 *  Input parameters:
167 *    maximum_tasks       - number of tasks to initialize
168 *
169 *  Output parameters:  NONE
170 */
171
172void _ITRON_Task_Manager_initialization(
173  unsigned32                        maximum_tasks,
174  unsigned32                        number_of_initialization_tasks,
175  itron_initialization_tasks_table *user_tasks
176)
177{
178
179  _ITRON_Task_Number_of_initialization_tasks = number_of_initialization_tasks;
180  _ITRON_Task_User_initialization_tasks = user_tasks;
181
182  /*
183   *  There may not be any ITRON_initialization tasks configured.
184   */
185
186#if 0
187  if ( user_tasks == NULL || number_of_initialization_tasks == 0 )
188    _Internal_error_Occurred( INTERNAL_ERROR_ITRON_API, TRUE, -1 );
189#endif
190
191  _Objects_Initialize_information(
192    &_ITRON_Task_Information,   /* object information table */
193    OBJECTS_ITRON_TASKS,        /* object class */
194    FALSE,                      /* TRUE if this is a global object class */
195    maximum_tasks,              /* maximum objects of this class */
196    sizeof( Thread_Control ),   /* size of this object's control block */
197    FALSE,                      /* TRUE if names for this object are strings */
198    ITRON_MAXIMUM_NAME_LENGTH,  /* maximum length of each object's name */
199    TRUE                        /* TRUE if this class is threads */
200  );
201
202  /*
203   *  Add all the extensions for this API
204   */
205
206  _User_extensions_Add_API_set( &_ITRON_Task_User_extensions );
207
208  _API_extensions_Add( &_ITRON_Task_API_extensions );
209
210  /*
211   *  XXX MP not supported
212   *  Register the MP Process Packet routine.
213   */
214
215}
Note: See TracBrowser for help on using the repository browser.