source: rtems-docs/c_user/key_concepts.rst @ 66220bc

4.115
Last change on this file since 66220bc was 66220bc, checked in by Chris Johns <chrisj@…>, on 01/26/16 at 10:49:59

Fix index error.

  • Property mode set to 100644
File size: 13.4 KB
Line 
1.. COMMENT: COPYRIGHT (c) 1988-2008.
2.. COMMENT: On-Line Applications Research Corporation (OAR).
3.. COMMENT: All rights reserved.
4
5Key Concepts
6############
7
8Introduction
9============
10
11The facilities provided by RTEMS are built upon a foundation of very powerful
12concepts.  These concepts must be understood before the application developer
13can efficiently utilize RTEMS.  The purpose of this chapter is to familiarize
14one with these concepts.
15
16.. _objects:
17
18Objects
19=======
20
21.. index:: objects
22
23RTEMS provides directives which can be used to dynamically create, delete, and
24manipulate a set of predefined object types.  These types include tasks,
25message queues, semaphores, memory regions, memory partitions, timers, ports,
26and rate monotonic periods.  The object-oriented nature of RTEMS encourages the
27creation of modular applications built upon re-usable "building block"
28routines.
29
30All objects are created on the local node as required by the application and
31have an RTEMS assigned ID.  All objects have a user-assigned name.  Although a
32relationship exists between an object's name and its RTEMS assigned ID, the
33name and ID are not identical.  Object names are completely arbitrary and
34selected by the user as a meaningful "tag" which may commonly reflect the
35object's use in the application.  Conversely, object IDs are designed to
36facilitate efficient object manipulation by the executive.
37
38Object Names
39------------
40.. index:: object name
41.. index:: rtems_object_name
42
43An object name is an unsigned thirty-two bit entity associated with the object
44by the user.  The data type ``rtems_name`` is used to store object
45names... index:: rtems_build_name
46
47Although not required by RTEMS, object names are often composed of four ASCII
48characters which help identify that object.  For example, a task which causes a
49light to blink might be called "LITE".  The ``rtems_build_name`` routine is
50provided to build an object name from four ASCII characters.  The following
51example illustrates this: .. code:: c
52
53.. code:: c
54
55    rtems_object_name my_name;
56    my_name = rtems_build_name( 'L', 'I', 'T', 'E' );
57
58However, it is not required that the application use ASCII characters to build
59object names.  For example, if an application requires one-hundred tasks, it
60would be difficult to assign meaningful ASCII names to each task.  A more
61convenient approach would be to name them the binary values one through
62one-hundred, respectively... index:: rtems_object_get_name
63
64RTEMS provides a helper routine, ``rtems_object_get_name``, which can be used
65to obtain the name of any RTEMS object using just its ID.  This routine
66attempts to convert the name into a printable string.
67
68The following example illustrates the use of this method to print an object
69name:
70
71.. code:: c
72
73    #include <rtems.h>
74    #include <rtems/bspIo.h>
75    void print_name(rtems_id id)
76    {
77        char  buffer[10];   /* name assumed to be 10 characters or less */
78        char *result;
79        result = rtems_object_get_name( id, sizeof(buffer), buffer );
80        printk( "ID=0x%08x name=%s\n", id, ((result) ? result : "no name") );
81    }
82
83Object IDs
84----------
85.. index:: object ID
86.. index:: object ID composition
87.. index:: rtems_id
88
89An object ID is a unique unsigned integer value which uniquely identifies an
90object instance.  Object IDs are passed as arguments to many directives in
91RTEMS and RTEMS translates the ID to an internal object pointer. The efficient
92manipulation of object IDs is critical to the performance of RTEMS services.
93Because of this, there are two object Id formats defined.  Each target
94architecture specifies which format it will use.  There is a thirty-two bit
95format which is used for most of the supported architectures and supports
96multiprocessor configurations.  There is also a simpler sixteen bit format
97which is appropriate for smaller target architectures and does not support
98multiprocessor configurations.
99
100Thirty-Two Object ID Format
101~~~~~~~~~~~~~~~~~~~~~~~~~~~
102
103The thirty-two bit format for an object ID is composed of four parts: API,
104object class, node, and index.  The data type ``rtems_id`` is used to store
105object IDs.
106
107.. code:: c
108
109    31      27 26   24 23          16 15                             0
110    +---------+-------+--------------+-------------------------------+
111    |         |       |              |                               |
112    |  Class  |  API  |     Node     |             Index             |
113    |         |       |              |                               |
114    +---------+-------+--------------+-------------------------------+
115
116The most significant five bits are the object class.  The next three bits
117indicate the API to which the object class belongs.  The next eight bits
118(16-23) are the number of the node on which this object was created.  The node
119number is always one (1) in a single processor system.  The least significant
120sixteen bits form an identifier within a particular object type.  This
121identifier, called the object index, ranges in value from 1 to the maximum
122number of objects configured for this object type.
123
124Sixteen Bit Object ID Format
125~~~~~~~~~~~~~~~~~~~~~~~~~~~~
126
127The sixteen bit format for an object ID is composed of three parts: API, object
128class, and index.  The data type ``rtems_id`` is used to store object IDs.
129
130.. code:: c
131
132    15      11 10    8 7            0
133    +---------+-------+--------------+
134    |         |       |              |
135    |  Class  |  API  |    Index     |
136    |         |       |              |
137    +---------+-------+--------------+
138
139The sixteen-bit format is designed to be as similar as possible to the
140thrity-two bit format.  The differences are limited to the eliminatation of the
141node field and reduction of the index field from sixteen-bits to 8-bits.  Thus
142the sixteen bit format only supports up to 255 object instances per API/Class
143combination and single processor systems.  As this format is typically utilized
144by sixteen-bit processors with limited address space, this is more than enough
145object instances.
146
147Object ID Description
148---------------------
149
150The components of an object ID make it possible to quickly locate any object in
151even the most complicated multiprocessor system.  Object ID's are associated
152with an object by RTEMS when the object is created and the corresponding ID is
153returned by the appropriate object create directive.  The object ID is required
154as input to all directives involving objects, except those which create an
155object or obtain the ID of an object.
156
157The object identification directives can be used to dynamically obtain a
158particular object's ID given its name.  This mapping is accomplished by
159searching the name table associated with this object type.  If the name is
160non-unique, then the ID associated with the first occurrence of the name will
161be returned to the application.  Since object IDs are returned when the object
162is created, the object identification directives are not necessary in a
163properly designed single processor application.
164
165In addition, services are provided to portably examine the subcomponents of an
166RTEMS ID.  These services are described in detail later in this manual but are
167prototyped as follows:
168
169.. index:: obtaining class from object ID
170.. index:: obtaining node from object ID
171.. index:: obtaining index from object ID
172.. index:: get class from object ID
173.. index:: get node from object ID
174.. index:: get index from object ID
175.. index:: rtems_object_id_get_api
176.. index:: rtems_object_id_get_class
177.. index:: rtems_object_id_get_node
178.. index:: rtems_object_id_get_index
179
180.. code:: c
181
182    uint32_t rtems_object_id_get_api( rtems_id );
183    uint32_t rtems_object_id_get_class( rtems_id );
184    uint32_t rtems_object_id_get_node( rtems_id );
185    uint32_t rtems_object_id_get_index( rtems_id );
186
187An object control block is a data structure defined by RTEMS which contains the
188information necessary to manage a particular object type.  For efficiency
189reasons, the format of each object type's control block is different.  However,
190many of the fields are similar in function.  The number of each type of control
191block is application dependent and determined by the values specified in the
192user's Configuration Table.  An object control block is allocated at object
193create time and freed when the object is deleted.  With the exception of user
194extension routines, object control blocks are not directly manipulated by user
195applications.
196
197Communication and Synchronization
198=================================
199.. index:: communication and synchronization
200
201In real-time multitasking applications, the ability for cooperating execution
202threads to communicate and synchronize with each other is imperative.  A
203real-time executive should provide an application with the following
204capabilities:
205
206- Data transfer between cooperating tasks
207
208- Data transfer between tasks and ISRs
209
210- Synchronization of cooperating tasks
211
212- Synchronization of tasks and ISRs
213
214Most RTEMS managers can be used to provide some form of communication and/or
215synchronization.  However, managers dedicated specifically to communication and
216synchronization provide well established mechanisms which directly map to the
217application's varying needs.  This level of flexibility allows the application
218designer to match the features of a particular manager with the complexity of
219communication and synchronization required.  The following managers were
220specifically designed for communication and synchronization:
221
222- Semaphore
223
224- Message Queue
225
226- Event
227
228- Signal
229
230The semaphore manager supports mutual exclusion involving the synchronization
231of access to one or more shared user resources.  Binary semaphores may utilize
232the optional priority inheritance algorithm to avoid the problem of priority
233inversion.  The message manager supports both communication and
234synchronization, while the event manager primarily provides a high performance
235synchronization mechanism.  The signal manager supports only asynchronous
236communication and is typically used for exception handling.
237
238Time
239====
240.. index:: time
241
242The development of responsive real-time applications requires an understanding
243of how RTEMS maintains and supports time-related operations.  The basic unit of
244time in RTEMS is known as a tick.  The frequency of clock ticks is completely
245application dependent and determines the granularity and accuracy of all
246interval and calendar time operations... index:: rtems_interval
247
248By tracking time in units of ticks, RTEMS is capable of supporting interval
249timing functions such as task delays, timeouts, timeslicing, the delayed
250execution of timer service routines, and the rate monotonic scheduling of
251tasks.  An interval is defined as a number of ticks relative to the current
252time.  For example, when a task delays for an interval of ten ticks, it is
253implied that the task will not execute until ten clock ticks have occurred.
254All intervals are specified using data type ``rtems_interval``.
255
256A characteristic of interval timing is that the actual interval period may be a
257fraction of a tick less than the interval requested.  This occurs because the
258time at which the delay timer is set up occurs at some time between two clock
259ticks.  Therefore, the first countdown tick occurs in less than the complete
260time interval for a tick.  This can be a problem if the clock granularity is
261large.
262
263The rate monotonic scheduling algorithm is a hard real-time scheduling
264methodology.  This methodology provides rules which allows one to guarantee
265that a set of independent periodic tasks will always meet their deadlines -
266even under transient overload conditions.  The rate monotonic manager provides
267directives built upon the Clock Manager's interval timer support routines.
268
269Interval timing is not sufficient for the many applications which require that
270time be kept in wall time or true calendar form.  Consequently, RTEMS maintains
271the current date and time.  This allows selected time operations to be
272scheduled at an actual calendar date and time.  For example, a task could
273request to delay until midnight on New Year's Eve before lowering the ball at
274Times Square.  The data type ``rtems_time_of_day`` is used to specify calendar
275time in RTEMS services.  See `Time and Date Data Structures`_
276
277... index:: rtems_time_of_day
278
279Obviously, the directives which use intervals or wall time cannot operate
280without some external mechanism which provides a periodic clock tick.  This
281clock tick is typically provided by a real time clock or counter/timer device.
282
283Memory Management
284=================
285.. index:: memory management
286
287RTEMS memory management facilities can be grouped into two classes: dynamic
288memory allocation and address translation.  Dynamic memory allocation is
289required by applications whose memory requirements vary through the
290application's course of execution.  Address translation is needed by
291applications which share memory with another CPU or an intelligent Input/Output
292processor.  The following RTEMS managers provide facilities to manage memory:
293
294- Region
295
296- Partition
297
298- Dual Ported Memory
299
300RTEMS memory management features allow an application to create simple memory
301pools of fixed size buffers and/or more complex memory pools of variable size
302segments.  The partition manager provides directives to manage and maintain
303pools of fixed size entities such as resource control blocks.  Alternatively,
304the region manager provides a more general purpose memory allocation scheme
305that supports variable size blocks of memory which are dynamically obtained and
306freed by the application.  The dual-ported memory manager provides executive
307support for address translation between internal and external dual-ported RAM
308address space.
Note: See TracBrowser for help on using the repository browser.