[0074691a] | 1 | RTEMS C++ Library |
---|
| 2 | ================= |
---|
| 3 | |
---|
| 4 | The RTEMS C++ Library or librtems++ is a wrapper for the RTEMS API. |
---|
| 5 | The classes provide as close a match to the RTEMS C API, for |
---|
| 6 | performance, to share the existing C documentation as much as |
---|
| 7 | possible, and to allow easy tracking of any changes to the RTEMS C |
---|
| 8 | API. |
---|
| 9 | |
---|
| 10 | The C++ interface only uses RTEMS API calls. No external references |
---|
| 11 | or internal interfaces are used. This allows the classes to be used |
---|
| 12 | in separately compiled modules or applications which link to the RTEMS |
---|
| 13 | trap interface. |
---|
| 14 | |
---|
| 15 | (This is the goal, which has not quite been reached. The TOD macro for |
---|
| 16 | micro-seconds to ticks is used, and this uses an internal global RTEMS |
---|
| 17 | variable) |
---|
| 18 | |
---|
| 19 | The C++ interface does not deal with RTEMS initialisation or the |
---|
| 20 | device driver interface. The current view is these parts of a system |
---|
| 21 | are best handled in the current manner. This means BSP for |
---|
| 22 | initialisation and the C API for drivers. |
---|
| 23 | |
---|
| 24 | RTEMS C++ Classes |
---|
| 25 | ================= |
---|
| 26 | |
---|
| 27 | The classes map to the managers of RTEMS. |
---|
| 28 | |
---|
| 29 | The methods have default values selected which try to fit most cases |
---|
| 30 | or follow the documented RTEMS default values. Moving from left to |
---|
| 31 | right the parameters become less used, allowing the defaults to be |
---|
| 32 | selected. An example is the scope parameter for most classes. This |
---|
| 33 | can be local or global. I assume that most RTEMS objects are local, |
---|
| 34 | therefore it has been made the last parameter. |
---|
| 35 | |
---|
| 36 | Inline methods have been used for methods which are commonly used in |
---|
| 37 | applications. This tries to add the minimum of overhead. For |
---|
| 38 | example, the methods to send or receive events are inline, while all |
---|
| 39 | methods for control of a task are not. |
---|
| 40 | |
---|
| 41 | The RTEMS types, enumerations, and defines are used. If a new type, |
---|
| 42 | enumeration or define is made it will map directly to the RTEMS |
---|
| 43 | equivalent. For example the enumeration Scope is defined for various |
---|
| 44 | classes which can be local or global. The elements of the enumeration |
---|
| 45 | are forced to the same value as the RTEMS values. An enumeration is |
---|
| 46 | used in this case to allow the compiler to type check a little |
---|
| 47 | better. It saves having to check only RTEMS_LOCAL or RTEMS_GLOBAL is |
---|
| 48 | passed as a parameter (I am not convinced this is really needed as the |
---|
| 49 | goal was to not define anything and to only use what RTEMS provided). |
---|
| 50 | |
---|
| 51 | Where possible the various parts of an option bit set, or mode can be |
---|
| 52 | controlled separately or controlled as a group. An example is the |
---|
| 53 | task mode. The RTEMS C API allows a set of modes to be modified at |
---|
| 54 | once. The TaskMode class allows this to occur, while also providing |
---|
| 55 | methods to control a single mode item. |
---|
| 56 | |
---|
| 57 | The name of an object is always passed as a string. The classes turn |
---|
| 58 | the string into a rtems_name variable. The string does not have to be |
---|
| 59 | nul character terminated. |
---|
| 60 | |
---|
| 61 | The RTEMS C API uses 'delete' to remove or kill an RTEMS object. This |
---|
| 62 | is a reserved word in C++, so the word 'destroy' is used instead. |
---|
| 63 | |
---|
| 64 | Calling the classes from interrupts follows the rules of RTEMS. An |
---|
| 65 | exception introduced by the class library is the last status code. |
---|
| 66 | There is only one last status code for each instance of the library's |
---|
| 67 | classes and it is not protected. This needs to be watched for. Maybe |
---|
| 68 | a better solution needs to be found, such as interrupt calls do not set |
---|
| 69 | the last status code. |
---|
| 70 | |
---|
| 71 | RTEMS objects created by the C++ library can be operated on by C code |
---|
| 72 | just as any other RTEMS object. If limitations exist they should be |
---|
| 73 | documented in under the class. |
---|
| 74 | |
---|
| 75 | RTEMS Object Ownership |
---|
| 76 | ====================== |
---|
| 77 | |
---|
| 78 | The concept of ownership of an object is not defined as part of the |
---|
| 79 | RTEMS C API. A piece of code executing as part a task can create a |
---|
| 80 | message queue. Another piece of code running as part of a different |
---|
| 81 | task can destroy the message queue. Correct behavior between the code |
---|
| 82 | that creates the message queue and the code which destroy's the |
---|
| 83 | message queue must be provided by the programmer. |
---|
| 84 | |
---|
| 85 | The librtems++ supports the concept of ownership of an RTEMS object. |
---|
| 86 | Only the C++ object that creates the RTEMS object can destroy it. A |
---|
| 87 | C++ object can connect to an existing RTEMS object and control it, |
---|
| 88 | how-ever it can not destroy it. |
---|
| 89 | |
---|
| 90 | Copy constructors and assignment operators are provided to in-force |
---|
| 91 | this rule. |
---|
| 92 | |
---|
| 93 | Ownership only applies to classes that create RTEMS objects. These |
---|
| 94 | classes contain a flag which signals ownership of the id. |
---|
| 95 | |
---|
| 96 | Timeouts |
---|
| 97 | ======== |
---|
| 98 | |
---|
| 99 | The timeout value is specified in micro-seconds. The classes turn the |
---|
| 100 | micro-second timeout value into ticks required by the RTEMS C API. |
---|
| 101 | |
---|
| 102 | This causes a problem for timeout values which are less than one tick. |
---|
| 103 | This case is tested for and the timeout value is set to one tick. All |
---|
| 104 | other cases round down to the nearest tick. |
---|
| 105 | |
---|
| 106 | Status Codes |
---|
| 107 | ============ |
---|
| 108 | |
---|
| 109 | All classes which form the C++ API are derived from the StatusCode |
---|
| 110 | class. This class provides a common method for handling the status |
---|
| 111 | code returned by RTEMS. |
---|
| 112 | |
---|
| 113 | The last returned status code is held in the StatusCode object. It |
---|
| 114 | can be queried directly, or as a boolean. You can also obtain an |
---|
| 115 | error string for the status code. |
---|
| 116 | |
---|
| 117 | The setting of a status code is restricted to derived classes. |
---|
| 118 | |
---|
| 119 | The last status code attribute of the class is only ever set to an |
---|
| 120 | RTEMS defined status code. |
---|
| 121 | |
---|
| 122 | Event Class |
---|
| 123 | =========== |
---|
| 124 | |
---|
| 125 | The event class allows users to send and receive events to and from |
---|
| 126 | tasks. |
---|
| 127 | |
---|
| 128 | Events objects are by default connected the RTEMS_SELF task. A send |
---|
| 129 | or receive will operate on the task currently executing. |
---|
| 130 | |
---|
| 131 | An Event object can be connected to a task using the connect method. |
---|
| 132 | The name is the name of the task. Connection can also be achieved by |
---|
| 133 | using the copy constructor or assignment operator. |
---|
| 134 | |
---|
| 135 | Events can be sent to a task by specifying an RTEMS task id, or by |
---|
| 136 | passing a reference to a Task object. |
---|
| 137 | |
---|
| 138 | Interrupt Class |
---|
| 139 | =============== |
---|
| 140 | |
---|
| 141 | The interrupt class allows a protected virtual method of a derived |
---|
| 142 | class to be an interrupt handler. |
---|
| 143 | |
---|
| 144 | You derive from this class and provide the handler method. The next |
---|
| 145 | interrupt after the vector is caught will cause the handler method to |
---|
| 146 | be entered. |
---|
| 147 | |
---|
| 148 | You can chain the interrupt by calling the chain method. If the old |
---|
| 149 | handler is not an instance of this class the chain is passed as "void |
---|
| 150 | (*)(void)". If it is an instance of this class, the handler method is |
---|
| 151 | directly called. (Chaining has not been tested) |
---|
| 152 | |
---|
| 153 | This class implements a table of pointers to the last instance to |
---|
| 154 | catch the interrupt. A static method of the class catches the |
---|
| 155 | interrupt and re-directs the interrupt to the instance in the table. |
---|
| 156 | The re-direct adds a additional virtual function call and return to |
---|
| 157 | the overhead of the interrupt. For a i386 type processor this is |
---|
| 158 | about 12 instructions including the function call entry. |
---|
| 159 | |
---|
| 160 | Message Queue Class |
---|
| 161 | =================== |
---|
| 162 | |
---|
| 163 | The MessageQueue class allows message queue's to be created, or |
---|
| 164 | connected too. Only the creator can destroy a message queue. |
---|
| 165 | |
---|
| 166 | The class implements, sending, urgent sending, broadcast, flushing, |
---|
| 167 | and receiving. |
---|
| 168 | |
---|
| 169 | Semaphore Class |
---|
| 170 | =============== |
---|
| 171 | |
---|
| 172 | The Semaphore class allows semaphores to be created, or connected |
---|
| 173 | too. Only the creator can destroy a semaphore. |
---|
| 174 | |
---|
| 175 | All types of semaphores can be created. |
---|
| 176 | |
---|
| 177 | (Not tested in the test code) |
---|
| 178 | |
---|
| 179 | Task Class |
---|
| 180 | ========== |
---|
| 181 | |
---|
| 182 | The Task class allows tasks to be created, or connected too. Only the |
---|
| 183 | creator can destroy a task. |
---|
| 184 | |
---|
| 185 | If creating a task, derive from the Task class and provide the body |
---|
| 186 | method. The body method is the entry point for a task. When |
---|
| 187 | connecting to an existing task, no body method is required to be |
---|
| 188 | provided. It is how-ever required if you create a task. This is not |
---|
| 189 | enforced by the compiler, how-ever the default body will be entered, |
---|
| 190 | and it contains no code. The RTEMS default behaviour for a task that |
---|
| 191 | returns occurs. |
---|
| 192 | |
---|
| 193 | The mode of a task is controlled using the TaskMode class. |
---|
| 194 | |
---|
| 195 | The Task class allows you to start, restart, suspend, and resume a |
---|
| 196 | task. You can control the priority, and access the note-pad |
---|
| 197 | registers. The task can also be slept using the wake_after and |
---|
| 198 | wake_when methods. |
---|
| 199 | |
---|
| 200 | Currently the task argument is used to pass the 'this' pointer to the |
---|
| 201 | libraries default task body. The actual argument is held in the class |
---|
| 202 | instance and passed to the virtual body method. This means of passing |
---|
| 203 | the 'this' pointer through RTEMS to the default task body requires the |
---|
| 204 | actual task object to perform a restart call. This is not really the |
---|
| 205 | best solution to the problem. Another solution is to remove a notpad |
---|
| 206 | register, say 31 from the task and use it. This would mean any Task |
---|
| 207 | object could stop and restart a task how-ever a notpad register is |
---|
| 208 | lost. Any other ideas are welcome. |
---|
| 209 | |
---|
| 210 | Task Mode Class |
---|
| 211 | =============== |
---|
| 212 | |
---|
| 213 | The TaskMode class allows you to query or change the mode of a task. |
---|
| 214 | The object only operates on the currently executing task. |
---|
| 215 | |
---|
| 216 | The standard flags defined in RTEMS are used. |
---|
| 217 | |
---|
| 218 | Methods are provided to operate on a group of modes which are required |
---|
| 219 | to be changed in a single operation. The mode and mask is specified |
---|
| 220 | by ORing the required flags as documented in the RTEMS manual. |
---|
| 221 | |
---|
| 222 | Methods are provided for accessing and controlling a specific mode. |
---|
| 223 | The returned value will only contain the requested mode's flags, and |
---|
| 224 | only the that mode will be changed when setting a mode. |
---|
| 225 | |
---|
| 226 | Timer Class |
---|
| 227 | =========== |
---|
| 228 | |
---|
| 229 | The Timer class allows timers to be created. You cannot connect to an |
---|
| 230 | existing timer. |
---|
| 231 | |
---|
| 232 | You derive from the Timer class and provide the trigger method. This |
---|
| 233 | method is called when the timer triggers or times out. |
---|
| 234 | |
---|
| 235 | You can request a single shot timer using the fire_after or fire_when |
---|
| 236 | methods, or a periodic timer by calling the repeat_file_at method. |
---|
| 237 | |
---|
| 238 | You cannot copy timer objects. |
---|
| 239 | |
---|
| 240 | Contact |
---|
| 241 | ======= |
---|
| 242 | Send any question to me Chris Johns at cjohns@plessey.com.au, or the RTEMS |
---|
| 243 | mailing list. |
---|
| 244 | |
---|
| 245 | To Do |
---|
| 246 | ===== |
---|
| 247 | |
---|
| 248 | 1) Develop a complete test suite (under way, cjohns@plessey.com.au). |
---|
| 249 | |
---|
| 250 | 2) Complete wrapping the remaining RTEMS C API. |
---|
| 251 | |
---|
| 252 | 3) Provide light weight cout/cerr/clog classes based on printf for |
---|
| 253 | embedded systems. |
---|
| 254 | |
---|
| 255 | 4) Provide a memory serial class which maps the <</>> operators onto |
---|
| 256 | raw memory in network byte order independent of CPU byte order. |
---|
| 257 | |
---|
| 258 | 5) Fix the Task class so any Task object can restart a task. |
---|
| 259 | |
---|
| 260 | 6) Provide some frame work classes which allow actor type objects that |
---|
| 261 | start in an ordered manner. |
---|
| 262 | |
---|