xtensa_config.h 7.6 KB

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