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