9797
9898#include "xtensa_rtos.h"
9999
100- #include "rom/ets_sys.h"
100+ #if CONFIG_IDF_TARGET_ESP32S2
101+ #include "esp32s2/rom/ets_sys.h"
102+ #elif CONFIG_IDF_TARGET_ESP32
103+ #include "esp32/rom/ets_sys.h"
104+ #endif
101105#include "soc/cpu.h"
102106
103107#include "FreeRTOS.h"
104108#include "task.h"
105109
106- #include "esp_panic.h"
110+ #include "esp_private/panic_reason.h"
111+ #include "esp_debug_helpers.h"
107112#include "esp_heap_caps.h"
108- #include "esp_crosscore_int .h"
113+ #include "esp_private/crosscore_int .h"
109114
110115#include "esp_intr_alloc.h"
116+ #include "esp_log.h"
111117
112118/* Defined in portasm.h */
113119extern void _frxt_tick_timer_init ( void );
@@ -133,6 +139,19 @@ unsigned port_interruptNesting[ portNUM_PROCESSORS ] = { 0 }; /* Interrupt nest
133139/* User exception dispatcher when exiting */
134140void _xt_user_exit ( void );
135141
142+ #if CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER
143+ /* Wrapper to allow task functions to return (increases stack overhead by 16 bytes) */
144+ static void vPortTaskWrapper ( TaskFunction_t pxCode ,
145+ void * pvParameters )
146+ {
147+ pxCode ( pvParameters );
148+ /*FreeRTOS tasks should not return. Log the task name and abort. */
149+ char * pcTaskName = pcTaskGetTaskName ( NULL );
150+ ESP_LOGE ( "FreeRTOS" , "FreeRTOS Task \"%s\" should not return, Aborting now!" , pcTaskName );
151+ abort ();
152+ }
153+ #endif /* if CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER */
154+
136155/*
137156 * Stack initialization
138157 */
@@ -168,21 +187,35 @@ void _xt_user_exit( void );
168187 frame = ( XtExcFrame * ) sp ;
169188
170189 /* Explicitly initialize certain saved registers */
171- frame -> pc = ( UBaseType_t ) pxCode ; /* task entrypoint */
172- frame -> a0 = 0 ; /* to terminate GDB backtrace */
173- frame -> a1 = ( UBaseType_t ) sp + XT_STK_FRMSZ ; /* physical top of stack frame */
174- frame -> exit = ( UBaseType_t ) _xt_user_exit ; /* user exception exit dispatcher */
190+ #if CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER
191+ frame -> pc = ( UBaseType_t ) vPortTaskWrapper ; /* task wrapper */
192+ #else
193+ frame -> pc = ( UBaseType_t ) pxCode ; /* task entrypoint */
194+ #endif
195+ frame -> a0 = 0 ; /* to terminate GDB backtrace */
196+ frame -> a1 = ( UBaseType_t ) sp + XT_STK_FRMSZ ; /* physical top of stack frame */
197+ frame -> exit = ( UBaseType_t ) _xt_user_exit ; /* user exception exit dispatcher */
175198
176199 /* Set initial PS to int level 0, EXCM disabled ('rfe' will enable), user mode. */
177200 /* Also set entry point argument parameter. */
178201 #ifdef __XTENSA_CALL0_ABI__
179- frame -> a2 = ( UBaseType_t ) pvParameters ;
202+ #if CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER
203+ frame -> a2 = ( UBaseType_t ) pxCode ;
204+ frame -> a3 = ( UBaseType_t ) pvParameters ;
205+ #else
206+ frame -> a2 = ( UBaseType_t ) pvParameters ;
207+ #endif
180208 frame -> ps = PS_UM | PS_EXCM ;
181209 #else
182210 /* + for windowed ABI also set WOE and CALLINC (pretend task was 'call4'd). */
183- frame -> a6 = ( UBaseType_t ) pvParameters ;
211+ #if CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER
212+ frame -> a6 = ( UBaseType_t ) pxCode ;
213+ frame -> a7 = ( UBaseType_t ) pvParameters ;
214+ #else
215+ frame -> a6 = ( UBaseType_t ) pvParameters ;
216+ #endif
184217 frame -> ps = PS_UM | PS_EXCM | PS_WOE | PS_CALLINC ( 1 );
185- #endif
218+ #endif /* ifdef __XTENSA_CALL0_ABI__ */
186219
187220 #ifdef XT_USE_SWPRI
188221 /* Set the initial virtual priority mask value to all 1's. */
0 commit comments