1 /* 2 * SPDX-FileCopyrightText: 2015-2019 Cadence Design Systems, Inc. 3 * 4 * SPDX-License-Identifier: MIT 5 * 6 * SPDX-FileContributor: 2016-2022 Espressif Systems (Shanghai) CO LTD 7 */ 8 /* 9 * Copyright (c) 2015-2019 Cadence Design Systems, Inc. 10 * 11 * Permission is hereby granted, free of charge, to any person obtaining 12 * a copy of this software and associated documentation files (the 13 * "Software"), to deal in the Software without restriction, including 14 * without limitation the rights to use, copy, modify, merge, publish, 15 * distribute, sublicense, and/or sell copies of the Software, and to 16 * permit persons to whom the Software is furnished to do so, subject to 17 * the following conditions: 18 * 19 * The above copyright notice and this permission notice shall be included 20 * in all copies or substantial portions of the Software. 21 * 22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 25 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 26 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 27 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 */ 30 31 /******************************************************************************* 32 * 33 * Configuration-specific information for Xtensa build. This file must be 34 * included in FreeRTOSConfig.h to properly set up the config-dependent 35 * parameters correctly. 36 * 37 * NOTE: To enable thread-safe C library support, XT_USE_THREAD_SAFE_CLIB must 38 * be defined to be > 0 somewhere above or on the command line. 39 * 40 *******************************************************************************/ 41 42 #ifndef XTENSA_CONFIG_H 43 #define XTENSA_CONFIG_H 44 45 /* *INDENT-OFF* */ 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 /* *INDENT-ON* */ 50 51 #include <xtensa/hal.h> 52 #include <xtensa/config/core.h> 53 #include <xtensa/config/system.h> /* required for XSHAL_CLIB */ 54 55 #include "xtensa_context.h" 56 57 58 /*----------------------------------------------------------------------------- 59 * STACK REQUIREMENTS 60 * 61 * This section defines the minimum stack size, and the extra space required to 62 * be allocated for saving coprocessor state and/or C library state information 63 * (if thread safety is enabled for the C library). The sizes are in bytes. 64 * 65 * Stack sizes for individual tasks should be derived from these minima based on 66 * the maximum call depth of the task and the maximum level of interrupt nesting. 67 * A minimum stack size is defined by XT_STACK_MIN_SIZE. This minimum is based 68 * on the requirement for a task that calls nothing else but can be interrupted. 69 * This assumes that interrupt handlers do not call more than a few levels deep. 70 * If this is not true, i.e. one or more interrupt handlers make deep calls then 71 * the minimum must be increased. 72 * 73 * If the Xtensa processor configuration includes coprocessors, then space is 74 * allocated to save the coprocessor state on the stack. 75 * 76 * If thread safety is enabled for the C runtime library, (XT_USE_THREAD_SAFE_CLIB 77 * is defined) then space is allocated to save the C library context in the TCB. 78 * 79 * Allocating insufficient stack space is a common source of hard-to-find errors. 80 * During development, it is best to enable the FreeRTOS stack checking features. 81 * 82 * Usage: 83 * 84 * XT_USE_THREAD_SAFE_CLIB -- Define this to a nonzero value to enable thread-safe 85 * use of the C library. This will require extra stack 86 * space to be allocated for tasks that use the C library 87 * reentrant functions. See below for more information. 88 * 89 * NOTE: The Xtensa toolchain supports multiple C libraries and not all of them 90 * support thread safety. Check your core configuration to see which C library 91 * was chosen for your system. 92 * 93 * XT_STACK_MIN_SIZE -- The minimum stack size for any task. It is recommended 94 * that you do not use a stack smaller than this for any 95 * task. In case you want to use stacks smaller than this 96 * size, you must verify that the smaller size(s) will work 97 * under all operating conditions. 98 * 99 * XT_STACK_EXTRA -- The amount of extra stack space to allocate for a task 100 * that does not make C library reentrant calls. Add this 101 * to the amount of stack space required by the task itself. 102 * 103 * XT_STACK_EXTRA_CLIB -- The amount of space to allocate for C library state. 104 * 105 * -----------------------------------------------------------------------------*/ 106 107 /* Extra space required for interrupt/exception hooks. */ 108 #ifdef XT_INTEXC_HOOKS 109 #ifdef __XTENSA_CALL0_ABI__ 110 #define STK_INTEXC_EXTRA 0x200 111 #else 112 #define STK_INTEXC_EXTRA 0x180 113 #endif 114 #else 115 #define STK_INTEXC_EXTRA 0 116 #endif 117 118 #define XT_CLIB_CONTEXT_AREA_SIZE 0 119 120 /*------------------------------------------------------------------------------ 121 * Extra size -- interrupt frame plus coprocessor save area plus hook space. 122 * NOTE: Make sure XT_INTEXC_HOOKS is undefined unless you really need the hooks. 123 * ------------------------------------------------------------------------------*/ 124 #ifdef __XTENSA_CALL0_ABI__ 125 #define XT_XTRA_SIZE ( XT_STK_FRMSZ + STK_INTEXC_EXTRA + 0x10 + XT_CP_SIZE ) 126 #else 127 #define XT_XTRA_SIZE ( XT_STK_FRMSZ + STK_INTEXC_EXTRA + 0x20 + XT_CP_SIZE ) 128 #endif 129 130 /*------------------------------------------------------------------------------ 131 * Space allocated for user code -- function calls and local variables. 132 * NOTE: This number can be adjusted to suit your needs. You must verify that the 133 * amount of space you reserve is adequate for the worst-case conditions in your 134 * application. 135 * NOTE: The windowed ABI requires more stack, since space has to be reserved 136 * for spilling register windows. 137 * ------------------------------------------------------------------------------*/ 138 #ifdef __XTENSA_CALL0_ABI__ 139 #define XT_USER_SIZE 0x200 140 #else 141 #define XT_USER_SIZE 0x400 142 #endif 143 144 /* Minimum recommended stack size. */ 145 #define XT_STACK_MIN_SIZE ( ( XT_XTRA_SIZE + XT_USER_SIZE ) / sizeof( unsigned char ) ) 146 147 /* OS overhead with and without C library thread context. */ 148 #define XT_STACK_EXTRA ( XT_XTRA_SIZE ) 149 #define XT_STACK_EXTRA_CLIB ( XT_XTRA_SIZE + XT_CLIB_CONTEXT_AREA_SIZE ) 150 151 /* *INDENT-OFF* */ 152 #ifdef __cplusplus 153 } 154 #endif 155 /* *INDENT-ON* */ 156 157 #endif /* XTENSA_CONFIG_H */ 158