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