[ae68ff0] | 1 | @c |
---|
[4ffbc49] | 2 | @c COPYRIGHT (c) 1988-2007. |
---|
[ae68ff0] | 3 | @c On-Line Applications Research Corporation (OAR). |
---|
| 4 | @c All rights reserved. |
---|
| 5 | @c |
---|
[139b2e4a] | 6 | @c $Id$ |
---|
| 7 | @c |
---|
[ae68ff0] | 8 | |
---|
| 9 | @c |
---|
| 10 | @c The following figure was replaced with an ASCII equivalent. |
---|
| 11 | @c Figure 2-1 Object ID Composition |
---|
| 12 | @c |
---|
[20515fc] | 13 | |
---|
[ae68ff0] | 14 | @chapter Key Concepts |
---|
[20515fc] | 15 | |
---|
[ae68ff0] | 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 | |
---|
[169502e] | 26 | @cindex objects |
---|
| 27 | |
---|
[ae68ff0] | 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 | |
---|
[adee5979] | 46 | @subsection Object Names |
---|
| 47 | |
---|
[169502e] | 48 | @cindex object name |
---|
[adee5979] | 49 | @findex rtems_object_name |
---|
[169502e] | 50 | |
---|
[ae68ff0] | 51 | An object name is an unsigned thirty-two bit entity |
---|
[adee5979] | 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 | |
---|
[4ffbc49] | 64 | @ifset is-C |
---|
[adee5979] | 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 | |
---|
[4ffbc49] | 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 | |
---|
[ae68ff0] | 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 | |
---|
[4ffbc49] | 87 | @ifset is-C |
---|
[8d50380] | 88 | @findex rtems_object_get_name |
---|
[35a81f8] | 89 | |
---|
[8d50380] | 90 | RTEMS provides a helper routine, @code{@value{DIRPREFIX}object_get_name}, |
---|
[35a81f8] | 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 the_object) |
---|
| 102 | @{ |
---|
| 103 | char buffer[10]; /* name assumed to be 10 characters or less */ |
---|
| 104 | char *result; |
---|
| 105 | |
---|
[8d50380] | 106 | result = rtems_object_get_name( id, sizeof(buffer), buffer ); |
---|
[35a81f8] | 107 | printk( "ID=0x%08x name=%s\n", id, ((result) ? result : "no name") ); |
---|
| 108 | @} |
---|
| 109 | @end example |
---|
| 110 | @end ifset |
---|
| 111 | |
---|
| 112 | |
---|
[adee5979] | 113 | @subsection Object IDs |
---|
| 114 | |
---|
[169502e] | 115 | @cindex object ID |
---|
[71689d44] | 116 | @cindex object ID composition |
---|
[adee5979] | 117 | @findex rtems_id |
---|
[169502e] | 118 | |
---|
[ae68ff0] | 119 | @need 3000 |
---|
| 120 | |
---|
[2bf21fc8] | 121 | An object ID is a unique unsigned integer value which uniquely identifies |
---|
| 122 | an object instance. Object IDs are passed as arguments to many directives |
---|
| 123 | in RTEMS and RTEMS translates the ID to an internal object pointer. The |
---|
| 124 | efficient manipulation of object IDs is critical to the performance |
---|
| 125 | of RTEMS services. Because of this, there are two object Id formats |
---|
| 126 | defined. Each target architecture specifies which format it will use. |
---|
| 127 | There is a thirty-two bit format which is used for most of the supported |
---|
| 128 | architectures and supports multiprocessor configurations. There is also |
---|
| 129 | a simpler sixteen bit format which is appropriate for smaller target |
---|
| 130 | architectures and does not support multiprocessor configurations. |
---|
| 131 | |
---|
| 132 | @subsubsection Thirty-Two Object ID Format |
---|
| 133 | |
---|
| 134 | The thirty-two bit format for an object ID is composed of four parts: API, |
---|
| 135 | object class, node, and index. The data type @code{@value{DIRPREFIX}id} |
---|
| 136 | is used to store object IDs. |
---|
[adee5979] | 137 | |
---|
[ae68ff0] | 138 | |
---|
[bd861cc6] | 139 | @float Figure,fig:Object-Id-32 |
---|
| 140 | @caption{Thirty-Two Bit Object Id} |
---|
| 141 | |
---|
[ae68ff0] | 142 | @ifset use-ascii |
---|
| 143 | @example |
---|
| 144 | @group |
---|
[1fa78236] | 145 | 31 27 26 24 23 16 15 0 |
---|
| 146 | +---------+-------+--------------+-------------------------------+ |
---|
| 147 | | | | | | |
---|
| 148 | | Class | API | Node | Index | |
---|
| 149 | | | | | | |
---|
| 150 | +---------+-------+--------------+-------------------------------+ |
---|
[ae68ff0] | 151 | @end group |
---|
| 152 | @end example |
---|
| 153 | @end ifset |
---|
| 154 | |
---|
| 155 | @ifset use-tex |
---|
[1fa78236] | 156 | @sp1 |
---|
[bd861cc6] | 157 | @center{@image{ObjectId-32Bits,,2in,Thirty-Two Bit Object Id}} |
---|
[ae68ff0] | 158 | @end ifset |
---|
| 159 | |
---|
| 160 | @ifset use-html |
---|
| 161 | @html |
---|
[1a34b8c] | 162 | <P ALIGN="center"><IMG SRC="ObjectId-32Bits.png" |
---|
[bd861cc6] | 163 | WIDTH=550 HEIGHT=400 ALT="Thirty-Two Bit Object Id"></P> |
---|
[ae68ff0] | 164 | @end html |
---|
| 165 | @end ifset |
---|
[bd861cc6] | 166 | @end float |
---|
[ae68ff0] | 167 | |
---|
[1fa78236] | 168 | The most significant five bits are the object class. The next |
---|
| 169 | three bits indicate the API to which the object class belongs. |
---|
| 170 | The next eight bits (16-23) are the number of the node on which |
---|
| 171 | this object was created. The node number is always one (1) in a single |
---|
[71689d44] | 172 | processor system. The least significant sixteen bits form an |
---|
| 173 | identifier within a particular object type. This identifier, |
---|
| 174 | called the object index, ranges in value from 1 to the maximum |
---|
| 175 | number of objects configured for this object type. |
---|
| 176 | |
---|
[2bf21fc8] | 177 | @subsubsection Sixteen Bit Object ID Format |
---|
| 178 | |
---|
| 179 | The sixteen bit format for an object ID is composed of three parts: API, |
---|
| 180 | object class, and index. The data type @code{@value{DIRPREFIX}id} |
---|
| 181 | is used to store object IDs. |
---|
| 182 | |
---|
[bd861cc6] | 183 | @float Figure,fig:Object-Id-16 |
---|
| 184 | @caption{Sixteen Bit Object Id} |
---|
| 185 | |
---|
[2bf21fc8] | 186 | |
---|
| 187 | @ifset use-ascii |
---|
| 188 | @example |
---|
| 189 | @group |
---|
| 190 | 15 11 10 8 7 0 |
---|
| 191 | +---------+-------+--------------+ |
---|
| 192 | | | | | |
---|
| 193 | | Class | API | Index | |
---|
| 194 | | | | | |
---|
| 195 | +---------+-------+--------------+ |
---|
| 196 | @end group |
---|
| 197 | @end example |
---|
| 198 | @end ifset |
---|
| 199 | |
---|
| 200 | @ifset use-tex |
---|
| 201 | @sp1 |
---|
[bd861cc6] | 202 | @center{@image{ObjectId-16Bits,,2in,Sixteen Bit Object Id}} |
---|
[2bf21fc8] | 203 | @end ifset |
---|
| 204 | |
---|
| 205 | @ifset use-html |
---|
| 206 | @html |
---|
| 207 | <P ALIGN="center"><IMG SRC="ObjectId-16Bits.png" |
---|
| 208 | WIDTH=550 HEIGHT=400 ALT="16 Bit Object Id"></P> |
---|
| 209 | @end html |
---|
| 210 | @end ifset |
---|
[bd861cc6] | 211 | @end float |
---|
[2bf21fc8] | 212 | |
---|
| 213 | The sixteen-bit format is designed to be as similar as possible to the |
---|
| 214 | thrity-two bit format. The differences are limited to the eliminatation |
---|
| 215 | of the node field and reduction of the index field from sixteen-bits |
---|
| 216 | to 8-bits. Thus the sixteen bit format only supports up to 255 object |
---|
| 217 | instances per API/Class combination and single processor systems. |
---|
| 218 | As this format is typically utilized by sixteen-bit processors with |
---|
| 219 | limited address space, this is more than enough object instances. |
---|
| 220 | |
---|
| 221 | @subsection Object ID Description |
---|
| 222 | |
---|
| 223 | The components of an object ID make it possible |
---|
[ae68ff0] | 224 | to quickly locate any object in even the most complicated |
---|
| 225 | multiprocessor system. Object ID's are associated with an |
---|
| 226 | object by RTEMS when the object is created and the corresponding |
---|
| 227 | ID is returned by the appropriate object create directive. The |
---|
| 228 | object ID is required as input to all directives involving |
---|
| 229 | objects, except those which create an object or obtain the ID of |
---|
| 230 | an object. |
---|
| 231 | |
---|
| 232 | The object identification directives can be used to |
---|
| 233 | dynamically obtain a particular object's ID given its name. |
---|
| 234 | This mapping is accomplished by searching the name table |
---|
| 235 | associated with this object type. If the name is non-unique, |
---|
| 236 | then the ID associated with the first occurrence of the name |
---|
| 237 | will be returned to the application. Since object IDs are |
---|
| 238 | returned when the object is created, the object identification |
---|
| 239 | directives are not necessary in a properly designed single |
---|
| 240 | processor application. |
---|
| 241 | |
---|
[71689d44] | 242 | In addition, services are provided to portably examine the |
---|
[d5671b1] | 243 | subcomponents of an RTEMS ID. These services are |
---|
| 244 | described in detail later in this manual but are prototyped |
---|
| 245 | as follows: |
---|
[71689d44] | 246 | |
---|
| 247 | @cindex obtaining class from object ID |
---|
| 248 | @cindex obtaining node from object ID |
---|
| 249 | @cindex obtaining index from object ID |
---|
| 250 | @cindex get class from object ID |
---|
| 251 | @cindex get node from object ID |
---|
| 252 | @cindex get index from object ID |
---|
[d5671b1] | 253 | @findex rtems_object_id_get_api |
---|
| 254 | @findex rtems_object_id_get_class |
---|
| 255 | @findex rtems_object_id_get_node |
---|
| 256 | @findex rtems_object_id_get_index |
---|
[71689d44] | 257 | |
---|
| 258 | @example |
---|
[d5671b1] | 259 | uint32_t rtems_object_id_get_api( rtems_id ); |
---|
| 260 | uint32_t rtems_object_id_get_class( rtems_id ); |
---|
| 261 | uint32_t rtems_object_id_get_node( rtems_id ); |
---|
| 262 | uint32_t rtems_object_id_get_index( rtems_id ); |
---|
[71689d44] | 263 | @end example |
---|
| 264 | |
---|
[ae68ff0] | 265 | An object control block is a data structure defined |
---|
| 266 | by RTEMS which contains the information necessary to manage a |
---|
| 267 | particular object type. For efficiency reasons, the format of |
---|
| 268 | each object type's control block is different. However, many of |
---|
| 269 | the fields are similar in function. The number of each type of |
---|
| 270 | control block is application dependent and determined by the |
---|
| 271 | values specified in the user's Configuration Table. An object |
---|
| 272 | control block is allocated at object create time and freed when |
---|
| 273 | the object is deleted. With the exception of user extension |
---|
| 274 | routines, object control blocks are not directly manipulated by |
---|
| 275 | user applications. |
---|
| 276 | |
---|
| 277 | @section Communication and Synchronization |
---|
| 278 | |
---|
[169502e] | 279 | @cindex communication and synchronization |
---|
| 280 | |
---|
[ae68ff0] | 281 | In real-time multitasking applications, the ability |
---|
| 282 | for cooperating execution threads to communicate and synchronize |
---|
| 283 | with each other is imperative. A real-time executive should |
---|
| 284 | provide an application with the following capabilities: |
---|
| 285 | |
---|
| 286 | @itemize @bullet |
---|
| 287 | @item Data transfer between cooperating tasks |
---|
| 288 | @item Data transfer between tasks and ISRs |
---|
| 289 | @item Synchronization of cooperating tasks |
---|
| 290 | @item Synchronization of tasks and ISRs |
---|
| 291 | @end itemize |
---|
| 292 | |
---|
| 293 | Most RTEMS managers can be used to provide some form |
---|
| 294 | of communication and/or synchronization. However, managers |
---|
| 295 | dedicated specifically to communication and synchronization |
---|
| 296 | provide well established mechanisms which directly map to the |
---|
| 297 | application's varying needs. This level of flexibility allows |
---|
| 298 | the application designer to match the features of a particular |
---|
| 299 | manager with the complexity of communication and synchronization |
---|
| 300 | required. The following managers were specifically designed for |
---|
| 301 | communication and synchronization: |
---|
| 302 | |
---|
| 303 | @itemize @bullet |
---|
| 304 | @item Semaphore |
---|
| 305 | @item Message Queue |
---|
| 306 | @item Event |
---|
| 307 | @item Signal |
---|
| 308 | @end itemize |
---|
| 309 | |
---|
| 310 | The semaphore manager supports mutual exclusion |
---|
| 311 | involving the synchronization of access to one or more shared |
---|
| 312 | user resources. Binary semaphores may utilize the optional |
---|
| 313 | priority inheritance algorithm to avoid the problem of priority |
---|
| 314 | inversion. The message manager supports both communication and |
---|
| 315 | synchronization, while the event manager primarily provides a |
---|
| 316 | high performance synchronization mechanism. The signal manager |
---|
| 317 | supports only asynchronous communication and is typically used |
---|
| 318 | for exception handling. |
---|
| 319 | |
---|
| 320 | @section Time |
---|
| 321 | |
---|
[169502e] | 322 | @cindex time |
---|
| 323 | |
---|
[ae68ff0] | 324 | The development of responsive real-time applications |
---|
| 325 | requires an understanding of how RTEMS maintains and supports |
---|
| 326 | time-related operations. The basic unit of time in RTEMS is |
---|
| 327 | known as a tick. The frequency of clock ticks is completely |
---|
| 328 | application dependent and determines the granularity and |
---|
| 329 | accuracy of all interval and calendar time operations. |
---|
| 330 | |
---|
[adee5979] | 331 | @findex rtems_interval |
---|
| 332 | |
---|
[ae68ff0] | 333 | By tracking time in units of ticks, RTEMS is capable |
---|
| 334 | of supporting interval timing functions such as task delays, |
---|
| 335 | timeouts, timeslicing, the delayed execution of timer service |
---|
| 336 | routines, and the rate monotonic scheduling of tasks. An |
---|
| 337 | interval is defined as a number of ticks relative to the current |
---|
| 338 | time. For example, when a task delays for an interval of ten |
---|
| 339 | ticks, it is implied that the task will not execute until ten |
---|
| 340 | clock ticks have occurred. |
---|
[adee5979] | 341 | All intervals are specified using data type |
---|
| 342 | @code{@value{DIRPREFIX}interval}. |
---|
[ae68ff0] | 343 | |
---|
| 344 | A characteristic of interval timing is that the |
---|
| 345 | actual interval period may be a fraction of a tick less than the |
---|
| 346 | interval requested. This occurs because the time at which the |
---|
| 347 | delay timer is set up occurs at some time between two clock |
---|
| 348 | ticks. Therefore, the first countdown tick occurs in less than |
---|
| 349 | the complete time interval for a tick. This can be a problem if |
---|
| 350 | the clock granularity is large. |
---|
| 351 | |
---|
| 352 | The rate monotonic scheduling algorithm is a hard |
---|
| 353 | real-time scheduling methodology. This methodology provides |
---|
| 354 | rules which allows one to guarantee that a set of independent |
---|
| 355 | periodic tasks will always meet their deadlines -- even under |
---|
| 356 | transient overload conditions. The rate monotonic manager |
---|
| 357 | provides directives built upon the Clock Manager's interval |
---|
| 358 | timer support routines. |
---|
| 359 | |
---|
| 360 | Interval timing is not sufficient for the many |
---|
| 361 | applications which require that time be kept in wall time or |
---|
| 362 | true calendar form. Consequently, RTEMS maintains the current |
---|
| 363 | date and time. This allows selected time operations to be |
---|
| 364 | scheduled at an actual calendar date and time. For example, a |
---|
| 365 | task could request to delay until midnight on New Year's Eve |
---|
| 366 | before lowering the ball at Times Square. |
---|
[adee5979] | 367 | The data type @code{@value{DIRPREFIX}time_of_day} is used to specify |
---|
| 368 | calendar time in RTEMS services. |
---|
| 369 | @xref{Clock Manager Time and Date Data Structures, , Time and Date Data Structures}. |
---|
| 370 | @findex rtems_time_of_day |
---|
[ae68ff0] | 371 | |
---|
| 372 | Obviously, the directives which use intervals or wall |
---|
| 373 | time cannot operate without some external mechanism which |
---|
| 374 | provides a periodic clock tick. This clock tick is typically |
---|
| 375 | provided by a real time clock or counter/timer device. |
---|
| 376 | |
---|
| 377 | @section Memory Management |
---|
| 378 | |
---|
[169502e] | 379 | @cindex memory management |
---|
| 380 | |
---|
[ae68ff0] | 381 | RTEMS memory management facilities can be grouped |
---|
| 382 | into two classes: dynamic memory allocation and address |
---|
| 383 | translation. Dynamic memory allocation is required by |
---|
| 384 | applications whose memory requirements vary through the |
---|
| 385 | application's course of execution. Address translation is |
---|
| 386 | needed by applications which share memory with another CPU or an |
---|
| 387 | intelligent Input/Output processor. The following RTEMS |
---|
| 388 | managers provide facilities to manage memory: |
---|
| 389 | |
---|
| 390 | @itemize @bullet |
---|
| 391 | @item Region |
---|
| 392 | |
---|
| 393 | @item Partition |
---|
| 394 | |
---|
| 395 | @item Dual Ported Memory |
---|
| 396 | @end itemize |
---|
| 397 | |
---|
| 398 | RTEMS memory management features allow an application |
---|
| 399 | to create simple memory pools of fixed size buffers and/or more |
---|
| 400 | complex memory pools of variable size segments. The partition |
---|
| 401 | manager provides directives to manage and maintain pools of |
---|
| 402 | fixed size entities such as resource control blocks. |
---|
| 403 | Alternatively, the region manager provides a more general |
---|
| 404 | purpose memory allocation scheme that supports variable size |
---|
| 405 | blocks of memory which are dynamically obtained and freed by the |
---|
| 406 | application. The dual-ported memory manager provides executive |
---|
| 407 | support for address translation between internal and external |
---|
| 408 | dual-ported RAM address space. |
---|