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
6 * SPDX-License-Identifier: MIT
\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
15 * The above copyright notice and this permission notice shall be included in all
\r
16 * copies or substantial portions of the Software.
\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
25 * https://www.FreeRTOS.org
\r
26 * https://github.com/FreeRTOS
\r
37 #ifndef __ASSEMBLER__
\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
47 //#include "xtensa_context.h"
\r
49 /*-----------------------------------------------------------
\r
50 * Port specific definitions.
\r
52 * The settings in this file configure FreeRTOS correctly for the
\r
53 * given hardware and compiler.
\r
55 * These settings should not be altered.
\r
56 *-----------------------------------------------------------
\r
59 /* Type definitions. */
\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
69 typedef portSTACK_TYPE StackType_t;
\r
70 typedef portBASE_TYPE BaseType_t;
\r
71 typedef unsigned portBASE_TYPE UBaseType_t;
\r
73 #if( configUSE_16_BIT_TICKS == 1 )
\r
74 typedef uint16_t TickType_t;
\r
75 #define portMAX_DELAY ( TickType_t ) 0xffff
\r
77 typedef uint32_t TickType_t;
\r
78 #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
\r
80 /*-----------------------------------------------------------*/
\r
83 #include "portbenchmark.h"
\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
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
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
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
106 /*-----------------------------------------------------------*/
\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
115 /* Fine resolution time */
\r
116 #define portGET_RUN_TIME_COUNTER_VALUE() xthal_get_ccount()
\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
127 /*-----------------------------------------------------------*/
\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
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
138 #if XCHAL_CP_NUM > 0
\r
139 volatile StackType_t* coproc_area; // Pointer to coprocessor save area; MUST BE FIRST
\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
147 #if configUSE_TRACE_FACILITY_2
\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
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
166 #if configUSE_TRACE_FACILITY_2
\r
167 #include "porttrace.h"
\r
170 // configASSERT_2 if requested
\r
174 #define configASSERT( x ) if (!(x)) { porttracePrint(-1); printf("\nAssertion failed in %s:%d\n", __FILE__, __LINE__); exit(-1); }
\r
178 /* C library support -- only XCLIB and NEWLIB are supported. */
\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
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
187 #if (XT_USE_THREAD_SAFE_CLIB > 0u) && (XSHAL_CLIB == XTHAL_CLIB_NEWLIB)
\r
188 extern void vPortClibInit(void);
\r
190 // This C library cleanup is not currently done by FreeRTOS when deleting a task
\r
192 #define portCLEAN_UP_TCB(pxTCB) vPortCleanUpTcbClib(&((pxTCB)->xNewLib_reent))
\r
193 static inline void vPortCleanUpTcbClib(struct _reent *ptr)
\r
195 FILE * fp = &(ptr->__sf[0]);
\r
197 for (i = 0; i < 3; ++i, ++fp) {
\r
201 #endif // NEWLIB support
\r
203 #endif // __ASSEMBLER__
\r
209 #endif /* PORTMACRO_H */
\r