1 /*******************************************************************************
2 // Copyright (c) 2003-2015 Cadence Design Systems, Inc.
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included
13 // in all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 --------------------------------------------------------------------------------
23 
24   Configuration-specific information for Xtensa build. This file must be
25   included in FreeRTOSConfig.h to properly set up the config-dependent
26   parameters correctly.
27 
28   NOTE: To enable thread-safe C library support, XT_USE_THREAD_SAFE_CLIB must
29   be defined to be > 0 somewhere above or on the command line.
30 
31 *******************************************************************************/
32 
33 #ifndef XTENSA_CONFIG_H
34 #define XTENSA_CONFIG_H
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #include <xtensa/hal.h>
41 #include <xtensa/config/core.h>
42 #include <xtensa/config/system.h>	/* required for XSHAL_CLIB */
43 
44 #include "xtensa_context.h"
45 
46 
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 
96 /* Extra space required for interrupt/exception hooks. */
97 #ifdef XT_INTEXC_HOOKS
98   #ifdef __XTENSA_CALL0_ABI__
99     #define STK_INTEXC_EXTRA        0x200
100   #else
101     #define STK_INTEXC_EXTRA        0x180
102   #endif
103 #else
104   #define STK_INTEXC_EXTRA          0
105 #endif
106 
107 #define XT_CLIB_CONTEXT_AREA_SIZE         0
108 
109 /*------------------------------------------------------------------------------
110   Extra size -- interrupt frame plus coprocessor save area plus hook space.
111   NOTE: Make sure XT_INTEXC_HOOKS is undefined unless you really need the hooks.
112 ------------------------------------------------------------------------------*/
113 #ifdef __XTENSA_CALL0_ABI__
114   #define XT_XTRA_SIZE            (XT_STK_FRMSZ + STK_INTEXC_EXTRA + 0x10 + XT_CP_SIZE)
115 #else
116   #define XT_XTRA_SIZE            (XT_STK_FRMSZ + STK_INTEXC_EXTRA + 0x20 + XT_CP_SIZE)
117 #endif
118 
119 /*------------------------------------------------------------------------------
120   Space allocated for user code -- function calls and local variables.
121   NOTE: This number can be adjusted to suit your needs. You must verify that the
122   amount of space you reserve is adequate for the worst-case conditions in your
123   application.
124   NOTE: The windowed ABI requires more stack, since space has to be reserved
125   for spilling register windows.
126 ------------------------------------------------------------------------------*/
127 #ifdef __XTENSA_CALL0_ABI__
128   #define XT_USER_SIZE            0x200
129 #else
130   #define XT_USER_SIZE            0x400
131 #endif
132 
133 /* Minimum recommended stack size. */
134 #define XT_STACK_MIN_SIZE         ((XT_XTRA_SIZE + XT_USER_SIZE) / sizeof(unsigned char))
135 
136 /* OS overhead with and without C library thread context. */
137 #define XT_STACK_EXTRA            (XT_XTRA_SIZE)
138 #define XT_STACK_EXTRA_CLIB       (XT_XTRA_SIZE + XT_CLIB_CONTEXT_AREA_SIZE)
139 
140 
141 #ifdef __cplusplus
142 }
143 #endif
144 
145 #endif /* XTENSA_CONFIG_H */
146