1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup RTEMSScoreStack |
---|
7 | * |
---|
8 | * @brief This header file provides interfaces of the |
---|
9 | * @ref RTEMSScoreStack which are used by the implementation and the |
---|
10 | * @ref RTEMSImplApplConfig. |
---|
11 | */ |
---|
12 | |
---|
13 | /* |
---|
14 | * Copyright (C) 2022 embedded brains GmbH |
---|
15 | * Copyright (C) 1989, 2021 On-Line Applications Research Corporation (OAR) |
---|
16 | * |
---|
17 | * Redistribution and use in source and binary forms, with or without |
---|
18 | * modification, are permitted provided that the following conditions |
---|
19 | * are met: |
---|
20 | * 1. Redistributions of source code must retain the above copyright |
---|
21 | * notice, this list of conditions and the following disclaimer. |
---|
22 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
23 | * notice, this list of conditions and the following disclaimer in the |
---|
24 | * documentation and/or other materials provided with the distribution. |
---|
25 | * |
---|
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
36 | * POSSIBILITY OF SUCH DAMAGE. |
---|
37 | */ |
---|
38 | |
---|
39 | #ifndef _RTEMS_SCORE_STACK_H |
---|
40 | #define _RTEMS_SCORE_STACK_H |
---|
41 | |
---|
42 | #include <rtems/score/basedefs.h> |
---|
43 | |
---|
44 | #ifdef __cplusplus |
---|
45 | extern "C" { |
---|
46 | #endif |
---|
47 | |
---|
48 | /** |
---|
49 | * @defgroup RTEMSScoreStack Stack Handler |
---|
50 | * |
---|
51 | * @ingroup RTEMSScore |
---|
52 | * |
---|
53 | * @brief This group contains the Stack Handler implementation. |
---|
54 | * |
---|
55 | * This handler encapsulates functionality which is used in the management |
---|
56 | * of thread stacks. It provides mechanisms which can be used to initialize |
---|
57 | * and utilize stacks. |
---|
58 | * |
---|
59 | * @{ |
---|
60 | */ |
---|
61 | |
---|
62 | /** |
---|
63 | * The following constant defines the minimum stack size which every |
---|
64 | * thread must exceed. |
---|
65 | */ |
---|
66 | #define STACK_MINIMUM_SIZE CPU_STACK_MINIMUM_SIZE |
---|
67 | |
---|
68 | /** |
---|
69 | * The following defines the control block used to manage each stack. |
---|
70 | */ |
---|
71 | typedef struct { |
---|
72 | /** This is the stack size. */ |
---|
73 | size_t size; |
---|
74 | /** This is the low memory address of stack. */ |
---|
75 | void *area; |
---|
76 | } Stack_Control; |
---|
77 | |
---|
78 | /** |
---|
79 | * @brief The stack allocator initialization handler. |
---|
80 | * |
---|
81 | * @param stack_space_size The size of the stack space in bytes. |
---|
82 | */ |
---|
83 | typedef void ( *Stack_Allocator_initialize )( size_t stack_space_size ); |
---|
84 | |
---|
85 | /** |
---|
86 | * @brief Stack allocator allocate handler. |
---|
87 | * |
---|
88 | * @param stack_size The size of the stack area to allocate in bytes. |
---|
89 | * |
---|
90 | * @retval NULL Not enough memory. |
---|
91 | * @retval other Pointer to begin of stack area. |
---|
92 | */ |
---|
93 | typedef void *( *Stack_Allocator_allocate )( size_t stack_size ); |
---|
94 | |
---|
95 | /** |
---|
96 | * @brief Stack allocator free handler. |
---|
97 | * |
---|
98 | * @param] addr A pointer to previously allocated stack area or NULL. |
---|
99 | */ |
---|
100 | typedef void ( *Stack_Allocator_free )( void *addr ); |
---|
101 | |
---|
102 | /** |
---|
103 | * @brief Stack allocator allocate for idle handler. |
---|
104 | * |
---|
105 | * The allocate for idle handler is optional even when the user thread stack |
---|
106 | * allocator and deallocator are configured. |
---|
107 | * |
---|
108 | * @param cpu is the index of the CPU for the IDLE thread using this stack. |
---|
109 | * |
---|
110 | * @param stack_size[in, out] is pointer to a size_t object. On function |
---|
111 | * entry, the object contains the proposed size of the stack area to allocate |
---|
112 | * in bytes. The proposed size does not take the actual thread-local storage |
---|
113 | * size of the application into account. The stack allocator can modify the |
---|
114 | * size to ensure that there is enough space available in the stack area for |
---|
115 | * the thread-local storage. |
---|
116 | * |
---|
117 | * @retval NULL There was not enough memory available to allocate a stack area. |
---|
118 | * |
---|
119 | * @return Returns the pointer to begin of the allocated stack area. |
---|
120 | */ |
---|
121 | typedef void *( *Stack_Allocator_allocate_for_idle )( |
---|
122 | uint32_t cpu, |
---|
123 | size_t *stack_size |
---|
124 | ); |
---|
125 | |
---|
126 | /** |
---|
127 | * @brief The minimum stack size. |
---|
128 | * |
---|
129 | * Application provided via <rtems/confdefs.h>. |
---|
130 | */ |
---|
131 | extern uint32_t rtems_minimum_stack_size; |
---|
132 | |
---|
133 | /** |
---|
134 | * @brief The configured stack space size. |
---|
135 | * |
---|
136 | * Application provided via <rtems/confdefs.h>. |
---|
137 | */ |
---|
138 | extern const uintptr_t _Stack_Space_size; |
---|
139 | |
---|
140 | /** |
---|
141 | * @brief Indicates if the stack allocator avoids the workspace. |
---|
142 | * |
---|
143 | * Application provided via <rtems/confdefs.h>. |
---|
144 | */ |
---|
145 | extern const bool _Stack_Allocator_avoids_workspace; |
---|
146 | |
---|
147 | /** |
---|
148 | * @brief The stack allocator initialization handler. |
---|
149 | * |
---|
150 | * Application provided via <rtems/confdefs.h>. |
---|
151 | */ |
---|
152 | extern const Stack_Allocator_initialize _Stack_Allocator_initialize; |
---|
153 | |
---|
154 | /** |
---|
155 | * @brief The stack allocator allocate handler. |
---|
156 | * |
---|
157 | * Application provided via <rtems/confdefs.h>. |
---|
158 | */ |
---|
159 | extern const Stack_Allocator_allocate _Stack_Allocator_allocate; |
---|
160 | |
---|
161 | /** |
---|
162 | * @brief The stack allocator free handler. |
---|
163 | * |
---|
164 | * Application provided via <rtems/confdefs.h>. |
---|
165 | */ |
---|
166 | extern const Stack_Allocator_free _Stack_Allocator_free; |
---|
167 | |
---|
168 | /** |
---|
169 | * @brief Do the stack allocator initialization during system initialize. |
---|
170 | * |
---|
171 | * This function is used to initialize application provided stack allocators. |
---|
172 | */ |
---|
173 | void _Stack_Allocator_do_initialize( void ); |
---|
174 | |
---|
175 | /** |
---|
176 | * @brief Allocates the IDLE thread storage area from the workspace. |
---|
177 | * |
---|
178 | * If the thread storage area cannot be allocated, then the |
---|
179 | * ::INTERNAL_ERROR_NO_MEMORY_FOR_IDLE_TASK_STACK fatal error will occur. |
---|
180 | * |
---|
181 | * @param unused is an unused parameter. |
---|
182 | * |
---|
183 | * @param stack_size[in] is pointer to a size_t object. On function entry, the |
---|
184 | * object contains the size of the task storage area to allocate in bytes. |
---|
185 | * |
---|
186 | * @return Returns a pointer to the begin of the allocated task storage area. |
---|
187 | */ |
---|
188 | void *_Stack_Allocator_allocate_for_idle_workspace( |
---|
189 | uint32_t unused, |
---|
190 | size_t *storage_size |
---|
191 | ); |
---|
192 | |
---|
193 | /** |
---|
194 | * @brief The size in bytes of the idle thread storage area used by |
---|
195 | * _Stack_Allocator_allocate_for_idle_static(). |
---|
196 | * |
---|
197 | * Application provided via <rtems/confdefs.h>. |
---|
198 | */ |
---|
199 | extern const size_t _Stack_Allocator_allocate_for_idle_storage_size; |
---|
200 | |
---|
201 | /** |
---|
202 | * @brief The thread storage areas used by |
---|
203 | * _Stack_Allocator_allocate_for_idle_static(). |
---|
204 | * |
---|
205 | * Application provided via <rtems/confdefs.h>. |
---|
206 | */ |
---|
207 | extern char _Stack_Allocator_allocate_for_idle_storage_areas[]; |
---|
208 | |
---|
209 | /** |
---|
210 | * @brief Allocates the IDLE thread storage from the memory statically |
---|
211 | * allocated by <rtems/confdefs.h>. |
---|
212 | * |
---|
213 | * @param cpu_index is the index of the CPU for the IDLE thread using this stack. |
---|
214 | * |
---|
215 | * @param stack_size[out] is pointer to a size_t object. On function return, the |
---|
216 | * object value is set to the value of |
---|
217 | * ::_Stack_Allocator_allocate_for_idle_storage_size. |
---|
218 | * |
---|
219 | * @return Returns a pointer to the begin of the allocated task storage area. |
---|
220 | */ |
---|
221 | void *_Stack_Allocator_allocate_for_idle_static( |
---|
222 | uint32_t cpu_index, |
---|
223 | size_t *storage_size |
---|
224 | ); |
---|
225 | |
---|
226 | /** |
---|
227 | * @brief The stack allocator allocate stack for idle thread handler. |
---|
228 | * |
---|
229 | * Application provided via <rtems/confdefs.h>. |
---|
230 | */ |
---|
231 | extern const Stack_Allocator_allocate_for_idle |
---|
232 | _Stack_Allocator_allocate_for_idle; |
---|
233 | |
---|
234 | /** @} */ |
---|
235 | |
---|
236 | #ifdef __cplusplus |
---|
237 | } |
---|
238 | #endif |
---|
239 | |
---|
240 | #endif |
---|
241 | /* end of include file */ |
---|