source: rtems/doc/user/userext.t @ 169502e

4.104.114.84.95
Last change on this file since 169502e was 169502e, checked in by Joel Sherrill <joel.sherrill@…>, on 10/11/99 at 19:03:05

Turned on concept and function name indexing.

  • Property mode set to 100644
File size: 20.8 KB
Line 
1@c
2@c  COPYRIGHT (c) 1988-1998.
3@c  On-Line Applications Research Corporation (OAR).
4@c  All rights reserved.
5@c
6@c  $Id$
7@c
8
9@chapter User Extensions Manager
10
11@cindex user extensions
12
13@section Introduction
14
15The RTEMS User Extensions Manager allows the
16application developer to augment the executive by allowing them
17to supply extension routines which are invoked at critical
18system events.  The directives provided by the user extensions
19manager are:
20
21@itemize @bullet
22@item @code{@value{DIRPREFIX}extension_create} - Create an extension set
23@item @code{@value{DIRPREFIX}extension_ident} - Get ID of an extension set
24@item @code{@value{DIRPREFIX}extension_delete} - Delete an extension set
25@end itemize
26
27@section Background
28
29User extension routines are invoked when the
30following system events occur:
31
32@itemize @bullet
33@item Task creation
34@item Task initiation
35@item Task reinitiation
36@item Task deletion
37@item Task context switch
38@item Post task context switch
39@item Task begin
40@item Task exits
41@item Fatal error detection
42@end itemize
43
44These extensions are invoked as a function with
45arguments that are appropriate to the system event.
46
47@subsection Extension Sets
48
49@cindex extension set
50
51An extension set is defined as a set of routines
52which are invoked at each of the critical system events at which
53user extension routines are invoked.  Together a set of these
54routines typically perform a specific functionality such as
55performance monitoring or debugger support.  RTEMS is informed of
56the entry points which constitute an extension set via the
57following @value{STRUCTURE}:
58
59@ifset is-C
60@example
61@group
62typedef struct @{
63  rtems_task_create_extension      thread_create;
64  rtems_task_start_extension       thread_start;
65  rtems_task_restart_extension     thread_restart;
66  rtems_task_delete_extension      thread_delete;
67  rtems_task_switch_extension      thread_switch;
68  rtems_task_begin_extension       thread_begin;
69  rtems_task_exitted_extension     thread_exitted;
70  rtems_fatal_extension            fatal;
71@} User_extensions_Table;
72@end group
73@end example
74@end ifset
75
76@ifset is-Ada
77@example
78type Extensions_Table is
79   record
80      Task_Create      : RTEMS.Task_Create_Extension;
81      Task_Start       : RTEMS.Task_Start_Extension;
82      Task_Restart     : RTEMS.Task_Restart_Extension;
83      Task_Delete      : RTEMS.Task_Delete_Extension;
84      Task_Switch      : RTEMS.Task_Switch_Extension;
85      Task_Post_Switch : RTEMS.Task_Post_Switch_Extension;
86      Task_Begin       : RTEMS.Task_Begin_Extension;
87      Task_Exitted     : RTEMS.Task_Exitted_Extension;
88      Fatal            : RTEMS.Fatal_Error_Extension;
89   end record;
90@end example
91@end ifset
92
93
94RTEMS allows the user to have multiple extension sets
95active at the same time.  First, a single static extension set
96may be defined as the application's User Extension Table which
97is included as part of the Configuration Table.  This extension
98set is active for the entire life of the system and may not be
99deleted.  This extension set is especially important because it
100is the only way the application can provided a FATAL error
101extension which is invoked if RTEMS fails during the
102initialize_executive directive.  The static extension set is
103optional and may be configured as NULL if no static extension
104set is required.
105
106Second, the user can install dynamic extensions using
107the @code{@value{DIRPREFIX}extension_create}
108directive.  These extensions are RTEMS
109objects in that they have a name, an ID, and can be dynamically
110created and deleted.  In contrast to the static extension set,
111these extensions can only be created and installed after the
112initialize_executive directive successfully completes execution.
113Dynamic extensions are useful for encapsulating the
114functionality of an extension set.  For example, the application
115could use extensions to manage a special coprocessor, do
116performance monitoring, and to do stack bounds checking.  Each
117of these extension sets could be written and installed
118independently of the others.
119
120All user extensions are optional and RTEMS places no
121naming  restrictions on the user.
122
123@subsection TCB Extension Area
124
125@cindex TCB extension area
126
127RTEMS provides for a pointer to a user-defined data
128area for each extension set to be linked to each task's control
129block.  This set of pointers is an extension of the TCB and can
130be used to store additional data required by the user's
131extension functions.  It is also possible for a user extension
132to utilize the notepad locations associated with each task
133although this may conflict with application usage of those
134particular notepads.
135
136The TCB extension is an array of pointers in the TCB.
137The number of pointers in the area is the same as the number of
138user extension sets configured.  This allows an application to
139augment the TCB with user-defined information.  For example, an
140application could implement task profiling by storing timing
141statistics in the TCB's extended memory area.  When a task
142context switch is being executed, the TASK_SWITCH extension
143could read a real-time clock to calculate how long the task
144being swapped out has run as well as timestamp the starting time
145for the task being swapped in.
146
147If used, the extended memory area for the TCB should
148be allocated and the TCB extension pointer should be set at the
149time the task is created or started by either the TASK_CREATE or
150TASK_START extension.  The application is responsible for
151managing this extended memory area for the TCBs.  The memory may
152be reinitialized by the TASK_RESTART extension and should be
153deallocated by the TASK_DELETE extension when the task is
154deleted.  Since the TCB extension buffers would most likely be
155of a fixed size, the RTEMS partition manager could be used to
156manage the application's extended memory area.  The application
157could create a partition of fixed size TCB extension buffers and
158use the partition manager's allocation and deallocation
159directives to obtain and release the extension buffers.
160
161@subsection Extensions
162
163The sections that follow will contain a description
164of each extension.  Each section will contain a prototype of a
165function with the appropriate calling sequence for the
166corresponding extension.  The names given for the @value{LANGUAGE}
167@value{ROUTINE} and
168its arguments are all defined by the user.  The names used in
169the examples were arbitrarily chosen and impose no naming
170conventions on the user.
171
172@subsection TASK_CREATE Extension
173
174The TASK_CREATE extension directly corresponds to the
175task_create directive.  If this extension is defined in any
176static or dynamic extension set and a task is being created,
177then the extension routine will automatically be invoked by
178RTEMS.  The extension should have a prototype similar to the
179following:
180
181@ifset is-C
182@example
183rtems_extension user_task_create(
184  rtems_tcb *current_task,
185  rtems_tcb *new_task
186);
187@end example
188@end ifset
189
190@ifset is-Ada
191@example
192procedure User_Task_Create (
193   Current_Task : in     RTEMS.TCB_Pointer;
194   New_Task     : in     RTEMS.TCB_Pointer
195);
196@end example
197@end ifset
198
199where current_task can be used to access the TCB for
200the currently executing task, and new_task can be used to access
201the TCB for the new task being created.  This extension is
202invoked from the task_create directive after new_task has been
203completely initialized, but before it is placed on a ready TCB
204chain.
205
206@subsection TASK_START Extension
207
208The TASK_START extension directly corresponds to the
209task_start directive.  If this extension is defined in any
210static or dynamic extension set and a task is being started,
211then the extension routine will automatically be invoked by
212RTEMS.  The extension should have a prototype similar to the
213following:
214
215@ifset is-C
216@example
217rtems_extension user_task_start(
218  rtems_tcb *current_task,
219  rtems_tcb *started_task
220);
221@end example
222@end ifset
223
224@ifset is-Ada
225@example
226procedure User_Task_Start (
227   Current_Task : in     RTEMS.TCB_Pointer;
228   Started_Task : in     RTEMS.TCB_Pointer
229);
230@end example
231@end ifset
232
233where current_task can be used to access the TCB for
234the currently executing task, and started_task can be used to
235access the TCB for the dormant task being started. This
236extension is invoked from the task_start directive after
237started_task has been made ready to start execution, but before
238it is placed on a ready TCB chain.
239
240@subsection TASK_RESTART Extension
241
242The TASK_RESTART extension directly corresponds to
243the task_restart directive.  If this extension is defined in any
244static or dynamic extension set and a task is being restarted,
245then the extension should have a prototype similar to the
246following:
247
248@ifset is-C
249@example
250rtems_extension user_task_restart(
251  rtems_tcb *current_task,
252  rtems_tcb *restarted_task
253);
254@end example
255@end ifset
256
257@ifset is-Ada
258@example
259procedure User_Task_Restart (
260   Current_Task   : in     RTEMS.TCB_Pointer;
261   Restarted_Task : in     RTEMS.TCB_Pointer
262);
263@end example
264@end ifset
265
266where current_task can be used to access the TCB for
267the currently executing task, and restarted_task can be used to
268access the TCB for the task being restarted. This extension is
269invoked from the task_restart directive after restarted_task has
270been made ready to start execution, but before it is placed on a
271ready TCB chain.
272
273@subsection TASK_DELETE Extension
274
275The TASK_DELETE extension is associated with the
276task_delete directive.  If this extension is defined in any
277static or dynamic extension set and a task is being deleted,
278then the extension routine will automatically be invoked by
279RTEMS.  The extension should have a prototype similar to the
280following:
281
282@ifset is-C
283@example
284rtems_extension user_task_delete(
285  rtems_tcb *current_task,
286  rtems_tcb *deleted_task
287);
288@end example
289@end ifset
290
291@ifset is-Ada
292@example
293procedure User_Task_Delete (
294   Current_Task : in     RTEMS.TCB_Pointer;
295   Deleted_Task : in     RTEMS.TCB_Pointer
296);
297@end example
298@end ifset
299
300where current_task can be used to access the TCB for
301the currently executing task, and deleted_task can be used to
302access the TCB for the task being deleted. This extension is
303invoked from the task_delete directive after the TCB has been
304removed from a ready TCB chain, but before all its resources
305including the TCB have been returned to their respective free
306pools.  This extension should not call any RTEMS directives if a
307task is deleting itself (current_task is equal to deleted_task).
308
309@subsection TASK_SWITCH Extension
310
311The TASK_SWITCH extension corresponds to a task
312context switch.  If this extension is defined in any static or
313dynamic extension set and a task context switch is in progress,
314then the extension routine will automatically be invoked by
315RTEMS.  The extension should have a prototype similar to the
316following:
317
318@ifset is-C
319@example
320rtems_extension user_task_switch(
321  rtems_tcb *current_task,
322  rtems_tcb *heir_task
323);
324@end example
325@end ifset
326
327@ifset is-Ada
328@example
329procedure User_Task_Switch (
330   Current_Task : in     RTEMS.TCB_Pointer;
331   Heir_Task    : in     RTEMS.TCB_Pointer
332);
333@end example
334@end ifset
335
336where current_task can be used to access the TCB for
337the task that is being swapped out, and heir_task can be used to
338access the TCB for the task being swapped in.  This extension is
339invoked from RTEMS' dispatcher routine after the current_task
340context has been saved, but before the heir_task context has
341been restored.  This extension should not call any RTEMS
342directives.
343
344@subsection TASK_BEGIN Extension
345
346The TASK_BEGIN extension is invoked when a task
347begins execution.  It is invoked immediately before the body of
348the starting procedure and executes in the context in the task.
349This user extension have a prototype similar to the following:
350
351@ifset is-C
352@example
353rtems_extension user_task_begin(
354  rtems_tcb *current_task
355);
356@end example
357@end ifset
358
359@ifset is-Ada
360@example
361procedure User_Task_Begin (
362   Current_Task : in     RTEMS.TCB_Pointer
363);
364@end example
365@end ifset
366
367where current_task can be used to access the TCB for
368the currently executing task which has begun.  The distinction
369between the TASK_BEGIN and TASK_START extension is that the
370TASK_BEGIN extension is executed in the context of the actual
371task while the TASK_START extension is executed in the context
372of the task performing the task_start directive.  For most
373extensions, this is not a critical distinction.
374
375@subsection TASK_EXITTED Extension
376
377The TASK_EXITTED extension is invoked when a task
378exits the body of the starting procedure by either an implicit
379or explicit return statement.  This user extension have a
380prototype similar to the following:
381
382@ifset is-C
383@example
384rtems_extension user_task_exitted(
385  rtems_tcb *current_task
386);
387@end example
388@end ifset
389
390@ifset is-Ada
391@example
392procedure User_Task_Exitted (
393   Current_Task : in     RTEMS.TCB_Pointer
394);
395@end example
396@end ifset
397
398where current_task can be used to access the TCB for
399the currently executing task which has just exitted.
400
401Although exiting of task is often considered to be a
402fatal error, this extension allows recovery by either restarting
403or deleting the exiting task.  If the user does not wish to
404recover, then a fatal error may be reported.  If the user does
405not provide a TASK_EXITTED extension or the provided handler
406returns control to RTEMS, then the RTEMS default handler will be
407used.  This default handler invokes the directive
408fatal_error_occurred with the @code{@value{RPREFIX}TASK_EXITTED} directive status.
409
410@lowersections
411
412@subsection FATAL Error Extension
413
414The FATAL error extension is associated with the
415fatal_error_occurred directive.  If this extension is defined in
416any static or dynamic extension set and the fatal_error_occurred
417directive has been invoked, then this extension will be called.
418This extension should have a prototype similar to the following:
419
420@ifset is-C
421@example
422rtems_extension user_fatal_error(
423  Internal_errors_Source  the_source,
424  rtems_boolean           is_internal,
425  rtems_unsigned32        the_error
426);
427@end example
428@end ifset
429
430@ifset is-Ada
431@example
432procedure User_Fatal_Error (
433   Error : in     RTEMS.Unsigned32
434);
435@end example
436@end ifset
437
438where the_error is the error code passed to the
439fatal_error_occurred directive. This extension is invoked from
440the fatal_error_occurred directive.
441
442If defined, the user's FATAL error extension is
443invoked before RTEMS' default fatal error routine is invoked and
444the processor is stopped.  For example, this extension could be
445used to pass control to a debugger when a fatal error occurs.
446This extension should not call any RTEMS directives.
447
448@raisesections
449
450@subsection Order of Invocation
451
452When one of the critical system events occur, the
453user extensions are invoked in either "forward" or "reverse"
454order.  Forward order indicates that the static extension set is
455invoked followed by the dynamic extension sets in the order in
456which they were created.  Reverse order means that the dynamic
457extension sets are invoked in the opposite of the order in which
458they were created followed by the static extension set.  By
459invoking the extension sets in this order, extensions can be
460built upon one another.  At the following system events, the
461extensions are invoked in forward order:
462
463@itemize @bullet
464@item Task creation
465@item Task initiation
466@item Task reinitiation
467@item Task deletion
468@item Task context switch
469@item Post task context switch
470@item Task begins to execute
471@end itemize
472
473
474At the following system events, the extensions are
475invoked in reverse order:
476
477@itemize @bullet
478@item Task deletion
479@item Fatal error detection
480@end itemize
481
482At these system events, the extensions are invoked in
483reverse order to insure that if an extension set is built upon
484another, the more complicated extension is invoked before the
485extension set it is built upon.  For example, by invoking the
486static extension set last it is known that the "system" fatal
487error extension will be the last fatal error extension executed.
488Another example is use of the task delete extension by the
489Standard C Library.  Extension sets which are installed after
490the Standard C Library will operate correctly even if they
491utilize the C Library because the C Library's TASK_DELETE
492extension is invoked after that of the other extensions.
493
494@section Operations
495
496@subsection Creating an Extension Set
497
498The @code{@value{DIRPREFIX}extension_create} directive creates and installs
499an extension set by allocating a Extension Set Control Block
500(ESCB), assigning the extension set a user-specified name, and
501assigning it an extension set ID.  Newly created extension sets
502are immediately installed and are invoked upon the next system
503even supporting an extension.
504
505@subsection Obtaining Extension Set IDs
506
507When an extension set is created, RTEMS generates a
508unique extension set ID and assigns it to the created extension
509set until it is deleted.  The extension ID may be obtained by
510either of two methods.  First, as the result of an invocation of
511the @code{@value{DIRPREFIX}extension_create}
512directive, the extension set ID is stored
513in a user provided location.  Second, the extension set ID may
514be obtained later using the @code{@value{DIRPREFIX}extension_ident}
515directive.  The extension set ID is used by other directives
516to manipulate this extension set.
517
518@subsection Deleting an Extension Set
519
520The @code{@value{DIRPREFIX}extension_delete} directive is used to delete an
521extension set.  The extension set's control block is returned to
522the ESCB free list when it is deleted.  An extension set can be
523deleted by a task other than the task which created the
524extension set.  Any subsequent references to the extension's
525name and ID are invalid.
526
527@section Directives
528
529This section details the user extension manager's
530directives.  A subsection is dedicated to each of this manager's
531directives and describes the calling sequence, related
532constants, usage, and status codes.
533
534@c
535@c
536@c
537@page
538@subsection EXTENSION_CREATE - Create a extension set
539
540@cindex create an extension set
541
542@subheading CALLING SEQUENCE:
543
544@ifset is-C
545@findex rtems_extension_create
546@example
547rtems_status_code rtems_extension_create(
548  rtems_name              name,
549  rtems_extensions_table *table,
550  rtems_id               *id
551);
552@end example
553@end ifset
554
555@ifset is-Ada
556@example
557procedure Extension_Create (
558   Name   : in     RTEMS.Name;
559   Table  : in     RTEMS.Extensions_Table_Pointer;
560   ID     :    out RTEMS.ID;
561   Result :    out RTEMS.Status_Codes
562);
563@end example
564@end ifset
565
566@subheading DIRECTIVE STATUS CODES:
567@code{@value{RPREFIX}SUCCESSFUL} -  extension set created successfully@*
568@code{@value{RPREFIX}INVALID_NAME} - invalid extension set name@*
569@code{@value{RPREFIX}TOO_MANY} - too many extension sets created
570
571@subheading DESCRIPTION:
572
573This directive creates a extension set.  The assigned
574extension set id is returned in id.  This id is used to access
575the extension set with other user extension manager directives.
576For control and maintenance of the extension set, RTEMS
577allocates an ESCB from the local ESCB free pool and initializes
578it.
579
580@subheading NOTES:
581
582This directive will not cause the calling task to be
583preempted.
584
585@c
586@c
587@c
588@page
589@subsection EXTENSION_IDENT - Get ID of a extension set
590
591@cindex get ID of an extension set
592@cindex obtain ID of an extension set
593
594@subheading CALLING SEQUENCE:
595
596@ifset is-C
597@findex rtems_extension_ident
598@example
599rtems_status_code rtems_extension_ident(
600  rtems_name  name,
601  rtems_id   *id
602);
603@end example
604@end ifset
605
606@ifset is-Ada
607@example
608procedure Extension_Ident (
609   Name   : in     RTEMS.Name;
610   ID     :    out RTEMS.ID;
611   Result :    out RTEMS.Status_Codes
612);
613@end example
614@end ifset
615
616@subheading DIRECTIVE STATUS CODES:
617@code{@value{RPREFIX}SUCCESSFUL} -  extension set identified successfully@*
618@code{@value{RPREFIX}INVALID_NAME} - extension set name not found
619
620@subheading DESCRIPTION:
621
622This directive obtains the extension set id
623associated with the extension set name to be acquired.  If the
624extension set name is not unique, then the extension set id will
625match one of the extension sets with that name.  However, this
626extension set id is not guaranteed to correspond to the desired
627extension set.  The extension set id is used to access this
628extension set in other extension set related directives.
629
630@subheading NOTES:
631
632This directive will not cause the running task to be
633preempted.
634
635@c
636@c
637@c
638@page
639@subsection EXTENSION_DELETE - Delete a extension set
640
641@cindex delete an extension set
642
643@subheading CALLING SEQUENCE:
644
645@ifset is-C
646@findex rtems_extension_delete
647@example
648rtems_status_code rtems_extension_delete(
649  rtems_id id
650);
651@end example
652@end ifset
653
654@ifset is-Ada
655@example
656procedure Extension_Delete (
657   ID     : in     RTEMS.ID;
658   Result :    out RTEMS.Status_Codes
659);
660@end example
661@end ifset
662
663@subheading DIRECTIVE STATUS CODES:
664@code{@value{RPREFIX}SUCCESSFUL} -  extension set deleted successfully@*
665@code{@value{RPREFIX}INVALID_ID} - invalid extension set id
666
667@subheading DESCRIPTION:
668
669This directive deletes the extension set specified by
670id.  If the extension set is running, it is automatically
671canceled.  The ESCB for the deleted extension set is reclaimed
672by RTEMS.
673
674@subheading NOTES:
675
676This directive will not cause the running task to be
677preempted.
678
679A extension set can be deleted by a task other than
680the task which created the extension set.
681
682@subheading NOTES:
683
684This directive will not cause the running task to be
685preempted.
Note: See TracBrowser for help on using the repository browser.