xtensa_config.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. * Configuration-specific information for Xtensa build. This file must be
  32. * included in FreeRTOSConfig.h to properly set up the config-dependent
  33. * parameters correctly.
  34. *
  35. * NOTE: To enable thread-safe C library support, XT_USE_THREAD_SAFE_CLIB must
  36. * be defined to be > 0 somewhere above or on the command line.
  37. */
  38. #ifndef XTENSA_CONFIG_H
  39. #define XTENSA_CONFIG_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. #include <xtensa/hal.h>
  44. #include <xtensa/config/core.h>
  45. #include <xtensa/config/system.h> /* required for XSHAL_CLIB */
  46. #include "xtensa_context.h"
  47. /*-----------------------------------------------------------------------------
  48. * STACK REQUIREMENTS
  49. *
  50. * This section defines the minimum stack size, and the extra space required to
  51. * be allocated for saving coprocessor state and/or C library state information
  52. * (if thread safety is enabled for the C library). The sizes are in bytes.
  53. *
  54. * Stack sizes for individual tasks should be derived from these minima based on
  55. * the maximum call depth of the task and the maximum level of interrupt nesting.
  56. * A minimum stack size is defined by XT_STACK_MIN_SIZE. This minimum is based
  57. * on the requirement for a task that calls nothing else but can be interrupted.
  58. * This assumes that interrupt handlers do not call more than a few levels deep.
  59. * If this is not true, i.e. one or more interrupt handlers make deep calls then
  60. * the minimum must be increased.
  61. *
  62. * If the Xtensa processor configuration includes coprocessors, then space is
  63. * allocated to save the coprocessor state on the stack.
  64. *
  65. * If thread safety is enabled for the C runtime library, (XT_USE_THREAD_SAFE_CLIB
  66. * is defined) then space is allocated to save the C library context in the TCB.
  67. *
  68. * Allocating insufficient stack space is a common source of hard-to-find errors.
  69. * During development, it is best to enable the FreeRTOS stack checking features.
  70. *
  71. * Usage:
  72. *
  73. * XT_USE_THREAD_SAFE_CLIB -- Define this to a nonzero value to enable thread-safe
  74. * use of the C library. This will require extra stack
  75. * space to be allocated for tasks that use the C library
  76. * reentrant functions. See below for more information.
  77. *
  78. * NOTE: The Xtensa toolchain supports multiple C libraries and not all of them
  79. * support thread safety. Check your core configuration to see which C library
  80. * was chosen for your system.
  81. *
  82. * XT_STACK_MIN_SIZE -- The minimum stack size for any task. It is recommended
  83. * that you do not use a stack smaller than this for any
  84. * task. In case you want to use stacks smaller than this
  85. * size, you must verify that the smaller size(s) will work
  86. * under all operating conditions.
  87. *
  88. * XT_STACK_EXTRA -- The amount of extra stack space to allocate for a task
  89. * that does not make C library reentrant calls. Add this
  90. * to the amount of stack space required by the task itself.
  91. *
  92. * XT_STACK_EXTRA_CLIB -- The amount of space to allocate for C library state.
  93. *
  94. -----------------------------------------------------------------------------*/
  95. /* Extra space required for interrupt/exception hooks. */
  96. #ifdef XT_INTEXC_HOOKS
  97. #ifdef __XTENSA_CALL0_ABI__
  98. #define STK_INTEXC_EXTRA 0x200
  99. #else
  100. #define STK_INTEXC_EXTRA 0x180
  101. #endif
  102. #else
  103. #define STK_INTEXC_EXTRA 0
  104. #endif
  105. /* Check C library thread safety support and compute size of C library save area.
  106. For the supported libraries, we enable thread safety by default, and this can
  107. be overridden from the compiler/make command line. */
  108. #if (XSHAL_CLIB == XTHAL_CLIB_NEWLIB) || (XSHAL_CLIB == XTHAL_CLIB_XCLIB)
  109. #ifndef XT_USE_THREAD_SAFE_CLIB
  110. #define XT_USE_THREAD_SAFE_CLIB 1
  111. #endif
  112. #else
  113. #define XT_USE_THREAD_SAFE_CLIB 0
  114. #endif
  115. #if XT_USE_THREAD_SAFE_CLIB > 0u
  116. #if XSHAL_CLIB == XTHAL_CLIB_XCLIB
  117. #define XT_HAVE_THREAD_SAFE_CLIB 1
  118. #if !defined __ASSEMBLER__
  119. #include <sys/reent.h>
  120. #define XT_CLIB_CONTEXT_AREA_SIZE ((sizeof(struct _reent) + 15) + (-16))
  121. #define XT_CLIB_GLOBAL_PTR _reent_ptr
  122. #define _REENT_INIT_PTR _init_reent
  123. #define _impure_ptr _reent_ptr
  124. void _reclaim_reent(void * ptr);
  125. #endif
  126. #elif XSHAL_CLIB == XTHAL_CLIB_NEWLIB
  127. #define XT_HAVE_THREAD_SAFE_CLIB 1
  128. #if !defined __ASSEMBLER__
  129. #include <sys/reent.h>
  130. #define XT_CLIB_CONTEXT_AREA_SIZE ((sizeof(struct _reent) + 15) + (-16))
  131. #define XT_CLIB_GLOBAL_PTR _impure_ptr
  132. #endif
  133. #else
  134. #define XT_HAVE_THREAD_SAFE_CLIB 0
  135. #error The selected C runtime library is not thread safe.
  136. #endif
  137. #else
  138. #define XT_CLIB_CONTEXT_AREA_SIZE 0
  139. #endif
  140. /*------------------------------------------------------------------------------
  141. Extra size -- interrupt frame plus coprocessor save area plus hook space.
  142. NOTE: Make sure XT_INTEXC_HOOKS is undefined unless you really need the hooks.
  143. ------------------------------------------------------------------------------*/
  144. #ifdef __XTENSA_CALL0_ABI__
  145. #define XT_XTRA_SIZE (XT_STK_FRMSZ + STK_INTEXC_EXTRA + 0x10 + XT_CP_SIZE)
  146. #else
  147. #define XT_XTRA_SIZE (XT_STK_FRMSZ + STK_INTEXC_EXTRA + 0x20 + XT_CP_SIZE)
  148. #endif
  149. /*------------------------------------------------------------------------------
  150. Space allocated for user code -- function calls and local variables.
  151. NOTE: This number can be adjusted to suit your needs. You must verify that the
  152. amount of space you reserve is adequate for the worst-case conditions in your
  153. application.
  154. NOTE: The windowed ABI requires more stack, since space has to be reserved
  155. for spilling register windows.
  156. ------------------------------------------------------------------------------*/
  157. #ifdef __XTENSA_CALL0_ABI__
  158. #define XT_USER_SIZE 0x200
  159. #else
  160. #define XT_USER_SIZE 0x400
  161. #endif
  162. /* Minimum recommended stack size. */
  163. #define XT_STACK_MIN_SIZE ((XT_XTRA_SIZE + XT_USER_SIZE) / sizeof(unsigned char))
  164. /* OS overhead with and without C library thread context. */
  165. #define XT_STACK_EXTRA (XT_XTRA_SIZE)
  166. #define XT_STACK_EXTRA_CLIB (XT_XTRA_SIZE + XT_CLIB_CONTEXT_AREA_SIZE)
  167. #ifdef __cplusplus
  168. }
  169. #endif
  170. #endif /* XTENSA_CONFIG_H */