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