summaryrefslogtreecommitdiffstats
path: root/cpukit/itron/src/task.c
blob: c4e785a4bbfef4db132ba99eb3ccb3b9f9180e4c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.OARcorp.com/rtems/license.html.
 *
 *  $Id$
 */

#include <itron.h>

#include <rtems/score/thread.h>
#include <rtems/score/userext.h>
#include <rtems/score/wkspace.h>
#include <rtems/score/apiext.h>
#include <rtems/score/sysstate.h>

#include <rtems/itron/task.h>

/*
 *  _ITRON_Task_Create_extension
 *
 *  This routine is an extension routine that is invoked as part
 *  of creating any type of task or thread in the system.  If the
 *  task is created via another API, then this routine is invoked
 *  and this API given the opportunity to initialize its extension
 *  area.
 */

boolean _ITRON_Task_Create_extension(
  Thread_Control *executing,
  Thread_Control *created
)
{
  ITRON_API_Control *api;

  api = _Workspace_Allocate( sizeof( ITRON_API_Control ) );

  if ( !api )
    return FALSE;

  created->API_Extensions[ THREAD_API_ITRON ] = api;

  /*
   *  Initialize the ITRON API extension
   */

  return TRUE;
}

/*
 *  _ITRON_Task_Delete_extension
 *
 *  This extension routine is invoked when a task is deleted.
 */

User_extensions_routine _ITRON_Task_Delete_extension(
  Thread_Control *executing,
  Thread_Control *deleted
)
{
  (void) _Workspace_Free( deleted->API_Extensions[ THREAD_API_ITRON ] );
 
  deleted->API_Extensions[ THREAD_API_ITRON ] = NULL;
}

/*
 *  _ITRON_Task_Initialize_user_tasks
 *
 *  This routine creates and starts all configured user
 *  initialzation threads.
 */

void _ITRON_Task_Initialize_user_tasks( void )
{
  unsigned32                        index;
  unsigned32                        maximum;
  ER                                return_value;
  itron_initialization_tasks_table *user_tasks;

  /*
   *  NOTE:  This is slightly different from the Ada implementation.
   */

  user_tasks = _ITRON_Task_User_initialization_tasks;
  maximum    = _ITRON_Task_Number_of_initialization_tasks;

  if ( !user_tasks || maximum == 0 )
    return;

  for ( index=0 ; index < maximum ; index++ ) {
    
    return_value = cre_tsk(
       user_tasks[ index ].id,
       &user_tasks[ index ].attributes
    );

    if ( return_value != E_OK )
      _Internal_error_Occurred( INTERNAL_ERROR_ITRON_API, TRUE, return_value );

    return_value = sta_tsk( user_tasks[ index ].id, 0 );

    if ( return_value != E_OK )
      _Internal_error_Occurred( INTERNAL_ERROR_ITRON_API, TRUE, return_value );

  }
}

/*PAGE
 *
 *  _ITRON_Delete_task
 */

ER _ITRON_Delete_task(
  Thread_Control *the_thread
)
{
  Objects_Information     *the_information;

  the_information = _Objects_Get_information( the_thread->Object.id );
  if ( !the_information ) {
    return E_OBJ;             /* XXX - should never happen */
  }

  _Thread_Close( the_information, the_thread );

  _ITRON_Task_Free( the_thread );

  return E_OK;
}

/*
 *  At this point in time, the ITRON API does not need any other 
 *  extensions.  See the POSIX and RTEMS API extensions for 
 *  examples of how they can be used.
 */

/*
 *  Extension Tables
 */

API_extensions_Control _ITRON_Task_API_extensions = {
  { NULL, NULL },
  NULL,                                     /* predriver */
  _ITRON_Task_Initialize_user_tasks,       /* postdriver */
  NULL                                      /* post switch */
};

User_extensions_Control _ITRON_Task_User_extensions = {
  { NULL, NULL },
  { _ITRON_Task_Create_extension,             /* create */
    NULL,                                     /* start */
    NULL,                                     /* restart */
    _ITRON_Task_Delete_extension,             /* delete */
    NULL,                                     /* switch */
    NULL,                                     /* begin */
    NULL,                                     /* exitted */
    NULL                                      /* fatal */
  }
};

/*
 *  _ITRON_Task_Manager_initialization
 *
 *  This routine initializes all Task Manager related data structures.
 *
 *  Input parameters:
 *    maximum_tasks       - number of tasks to initialize
 *
 *  Output parameters:  NONE
 */

void _ITRON_Task_Manager_initialization(
  unsigned32                        maximum_tasks,
  unsigned32                        number_of_initialization_tasks,
  itron_initialization_tasks_table *user_tasks
)
{

  _ITRON_Task_Number_of_initialization_tasks = number_of_initialization_tasks;
  _ITRON_Task_User_initialization_tasks = user_tasks;

  /*
   *  There may not be any ITRON_initialization tasks configured.
   */

#if 0
  if ( user_tasks == NULL || number_of_initialization_tasks == 0 )
    _Internal_error_Occurred( INTERNAL_ERROR_ITRON_API, TRUE, -1 );
#endif

  _Objects_Initialize_information(
    &_ITRON_Task_Information,   /* object information table */
    OBJECTS_ITRON_TASKS,        /* object class */
    FALSE,                      /* TRUE if this is a global object class */
    maximum_tasks,              /* maximum objects of this class */
    sizeof( Thread_Control ),   /* size of this object's control block */
    FALSE,                      /* TRUE if names for this object are strings */
    ITRON_MAXIMUM_NAME_LENGTH,  /* maximum length of each object's name */
    TRUE                        /* TRUE if this class is threads */
  );

  /*
   *  Add all the extensions for this API
   */

  _User_extensions_Add_API_set( &_ITRON_Task_User_extensions );

  _API_extensions_Add( &_ITRON_Task_API_extensions );

  /*
   *  XXX MP not supported
   *  Register the MP Process Packet routine.
   */

}