Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:12

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSImplApplConfig
0007  *
0008  * @brief This header file evaluates configuration options related to the RTEMS
0009  *   Workspace configuration.
0010  */
0011 
0012 /*
0013  * Copyright (C) 2020, 2021 embedded brains GmbH & Co. KG
0014  *
0015  * Redistribution and use in source and binary forms, with or without
0016  * modification, are permitted provided that the following conditions
0017  * are met:
0018  * 1. Redistributions of source code must retain the above copyright
0019  *    notice, this list of conditions and the following disclaimer.
0020  * 2. Redistributions in binary form must reproduce the above copyright
0021  *    notice, this list of conditions and the following disclaimer in the
0022  *    documentation and/or other materials provided with the distribution.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #ifndef _RTEMS_CONFDEFS_WKSPACE_H
0038 #define _RTEMS_CONFDEFS_WKSPACE_H
0039 
0040 #ifndef __CONFIGURATION_TEMPLATE_h
0041 #error "Do not include this file directly, use <rtems/confdefs.h> instead"
0042 #endif
0043 
0044 #ifdef CONFIGURE_INIT
0045 
0046 #include <rtems/confdefs/bdbuf.h>
0047 #include <rtems/confdefs/inittask.h>
0048 #include <rtems/confdefs/initthread.h>
0049 #include <rtems/confdefs/objectsposix.h>
0050 #include <rtems/confdefs/percpu.h>
0051 #include <rtems/confdefs/threads.h>
0052 #include <rtems/confdefs/wkspacesupport.h>
0053 #include <rtems/score/coremsg.h>
0054 #include <rtems/score/context.h>
0055 #include <rtems/score/memory.h>
0056 #include <rtems/score/stack.h>
0057 #include <rtems/sysinit.h>
0058 
0059 #if CPU_STACK_ALIGNMENT > CPU_HEAP_ALIGNMENT
0060   #define _CONFIGURE_TASK_STACK_ALLOC_SIZE( _stack_size ) \
0061     ( RTEMS_ALIGN_UP( \
0062         ( _stack_size ) + CONTEXT_FP_SIZE, \
0063         CPU_STACK_ALIGNMENT \
0064       ) + CPU_STACK_ALIGNMENT - CPU_HEAP_ALIGNMENT )
0065 #else
0066   #define _CONFIGURE_TASK_STACK_ALLOC_SIZE( _stack_size ) \
0067     RTEMS_ALIGN_UP( ( _stack_size ) + CONTEXT_FP_SIZE, CPU_STACK_ALIGNMENT )
0068 #endif
0069 
0070 #ifdef CONFIGURE_TASK_STACK_FROM_ALLOCATOR
0071   #define _Configure_From_stackspace( _stack_size ) \
0072     CONFIGURE_TASK_STACK_FROM_ALLOCATOR( \
0073       _CONFIGURE_TASK_STACK_ALLOC_SIZE( _stack_size ) \
0074     )
0075 #else
0076   #define _Configure_From_stackspace( _stack_size ) \
0077     _Configure_From_workspace( \
0078       _CONFIGURE_TASK_STACK_ALLOC_SIZE( _stack_size ) \
0079     )
0080 #endif
0081 
0082 #ifndef CONFIGURE_EXTRA_TASK_STACKS
0083   #define CONFIGURE_EXTRA_TASK_STACKS 0
0084 #endif
0085 
0086 #ifndef CONFIGURE_EXECUTIVE_RAM_SIZE
0087 
0088 #define CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE( _messages, _size ) \
0089   _Configure_From_workspace( \
0090     ( _messages ) * ( _Configure_Align_up( _size, sizeof( uintptr_t ) ) \
0091         + sizeof( CORE_message_queue_Buffer ) ) )
0092 
0093 #ifndef CONFIGURE_MESSAGE_BUFFER_MEMORY
0094   #define CONFIGURE_MESSAGE_BUFFER_MEMORY 0
0095 #endif
0096 
0097 #ifndef CONFIGURE_MEMORY_OVERHEAD
0098   #define CONFIGURE_MEMORY_OVERHEAD 0
0099 #endif
0100 
0101 /*
0102  * We must be able to split the free block used for the second last allocation
0103  * into two parts so that we have a free block for the last allocation.  See
0104  * _Heap_Block_split().
0105  */
0106 #define _CONFIGURE_HEAP_HANDLER_OVERHEAD \
0107   _Configure_Align_up( HEAP_BLOCK_HEADER_SIZE, CPU_HEAP_ALIGNMENT )
0108 
0109 #define CONFIGURE_EXECUTIVE_RAM_SIZE \
0110   ( _CONFIGURE_MEMORY_FOR_POSIX_OBJECTS \
0111     + CONFIGURE_MESSAGE_BUFFER_MEMORY \
0112     + 1024 * CONFIGURE_MEMORY_OVERHEAD \
0113     + _CONFIGURE_HEAP_HANDLER_OVERHEAD )
0114 
0115 #if defined(CONFIGURE_IDLE_TASK_STORAGE_SIZE) || \
0116   defined(CONFIGURE_TASK_STACK_ALLOCATOR_FOR_IDLE)
0117   #define _CONFIGURE_IDLE_TASK_STACKS 0
0118 #else
0119   #define _CONFIGURE_IDLE_TASK_STACKS \
0120     ( _CONFIGURE_MAXIMUM_PROCESSORS * \
0121       _Configure_From_stackspace( CONFIGURE_IDLE_TASK_STACK_SIZE ) )
0122 #endif
0123 
0124 #define _CONFIGURE_STACK_SPACE_SIZE \
0125   ( _CONFIGURE_INIT_TASK_STACK_EXTRA \
0126     + _CONFIGURE_IDLE_TASK_STACKS \
0127     + _CONFIGURE_POSIX_INIT_THREAD_STACK_EXTRA \
0128     + _CONFIGURE_LIBBLOCK_TASKS_STACK_EXTRA \
0129     + CONFIGURE_EXTRA_TASK_STACKS \
0130     + rtems_resource_maximum_per_allocation( \
0131         _CONFIGURE_TASKS - CONFIGURE_MINIMUM_TASKS_WITH_USER_PROVIDED_STORAGE \
0132       ) \
0133       * _Configure_From_stackspace( CONFIGURE_MINIMUM_TASK_STACK_SIZE ) \
0134     + rtems_resource_maximum_per_allocation( CONFIGURE_MAXIMUM_POSIX_THREADS ) \
0135       * _Configure_From_stackspace( CONFIGURE_MINIMUM_POSIX_THREAD_STACK_SIZE ) \
0136     + _CONFIGURE_HEAP_HANDLER_OVERHEAD )
0137 
0138 #else /* CONFIGURE_EXECUTIVE_RAM_SIZE */
0139 
0140 #if CONFIGURE_EXTRA_TASK_STACKS != 0
0141   #error "CONFIGURE_EXECUTIVE_RAM_SIZE defined with request for CONFIGURE_EXTRA_TASK_STACKS"
0142 #endif
0143 
0144 #define _CONFIGURE_STACK_SPACE_SIZE 0
0145 
0146 #endif /* CONFIGURE_EXECUTIVE_RAM_SIZE */
0147 
0148 #ifdef __cplusplus
0149 extern "C" {
0150 #endif
0151 
0152 const uintptr_t _Workspace_Size = CONFIGURE_EXECUTIVE_RAM_SIZE;
0153 
0154 #ifdef CONFIGURE_UNIFIED_WORK_AREAS
0155   const bool _Workspace_Is_unified = true;
0156 
0157   struct Heap_Control *( * const _Workspace_Malloc_initializer )( void ) =
0158     _Workspace_Malloc_initialize_unified;
0159 #endif
0160 
0161 uint32_t rtems_minimum_stack_size = CONFIGURE_MINIMUM_TASK_STACK_SIZE;
0162 
0163 const uintptr_t _Stack_Space_size = _CONFIGURE_STACK_SPACE_SIZE;
0164 
0165 #if defined(CONFIGURE_TASK_STACK_ALLOCATOR) \
0166   && defined(CONFIGURE_TASK_STACK_DEALLOCATOR)
0167   /*
0168    * Ignore the following warnings from g++ and clang in the uses of
0169    * _CONFIGURE_ASSERT_NOT_NULL() below:
0170    *
0171    * warning: the address of 'f()' will never be NULL [-Waddress]
0172    *
0173    * warning: comparison of function 'f' not equal to a null pointer is always
0174    * true [-Wtautological-pointer-compare]
0175    */
0176   #pragma GCC diagnostic push
0177   #pragma GCC diagnostic ignored "-Waddress"
0178   #pragma GCC diagnostic ignored "-Wpragmas"
0179   #pragma GCC diagnostic ignored "-Wtautological-pointer-compare"
0180 
0181   /* Custom allocator may or may not use the work space. */ 
0182   #ifdef CONFIGURE_TASK_STACK_ALLOCATOR_AVOIDS_WORK_SPACE
0183     const bool _Stack_Allocator_avoids_workspace = true;
0184   #else
0185     const bool _Stack_Allocator_avoids_workspace = false;
0186   #endif
0187 
0188   /* Custom allocator may or may not need initialization. */
0189   #ifdef CONFIGURE_TASK_STACK_ALLOCATOR_INIT
0190     const Stack_Allocator_initialize _Stack_Allocator_initialize =
0191       _CONFIGURE_ASSERT_NOT_NULL(
0192         Stack_Allocator_initialize,
0193         CONFIGURE_TASK_STACK_ALLOCATOR_INIT
0194       );
0195 
0196     RTEMS_SYSINIT_ITEM(
0197       _Stack_Allocator_do_initialize,
0198       RTEMS_SYSINIT_STACK_ALLOCATOR,
0199       RTEMS_SYSINIT_ORDER_MIDDLE
0200     );
0201   #endif
0202 
0203   /* Custom allocator must include allocate and free */
0204   const Stack_Allocator_allocate _Stack_Allocator_allocate =
0205     _CONFIGURE_ASSERT_NOT_NULL(
0206       Stack_Allocator_allocate,
0207       CONFIGURE_TASK_STACK_ALLOCATOR
0208     );
0209 
0210   const Stack_Allocator_free _Stack_Allocator_free =
0211     _CONFIGURE_ASSERT_NOT_NULL(
0212       Stack_Allocator_free,
0213       CONFIGURE_TASK_STACK_DEALLOCATOR
0214     );
0215 
0216   #pragma GCC diagnostic pop
0217 
0218 /*
0219  * Must provide both a custom stack allocator and deallocator
0220  */
0221 #elif defined(CONFIGURE_TASK_STACK_ALLOCATOR) \
0222   || defined(CONFIGURE_TASK_STACK_DEALLOCATOR)
0223   #error "CONFIGURE_TASK_STACK_ALLOCATOR and CONFIGURE_TASK_STACK_DEALLOCATOR must be both defined or both undefined"
0224 #endif
0225 
0226 #ifdef CONFIGURE_IDLE_TASK_STORAGE_SIZE
0227   #ifdef CONFIGURE_TASK_STACK_ALLOCATOR_FOR_IDLE
0228     #error "CONFIGURE_IDLE_TASK_STORAGE_SIZE and CONFIGURE_TASK_STACK_ALLOCATOR_FOR_IDLE are mutually exclusive"
0229   #endif
0230 
0231   #define _CONFIGURE_IDLE_TASK_STORAGE_SIZE \
0232     RTEMS_ALIGN_UP( \
0233       RTEMS_TASK_STORAGE_SIZE( \
0234         CONFIGURE_IDLE_TASK_STORAGE_SIZE, \
0235         RTEMS_DEFAULT_ATTRIBUTES \
0236       ), \
0237       CPU_INTERRUPT_STACK_ALIGNMENT \
0238     )
0239 
0240   const size_t _Stack_Allocator_allocate_for_idle_storage_size =
0241     _CONFIGURE_IDLE_TASK_STORAGE_SIZE;
0242 
0243   char _Stack_Allocator_allocate_for_idle_storage_areas[
0244     _CONFIGURE_MAXIMUM_PROCESSORS * _CONFIGURE_IDLE_TASK_STORAGE_SIZE
0245   ] RTEMS_ALIGNED( CPU_INTERRUPT_STACK_ALIGNMENT )
0246   RTEMS_SECTION( ".rtemsstack.idle" );
0247 
0248   #define CONFIGURE_TASK_STACK_ALLOCATOR_FOR_IDLE \
0249     _Stack_Allocator_allocate_for_idle_static
0250 #endif
0251 
0252 #ifndef CONFIGURE_TASK_STACK_ALLOCATOR_FOR_IDLE
0253   #define CONFIGURE_TASK_STACK_ALLOCATOR_FOR_IDLE \
0254     _Stack_Allocator_allocate_for_idle_workspace
0255 #endif
0256 
0257 const Stack_Allocator_allocate_for_idle _Stack_Allocator_allocate_for_idle =
0258   CONFIGURE_TASK_STACK_ALLOCATOR_FOR_IDLE;
0259 
0260 #ifdef CONFIGURE_DIRTY_MEMORY
0261   RTEMS_SYSINIT_ITEM(
0262     _Memory_Dirty_free_areas,
0263     RTEMS_SYSINIT_DIRTY_MEMORY,
0264     RTEMS_SYSINIT_ORDER_MIDDLE
0265   );
0266 #endif
0267 
0268 #ifdef CONFIGURE_ZERO_WORKSPACE_AUTOMATICALLY
0269   const bool _Memory_Zero_before_use = true;
0270 
0271   RTEMS_SYSINIT_ITEM(
0272     _Memory_Zero_free_areas,
0273     RTEMS_SYSINIT_ZERO_MEMORY,
0274     RTEMS_SYSINIT_ORDER_MIDDLE
0275   );
0276 #endif
0277 
0278 #ifdef __cplusplus
0279 }
0280 #endif
0281 
0282 #endif /* CONFIGURE_INIT */
0283 
0284 #endif /* _RTEMS_CONFDEFS_WKSPACE_H */