[ae68ff0] | 1 | @c |
---|
[1e524995] | 2 | @c COPYRIGHT (c) 1988-1998. |
---|
[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 | |
---|
[169502e] | 46 | @cindex object name |
---|
| 47 | |
---|
[ae68ff0] | 48 | An object name is an unsigned thirty-two bit entity |
---|
| 49 | associated with the object by the user. Although not required |
---|
| 50 | by RTEMS, object names are typically composed of four ASCII |
---|
| 51 | characters which help identify that object. For example, a task |
---|
| 52 | which causes a light to blink might be called "LITE". Utilities |
---|
| 53 | are provided to build an object name from four ASCII characters |
---|
| 54 | and to decompose an object name into four ASCII characters. |
---|
| 55 | However, it is not required that the application use ASCII |
---|
| 56 | characters to build object names. For example, if an |
---|
| 57 | application requires one-hundred tasks, it would be difficult to |
---|
| 58 | assign meaningful ASCII names to each task. A more convenient |
---|
| 59 | approach would be to name them the binary values one through |
---|
| 60 | one-hundred, respectively. |
---|
| 61 | |
---|
[169502e] | 62 | @cindex object ID |
---|
[71689d44] | 63 | @cindex object ID composition |
---|
[169502e] | 64 | |
---|
[ae68ff0] | 65 | @need 3000 |
---|
| 66 | |
---|
| 67 | An object ID is a unique unsigned thirty-two bit |
---|
| 68 | entity composed of three parts: object class, node, and index. |
---|
| 69 | |
---|
| 70 | @ifset use-ascii |
---|
| 71 | @example |
---|
| 72 | @group |
---|
| 73 | 31 26 25 16 15 0 |
---|
| 74 | +-----------+------------------+-------------------------------+ |
---|
| 75 | | | | | |
---|
| 76 | | Class | Node | Index | |
---|
| 77 | | | | | |
---|
| 78 | +-----------+------------------+-------------------------------+ |
---|
| 79 | @end group |
---|
| 80 | @end example |
---|
| 81 | @end ifset |
---|
| 82 | |
---|
| 83 | @ifset use-tex |
---|
| 84 | @sp 1 |
---|
| 85 | @tex |
---|
| 86 | \centerline{\vbox{\offinterlineskip\halign{ |
---|
| 87 | \strut#& |
---|
| 88 | \hbox to 0.50in{\enskip#}& |
---|
| 89 | \hbox to 0.50in{\enskip#}& |
---|
| 90 | #& |
---|
| 91 | \hbox to 0.50in{\enskip#}& |
---|
| 92 | \hbox to 0.50in{\enskip#}& |
---|
| 93 | #& |
---|
| 94 | \hbox to 1.00in{\enskip#}& |
---|
| 95 | \hbox to 1.00in{\enskip#}& |
---|
| 96 | #\cr |
---|
| 97 | \multispan{9}\cr |
---|
| 98 | \multispan{2}31\hfil&\multispan{2}\hfil26\enskip& |
---|
| 99 | \multispan{1}\enskip25\hfil&\multispan{2}\hfil16\enskip& |
---|
| 100 | \multispan{1}\enskip15\hfil&\multispan{2}\hfil0\cr |
---|
| 101 | &&&&&&&&&\cr |
---|
| 102 | }}\hfil} |
---|
| 103 | \centerline{\vbox{\offinterlineskip\halign{ |
---|
| 104 | \strut\vrule#& |
---|
| 105 | \hbox to 0.50in{\enskip#}& |
---|
| 106 | \hbox to 0.50in{\enskip#}& |
---|
| 107 | \vrule#& |
---|
| 108 | \hbox to 0.50in{\enskip#}& |
---|
| 109 | \hbox to 0.50in{\enskip#}& |
---|
| 110 | \vrule#& |
---|
| 111 | \hbox to 0.50in{\enskip#}& |
---|
| 112 | \hbox to 0.50in{\enskip#}& |
---|
| 113 | \vrule#\cr |
---|
| 114 | \multispan{9}\cr |
---|
| 115 | \noalign{\hrule} |
---|
| 116 | &&&&&&&&&\cr |
---|
| 117 | &\multispan{2}\hfil Class\hfil&& |
---|
| 118 | \multispan{2}\hfil Node\hfil&& |
---|
| 119 | \multispan{2}\hfil Index\hfil&\cr |
---|
| 120 | &&&&&&&&&\cr |
---|
| 121 | \noalign{\hrule} |
---|
| 122 | }}\hfil} |
---|
| 123 | @end tex |
---|
| 124 | @end ifset |
---|
| 125 | |
---|
| 126 | @ifset use-html |
---|
| 127 | @html |
---|
| 128 | <CENTER> |
---|
| 129 | <TABLE COLS=6 WIDTH="60%" BORDER=0> |
---|
| 130 | <TR><TD ALIGN=left><STRONG>31</STRONG></TD> |
---|
| 131 | <TD ALIGN=right><STRONG>26</STRONG></TD> |
---|
| 132 | <TD ALIGN=left><STRONG>25</STRONG></TD> |
---|
| 133 | <TD ALIGN=right><STRONG>16</STRONG></TD> |
---|
| 134 | <TD ALIGN=left><STRONG>15</STRONG></TD> |
---|
| 135 | <TD ALIGN=right><STRONG>0</STRONG></TD></TR> |
---|
| 136 | </TABLE> |
---|
| 137 | </CENTER> |
---|
| 138 | <CENTER> |
---|
| 139 | <TABLE COLS=6 WIDTH="60%" BORDER=2> |
---|
| 140 | <TR><TD ALIGN=center COLSPAN=2>Class</TD> |
---|
| 141 | <TD ALIGN=center COLSPAN=2>Node</TD> |
---|
| 142 | <TD ALIGN=center COLSPAN=2>Index</TD></TD> |
---|
| 143 | </TABLE> |
---|
| 144 | </CENTER> |
---|
| 145 | @end html |
---|
| 146 | @end ifset |
---|
| 147 | |
---|
[71689d44] | 148 | The most significant six bits are the object class. The next |
---|
| 149 | ten bits are the number of the node on which this object was |
---|
| 150 | created. The node number is always one (1) in a single |
---|
| 151 | processor system. The least significant sixteen bits form an |
---|
| 152 | identifier within a particular object type. This identifier, |
---|
| 153 | called the object index, ranges in value from 1 to the maximum |
---|
| 154 | number of objects configured for this object type. |
---|
| 155 | |
---|
[ae68ff0] | 156 | |
---|
| 157 | The three components of an object ID make it possible |
---|
| 158 | to quickly locate any object in even the most complicated |
---|
| 159 | multiprocessor system. Object ID's are associated with an |
---|
| 160 | object by RTEMS when the object is created and the corresponding |
---|
| 161 | ID is returned by the appropriate object create directive. The |
---|
| 162 | object ID is required as input to all directives involving |
---|
| 163 | objects, except those which create an object or obtain the ID of |
---|
| 164 | an object. |
---|
| 165 | |
---|
| 166 | The object identification directives can be used to |
---|
| 167 | dynamically obtain a particular object's ID given its name. |
---|
| 168 | This mapping is accomplished by searching the name table |
---|
| 169 | associated with this object type. If the name is non-unique, |
---|
| 170 | then the ID associated with the first occurrence of the name |
---|
| 171 | will be returned to the application. Since object IDs are |
---|
| 172 | returned when the object is created, the object identification |
---|
| 173 | directives are not necessary in a properly designed single |
---|
| 174 | processor application. |
---|
| 175 | |
---|
[71689d44] | 176 | In addition, services are provided to portably examine the |
---|
| 177 | three subcomponents of an RTEMS ID. These services are |
---|
| 178 | prototyped as follows: |
---|
| 179 | |
---|
| 180 | @cindex obtaining class from object ID |
---|
| 181 | @cindex obtaining node from object ID |
---|
| 182 | @cindex obtaining index from object ID |
---|
| 183 | @cindex get class from object ID |
---|
| 184 | @cindex get node from object ID |
---|
| 185 | @cindex get index from object ID |
---|
| 186 | @findex rtems_get_class |
---|
| 187 | @findex rtems_get_node |
---|
| 188 | @findex rtems_get_index |
---|
| 189 | |
---|
| 190 | @example |
---|
| 191 | rtems_unsigned32 rtems_get_class( rtems_id ); |
---|
| 192 | rtems_unsigned32 rtems_get_node( rtems_id ); |
---|
| 193 | rtems_unsigned32 rtems_get_index( rtems_id ); |
---|
| 194 | @end example |
---|
| 195 | |
---|
[ae68ff0] | 196 | An object control block is a data structure defined |
---|
| 197 | by RTEMS which contains the information necessary to manage a |
---|
| 198 | particular object type. For efficiency reasons, the format of |
---|
| 199 | each object type's control block is different. However, many of |
---|
| 200 | the fields are similar in function. The number of each type of |
---|
| 201 | control block is application dependent and determined by the |
---|
| 202 | values specified in the user's Configuration Table. An object |
---|
| 203 | control block is allocated at object create time and freed when |
---|
| 204 | the object is deleted. With the exception of user extension |
---|
| 205 | routines, object control blocks are not directly manipulated by |
---|
| 206 | user applications. |
---|
| 207 | |
---|
| 208 | @section Communication and Synchronization |
---|
| 209 | |
---|
[169502e] | 210 | @cindex communication and synchronization |
---|
| 211 | |
---|
[ae68ff0] | 212 | In real-time multitasking applications, the ability |
---|
| 213 | for cooperating execution threads to communicate and synchronize |
---|
| 214 | with each other is imperative. A real-time executive should |
---|
| 215 | provide an application with the following capabilities: |
---|
| 216 | |
---|
| 217 | @itemize @bullet |
---|
| 218 | @item Data transfer between cooperating tasks |
---|
| 219 | @item Data transfer between tasks and ISRs |
---|
| 220 | @item Synchronization of cooperating tasks |
---|
| 221 | @item Synchronization of tasks and ISRs |
---|
| 222 | @end itemize |
---|
| 223 | |
---|
| 224 | Most RTEMS managers can be used to provide some form |
---|
| 225 | of communication and/or synchronization. However, managers |
---|
| 226 | dedicated specifically to communication and synchronization |
---|
| 227 | provide well established mechanisms which directly map to the |
---|
| 228 | application's varying needs. This level of flexibility allows |
---|
| 229 | the application designer to match the features of a particular |
---|
| 230 | manager with the complexity of communication and synchronization |
---|
| 231 | required. The following managers were specifically designed for |
---|
| 232 | communication and synchronization: |
---|
| 233 | |
---|
| 234 | @itemize @bullet |
---|
| 235 | @item Semaphore |
---|
| 236 | @item Message Queue |
---|
| 237 | @item Event |
---|
| 238 | @item Signal |
---|
| 239 | @end itemize |
---|
| 240 | |
---|
| 241 | The semaphore manager supports mutual exclusion |
---|
| 242 | involving the synchronization of access to one or more shared |
---|
| 243 | user resources. Binary semaphores may utilize the optional |
---|
| 244 | priority inheritance algorithm to avoid the problem of priority |
---|
| 245 | inversion. The message manager supports both communication and |
---|
| 246 | synchronization, while the event manager primarily provides a |
---|
| 247 | high performance synchronization mechanism. The signal manager |
---|
| 248 | supports only asynchronous communication and is typically used |
---|
| 249 | for exception handling. |
---|
| 250 | |
---|
| 251 | @section Time |
---|
| 252 | |
---|
[169502e] | 253 | @cindex time |
---|
| 254 | |
---|
[ae68ff0] | 255 | The development of responsive real-time applications |
---|
| 256 | requires an understanding of how RTEMS maintains and supports |
---|
| 257 | time-related operations. The basic unit of time in RTEMS is |
---|
| 258 | known as a tick. The frequency of clock ticks is completely |
---|
| 259 | application dependent and determines the granularity and |
---|
| 260 | accuracy of all interval and calendar time operations. |
---|
| 261 | |
---|
| 262 | By tracking time in units of ticks, RTEMS is capable |
---|
| 263 | of supporting interval timing functions such as task delays, |
---|
| 264 | timeouts, timeslicing, the delayed execution of timer service |
---|
| 265 | routines, and the rate monotonic scheduling of tasks. An |
---|
| 266 | interval is defined as a number of ticks relative to the current |
---|
| 267 | time. For example, when a task delays for an interval of ten |
---|
| 268 | ticks, it is implied that the task will not execute until ten |
---|
| 269 | clock ticks have occurred. |
---|
| 270 | |
---|
| 271 | A characteristic of interval timing is that the |
---|
| 272 | actual interval period may be a fraction of a tick less than the |
---|
| 273 | interval requested. This occurs because the time at which the |
---|
| 274 | delay timer is set up occurs at some time between two clock |
---|
| 275 | ticks. Therefore, the first countdown tick occurs in less than |
---|
| 276 | the complete time interval for a tick. This can be a problem if |
---|
| 277 | the clock granularity is large. |
---|
| 278 | |
---|
| 279 | The rate monotonic scheduling algorithm is a hard |
---|
| 280 | real-time scheduling methodology. This methodology provides |
---|
| 281 | rules which allows one to guarantee that a set of independent |
---|
| 282 | periodic tasks will always meet their deadlines -- even under |
---|
| 283 | transient overload conditions. The rate monotonic manager |
---|
| 284 | provides directives built upon the Clock Manager's interval |
---|
| 285 | timer support routines. |
---|
| 286 | |
---|
| 287 | Interval timing is not sufficient for the many |
---|
| 288 | applications which require that time be kept in wall time or |
---|
| 289 | true calendar form. Consequently, RTEMS maintains the current |
---|
| 290 | date and time. This allows selected time operations to be |
---|
| 291 | scheduled at an actual calendar date and time. For example, a |
---|
| 292 | task could request to delay until midnight on New Year's Eve |
---|
| 293 | before lowering the ball at Times Square. |
---|
| 294 | |
---|
| 295 | Obviously, the directives which use intervals or wall |
---|
| 296 | time cannot operate without some external mechanism which |
---|
| 297 | provides a periodic clock tick. This clock tick is typically |
---|
| 298 | provided by a real time clock or counter/timer device. |
---|
| 299 | |
---|
| 300 | @section Memory Management |
---|
| 301 | |
---|
[169502e] | 302 | @cindex memory management |
---|
| 303 | |
---|
[ae68ff0] | 304 | RTEMS memory management facilities can be grouped |
---|
| 305 | into two classes: dynamic memory allocation and address |
---|
| 306 | translation. Dynamic memory allocation is required by |
---|
| 307 | applications whose memory requirements vary through the |
---|
| 308 | application's course of execution. Address translation is |
---|
| 309 | needed by applications which share memory with another CPU or an |
---|
| 310 | intelligent Input/Output processor. The following RTEMS |
---|
| 311 | managers provide facilities to manage memory: |
---|
| 312 | |
---|
| 313 | @itemize @bullet |
---|
| 314 | @item Region |
---|
| 315 | |
---|
| 316 | @item Partition |
---|
| 317 | |
---|
| 318 | @item Dual Ported Memory |
---|
| 319 | @end itemize |
---|
| 320 | |
---|
| 321 | RTEMS memory management features allow an application |
---|
| 322 | to create simple memory pools of fixed size buffers and/or more |
---|
| 323 | complex memory pools of variable size segments. The partition |
---|
| 324 | manager provides directives to manage and maintain pools of |
---|
| 325 | fixed size entities such as resource control blocks. |
---|
| 326 | Alternatively, the region manager provides a more general |
---|
| 327 | purpose memory allocation scheme that supports variable size |
---|
| 328 | blocks of memory which are dynamically obtained and freed by the |
---|
| 329 | application. The dual-ported memory manager provides executive |
---|
| 330 | support for address translation between internal and external |
---|
| 331 | dual-ported RAM address space. |
---|