1 | .. SPDX-License-Identifier: CC-BY-SA-4.0 |
---|
2 | |
---|
3 | .. Copyright (C) 1988, 2008 On-Line Applications Research Corporation (OAR) |
---|
4 | |
---|
5 | Introduction |
---|
6 | ============ |
---|
7 | |
---|
8 | RTEMS must be configured for an application. This configuration encompasses a |
---|
9 | variety of information including the length of each clock tick, the maximum |
---|
10 | number of each information RTEMS object that can be created, the application |
---|
11 | initialization tasks, the task scheduling algorithm to be used, and the device |
---|
12 | drivers in the application. |
---|
13 | |
---|
14 | Although this information is contained in data structures that are used by |
---|
15 | RTEMS at system initialization time, the data structures themselves must not be |
---|
16 | generated by hand. RTEMS provides a set of macros system which provides a |
---|
17 | simple standard mechanism to automate the generation of these structures. |
---|
18 | |
---|
19 | .. index:: confdefs.h |
---|
20 | .. index:: <rtems/confdefs.h> |
---|
21 | |
---|
22 | The RTEMS header file ``<rtems/confdefs.h>`` is at the core of the automatic |
---|
23 | generation of system configuration. It is based on the idea of setting macros |
---|
24 | which define configuration parameters of interest to the application and |
---|
25 | defaulting or calculating all others. This variety of macros can automatically |
---|
26 | produce all of the configuration data required for an RTEMS application. |
---|
27 | |
---|
28 | .. sidebar: Trivia: |
---|
29 | |
---|
30 | The term ``confdefs`` is shorthand for a *Configuration Defaults*. |
---|
31 | |
---|
32 | As a general rule, application developers only specify values for the |
---|
33 | configuration parameters of interest to them. They define what resources or |
---|
34 | features they require. In most cases, when a parameter is not specified, it |
---|
35 | defaults to zero (0) instances, a standards compliant value, or disabled as |
---|
36 | appropriate. For example, by default there will be 256 task priority levels but |
---|
37 | this can be lowered by the application. This number of priority levels is |
---|
38 | required to be compliant with the RTEID/ORKID standards upon which the Classic |
---|
39 | API is based. There are similar cases where the default is selected to be |
---|
40 | compliant with the POSIX standard. |
---|
41 | |
---|
42 | For each configuration parameter in the configuration tables, the macro |
---|
43 | corresponding to that field is discussed. The RTEMS Maintainers expect that all |
---|
44 | systems can be easily configured using the ``<rtems/confdefs.h>`` mechanism and |
---|
45 | that using this mechanism will avoid internal RTEMS configuration changes |
---|
46 | impacting applications. |
---|
47 | |
---|
48 | Default Value Selection Philosophy |
---|
49 | ================================== |
---|
50 | |
---|
51 | The user should be aware that the defaults are intentionally set as low as |
---|
52 | possible. By default, no application resources are configured. The |
---|
53 | ``<rtems/confdefs.h>`` file ensures that at least one application task or |
---|
54 | thread is configured and that at least one of the initialization task/thread |
---|
55 | tables is configured. |
---|
56 | |
---|
57 | .. _Sizing the RTEMS Workspace: |
---|
58 | |
---|
59 | Sizing the RTEMS Workspace |
---|
60 | ========================== |
---|
61 | |
---|
62 | The RTEMS Workspace is a user-specified block of memory reserved for use by |
---|
63 | RTEMS. The application should NOT modify this memory. This area consists |
---|
64 | primarily of the RTEMS data structures whose exact size depends upon the values |
---|
65 | specified in the Configuration Table. In addition, task stacks and floating |
---|
66 | point context areas are dynamically allocated from the RTEMS Workspace. |
---|
67 | |
---|
68 | The ``<rtems/confdefs.h>`` mechanism calculates the size of the RTEMS Workspace |
---|
69 | automatically. It assumes that all tasks are floating point and that all will |
---|
70 | be allocated the minimum stack space. This calculation includes the amount of |
---|
71 | memory that will be allocated for internal use by RTEMS. The automatic |
---|
72 | calculation may underestimate the workspace size truly needed by the |
---|
73 | application, in which case one can use the ``CONFIGURE_MEMORY_OVERHEAD`` macro |
---|
74 | to add a value to the estimate. See :ref:`Specify Memory Overhead` for more |
---|
75 | details. |
---|
76 | |
---|
77 | The memory area for the RTEMS Workspace is determined by the BSP. In case the |
---|
78 | RTEMS Workspace is too large for the available memory, then a fatal run-time |
---|
79 | error occurs and the system terminates. |
---|
80 | |
---|
81 | The file ``<rtems/confdefs.h>`` will calculate the value of the |
---|
82 | ``work_space_size`` parameter of the Configuration Table. There are many |
---|
83 | parameters the application developer can specify to help ``<rtems/confdefs.h>`` |
---|
84 | in its calculations. Correctly specifying the application requirements via |
---|
85 | parameters such as ``CONFIGURE_EXTRA_TASK_STACKS`` and |
---|
86 | ``CONFIGURE_MAXIMUM_TASKS`` is critical for production software. |
---|
87 | |
---|
88 | For each class of objects, the allocation can operate in one of two ways. The |
---|
89 | default way has an ceiling on the maximum number of object instances which can |
---|
90 | concurrently exist in the system. Memory for all instances of that object class |
---|
91 | is reserved at system initialization. The second way allocates memory for an |
---|
92 | initial number of objects and increases the current allocation by a fixed |
---|
93 | increment when required. Both ways allocate space from inside the RTEMS |
---|
94 | Workspace. |
---|
95 | |
---|
96 | See :ref:`ConfigUnlimitedObjects` for more details about the second way, which |
---|
97 | allows for dynamic allocation of objects and therefore does not provide |
---|
98 | determinism. This mode is useful mostly for when the number of objects cannot |
---|
99 | be determined ahead of time or when porting software for which you do not know |
---|
100 | the object requirements. |
---|
101 | |
---|
102 | The space needed for stacks and for RTEMS objects will vary from one version of |
---|
103 | RTEMS and from one target processor to another. Therefore it is safest to use |
---|
104 | ``<rtems/confdefs.h>`` and specify your application's requirements in terms of |
---|
105 | the numbers of objects and multiples of ``RTEMS_MINIMUM_STACK_SIZE``, as far as |
---|
106 | is possible. The automatic estimates of space required will in general change |
---|
107 | when: |
---|
108 | |
---|
109 | - a configuration parameter is changed, |
---|
110 | |
---|
111 | - task or interrupt stack sizes change, |
---|
112 | |
---|
113 | - the floating point attribute of a task changes, |
---|
114 | |
---|
115 | - task floating point attribute is altered, |
---|
116 | |
---|
117 | - RTEMS is upgraded, or |
---|
118 | |
---|
119 | - the target processor is changed. |
---|
120 | |
---|
121 | Failure to provide enough space in the RTEMS Workspace may result in fatal |
---|
122 | run-time errors terminating the system. |
---|
123 | |
---|
124 | Potential Issues with RTEMS Workspace Size Estimation |
---|
125 | ===================================================== |
---|
126 | |
---|
127 | The ``<rtems/confdefs.h>`` file estimates the amount of memory required for the |
---|
128 | RTEMS Workspace. This estimate is only as accurate as the information given to |
---|
129 | ``<rtems/confdefs.h>`` and may be either too high or too low for a variety of |
---|
130 | reasons. Some of the reasons that ``<rtems/confdefs.h>`` may reserve too much |
---|
131 | memory for RTEMS are: |
---|
132 | |
---|
133 | - All tasks/threads are assumed to be floating point. |
---|
134 | |
---|
135 | Conversely, there are many more reasons that the resource estimate could be too |
---|
136 | low: |
---|
137 | |
---|
138 | - Task/thread stacks greater than minimum size must be accounted for explicitly |
---|
139 | by developer. |
---|
140 | |
---|
141 | - Memory for messages is not included. |
---|
142 | |
---|
143 | - Device driver requirements are not included. |
---|
144 | |
---|
145 | - Network stack requirements are not included. |
---|
146 | |
---|
147 | - Requirements for add-on libraries are not included. |
---|
148 | |
---|
149 | In general, ``<rtems/confdefs.h>`` is very accurate when given enough |
---|
150 | information. However, it is quite easy to use a library and forget to account |
---|
151 | for its resources. |
---|
152 | |
---|
153 | Format to be followed for making changes in this file |
---|
154 | ===================================================== |
---|
155 | |
---|
156 | MACRO NAME: |
---|
157 | Should be alphanumeric. Can have '_' (underscore). |
---|
158 | |
---|
159 | DATA TYPE: |
---|
160 | Please refer to all existing formats. |
---|
161 | |
---|
162 | RANGE: |
---|
163 | The range depends on the Data Type of the macro. |
---|
164 | |
---|
165 | - If the data type is of type task priority, then its value should be an |
---|
166 | integer in the range of 1 to 255. |
---|
167 | |
---|
168 | - If the data type is an integer, then it can have numbers, characters (in |
---|
169 | case the value is defined using another macro) and arithmetic operations |
---|
170 | (+, -, \*, /). |
---|
171 | |
---|
172 | - If the data type is a function pointer the first character should be an |
---|
173 | alphabet or an underscore. The rest of the string can be alphanumeric. |
---|
174 | |
---|
175 | - If the data type is RTEMS Attributes or RTEMS Mode then the string should |
---|
176 | be alphanumeric. |
---|
177 | |
---|
178 | - If the data type is RTEMS NAME then the value should be an integer>=0 or |
---|
179 | ``RTEMS_BUILD_NAME( 'U', 'I', '1', ' ' )`` |
---|
180 | |
---|
181 | DEFAULT VALUE: |
---|
182 | The default value should be in the following formats- Please note that the |
---|
183 | '.' (full stop) is necessary. |
---|
184 | |
---|
185 | - In case the value is not defined then: This is not defined by default. |
---|
186 | |
---|
187 | - If we know the default value then: The default value is XXX. |
---|
188 | |
---|
189 | - If the default value is BSP Specific then: This option is BSP specific. |
---|
190 | |
---|
191 | DESCRIPTION: |
---|
192 | The description of the macro. (No specific format) |
---|
193 | |
---|
194 | NOTES: |
---|
195 | Any further notes. (No specific format) |
---|
196 | |
---|
197 | Configuration Example |
---|
198 | ===================== |
---|
199 | |
---|
200 | In the following example, the configuration information for a system with a |
---|
201 | single message queue, four (4) tasks, and a timeslice of fifty (50) |
---|
202 | milliseconds is as follows: |
---|
203 | |
---|
204 | .. code-block:: c |
---|
205 | |
---|
206 | #include <bsp.h> |
---|
207 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
208 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
209 | #define CONFIGURE_MICROSECONDS_PER_TICK 1000 /* 1 millisecond */ |
---|
210 | #define CONFIGURE_TICKS_PER_TIMESLICE 50 /* 50 milliseconds */ |
---|
211 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
212 | #define CONFIGURE_MAXIMUM_TASKS 4 |
---|
213 | #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1 |
---|
214 | #define CONFIGURE_MESSAGE_BUFFER_MEMORY \ |
---|
215 | CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(20, sizeof(struct USER_MESSAGE)) |
---|
216 | #define CONFIGURE_INIT |
---|
217 | #include <rtems/confdefs.h> |
---|
218 | |
---|
219 | In this example, only a few configuration parameters are specified. The impact |
---|
220 | of these are as follows: |
---|
221 | |
---|
222 | - The example specified ``CONFIGURE_RTEMS_INIT_TASK_TABLE`` but did not specify |
---|
223 | any additional parameters. This results in a configuration of an application |
---|
224 | which will begin execution of a single initialization task named ``Init`` |
---|
225 | which is non-preemptible and at priority one (1). |
---|
226 | |
---|
227 | - By specifying ``CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER``, this application |
---|
228 | is configured to have a clock tick device driver. Without a clock tick device |
---|
229 | driver, RTEMS has no way to know that time is passing and will be unable to |
---|
230 | support delays and wall time. Further configuration details about time are |
---|
231 | provided. Per ``CONFIGURE_MICROSECONDS_PER_TICK`` and |
---|
232 | ``CONFIGURE_TICKS_PER_TIMESLICE``, the user specified they wanted a clock |
---|
233 | tick to occur each millisecond, and that the length of a timeslice would be |
---|
234 | fifty (50) milliseconds. |
---|
235 | |
---|
236 | - By specifying ``CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER``, the application |
---|
237 | will include a console device driver. Although the console device driver may |
---|
238 | support a combination of multiple serial ports and display and keyboard |
---|
239 | combinations, it is only required to provide a single device named |
---|
240 | ``/dev/console``. This device will be used for Standard Input, Output and |
---|
241 | Error I/O Streams. Thus when ``CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER`` |
---|
242 | is specified, implicitly three (3) file descriptors are reserved for the |
---|
243 | Standard I/O Streams and those file descriptors are associated with |
---|
244 | ``/dev/console`` during initialization. All console devices are expected to |
---|
245 | support the POSIX*termios* interface. |
---|
246 | |
---|
247 | - The example above specifies via ``CONFIGURE_MAXIMUM_TASKS`` that the |
---|
248 | application requires a maximum of four (4) simultaneously existing Classic |
---|
249 | API tasks. Similarly, by specifying ``CONFIGURE_MAXIMUM_MESSAGE_QUEUES``, |
---|
250 | there may be a maximum of only one (1) concurrently existent Classic API |
---|
251 | message queues. |
---|
252 | |
---|
253 | - The most surprising configuration parameter in this example is the use of |
---|
254 | ``CONFIGURE_MESSAGE_BUFFER_MEMORY``. Message buffer memory is allocated from |
---|
255 | the RTEMS Workspace and must be accounted for. In this example, the single |
---|
256 | message queue will have up to twenty (20) messages of type ``struct |
---|
257 | USER_MESSAGE``. |
---|
258 | |
---|
259 | - The ``CONFIGURE_INIT`` constant must be defined in order to make |
---|
260 | ``<rtems/confdefs.h>`` instantiate the configuration data structures. This |
---|
261 | can only be defined in one source file per application that includes |
---|
262 | ``<rtems/confdefs.h>`` or the symbol table will be instantiated multiple |
---|
263 | times and linking errors produced. |
---|
264 | |
---|
265 | This example illustrates that parameters have default values. Among other |
---|
266 | things, the application implicitly used the following defaults: |
---|
267 | |
---|
268 | - All unspecified types of communications and synchronization objects in the |
---|
269 | Classic and POSIX Threads API have maximums of zero (0). |
---|
270 | |
---|
271 | - The filesystem will be the default filesystem which is the In-Memory File |
---|
272 | System (IMFS). |
---|
273 | |
---|
274 | - The application will have the default number of priority levels. |
---|
275 | |
---|
276 | - The minimum task stack size will be that recommended by RTEMS for the target |
---|
277 | architecture. |
---|
278 | |
---|
279 | .. _ConfigUnlimitedObjects: |
---|
280 | |
---|
281 | Unlimited Objects |
---|
282 | ================= |
---|
283 | |
---|
284 | In real-time embedded systems the RAM is normally a limited, critical resource |
---|
285 | and dynamic allocation is avoided as much as possible to ensure predictable, |
---|
286 | deterministic execution times. For such cases, see :ref:`Sizing the RTEMS |
---|
287 | Workspace` for an overview of how to tune the size of the workspace. |
---|
288 | Frequently when users are porting software to RTEMS the precise resource |
---|
289 | requirements of the software is unknown. In these situations users do not need |
---|
290 | to control the size of the workspace very tightly because they just want to get |
---|
291 | the new software to run; later they can tune the workspace size as needed. |
---|
292 | |
---|
293 | The following object classes in the Classic API can be configured in unlimited |
---|
294 | mode: |
---|
295 | |
---|
296 | - Barriers |
---|
297 | |
---|
298 | - Message Queues |
---|
299 | |
---|
300 | - Partitions |
---|
301 | |
---|
302 | - Periods |
---|
303 | |
---|
304 | - Ports |
---|
305 | |
---|
306 | - Regions |
---|
307 | |
---|
308 | - Semaphores |
---|
309 | |
---|
310 | - Tasks |
---|
311 | |
---|
312 | - Timers |
---|
313 | |
---|
314 | Additionally, the following object classes from the POSIX API can be configured |
---|
315 | in unlimited mode: |
---|
316 | |
---|
317 | - Keys -- :c:func:`pthread_key_create` |
---|
318 | |
---|
319 | - Key Value Pairs -- :c:func:`pthread_setspecific` |
---|
320 | |
---|
321 | - Message Queues -- :c:func:`mq_open` |
---|
322 | |
---|
323 | - Named Semaphores -- :c:func:`sem_open` |
---|
324 | |
---|
325 | - Shared Memory -- :c:func:`shm_open` |
---|
326 | |
---|
327 | - Threads -- :c:func:`pthread_create` |
---|
328 | |
---|
329 | - Timers -- :c:func:`timer_create` |
---|
330 | |
---|
331 | .. warning:: |
---|
332 | |
---|
333 | The following object classes can *not* be configured in unlimited mode: |
---|
334 | |
---|
335 | - Drivers |
---|
336 | |
---|
337 | - File Descriptors |
---|
338 | |
---|
339 | - POSIX Queued Signals |
---|
340 | |
---|
341 | - User Extensions |
---|
342 | |
---|
343 | Due to the memory requirements of unlimited objects it is strongly recommended |
---|
344 | to use them only in combination with the unified work areas. See :ref:`Separate |
---|
345 | or Unified Work Areas` for more information on unified work areas. |
---|
346 | |
---|
347 | The following example demonstrates how the two simple configuration defines for |
---|
348 | unlimited objects and unified works areas can replace many seperate |
---|
349 | configuration defines for supported object classes: |
---|
350 | |
---|
351 | .. code-block:: c |
---|
352 | |
---|
353 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
354 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
355 | #define CONFIGURE_UNIFIED_WORK_AREAS |
---|
356 | #define CONFIGURE_UNLIMITED_OBJECTS |
---|
357 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
358 | #define CONFIGURE_INIT |
---|
359 | #include <rtems/confdefs.h> |
---|
360 | |
---|
361 | Users are cautioned that using unlimited objects is not recommended for |
---|
362 | production software unless the dynamic growth is absolutely required. It is |
---|
363 | generally considered a safer embedded systems programming practice to know the |
---|
364 | system limits rather than experience an out of memory error at an arbitrary and |
---|
365 | largely unpredictable time in the field. |
---|
366 | |
---|
367 | .. index:: rtems_resource_unlimited |
---|
368 | |
---|
369 | .. _ConfigUnlimitedObjectsClass: |
---|
370 | |
---|
371 | Unlimited Objects by Class |
---|
372 | -------------------------- |
---|
373 | |
---|
374 | When the number of objects is not known ahead of time, RTEMS provides an |
---|
375 | auto-extending mode that can be enabled individually for each object type by |
---|
376 | using the macro ``rtems_resource_unlimited``. This takes a value as a |
---|
377 | parameter, and is used to set the object maximum number field in an API |
---|
378 | Configuration table. The value is an allocation unit size. When RTEMS is |
---|
379 | required to grow the object table it is grown by this size. The kernel will |
---|
380 | return the object memory back to the RTEMS Workspace when an object is |
---|
381 | destroyed. The kernel will only return an allocated block of objects to the |
---|
382 | RTEMS Workspace if at least half the allocation size of free objects remain |
---|
383 | allocated. RTEMS always keeps one allocation block of objects allocated. Here |
---|
384 | is an example of using ``rtems_resource_unlimited``: |
---|
385 | |
---|
386 | .. code-block:: c |
---|
387 | |
---|
388 | #define CONFIGURE_MAXIMUM_TASKS rtems_resource_unlimited(5) |
---|
389 | |
---|
390 | .. index:: rtems_resource_is_unlimited |
---|
391 | .. index:: rtems_resource_maximum_per_allocation |
---|
392 | |
---|
393 | Object maximum specifications can be evaluated with the |
---|
394 | ``rtems_resource_is_unlimited`` and``rtems_resource_maximum_per_allocation`` |
---|
395 | macros. |
---|
396 | |
---|
397 | .. _ConfigUnlimitedObjectsDefault: |
---|
398 | |
---|
399 | Unlimited Objects by Default |
---|
400 | ---------------------------- |
---|
401 | |
---|
402 | To ease the burden of developers who are porting new software RTEMS also |
---|
403 | provides the capability to make all object classes listed above operate in |
---|
404 | unlimited mode in a simple manner. The application developer is only |
---|
405 | responsible for enabling unlimited objects |
---|
406 | (:ref:`CONFIGURE_UNLIMITED_OBJECTS`) and specifying the allocation size |
---|
407 | (:ref:`CONFIGURE_UNLIMITED_ALLOCATION_SIZE`). |
---|
408 | |
---|
409 | .. code-block:: c |
---|
410 | |
---|
411 | #define CONFIGURE_UNLIMITED_OBJECTS |
---|
412 | #define CONFIGURE_UNLIMITED_ALLOCATION_SIZE 5 |
---|