[b96254f] | 1 | /** |
---|
[c42d1a4] | 2 | * @file |
---|
[5fc855d] | 3 | * |
---|
| 4 | * @ingroup ClassicUserExtensions |
---|
| 5 | * |
---|
[c42d1a4] | 6 | * @brief User Extensions API. |
---|
[b96254f] | 7 | */ |
---|
[28352fae] | 8 | |
---|
[b96254f] | 9 | /* |
---|
[790b50b] | 10 | * COPYRIGHT (c) 1989-2008. |
---|
[ac7d5ef0] | 11 | * On-Line Applications Research Corporation (OAR). |
---|
| 12 | * |
---|
[98e4ebf5] | 13 | * The license and distribution terms for this file may be |
---|
| 14 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 15 | * http://www.rtems.org/license/LICENSE. |
---|
[ac7d5ef0] | 16 | */ |
---|
| 17 | |
---|
[092f142a] | 18 | #ifndef _RTEMS_EXTENSION_H |
---|
| 19 | #define _RTEMS_EXTENSION_H |
---|
[ac7d5ef0] | 20 | |
---|
[6f1384c] | 21 | #include <rtems/rtems/status.h> |
---|
| 22 | #include <rtems/rtems/types.h> |
---|
[5fc855d] | 23 | #include <rtems/score/userext.h> |
---|
[3a4ae6c] | 24 | |
---|
[2c8b87f] | 25 | #ifdef __cplusplus |
---|
| 26 | extern "C" { |
---|
| 27 | #endif |
---|
| 28 | |
---|
[c42d1a4] | 29 | typedef User_extensions_routine |
---|
[c52568d] | 30 | rtems_extension RTEMS_DEPRECATED; |
---|
[c42d1a4] | 31 | |
---|
| 32 | /** |
---|
| 33 | * @defgroup ClassicUserExtensions User Extensions |
---|
| 34 | * |
---|
| 35 | * @ingroup ClassicRTEMS |
---|
| 36 | * |
---|
| 37 | * @brief The User Extensions Manager allows the application developer to |
---|
| 38 | * augment the executive by allowing them to supply extension routines which |
---|
[28352fae] | 39 | * are invoked at critical system events. |
---|
[c42d1a4] | 40 | * |
---|
| 41 | * @section ClassicUserExtensionsSets Extension Sets |
---|
| 42 | * |
---|
| 43 | * An @ref User_extensions_Table "extension set" is defined as a set of |
---|
| 44 | * routines which are invoked at each of the critical system events at which |
---|
| 45 | * user extension routines are invoked. Together a set of these routines |
---|
| 46 | * typically perform a specific functionality such as performance monitoring or |
---|
| 47 | * debugger support. |
---|
| 48 | * |
---|
| 49 | * RTEMS allows the user to have multiple extension sets active at the same |
---|
| 50 | * time. First, a single static extension set may be defined as the |
---|
| 51 | * application's User Extension Table which is included as part of the |
---|
| 52 | * Configuration Table. This extension set is active for the entire life of the |
---|
| 53 | * system and may not be deleted. This extension set is especially important |
---|
| 54 | * because it is the only way the application can provided a fatal error |
---|
| 55 | * extension which is invoked if RTEMS fails during the |
---|
| 56 | * rtems_initialize_data_structures() directive. The static extension set is |
---|
| 57 | * optional and may be configured as @c NULL if no static extension set is |
---|
| 58 | * required. |
---|
| 59 | * |
---|
| 60 | * Second, the user can install dynamic extensions using the |
---|
| 61 | * rtems_extension_create() directive. These extensions are RTEMS objects in |
---|
| 62 | * that they have a name, an ID, and can be dynamically created and deleted. In |
---|
| 63 | * contrast to the static extension set, these extensions can only be created |
---|
| 64 | * and installed after the rtems_initialize_data_structures() directive |
---|
| 65 | * successfully completes execution. Dynamic extensions are useful for |
---|
| 66 | * encapsulating the functionality of an extension set. For example, the |
---|
| 67 | * application could use extensions to manage a special coprocessor, do |
---|
| 68 | * performance monitoring, and to do stack bounds checking. Each of these |
---|
| 69 | * extension sets could be written and installed independently of the others. |
---|
| 70 | * |
---|
| 71 | * All user extensions are optional and RTEMS places no naming restrictions on |
---|
| 72 | * the user. The user extension entry points are copied into an internal RTEMS |
---|
| 73 | * structure. This means the user does not need to keep the table after |
---|
| 74 | * creating it, and changing the handler entry points dynamically in a table |
---|
| 75 | * once created has no effect. Creating a table local to a function can save |
---|
| 76 | * space in space limited applications. |
---|
| 77 | * |
---|
| 78 | * Extension switches do not effect the context switch overhead if no switch |
---|
| 79 | * handler is installed. |
---|
| 80 | * |
---|
| 81 | * @section ClassicUserExtensionsTCB Task Control Block Area |
---|
| 82 | * |
---|
| 83 | * RTEMS provides for a pointer to a user-defined data area for each extension |
---|
| 84 | * set to be linked to each task's control block (TCB). This area is only |
---|
| 85 | * available for the dynamic extensions. This set of pointers is an extension |
---|
| 86 | * of the TCB and can be used to store additional data required by the user's |
---|
[d5154d0f] | 87 | * extension functions. |
---|
[c42d1a4] | 88 | * |
---|
| 89 | * The TCB extension is an array of pointers in the TCB. The index into the |
---|
| 90 | * table can be obtained from the extension identifier returned when the |
---|
| 91 | * extension is created: |
---|
| 92 | * |
---|
| 93 | * @code |
---|
| 94 | * rtems_tcb *task = some_task; |
---|
| 95 | * size_t index = rtems_object_id_get_index(extension_id); |
---|
| 96 | * void *extension_data = task->extensions [index]; |
---|
| 97 | * @endcode |
---|
| 98 | * |
---|
| 99 | * The number of pointers in the area is the same as the number of user |
---|
| 100 | * extension sets configured. This allows an application to augment the TCB |
---|
| 101 | * with user-defined information. For example, an application could implement |
---|
| 102 | * task profiling by storing timing statistics in the TCB's extended memory |
---|
| 103 | * area. When a task context switch is being executed, the task switch |
---|
| 104 | * extension could read a real-time clock to calculate how long the task being |
---|
| 105 | * swapped out has run as well as timestamp the starting time for the task |
---|
| 106 | * being swapped in. |
---|
| 107 | * |
---|
| 108 | * If used, the extended memory area for the TCB should be allocated and the |
---|
| 109 | * TCB extension pointer should be set at the time the task is created or |
---|
| 110 | * started by either the task create or task start extension. The application |
---|
| 111 | * is responsible for managing this extended memory area for the TCBs. The |
---|
| 112 | * memory may be reinitialized by the task restart extension and should be |
---|
| 113 | * deallocated by the task delete extension when the task is deleted. Since the |
---|
| 114 | * TCB extension buffers would most likely be of a fixed size, the RTEMS |
---|
| 115 | * partition manager could be used to manage the application's extended memory |
---|
| 116 | * area. The application could create a partition of fixed size TCB extension |
---|
| 117 | * buffers and use the partition manager's allocation and deallocation |
---|
| 118 | * directives to obtain and release the extension buffers. |
---|
| 119 | * |
---|
| 120 | * @section ClassicUserExtensionsOrder Order of Invokation |
---|
| 121 | * |
---|
| 122 | * When one of the critical system events occur, the user extensions are |
---|
| 123 | * invoked in either @a forward or @a reverse order. Forward order indicates |
---|
| 124 | * that the static extension set is invoked followed by the dynamic extension |
---|
| 125 | * sets in the order in which they were created. Reverse order means that the |
---|
| 126 | * dynamic extension sets are invoked in the opposite of the order in which |
---|
| 127 | * they were created followed by the static extension set. By invoking the |
---|
| 128 | * extension sets in this order, extensions can be built upon one another. At |
---|
| 129 | * the following system events, the extensions are invoked in forward order: |
---|
| 130 | * |
---|
| 131 | * - Task creation |
---|
[b7de5de] | 132 | * - Task start |
---|
| 133 | * - Task restart |
---|
[c42d1a4] | 134 | * - Task context switch |
---|
| 135 | * - Post task context switch |
---|
[28352fae] | 136 | * - Task begins to execute |
---|
[c42d1a4] | 137 | * |
---|
| 138 | * At the following system events, the extensions are invoked in reverse order: |
---|
| 139 | * |
---|
[08d01a1] | 140 | * - Task exit |
---|
[c42d1a4] | 141 | * - Task deletion |
---|
[28352fae] | 142 | * - Fatal error detection |
---|
[c42d1a4] | 143 | * |
---|
| 144 | * At these system events, the extensions are invoked in reverse order to |
---|
| 145 | * insure that if an extension set is built upon another, the more complicated |
---|
| 146 | * extension is invoked before the extension set it is built upon. For example, |
---|
| 147 | * by invoking the static extension set last it is known that the "system" |
---|
| 148 | * fatal error extension will be the last fatal error extension executed. |
---|
| 149 | * Another example is use of the task delete extension by the Standard C |
---|
| 150 | * Library. Extension sets which are installed after the Standard C Library |
---|
| 151 | * will operate correctly even if they utilize the C Library because the C |
---|
| 152 | * Library's task delete extension is invoked after that of the other |
---|
| 153 | * extensions. |
---|
[3a4ae6c] | 154 | */ |
---|
[b697bc6] | 155 | /**@{**/ |
---|
[3a4ae6c] | 156 | |
---|
| 157 | typedef User_extensions_thread_create_extension rtems_task_create_extension; |
---|
| 158 | typedef User_extensions_thread_delete_extension rtems_task_delete_extension; |
---|
| 159 | typedef User_extensions_thread_start_extension rtems_task_start_extension; |
---|
| 160 | typedef User_extensions_thread_restart_extension rtems_task_restart_extension; |
---|
| 161 | typedef User_extensions_thread_switch_extension rtems_task_switch_extension; |
---|
| 162 | typedef User_extensions_thread_begin_extension rtems_task_begin_extension; |
---|
| 163 | typedef User_extensions_thread_exitted_extension rtems_task_exitted_extension; |
---|
| 164 | typedef User_extensions_fatal_extension rtems_fatal_extension; |
---|
[d1505a1] | 165 | typedef User_extensions_thread_terminate_extension rtems_task_terminate_extension; |
---|
[3a4ae6c] | 166 | |
---|
| 167 | typedef User_extensions_Table rtems_extensions_table; |
---|
[ac7d5ef0] | 168 | |
---|
[e4b40531] | 169 | typedef Internal_errors_Source rtems_fatal_source; |
---|
| 170 | |
---|
| 171 | typedef Internal_errors_t rtems_fatal_code; |
---|
| 172 | |
---|
[c42d1a4] | 173 | /** |
---|
| 174 | * @brief Creates an extension set object. |
---|
[ac7d5ef0] | 175 | * |
---|
[c42d1a4] | 176 | * This directive creates a extension set object from the extension table |
---|
| 177 | * @a extension_table. The assigned extension set identifier is returned in |
---|
| 178 | * @a id. The identifier is used to access this extension set in other |
---|
| 179 | * extension set related directives. The name @a name will be assigned to the |
---|
| 180 | * extension set object. |
---|
[ac7d5ef0] | 181 | * |
---|
[c42d1a4] | 182 | * Newly created extension sets are immediately installed and are invoked upon |
---|
| 183 | * the next system event supporting an extension. |
---|
[ac7d5ef0] | 184 | * |
---|
[c42d1a4] | 185 | * This directive will not cause the calling task to be preempted. |
---|
[ac7d5ef0] | 186 | * |
---|
[c42d1a4] | 187 | * @retval RTEMS_SUCCESSFUL Extension set created successfully. |
---|
| 188 | * @retval RTEMS_INVALID_ADDRESS Identifier pointer is @c NULL. |
---|
| 189 | * @retval RTEMS_INVALID_NAME Invalid extension set name. |
---|
| 190 | * @retval RTEMS_TOO_MANY Too many extension sets created. |
---|
[ac7d5ef0] | 191 | */ |
---|
| 192 | rtems_status_code rtems_extension_create( |
---|
[b7de5de] | 193 | rtems_name name, |
---|
| 194 | const rtems_extensions_table *extension_table, |
---|
| 195 | rtems_id *id |
---|
[ac7d5ef0] | 196 | ); |
---|
| 197 | |
---|
[c42d1a4] | 198 | /** |
---|
| 199 | * @brief Identifies an extension set object by a name. |
---|
| 200 | * |
---|
| 201 | * This directive obtains an extension set identifier in @a id associated with |
---|
| 202 | * the extension set name @a name. If the extension set name is not unique, |
---|
| 203 | * then the extension set identifier will match one of the extension sets with |
---|
| 204 | * that name. However, this extension set identifier is not guaranteed to |
---|
| 205 | * correspond to the desired extension set. The extension set identifier is |
---|
| 206 | * used to access this extension set in other extension set related directives. |
---|
[ac7d5ef0] | 207 | * |
---|
[c42d1a4] | 208 | * This directive will not cause the calling task to be preempted. |
---|
[ac7d5ef0] | 209 | * |
---|
[c42d1a4] | 210 | * @retval RTEMS_SUCCESSFUL Extension set identified successfully. |
---|
| 211 | * @retval RTEMS_INVALID_ADDRESS Identifier pointer is @c NULL. |
---|
| 212 | * @retval RTEMS_INVALID_NAME Extension set name not found or invalid name. |
---|
[ac7d5ef0] | 213 | */ |
---|
| 214 | rtems_status_code rtems_extension_ident( |
---|
[c42d1a4] | 215 | rtems_name name, |
---|
| 216 | rtems_id *id |
---|
[ac7d5ef0] | 217 | ); |
---|
| 218 | |
---|
[c42d1a4] | 219 | /** |
---|
| 220 | * @brief Deletes an extension set object specified by the identifier @a id. |
---|
| 221 | * |
---|
| 222 | * Any subsequent references to the extension's name and identifier are |
---|
| 223 | * invalid. |
---|
[ac7d5ef0] | 224 | * |
---|
[c42d1a4] | 225 | * This directive will not cause the calling task to be preempted. |
---|
[ac7d5ef0] | 226 | * |
---|
[c42d1a4] | 227 | * @retval RTEMS_SUCCESSFUL Extension set deleted successfully. |
---|
| 228 | * @retval RTEMS_INVALID_ID Invalid extension set identifier. |
---|
[ac7d5ef0] | 229 | */ |
---|
| 230 | rtems_status_code rtems_extension_delete( |
---|
[c42d1a4] | 231 | rtems_id id |
---|
[ac7d5ef0] | 232 | ); |
---|
| 233 | |
---|
[c42d1a4] | 234 | /** @} */ |
---|
| 235 | |
---|
[ac7d5ef0] | 236 | #ifdef __cplusplus |
---|
| 237 | } |
---|
| 238 | #endif |
---|
| 239 | |
---|
| 240 | #endif |
---|
| 241 | /* end of include file */ |
---|