Skip to content

Commit 3d4d171

Browse files
Reintroduce Espressif's IDF v4.2 changes to ESP32 port (#193)
* Renamed old port to ESP_IDF_V3 * Update ESP32 port files to support IDF v4.2. * Add changes required to support ESP32-S2 Co-authored-by: Shubham Kulkarni <shubham.kulkarni@espressif.com>
1 parent 77ad717 commit 3d4d171

28 files changed

+7086
-34
lines changed

portable/ThirdParty/GCC/Xtensa_ESP32/FreeRTOS-openocd.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#define USED
2020
#endif
2121

22-
#ifdef CONFIG_ESP32_DEBUG_OCDAWARE
23-
const int USED DRAM_ATTR uxTopUsedPriority = configMAX_PRIORITIES - 1;
24-
#endif
22+
/*
23+
* This file is no longer needed as AFTER FreeRTOS V10.14.1 OpenOCD is fixed in the kernel.
24+
* #ifdef CONFIG_ESP32_DEBUG_OCDAWARE
25+
* const int USED DRAM_ATTR uxTopUsedPriority = configMAX_PRIORITIES - 1;
26+
* #endif
27+
*/

portable/ThirdParty/GCC/Xtensa_ESP32/include/portmacro.h

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,32 @@
307307
uint32_t compare,
308308
uint32_t * set )
309309
{
310-
__asm__ __volatile__ (
311-
"WSR %2,SCOMPARE1 \n"
312-
"S32C1I %0, %1, 0 \n"
313-
: "=r" ( *set )
314-
: "r" ( addr ), "r" ( compare ), "0" ( *set )
315-
);
310+
#if ( XCHAL_HAVE_S32C1I > 0 )
311+
__asm__ __volatile__ (
312+
"WSR %2,SCOMPARE1 \n"
313+
"S32C1I %0, %1, 0 \n"
314+
: "=r" ( *set )
315+
: "r" ( addr ), "r" ( compare ), "0" ( *set )
316+
);
317+
#else
318+
/* No S32C1I, so do this by disabling and re-enabling interrupts (slower) */
319+
uint32_t intlevel, old_value;
320+
__asm__ __volatile__ ( "rsil %0, " XTSTR( XCHAL_EXCM_LEVEL ) "\n"
321+
: "=r" ( intlevel ) );
322+
323+
old_value = *addr;
324+
325+
if( old_value == compare )
326+
{
327+
*addr = *set;
328+
}
329+
330+
__asm__ __volatile__ ( "memw \n"
331+
"wsr %0, ps\n"
332+
: : "r" ( intlevel ) );
333+
334+
*set = old_value;
335+
#endif /* if ( XCHAL_HAVE_S32C1I > 0 ) */
316336
}
317337

318338
void uxPortCompareSetExtram( volatile uint32_t * addr,
@@ -409,13 +429,6 @@
409429
#define xPortGetFreeHeapSize esp_get_free_heap_size
410430
#define xPortGetMinimumEverFreeHeapSize esp_get_minimum_free_heap_size
411431

412-
/*
413-
* Send an interrupt to another core in order to make the task running
414-
* on it yield for a higher-priority task.
415-
*/
416-
417-
void vPortYieldOtherCore( BaseType_t coreid ) PRIVILEGED_FUNCTION;
418-
419432

420433
/*
421434
* Callback to set a watchpoint on the end of the stack. Called every context switch to change the stack

portable/ThirdParty/GCC/Xtensa_ESP32/port.c

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,23 @@
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 */
113119
extern void _frxt_tick_timer_init( void );
@@ -133,6 +139,19 @@ unsigned port_interruptNesting[ portNUM_PROCESSORS ] = { 0 }; /* Interrupt nest
133139
/* User exception dispatcher when exiting */
134140
void _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. */

portable/ThirdParty/GCC/Xtensa_ESP32/portasm.S

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,24 @@ _frxt_int_enter:
138138
mull a2, a4, a2
139139
add a1, a1, a2 /* for current proc */
140140

141+
#ifdef CONFIG_FREERTOS_FPU_IN_ISR
142+
#if XCHAL_CP_NUM > 0
143+
rsr a3, CPENABLE /* Restore thread scope CPENABLE */
144+
addi sp, sp,-4 /* ISR will manage FPU coprocessor by forcing */
145+
s32i a3, a1, 0 /* its trigger */
146+
#endif
147+
#endif
148+
141149
.Lnested:
142150
1:
151+
#ifdef CONFIG_FREERTOS_FPU_IN_ISR
152+
#if XCHAL_CP_NUM > 0
153+
movi a3, 0 /* whilst ISRs pending keep CPENABLE exception active */
154+
wsr a3, CPENABLE
155+
rsync
156+
#endif
157+
#endif
158+
143159
mov a0, a12 /* restore return addr and return */
144160
ret
145161

@@ -176,6 +192,15 @@ _frxt_int_exit:
176192
s32i a2, a3, 0 /* save nesting count */
177193
bnez a2, .Lnesting /* !=0 after decr so still nested */
178194

195+
#ifdef CONFIG_FREERTOS_FPU_IN_ISR
196+
#if XCHAL_CP_NUM > 0
197+
l32i a3, sp, 0 /* Grab last CPENABLE before leave ISR */
198+
addi sp, sp, 4
199+
wsr a3, CPENABLE
200+
rsync /* ensure CPENABLE was modified */
201+
#endif
202+
#endif
203+
179204
movi a2, pxCurrentTCB
180205
addx4 a2, a4, a2
181206
l32i a2, a2, 0 /* a2 = current TCB */
@@ -642,7 +667,6 @@ _frxt_task_coproc_state:
642667
addx4 a15, a3, a15
643668
l32i a15, a15, 0 /* && pxCurrentTCB != 0) { */
644669

645-
646670
beqz a15, 2f
647671
l32i a15, a15, CP_TOPOFSTACK_OFFS
648672
ret

portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_init.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@
3434
#endif
3535

3636
#include "xtensa_rtos.h"
37-
#include "esp_clk.h"
37+
#if CONFIG_IDF_TARGET_ESP32S2
38+
#include "esp32s2/clk.h"
39+
#elif CONFIG_IDF_TARGET_ESP32
40+
#include "esp32/clk.h"
41+
#endif
3842

3943
#ifdef XT_RTOS_TIMER_INT
4044

portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_intr.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@
3434
#include "freertos/xtensa_api.h"
3535
#include "freertos/portable.h"
3636

37-
#include "rom/ets_sys.h"
37+
#if CONFIG_IDF_TARGET_ESP32S2
38+
#include "esp32s2/rom/ets_sys.h"
39+
#elif CONFIG_IDF_TARGET_ESP32
40+
#include "esp32/rom/ets_sys.h"
41+
#endif
3842

3943
#if XCHAL_HAVE_EXCEPTIONS
4044

portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_vector_defaults.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "xtensa_rtos.h"
16-
#include "esp_panic.h"
16+
#include "esp_private/panic_reason.h"
1717
#include "sdkconfig.h"
1818
#include "soc/soc.h"
1919

0 commit comments

Comments
 (0)