source: rtems/cpukit/rtems/src/tasks.c @ f4d9ab3e

4.115
Last change on this file since f4d9ab3e was f4d9ab3e, checked in by Sebastian Huber <sebastian.huber@…>, on 07/23/13 at 09:33:56

rtems: Create asr implementation header

Move implementation specific parts of asr.h and asr.inl into new header
file asrimpl.h. The asr.h contains now only the application visible
API.

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