]> begriffs open source - freertos/blob - portable/ThirdParty/XCC/Xtensa/portmacro.h
Style: Change FreeRTOS websites in comments (#131)
[freertos] / portable / ThirdParty / XCC / Xtensa / portmacro.h
1 \r
2 /*\r
3  * FreeRTOS Kernel V10.0.0\r
4  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
5  *\r
6  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
7  * this software and associated documentation files (the "Software"), to deal in\r
8  * the Software without restriction, including without limitation the rights to\r
9  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
10  * the Software, and to permit persons to whom the Software is furnished to do so,\r
11  * subject to the following conditions:\r
12  *\r
13  * The above copyright notice and this permission notice shall be included in all\r
14  * copies or substantial portions of the Software. If you wish to use our Amazon\r
15  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
16  *\r
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
19  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
20  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
23  *\r
24  * https://www.FreeRTOS.org\r
25  * https://github.com/FreeRTOS\r
26  *\r
27  * 1 tab == 4 spaces!\r
28  */\r
29 \r
30 /*\r
31  * Copyright (c) 2015-2019 Cadence Design Systems, Inc.\r
32  *\r
33  * Permission is hereby granted, free of charge, to any person obtaining\r
34  * a copy of this software and associated documentation files (the\r
35  * "Software"), to deal in the Software without restriction, including\r
36  * without limitation the rights to use, copy, modify, merge, publish,\r
37  * distribute, sublicense, and/or sell copies of the Software, and to\r
38  * permit persons to whom the Software is furnished to do so, subject to\r
39  * the following conditions:\r
40  *\r
41  * The above copyright notice and this permission notice shall be included\r
42  * in all copies or substantial portions of the Software.\r
43  *\r
44  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
45  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
46  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r
47  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\r
48  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\r
49  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\r
50  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
51  */\r
52 \r
53 #ifndef PORTMACRO_H\r
54 #define PORTMACRO_H\r
55 \r
56 #ifdef __cplusplus\r
57 extern "C" {\r
58 #endif\r
59 \r
60 #ifndef __ASSEMBLER__\r
61 \r
62 #include <stdint.h>\r
63 \r
64 #include <xtensa/tie/xt_core.h>\r
65 #include <xtensa/hal.h>\r
66 #include <xtensa/config/core.h>\r
67 #include <xtensa/config/system.h>       /* required for XSHAL_CLIB */\r
68 #include <xtensa/xtruntime.h>\r
69 \r
70 //#include "xtensa_context.h"\r
71 \r
72 /*-----------------------------------------------------------\r
73  * Port specific definitions.\r
74  *\r
75  * The settings in this file configure FreeRTOS correctly for the\r
76  * given hardware and compiler.\r
77  *\r
78  * These settings should not be altered.\r
79  *-----------------------------------------------------------\r
80  */\r
81 \r
82 /* Type definitions. */\r
83 \r
84 #define portCHAR                int8_t\r
85 #define portFLOAT               float\r
86 #define portDOUBLE              double\r
87 #define portLONG                int32_t\r
88 #define portSHORT               int16_t\r
89 #define portSTACK_TYPE  uint32_t\r
90 #define portBASE_TYPE   int\r
91 \r
92 typedef portSTACK_TYPE                  StackType_t;\r
93 typedef portBASE_TYPE                   BaseType_t;\r
94 typedef unsigned portBASE_TYPE  UBaseType_t;\r
95 \r
96 #if( configUSE_16_BIT_TICKS == 1 )\r
97         typedef uint16_t TickType_t;\r
98         #define portMAX_DELAY ( TickType_t ) 0xffff\r
99 #else\r
100         typedef uint32_t TickType_t;\r
101         #define portMAX_DELAY ( TickType_t ) 0xffffffffUL\r
102 #endif\r
103 /*-----------------------------------------------------------*/\r
104 \r
105 // portbenchmark\r
106 #include "portbenchmark.h"\r
107 \r
108 /* Critical section management. NW-TODO: replace XTOS_SET_INTLEVEL with more efficient version, if any? */\r
109 // These cannot be nested. They should be used with a lot of care and cannot be called from interrupt level.\r
110 #define portDISABLE_INTERRUPTS()      do { XTOS_SET_INTLEVEL(XCHAL_EXCM_LEVEL); portbenchmarkINTERRUPT_DISABLE(); } while (0)\r
111 #define portENABLE_INTERRUPTS()       do { portbenchmarkINTERRUPT_RESTORE(0); XTOS_SET_INTLEVEL(0); } while (0)\r
112 \r
113 // These can be nested\r
114 #define portCRITICAL_NESTING_IN_TCB 1  // For now, let FreeRTOS' (tasks.c) manage critical nesting\r
115 void vTaskEnterCritical(void);\r
116 void vTaskExitCritical(void);\r
117 #define portENTER_CRITICAL()        vTaskEnterCritical()\r
118 #define portEXIT_CRITICAL()         vTaskExitCritical()\r
119 \r
120 // Cleaner and preferred solution allows nested interrupts disabling and restoring via local registers or stack.\r
121 // They can be called from interrupts too.\r
122 static inline unsigned portENTER_CRITICAL_NESTED() { unsigned state = XTOS_SET_INTLEVEL(XCHAL_EXCM_LEVEL); portbenchmarkINTERRUPT_DISABLE(); return state; }\r
123 #define portEXIT_CRITICAL_NESTED(state)   do { portbenchmarkINTERRUPT_RESTORE(state); XTOS_RESTORE_JUST_INTLEVEL(state); } while (0)\r
124 \r
125 // These FreeRTOS versions are similar to the nested versions above\r
126 #define portSET_INTERRUPT_MASK_FROM_ISR()            portENTER_CRITICAL_NESTED()\r
127 #define portCLEAR_INTERRUPT_MASK_FROM_ISR(state)     portEXIT_CRITICAL_NESTED(state)\r
128 \r
129 /*-----------------------------------------------------------*/\r
130 \r
131 /* Architecture specifics. */\r
132 #define portSTACK_GROWTH                        ( -1 )\r
133 #define portTICK_PERIOD_MS                      ( ( TickType_t ) 1000 / configTICK_RATE_HZ )\r
134 #define portBYTE_ALIGNMENT                      4\r
135 #define portNOP()                                       XT_NOP()\r
136 /*-----------------------------------------------------------*/\r
137 \r
138 /* Fine resolution time */\r
139 #define portGET_RUN_TIME_COUNTER_VALUE()  xthal_get_ccount()\r
140 \r
141 /* Kernel utilities. */\r
142 void vPortYield( void );\r
143 void _frxt_setup_switch( void );\r
144 #define portYIELD()       vPortYield()\r
145 #define portYIELD_FROM_ISR( xHigherPriorityTaskWoken )  \\r
146         if ( ( xHigherPriorityTaskWoken ) != 0 ) {      \\r
147                 _frxt_setup_switch();                   \\r
148         }\r
149 \r
150 /*-----------------------------------------------------------*/\r
151 \r
152 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
153 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
154 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
155 \r
156 // When coprocessors are defined, we to maintain a pointer to coprocessors area.\r
157 // We currently use a hack: redefine field xMPU_SETTINGS in TCB block as a structure that can hold:\r
158 // MPU wrappers, coprocessor area pointer, trace code structure, and more if needed.\r
159 // The field is normally used for memory protection. FreeRTOS should create another general purpose field.\r
160 typedef struct {\r
161         #if XCHAL_CP_NUM > 0\r
162         volatile StackType_t* coproc_area; // Pointer to coprocessor save area; MUST BE FIRST\r
163         #endif\r
164 \r
165         #if portUSING_MPU_WRAPPERS\r
166         // Define here mpu_settings, which is port dependent\r
167         int mpu_setting; // Just a dummy example here; MPU not ported to Xtensa yet\r
168         #endif\r
169 \r
170         #if configUSE_TRACE_FACILITY_2\r
171         struct {\r
172                 // Cf. porttraceStamp()\r
173                 int taskstamp;        /* Stamp from inside task to see where we are */\r
174                 int taskstampcount;   /* A counter usually incremented when we restart the task's loop */\r
175         } porttrace;\r
176         #endif\r
177 } xMPU_SETTINGS;\r
178 \r
179 // Main hack to use MPU_wrappers even when no MPU is defined (warning: mpu_setting should not be accessed; otherwise move this above xMPU_SETTINGS)\r
180 #if (XCHAL_CP_NUM > 0 || configUSE_TRACE_FACILITY_2) && !portUSING_MPU_WRAPPERS   // If MPU wrappers not used, we still need to allocate coproc area\r
181         #undef portUSING_MPU_WRAPPERS\r
182         #define portUSING_MPU_WRAPPERS 1   // Enable it to allocate coproc area\r
183         #define MPU_WRAPPERS_H             // Override mpu_wrapper.h to disable unwanted code\r
184         #define PRIVILEGED_FUNCTION\r
185         #define PRIVILEGED_DATA\r
186 #endif\r
187 \r
188 // porttrace\r
189 #if configUSE_TRACE_FACILITY_2\r
190 #include "porttrace.h"\r
191 #endif\r
192 \r
193 // configASSERT_2 if requested\r
194 #if configASSERT_2\r
195 #include <stdio.h>\r
196 void exit(int);\r
197 #define configASSERT( x )   if (!(x)) { porttracePrint(-1); printf("\nAssertion failed in %s:%d\n", __FILE__, __LINE__); exit(-1); }\r
198 #endif\r
199 \r
200 \r
201 /* C library support -- only XCLIB and NEWLIB are supported. */\r
202 \r
203 /* To enable thread-safe C library support, XT_USE_THREAD_SAFE_CLIB must be\r
204    defined to be > 0 somewhere above or on the command line. */\r
205 \r
206 #if (XT_USE_THREAD_SAFE_CLIB > 0u) && (XSHAL_CLIB == XTHAL_CLIB_XCLIB)\r
207 extern void vPortClibInit(void);\r
208 \r
209 // No cleanup necessary at this time.\r
210 #define portCLEAN_UP_TCB(pxTCB)\r
211 #endif // XCLIB support\r
212 \r
213 #if (XT_USE_THREAD_SAFE_CLIB > 0u) && (XSHAL_CLIB == XTHAL_CLIB_NEWLIB)\r
214 extern void vPortClibInit(void);\r
215 \r
216 // This C library cleanup is not currently done by FreeRTOS when deleting a task\r
217 #include <stdio.h>\r
218 #define portCLEAN_UP_TCB(pxTCB)   vPortCleanUpTcbClib(&((pxTCB)->xNewLib_reent))\r
219 static inline void vPortCleanUpTcbClib(struct _reent *ptr)\r
220 {\r
221     FILE * fp = &(ptr->__sf[0]);\r
222     int i;\r
223     for (i = 0; i < 3; ++i, ++fp) {\r
224         fp->_close = NULL;\r
225     }\r
226 }\r
227 #endif // NEWLIB support\r
228 \r
229 #endif // __ASSEMBLER__\r
230 \r
231 #ifdef __cplusplus\r
232 }\r
233 #endif\r
234 \r
235 #endif /* PORTMACRO_H */\r
236 \r