source: rtems/doc/user/userext.t @ adee5979

4.104.114.84.95
Last change on this file since adee5979 was adee5979, checked in by Joel Sherrill <joel.sherrill@…>, on 05/04/00 at 19:45:17

Numerous changes based on comments from Stephan Wilms <Stephan.Wilms@…>
including a new section in the Getting Started called "Where to
Go From Here", lots of index entries added, and more configuration
table information.

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