]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/ThirdParty/XCC/Xtensa/portmacro.h
Add Xtensa port
[freertos] / FreeRTOS / Source / portable / ThirdParty / XCC / Xtensa / portmacro.h
1 /*\r
2     FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
28     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
29     >>!   obliged to provide the source code for proprietary components     !<<\r
30     >>!   outside of the FreeRTOS kernel.                                   !<<\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 #ifndef PORTMACRO_H\r
67 #define PORTMACRO_H\r
68 \r
69 #ifdef __cplusplus\r
70 extern "C" {\r
71 #endif\r
72 \r
73 #ifndef __ASSEMBLER__\r
74 \r
75 #include <stdint.h>\r
76 \r
77 #include <xtensa/tie/xt_core.h>\r
78 #include <xtensa/hal.h>\r
79 #include <xtensa/config/core.h>\r
80 #include <xtensa/config/system.h>       /* required for XSHAL_CLIB */\r
81 #include <xtensa/xtruntime.h>\r
82 \r
83 //#include "xtensa_context.h"\r
84 \r
85 /*-----------------------------------------------------------\r
86  * Port specific definitions.\r
87  *\r
88  * The settings in this file configure FreeRTOS correctly for the\r
89  * given hardware and compiler.\r
90  *\r
91  * These settings should not be altered.\r
92  *-----------------------------------------------------------\r
93  */\r
94 \r
95 /* Type definitions. */\r
96 \r
97 #define portCHAR                int8_t\r
98 #define portFLOAT               float\r
99 #define portDOUBLE              double\r
100 #define portLONG                int32_t\r
101 #define portSHORT               int16_t\r
102 #define portSTACK_TYPE  uint8_t\r
103 #define portBASE_TYPE   int\r
104 \r
105 typedef portSTACK_TYPE                  StackType_t;\r
106 typedef portBASE_TYPE                   BaseType_t;\r
107 typedef unsigned portBASE_TYPE  UBaseType_t;\r
108 \r
109 #if( configUSE_16_BIT_TICKS == 1 )\r
110         typedef uint16_t TickType_t;\r
111         #define portMAX_DELAY ( TickType_t ) 0xffff\r
112 #else\r
113         typedef uint32_t TickType_t;\r
114         #define portMAX_DELAY ( TickType_t ) 0xffffffffUL\r
115 #endif\r
116 /*-----------------------------------------------------------*/\r
117 \r
118 // portbenchmark\r
119 #include "portbenchmark.h"\r
120 \r
121 /* Critical section management. NW-TODO: replace XTOS_SET_INTLEVEL with more efficient version, if any? */\r
122 // These cannot be nested. They should be used with a lot of care and cannot be called from interrupt level.\r
123 #define portDISABLE_INTERRUPTS()      do { XTOS_SET_INTLEVEL(XCHAL_EXCM_LEVEL); portbenchmarkINTERRUPT_DISABLE(); } while (0)\r
124 #define portENABLE_INTERRUPTS()       do { portbenchmarkINTERRUPT_RESTORE(0); XTOS_SET_INTLEVEL(0); } while (0)\r
125 \r
126 // These can be nested\r
127 #define portCRITICAL_NESTING_IN_TCB 1  // For now, let FreeRTOS' (tasks.c) manage critical nesting\r
128 void vTaskEnterCritical(void);\r
129 void vTaskExitCritical(void);\r
130 #define portENTER_CRITICAL()        vTaskEnterCritical()\r
131 #define portEXIT_CRITICAL()         vTaskExitCritical()\r
132 \r
133 // Cleaner and preferred solution allows nested interrupts disabling and restoring via local registers or stack.\r
134 // They can be called from interrupts too.\r
135 static inline unsigned portENTER_CRITICAL_NESTED() { unsigned state = XTOS_SET_INTLEVEL(XCHAL_EXCM_LEVEL); portbenchmarkINTERRUPT_DISABLE(); return state; }\r
136 #define portEXIT_CRITICAL_NESTED(state)   do { portbenchmarkINTERRUPT_RESTORE(state); XTOS_RESTORE_JUST_INTLEVEL(state); } while (0)\r
137 \r
138 // These FreeRTOS versions are similar to the nested versions above\r
139 #define portSET_INTERRUPT_MASK_FROM_ISR()            portENTER_CRITICAL_NESTED()\r
140 #define portCLEAR_INTERRUPT_MASK_FROM_ISR(state)     portEXIT_CRITICAL_NESTED(state)\r
141 /*-----------------------------------------------------------*/\r
142 \r
143 /* Architecture specifics. */\r
144 #define portSTACK_GROWTH                        ( -1 )\r
145 #define portTICK_PERIOD_MS                      ( ( TickType_t ) 1000 / configTICK_RATE_HZ )\r
146 #define portBYTE_ALIGNMENT                      4\r
147 #define portNOP()                                       XT_NOP()\r
148 /*-----------------------------------------------------------*/\r
149 \r
150 /* Fine resolution time */\r
151 #define portGET_RUN_TIME_COUNTER_VALUE()  xthal_get_ccount()\r
152 \r
153 /* Kernel utilities. */\r
154 void vPortYield( void );\r
155 void _frxt_setup_switch( void );\r
156 #define portYIELD()       vPortYield()\r
157 #define portYIELD_FROM_ISR( x )         if( ( x ) != 0 ) { _frxt_setup_switch(); }\r
158 /*-----------------------------------------------------------*/\r
159 \r
160 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
161 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
162 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
163 \r
164 // When coprocessors are defined, we to maintain a pointer to coprocessors area.\r
165 // We currently use a hack: redefine field xMPU_SETTINGS in TCB block as a structure that can hold:\r
166 // MPU wrappers, coprocessor area pointer, trace code structure, and more if needed.\r
167 // The field is normally used for memory protection. FreeRTOS should create another general purpose field.\r
168 typedef struct {\r
169         #if XCHAL_CP_NUM > 0\r
170         volatile StackType_t* coproc_area; // Pointer to coprocessor save area; MUST BE FIRST\r
171         #endif\r
172 \r
173         #if portUSING_MPU_WRAPPERS\r
174         // Define here mpu_settings, which is port dependent\r
175         int mpu_setting; // Just a dummy example here; MPU not ported to Xtensa yet\r
176         #endif\r
177 \r
178         #if configUSE_TRACE_FACILITY_2\r
179         struct {\r
180                 // Cf. porttraceStamp()\r
181                 int taskstamp;        /* Stamp from inside task to see where we are */\r
182                 int taskstampcount;   /* A counter usually incremented when we restart the task's loop */\r
183         } porttrace;\r
184         #endif\r
185 } xMPU_SETTINGS;\r
186 \r
187 // 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
188 #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
189         #undef portUSING_MPU_WRAPPERS\r
190         #define portUSING_MPU_WRAPPERS 1   // Enable it to allocate coproc area\r
191         #define MPU_WRAPPERS_H             // Override mpu_wrapper.h to disable unwanted code\r
192         #define PRIVILEGED_FUNCTION\r
193         #define PRIVILEGED_DATA\r
194 #endif\r
195 \r
196 // porttrace\r
197 #if configUSE_TRACE_FACILITY_2\r
198 #include "porttrace.h"\r
199 #endif\r
200 \r
201 // configASSERT_2 if requested\r
202 #if configASSERT_2\r
203 #include <stdio.h>\r
204 void exit(int);\r
205 #define configASSERT( x )   if (!(x)) { porttracePrint(-1); printf("\nAssertion failed in %s:%d\n", __FILE__, __LINE__); exit(-1); }\r
206 #endif\r
207 \r
208 \r
209 /* C library support -- only XCLIB and NEWLIB are supported. */\r
210 \r
211 /* To enable thread-safe C library support, XT_USE_THREAD_SAFE_CLIB must be\r
212    defined to be > 0 somewhere above or on the command line. */\r
213 \r
214 #if (XT_USE_THREAD_SAFE_CLIB > 0u) && (XSHAL_CLIB == XTHAL_CLIB_XCLIB)\r
215 extern void vPortClibInit(void);\r
216 \r
217 // No cleanup necessary at this time.\r
218 #define portCLEAN_UP_TCB(pxTCB)\r
219 #endif // XCLIB support\r
220 \r
221 #if (XT_USE_THREAD_SAFE_CLIB > 0u) && (XSHAL_CLIB == XTHAL_CLIB_NEWLIB)\r
222 extern void vPortClibInit(void);\r
223 \r
224 // This C library cleanup is not currently done by FreeRTOS when deleting a task\r
225 #include <stdio.h>\r
226 #define portCLEAN_UP_TCB(pxTCB)   vPortCleanUpTcbClib(&((pxTCB)->xNewLib_reent))\r
227 static inline void vPortCleanUpTcbClib(struct _reent *ptr)\r
228 {\r
229     FILE * fp = &(ptr->__sf[0]);\r
230     int i;\r
231     for (i = 0; i < 3; ++i, ++fp) {\r
232         fp->_close = NULL;\r
233     }\r
234 }\r
235 #endif // NEWLIB support\r
236 \r
237 #endif // __ASSEMBLER__\r
238 \r
239 #ifdef __cplusplus\r
240 }\r
241 #endif\r
242 \r
243 #endif /* PORTMACRO_H */\r
244 \r