source: rtems-docs/c_user/key_concepts.rst @ b8d3f6b

4.115
Last change on this file since b8d3f6b was b8d3f6b, checked in by Chris Johns <chrisj@…>, on 01/24/16 at 10:37:53

C user guide clean up. Up to timer manager.

  • 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:.. index:: obtaining class from object ID
168
169.. index:: obtaining node from object ID
170.. index:: obtaining index from object ID
171.. index:: get class from object ID
172.. index:: get node from object ID
173.. index:: get index from object ID
174.. index:: rtems_object_id_get_api
175.. index:: rtems_object_id_get_class
176.. index:: rtems_object_id_get_node
177.. index:: rtems_object_id_get_index
178
179.. code:: c
180
181    uint32_t rtems_object_id_get_api( rtems_id );
182    uint32_t rtems_object_id_get_class( rtems_id );
183    uint32_t rtems_object_id_get_node( rtems_id );
184    uint32_t rtems_object_id_get_index( rtems_id );
185
186An object control block is a data structure defined by RTEMS which contains the
187information necessary to manage a particular object type.  For efficiency
188reasons, the format of each object type's control block is different.  However,
189many of the fields are similar in function.  The number of each type of control
190block is application dependent and determined by the values specified in the
191user's Configuration Table.  An object control block is allocated at object
192create time and freed when the object is deleted.  With the exception of user
193extension routines, object control blocks are not directly manipulated by user
194applications.
195
196Communication and Synchronization
197=================================
198.. index:: communication and synchronization
199
200In real-time multitasking applications, the ability for cooperating execution
201threads to communicate and synchronize with each other is imperative.  A
202real-time executive should provide an application with the following
203capabilities:
204
205- Data transfer between cooperating tasks
206
207- Data transfer between tasks and ISRs
208
209- Synchronization of cooperating tasks
210
211- Synchronization of tasks and ISRs
212
213Most RTEMS managers can be used to provide some form of communication and/or
214synchronization.  However, managers dedicated specifically to communication and
215synchronization provide well established mechanisms which directly map to the
216application's varying needs.  This level of flexibility allows the application
217designer to match the features of a particular manager with the complexity of
218communication and synchronization required.  The following managers were
219specifically designed for communication and synchronization:
220
221- Semaphore
222
223- Message Queue
224
225- Event
226
227- Signal
228
229The semaphore manager supports mutual exclusion involving the synchronization
230of access to one or more shared user resources.  Binary semaphores may utilize
231the optional priority inheritance algorithm to avoid the problem of priority
232inversion.  The message manager supports both communication and
233synchronization, while the event manager primarily provides a high performance
234synchronization mechanism.  The signal manager supports only asynchronous
235communication and is typically used for exception handling.
236
237Time
238====
239.. index:: time
240
241The development of responsive real-time applications requires an understanding
242of how RTEMS maintains and supports time-related operations.  The basic unit of
243time in RTEMS is known as a tick.  The frequency of clock ticks is completely
244application dependent and determines the granularity and accuracy of all
245interval and calendar time operations... index:: rtems_interval
246
247By tracking time in units of ticks, RTEMS is capable of supporting interval
248timing functions such as task delays, timeouts, timeslicing, the delayed
249execution of timer service routines, and the rate monotonic scheduling of
250tasks.  An interval is defined as a number of ticks relative to the current
251time.  For example, when a task delays for an interval of ten ticks, it is
252implied that the task will not execute until ten clock ticks have occurred.
253All intervals are specified using data type ``rtems_interval``.
254
255A characteristic of interval timing is that the actual interval period may be a
256fraction of a tick less than the interval requested.  This occurs because the
257time at which the delay timer is set up occurs at some time between two clock
258ticks.  Therefore, the first countdown tick occurs in less than the complete
259time interval for a tick.  This can be a problem if the clock granularity is
260large.
261
262The rate monotonic scheduling algorithm is a hard real-time scheduling
263methodology.  This methodology provides rules which allows one to guarantee
264that a set of independent periodic tasks will always meet their deadlines -
265even under transient overload conditions.  The rate monotonic manager provides
266directives built upon the Clock Manager's interval timer support routines.
267
268Interval timing is not sufficient for the many applications which require that
269time be kept in wall time or true calendar form.  Consequently, RTEMS maintains
270the current date and time.  This allows selected time operations to be
271scheduled at an actual calendar date and time.  For example, a task could
272request to delay until midnight on New Year's Eve before lowering the ball at
273Times Square.  The data type ``rtems_time_of_day`` is used to specify calendar
274time in RTEMS services.  See `Time and Date Data Structures`_
275
276... index:: rtems_time_of_day
277
278Obviously, the directives which use intervals or wall time cannot operate
279without some external mechanism which provides a periodic clock tick.  This
280clock tick is typically provided by a real time clock or counter/timer device.
281
282Memory Management
283=================
284.. index:: memory management
285
286RTEMS memory management facilities can be grouped into two classes: dynamic
287memory allocation and address translation.  Dynamic memory allocation is
288required by applications whose memory requirements vary through the
289application's course of execution.  Address translation is needed by
290applications which share memory with another CPU or an intelligent Input/Output
291processor.  The following RTEMS managers provide facilities to manage memory:
292
293- Region
294
295- Partition
296
297- Dual Ported Memory
298
299RTEMS memory management features allow an application to create simple memory
300pools of fixed size buffers and/or more complex memory pools of variable size
301segments.  The partition manager provides directives to manage and maintain
302pools of fixed size entities such as resource control blocks.  Alternatively,
303the region manager provides a more general purpose memory allocation scheme
304that supports variable size blocks of memory which are dynamically obtained and
305freed by the application.  The dual-ported memory manager provides executive
306support for address translation between internal and external dual-ported RAM
307address space.
Note: See TracBrowser for help on using the repository browser.