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