RTEMS 6.1-rc2
Loading...
Searching...
No Matches
wkspace.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * Copyright (C) 2020, 2021 embedded brains GmbH & Co. KG
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef _RTEMS_CONFDEFS_WKSPACE_H
38#define _RTEMS_CONFDEFS_WKSPACE_H
39
40#ifndef __CONFIGURATION_TEMPLATE_h
41#error "Do not include this file directly, use <rtems/confdefs.h> instead"
42#endif
43
44#ifdef CONFIGURE_INIT
45
53#include <rtems/score/coremsg.h>
54#include <rtems/score/context.h>
55#include <rtems/score/memory.h>
56#include <rtems/score/stack.h>
57#include <rtems/sysinit.h>
58
59#if CPU_STACK_ALIGNMENT > CPU_HEAP_ALIGNMENT
60 #define _CONFIGURE_TASK_STACK_ALLOC_SIZE( _stack_size ) \
61 ( RTEMS_ALIGN_UP( \
62 ( _stack_size ) + CONTEXT_FP_SIZE, \
63 CPU_STACK_ALIGNMENT \
64 ) + CPU_STACK_ALIGNMENT - CPU_HEAP_ALIGNMENT )
65#else
66 #define _CONFIGURE_TASK_STACK_ALLOC_SIZE( _stack_size ) \
67 RTEMS_ALIGN_UP( ( _stack_size ) + CONTEXT_FP_SIZE, CPU_STACK_ALIGNMENT )
68#endif
69
70#ifdef CONFIGURE_TASK_STACK_FROM_ALLOCATOR
71 #define _Configure_From_stackspace( _stack_size ) \
72 CONFIGURE_TASK_STACK_FROM_ALLOCATOR( \
73 _CONFIGURE_TASK_STACK_ALLOC_SIZE( _stack_size ) \
74 )
75#else
76 #define _Configure_From_stackspace( _stack_size ) \
77 _Configure_From_workspace( \
78 _CONFIGURE_TASK_STACK_ALLOC_SIZE( _stack_size ) \
79 )
80#endif
81
82#ifndef CONFIGURE_EXTRA_TASK_STACKS
83 #define CONFIGURE_EXTRA_TASK_STACKS 0
84#endif
85
86#ifndef CONFIGURE_EXECUTIVE_RAM_SIZE
87
88#define CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE( _messages, _size ) \
89 _Configure_From_workspace( \
90 ( _messages ) * ( _Configure_Align_up( _size, sizeof( uintptr_t ) ) \
91 + sizeof( CORE_message_queue_Buffer ) ) )
92
93#ifndef CONFIGURE_MESSAGE_BUFFER_MEMORY
94 #define CONFIGURE_MESSAGE_BUFFER_MEMORY 0
95#endif
96
97#ifndef CONFIGURE_MEMORY_OVERHEAD
98 #define CONFIGURE_MEMORY_OVERHEAD 0
99#endif
100
101/*
102 * We must be able to split the free block used for the second last allocation
103 * into two parts so that we have a free block for the last allocation. See
104 * _Heap_Block_split().
105 */
106#define _CONFIGURE_HEAP_HANDLER_OVERHEAD \
107 _Configure_Align_up( HEAP_BLOCK_HEADER_SIZE, CPU_HEAP_ALIGNMENT )
108
109#define CONFIGURE_EXECUTIVE_RAM_SIZE \
110 ( _CONFIGURE_MEMORY_FOR_POSIX_OBJECTS \
111 + CONFIGURE_MESSAGE_BUFFER_MEMORY \
112 + 1024 * CONFIGURE_MEMORY_OVERHEAD \
113 + _CONFIGURE_HEAP_HANDLER_OVERHEAD )
114
115#if defined(CONFIGURE_IDLE_TASK_STORAGE_SIZE) || \
116 defined(CONFIGURE_TASK_STACK_ALLOCATOR_FOR_IDLE)
117 #define _CONFIGURE_IDLE_TASK_STACKS 0
118#else
119 #define _CONFIGURE_IDLE_TASK_STACKS \
120 ( _CONFIGURE_MAXIMUM_PROCESSORS * \
121 _Configure_From_stackspace( CONFIGURE_IDLE_TASK_STACK_SIZE ) )
122#endif
123
124#define _CONFIGURE_STACK_SPACE_SIZE \
125 ( _CONFIGURE_INIT_TASK_STACK_EXTRA \
126 + _CONFIGURE_IDLE_TASK_STACKS \
127 + _CONFIGURE_POSIX_INIT_THREAD_STACK_EXTRA \
128 + _CONFIGURE_LIBBLOCK_TASKS_STACK_EXTRA \
129 + CONFIGURE_EXTRA_TASK_STACKS \
130 + rtems_resource_maximum_per_allocation( \
131 _CONFIGURE_TASKS - CONFIGURE_MINIMUM_TASKS_WITH_USER_PROVIDED_STORAGE \
132 ) \
133 * _Configure_From_stackspace( CONFIGURE_MINIMUM_TASK_STACK_SIZE ) \
134 + rtems_resource_maximum_per_allocation( CONFIGURE_MAXIMUM_POSIX_THREADS ) \
135 * _Configure_From_stackspace( CONFIGURE_MINIMUM_POSIX_THREAD_STACK_SIZE ) \
136 + _CONFIGURE_HEAP_HANDLER_OVERHEAD )
137
138#else /* CONFIGURE_EXECUTIVE_RAM_SIZE */
139
140#if CONFIGURE_EXTRA_TASK_STACKS != 0
141 #error "CONFIGURE_EXECUTIVE_RAM_SIZE defined with request for CONFIGURE_EXTRA_TASK_STACKS"
142#endif
143
144#define _CONFIGURE_STACK_SPACE_SIZE 0
145
146#endif /* CONFIGURE_EXECUTIVE_RAM_SIZE */
147
148#ifdef __cplusplus
149extern "C" {
150#endif
151
153
154#ifdef CONFIGURE_UNIFIED_WORK_AREAS
155 const bool _Workspace_Is_unified = true;
156
157 struct Heap_Control *( * const _Workspace_Malloc_initializer )( void ) =
159#endif
160
162
163const uintptr_t _Stack_Space_size = _CONFIGURE_STACK_SPACE_SIZE;
164
165#if defined(CONFIGURE_TASK_STACK_ALLOCATOR) \
166 && defined(CONFIGURE_TASK_STACK_DEALLOCATOR)
167 /*
168 * Ignore the following warnings from g++ and clang in the uses of
169 * _CONFIGURE_ASSERT_NOT_NULL() below:
170 *
171 * warning: the address of 'f()' will never be NULL [-Waddress]
172 *
173 * warning: comparison of function 'f' not equal to a null pointer is always
174 * true [-Wtautological-pointer-compare]
175 */
176 #pragma GCC diagnostic push
177 #pragma GCC diagnostic ignored "-Waddress"
178 #pragma GCC diagnostic ignored "-Wpragmas"
179 #pragma GCC diagnostic ignored "-Wtautological-pointer-compare"
180
181 /* Custom allocator may or may not use the work space. */
182 #ifdef CONFIGURE_TASK_STACK_ALLOCATOR_AVOIDS_WORK_SPACE
183 const bool _Stack_Allocator_avoids_workspace = true;
184 #else
185 const bool _Stack_Allocator_avoids_workspace = false;
186 #endif
187
188 /* Custom allocator may or may not need initialization. */
189 #ifdef CONFIGURE_TASK_STACK_ALLOCATOR_INIT
191 _CONFIGURE_ASSERT_NOT_NULL(
194 );
195
198 RTEMS_SYSINIT_STACK_ALLOCATOR,
199 RTEMS_SYSINIT_ORDER_MIDDLE
200 );
201 #endif
202
203 /* Custom allocator must include allocate and free */
205 _CONFIGURE_ASSERT_NOT_NULL(
208 );
209
211 _CONFIGURE_ASSERT_NOT_NULL(
214 );
215
216 #pragma GCC diagnostic pop
217
218/*
219 * Must provide both a custom stack allocator and deallocator
220 */
221#elif defined(CONFIGURE_TASK_STACK_ALLOCATOR) \
222 || defined(CONFIGURE_TASK_STACK_DEALLOCATOR)
223 #error "CONFIGURE_TASK_STACK_ALLOCATOR and CONFIGURE_TASK_STACK_DEALLOCATOR must be both defined or both undefined"
224#endif
225
226#ifdef CONFIGURE_IDLE_TASK_STORAGE_SIZE
227 #ifdef CONFIGURE_TASK_STACK_ALLOCATOR_FOR_IDLE
228 #error "CONFIGURE_IDLE_TASK_STORAGE_SIZE and CONFIGURE_TASK_STACK_ALLOCATOR_FOR_IDLE are mutually exclusive"
229 #endif
230
231 #define _CONFIGURE_IDLE_TASK_STORAGE_SIZE \
232 RTEMS_ALIGN_UP( \
233 RTEMS_TASK_STORAGE_SIZE( \
234 CONFIGURE_IDLE_TASK_STORAGE_SIZE, \
235 RTEMS_DEFAULT_ATTRIBUTES \
236 ), \
237 CPU_INTERRUPT_STACK_ALIGNMENT \
238 )
239
241 _CONFIGURE_IDLE_TASK_STORAGE_SIZE;
242
244 _CONFIGURE_MAXIMUM_PROCESSORS * _CONFIGURE_IDLE_TASK_STORAGE_SIZE
245 ] RTEMS_ALIGNED( CPU_INTERRUPT_STACK_ALIGNMENT )
246 RTEMS_SECTION( ".rtemsstack.idle" );
247
248 #define CONFIGURE_TASK_STACK_ALLOCATOR_FOR_IDLE \
249 _Stack_Allocator_allocate_for_idle_static
250#endif
251
252#ifndef CONFIGURE_TASK_STACK_ALLOCATOR_FOR_IDLE
253 #define CONFIGURE_TASK_STACK_ALLOCATOR_FOR_IDLE \
254 _Stack_Allocator_allocate_for_idle_workspace
255#endif
256
259
260#ifdef CONFIGURE_DIRTY_MEMORY
263 RTEMS_SYSINIT_DIRTY_MEMORY,
264 RTEMS_SYSINIT_ORDER_MIDDLE
265 );
266#endif
267
268#ifdef CONFIGURE_ZERO_WORKSPACE_AUTOMATICALLY
269 const bool _Memory_Zero_before_use = true;
270
273 RTEMS_SYSINIT_ZERO_MEMORY,
274 RTEMS_SYSINIT_ORDER_MIDDLE
275 );
276#endif
277
278#ifdef __cplusplus
279}
280#endif
281
282#endif /* CONFIGURE_INIT */
283
284#endif /* _RTEMS_CONFDEFS_WKSPACE_H */
This header file evaluates configuration options related to the block device cache configuration.
This header file evaluates configuration options related to the per-CPU configuration.
This header file provides the interfaces of the Context Handler.
This header file provides interfaces of the Message Queue Handler which are only used by the implemen...
This header file provides the interfaces of the Memory Handler.
This header file provides interfaces of the Stack Handler which are used by the implementation and th...
#define RTEMS_SECTION(_section)
Instructs the compiler to place the variable or function in the section.
Definition: basedefs.h:411
#define RTEMS_ALIGNED(_alignment)
Instructs the compiler in a declaration or definition to enforce the alignment.
Definition: basedefs.h:157
#define RTEMS_SYSINIT_ITEM(handler, module, order)
Creates the system initialization item associated with the handler, module, and order.
Definition: sysinit.h:204
#define CONFIGURE_EXECUTIVE_RAM_SIZE
This configuration option is an integer define.
Definition: appl-config.h:2729
#define CONFIGURE_MINIMUM_TASK_STACK_SIZE
This configuration option is an integer define.
Definition: appl-config.h:3271
#define CONFIGURE_TASK_STACK_ALLOCATOR_FOR_IDLE
This configuration option is an initializer define.
Definition: appl-config.h:5180
const bool _Memory_Zero_before_use
Indicates if the memory is zeroed during system initialization.
Definition: memoryzerobeforeuse.c:43
void _Memory_Dirty_free_areas(void)
Dirty all free memory areas of the system.
Definition: memorydirtyfreeareas.c:45
void _Memory_Zero_free_areas(void)
Zeros all free memory areas of the system.
Definition: memoryzerofreeareas.c:45
char _Stack_Allocator_allocate_for_idle_storage_areas[]
The thread storage areas used by _Stack_Allocator_allocate_for_idle_static().
void(* Stack_Allocator_initialize)(size_t stack_space_size)
The stack allocator initialization handler.
Definition: stack.h:83
const Stack_Allocator_allocate_for_idle _Stack_Allocator_allocate_for_idle
The stack allocator allocate stack for idle thread handler.
void _Stack_Allocator_do_initialize(void)
Do the stack allocator initialization during system initialize.
Definition: stackallocatorinit.c:44
void *(* Stack_Allocator_allocate_for_idle)(uint32_t cpu, size_t *stack_size)
Stack allocator allocate for idle handler.
Definition: stack.h:121
const bool _Stack_Allocator_avoids_workspace
Indicates if the stack allocator avoids the workspace.
Definition: stackallocator.c:45
void *(* Stack_Allocator_allocate)(size_t stack_size)
Stack allocator allocate handler.
Definition: stack.h:93
const uintptr_t _Stack_Space_size
The configured stack space size.
const Stack_Allocator_allocate _Stack_Allocator_allocate
The stack allocator allocate handler.
Definition: stackallocator.c:47
const size_t _Stack_Allocator_allocate_for_idle_storage_size
The size in bytes of the idle thread storage area used by _Stack_Allocator_allocate_for_idle_static()...
const Stack_Allocator_free _Stack_Allocator_free
The stack allocator free handler.
Definition: stackallocatorfree.c:44
const Stack_Allocator_initialize _Stack_Allocator_initialize
The stack allocator initialization handler.
void(* Stack_Allocator_free)(void *addr)
Stack allocator free handler.
Definition: stack.h:100
uint32_t rtems_minimum_stack_size
The minimum stack size.
const bool _Workspace_Is_unified
Indicates if the workspace and C program heap are unified.
Definition: wkspaceisunifieddefault.c:43
struct Heap_Control *(*const _Workspace_Malloc_initializer)(void)
This constant provides the C Program Heap initialization handler.
Definition: wkspacemallocinitdefault.c:43
const uintptr_t _Workspace_Size
The workspace size in bytes.
struct Heap_Control * _Workspace_Malloc_initialize_unified(void)
Initializes the C Program Heap so that it is unified with the RTEMS Workspace.
Definition: wkspacemallocinitunified.c:44
#define CONFIGURE_TASK_STACK_ALLOCATOR_INIT
Task stack allocator initialization configuration option.
Definition: stackalloc.h:89
#define CONFIGURE_TASK_STACK_ALLOCATOR
Task stack allocator configuration option.
Definition: stackalloc.h:94
#define CONFIGURE_TASK_STACK_DEALLOCATOR
Task stack deallocator configuration option.
Definition: stackalloc.h:99
This header file evaluates configuration options related to the Classic API initialization task confi...
This header file evaluates configuration options related to the POSIX initialization thread configura...
This header file evaluates configuration options related to the POSIX API objects configuration.
Control block used to manage a heap.
Definition: heap.h:339
This header file provides the API of the System Initialization Support.
This header file evaluates configuration options related to the thread configuration.
This header file provides support macros to evaluate configuration options related to the RTEMS Works...