1 /*
2 * SPDX-FileCopyrightText: 2020 Amazon.com, Inc. or its affiliates
3 * SPDX-FileCopyrightText: 2015-2019 Cadence Design Systems, Inc.
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * SPDX-FileContributor: 2016-2022 Espressif Systems (Shanghai) CO LTD
8 */
9 /*
10 * FreeRTOS Kernel V10.6.2
11 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining a copy of
14 * this software and associated documentation files (the "Software"), to deal in
15 * the Software without restriction, including without limitation the rights to
16 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
17 * the Software, and to permit persons to whom the Software is furnished to do so,
18 * subject to the following conditions:
19 *
20 * The above copyright notice and this permission notice shall be included in all
21 * copies or substantial portions of the Software. If you wish to use our Amazon
22 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
26 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
27 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
28 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 *
31 * https://www.FreeRTOS.org
32 * https://github.com/FreeRTOS
33 *
34 * 1 tab == 4 spaces!
35 */
36 /*
37 * Copyright (c) 2015-2019 Cadence Design Systems, Inc.
38 *
39 * Permission is hereby granted, free of charge, to any person obtaining
40 * a copy of this software and associated documentation files (the
41 * "Software"), to deal in the Software without restriction, including
42 * without limitation the rights to use, copy, modify, merge, publish,
43 * distribute, sublicense, and/or sell copies of the Software, and to
44 * permit persons to whom the Software is furnished to do so, subject to
45 * the following conditions:
46 *
47 * The above copyright notice and this permission notice shall be included
48 * in all copies or substantial portions of the Software.
49 *
50 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
51 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
52 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
53 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
54 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
55 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
56 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
57 */
58
59 #include <stdlib.h>
60 #include <string.h>
61 #include <xtensa/config/core.h>
62
63 #include "xtensa_rtos.h"
64 #include "esp_idf_version.h"
65
66 #if (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 2, 0))
67 #include "rom/ets_sys.h"
68 #include "esp_panic.h"
69 #include "esp_crosscore_int.h"
70 #else
71 #if CONFIG_IDF_TARGET_ESP32S3
72 #include "esp32s3/rom/ets_sys.h"
73 #elif CONFIG_IDF_TARGET_ESP32S2
74 #include "esp32s2/rom/ets_sys.h"
75 #elif CONFIG_IDF_TARGET_ESP32
76 #include "esp32/rom/ets_sys.h"
77 #endif
78 #include "esp_private/panic_reason.h"
79 #include "esp_debug_helpers.h"
80 #include "esp_private/crosscore_int.h"
81 #include "esp_log.h"
82 #endif /* ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 2, 0) */
83 #include "soc/cpu.h"
84
85 #include "FreeRTOS.h"
86 #include "task.h"
87
88 #include "esp_heap_caps.h"
89
90 #include "esp_intr_alloc.h"
91
92 #include "port_systick.h"
93
94 /* Defined in xtensa_context.S */
95 extern void _xt_coproc_init( void );
96
97 _Static_assert(tskNO_AFFINITY == CONFIG_FREERTOS_NO_AFFINITY, "incorrect tskNO_AFFINITY value");
98
99 /*-----------------------------------------------------------*/
100
101 extern volatile int port_xSchedulerRunning[portNUM_PROCESSORS];
102 unsigned port_interruptNesting[ portNUM_PROCESSORS ] = { 0 }; /* Interrupt nesting level. Increased/decreased in portasm.c, _frxt_int_enter/_frxt_int_exit */
103
104 /*-----------------------------------------------------------*/
105
106 /* User exception dispatcher when exiting */
107 void _xt_user_exit( void );
108
109 #if CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER
110 /* Wrapper to allow task functions to return (increases stack overhead by 16 bytes) */
vPortTaskWrapper(TaskFunction_t pxCode,void * pvParameters)111 static void vPortTaskWrapper( TaskFunction_t pxCode,
112 void * pvParameters )
113 {
114 pxCode( pvParameters );
115 /*FreeRTOS tasks should not return. Log the task name and abort. */
116 char * pcTaskName = pcTaskGetTaskName( NULL );
117 ESP_LOGE( "FreeRTOS", "FreeRTOS Task \"%s\" should not return, Aborting now!", pcTaskName );
118 abort();
119 }
120 #endif /* if CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER */
121
122 /*
123 * Stack initialization
124 */
125 /* *INDENT-OFF* */
126 #if portUSING_MPU_WRAPPERS
pxPortInitialiseStack(StackType_t * pxTopOfStack,TaskFunction_t pxCode,void * pvParameters,BaseType_t xRunPrivileged)127 StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
128 TaskFunction_t pxCode,
129 void * pvParameters,
130 BaseType_t xRunPrivileged )
131 #else
132 StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
133 TaskFunction_t pxCode,
134 void * pvParameters )
135 #endif
136 /* *INDENT-ON* */
137 {
138 StackType_t * sp;
139 StackType_t * tp;
140 XtExcFrame * frame;
141
142 #if XCHAL_CP_NUM > 0
143 uint32_t * p;
144 #endif
145
146 uint32_t * threadptr;
147 void * task_thread_local_start;
148 extern int _thread_local_start, _thread_local_end, _flash_rodata_start, _flash_rodata_align;
149
150 /* TODO: check that TLS area fits the stack */
151 uint32_t thread_local_sz = ( uint8_t * ) &_thread_local_end - ( uint8_t * ) &_thread_local_start;
152
153 thread_local_sz = ALIGNUP( 0x10, thread_local_sz );
154
155 /* Initialize task's stack so that we have the following structure at the top:
156
157 ----LOW ADDRESSES ----------------------------------------HIGH ADDRESSES----------
158 task stack | interrupt stack frame | thread local vars | co-processor save area |
159 ----------------------------------------------------------------------------------
160 | |
161 SP pxTopOfStack
162
163 All parts are aligned to 16 byte boundary.
164 */
165
166 /* Create interrupt stack frame aligned to 16 byte boundary */
167 sp = ( StackType_t * ) ( ( ( UBaseType_t ) pxTopOfStack - XT_CP_SIZE - thread_local_sz - XT_STK_FRMSZ ) & ~0xf );
168
169 /* Clear the entire frame (do not use memset() because we don't depend on C library) */
170 for( tp = sp; tp <= pxTopOfStack; ++tp )
171 {
172 *tp = 0;
173 }
174
175 frame = ( XtExcFrame * ) sp;
176
177 /* Explicitly initialize certain saved registers */
178 #if CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER
179 frame->pc = ( UBaseType_t ) vPortTaskWrapper; /* task wrapper */
180 #else
181 frame->pc = ( UBaseType_t ) pxCode; /* task entrypoint */
182 #endif
183 frame->a0 = 0; /* to terminate GDB backtrace */
184 frame->a1 = ( UBaseType_t ) sp + XT_STK_FRMSZ; /* physical top of stack frame */
185 frame->exit = ( UBaseType_t ) _xt_user_exit; /* user exception exit dispatcher */
186
187 /* Set initial PS to int level 0, EXCM disabled ('rfe' will enable), user mode. */
188 /* Also set entry point argument parameter. */
189 #ifdef __XTENSA_CALL0_ABI__
190 #if CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER
191 frame->a2 = ( UBaseType_t ) pxCode;
192 frame->a3 = ( UBaseType_t ) pvParameters;
193 #else
194 frame->a2 = ( UBaseType_t ) pvParameters;
195 #endif
196 frame->ps = PS_UM | PS_EXCM;
197 #else
198 /* + for windowed ABI also set WOE and CALLINC (pretend task was 'call4'd). */
199 #if CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER
200 frame->a6 = ( UBaseType_t ) pxCode;
201 frame->a7 = ( UBaseType_t ) pvParameters;
202 #else
203 frame->a6 = ( UBaseType_t ) pvParameters;
204 #endif
205 frame->ps = PS_UM | PS_EXCM | PS_WOE | PS_CALLINC( 1 );
206 #endif /* ifdef __XTENSA_CALL0_ABI__ */
207
208 #ifdef XT_USE_SWPRI
209 /* Set the initial virtual priority mask value to all 1's. */
210 frame->vpri = 0xFFFFFFFF;
211 #endif
212
213 /* Init threadptr register and set up TLS run-time area. */
214 task_thread_local_start = ( void * ) ( ( ( uint32_t ) pxTopOfStack - XT_CP_SIZE - thread_local_sz ) & ~0xf );
215 memcpy( task_thread_local_start, &_thread_local_start, thread_local_sz );
216 threadptr = ( uint32_t * ) ( sp + XT_STK_EXTRA );
217
218 /* Calculate THREADPTR value.
219 * The generated code will add THREADPTR value to a constant value determined at link time,
220 * to get the address of the TLS variable.
221 * The constant value is calculated by the linker as follows
222 * (search for 'tpoff' in elf32-xtensa.c in BFD):
223 * offset = address - tls_section_vma + align_up(TCB_SIZE, tls_section_alignment)
224 * where TCB_SIZE is hardcoded to 8.
225 */
226 const uint32_t tls_section_alignment = ( uint32_t ) &_flash_rodata_align; /* ALIGN value of .flash.rodata section */
227 const uint32_t tcb_size = 8; /* Unrelated to FreeRTOS, this is the constant from BFD */
228 const uint32_t base = ( tcb_size + tls_section_alignment - 1 ) & ( ~( tls_section_alignment - 1 ) );
229 *threadptr = ( uint32_t ) task_thread_local_start - ( ( uint32_t ) &_thread_local_start - ( uint32_t ) &_flash_rodata_start ) - base;
230
231 #if XCHAL_CP_NUM > 0
232 /* Init the coprocessor save area (see xtensa_context.h) */
233
234 /* No access to TCB here, so derive indirectly. Stack growth is top to bottom.
235 * //p = (uint32_t *) xMPUSettings->coproc_area;
236 */
237 p = ( uint32_t * ) ( ( ( uint32_t ) pxTopOfStack - XT_CP_SIZE ) & ~0xf );
238 configASSERT( ( uint32_t ) p >= frame->a1 );
239 p[ 0 ] = 0;
240 p[ 1 ] = 0;
241 p[ 2 ] = ( ( ( uint32_t ) p ) + 12 + XCHAL_TOTAL_SA_ALIGN - 1 ) & -XCHAL_TOTAL_SA_ALIGN;
242 #endif
243
244 return sp;
245 }
246
247 /*-----------------------------------------------------------*/
248
vPortEndScheduler(void)249 void vPortEndScheduler( void )
250 {
251 /* It is unlikely that the Xtensa port will get stopped. If required simply
252 * disable the tick interrupt here. */
253 abort();
254 }
255
256 /*-----------------------------------------------------------*/
257
xPortStartScheduler(void)258 BaseType_t xPortStartScheduler( void )
259 {
260 portDISABLE_INTERRUPTS();
261 /* Interrupts are disabled at this point and stack contains PS with enabled interrupts when task context is restored */
262
263 #if XCHAL_CP_NUM > 0
264 /* Initialize co-processor management for tasks. Leave CPENABLE alone. */
265 _xt_coproc_init();
266 #endif
267
268 /* Setup the hardware to generate the tick */
269 vPortSetupTimer();
270
271 /* NOTE: For ESP32-S3, vPortSetupTimer allocates an interrupt for the
272 * systimer which is used as the source for FreeRTOS systick.
273 *
274 * The behaviour of portEXIT_CRITICAL is different in FreeRTOS and ESP-IDF -
275 * the former enables the interrupts no matter what the state was at the beginning
276 * of the call while the latter restores the interrupt state to what was at the
277 * beginning of the call.
278 *
279 * This resulted in the interrupts being enabled before the _frxt_dispatch call,
280 * who was unable to switch context to the queued tasks.
281 */
282 portDISABLE_INTERRUPTS();
283
284 port_xSchedulerRunning[ xPortGetCoreID() ] = 1;
285
286 /* Cannot be directly called from C; never returns */
287 __asm__ volatile ( "call0 _frxt_dispatch\n" );
288
289 /* Should not get here. */
290 return pdTRUE;
291 }
292
293 /*-----------------------------------------------------------*/
294
vPortYieldOtherCore(BaseType_t coreid)295 void vPortYieldOtherCore( BaseType_t coreid )
296 {
297 esp_crosscore_int_send_yield( coreid );
298 }
299
300 /*-----------------------------------------------------------*/
301
302 /*
303 * Used to set coprocessor area in stack. Current hack is to reuse MPU pointer for coprocessor area.
304 */
305 #if portUSING_MPU_WRAPPERS
vPortStoreTaskMPUSettings(xMPU_SETTINGS * xMPUSettings,const struct xMEMORY_REGION * const xRegions,StackType_t * pxBottomOfStack,uint32_t usStackDepth)306 void vPortStoreTaskMPUSettings( xMPU_SETTINGS * xMPUSettings,
307 const struct xMEMORY_REGION * const xRegions,
308 StackType_t * pxBottomOfStack,
309 uint32_t usStackDepth )
310 {
311 #if XCHAL_CP_NUM > 0
312 xMPUSettings->coproc_area = ( StackType_t * ) ( ( uint32_t ) ( pxBottomOfStack + usStackDepth - 1 ));
313 xMPUSettings->coproc_area = ( StackType_t * ) ( ( ( portPOINTER_SIZE_TYPE ) xMPUSettings->coproc_area ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) );
314 xMPUSettings->coproc_area = ( StackType_t * ) ( ( ( uint32_t ) xMPUSettings->coproc_area - XT_CP_SIZE ) & ~0xf );
315
316 /* NOTE: we cannot initialize the coprocessor save area here because FreeRTOS is going to
317 * clear the stack area after we return. This is done in pxPortInitialiseStack().
318 */
319 #endif
320 }
321
vPortReleaseTaskMPUSettings(xMPU_SETTINGS * xMPUSettings)322 void vPortReleaseTaskMPUSettings( xMPU_SETTINGS * xMPUSettings )
323 {
324 /* If task has live floating point registers somewhere, release them */
325 _xt_coproc_release( xMPUSettings->coproc_area );
326 }
327
328 #endif /* if portUSING_MPU_WRAPPERS */
329
330 /*
331 * Returns true if the current core is in ISR context; low prio ISR, med prio ISR or timer tick ISR. High prio ISRs
332 * aren't detected here, but they normally cannot call C code, so that should not be an issue anyway.
333 */
xPortInIsrContext()334 BaseType_t xPortInIsrContext()
335 {
336 unsigned int irqStatus;
337 BaseType_t ret;
338
339 irqStatus = portSET_INTERRUPT_MASK_FROM_ISR();
340 ret = ( port_interruptNesting[ xPortGetCoreID() ] != 0 );
341 portCLEAR_INTERRUPT_MASK_FROM_ISR( irqStatus );
342 return ret;
343 }
344
345 /*
346 * This function will be called in High prio ISRs. Returns true if the current core was in ISR context
347 * before calling into high prio ISR context.
348 */
xPortInterruptedFromISRContext()349 BaseType_t IRAM_ATTR xPortInterruptedFromISRContext()
350 {
351 return( port_interruptNesting[ xPortGetCoreID() ] != 0 );
352 }
353
vPortEvaluateYieldFromISR(int argc,...)354 void IRAM_ATTR vPortEvaluateYieldFromISR( int argc, ... )
355 {
356 BaseType_t xYield;
357 va_list ap;
358 va_start( ap, argc );
359
360 if( argc )
361 {
362 xYield = ( BaseType_t )va_arg( ap, int );
363 va_end( ap );
364 }
365 else
366 {
367 //it is a empty parameter vPortYieldFromISR macro call:
368 va_end( ap );
369 traceISR_EXIT_TO_SCHEDULER();
370 _frxt_setup_switch();
371 return;
372 }
373
374 //Yield exists, so need evaluate it first then switch:
375 if( xYield == pdTRUE )
376 {
377 traceISR_EXIT_TO_SCHEDULER();
378 _frxt_setup_switch();
379 }
380 }
381
vPortAssertIfInISR()382 void vPortAssertIfInISR()
383 {
384 if( xPortInIsrContext() )
385 {
386 esp_rom_printf( "core=%d port_interruptNesting=%d\n\n", xPortGetCoreID(), port_interruptNesting[ xPortGetCoreID() ] );
387 }
388
389 configASSERT( !xPortInIsrContext() );
390 }
391
392 /*
393 * For kernel use: Initialize a per-CPU mux. Mux will be initialized unlocked.
394 */
vPortCPUInitializeMutex(portMUX_TYPE * mux)395 void vPortCPUInitializeMutex( portMUX_TYPE * mux )
396 {
397 #ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
398 esp_rom_printf( "Initializing mux %p\n", mux );
399 mux->lastLockedFn = "(never locked)";
400 mux->lastLockedLine = -1;
401 #endif
402 mux->owner = portMUX_FREE_VAL;
403 mux->count = 0;
404 }
405
406 #include "portmux_impl.h"
407
408 /*
409 * For kernel use: Acquire a per-CPU mux. Spinlocks, so don't hold on to these muxes for too long.
410 */
411 #ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
vPortCPUAcquireMutex(portMUX_TYPE * mux,const char * fnName,int line)412 void vPortCPUAcquireMutex( portMUX_TYPE * mux,
413 const char * fnName,
414 int line )
415 {
416 unsigned int irqStatus = portSET_INTERRUPT_MASK_FROM_ISR();
417
418 vPortCPUAcquireMutexIntsDisabled( mux, portMUX_NO_TIMEOUT, fnName, line );
419 portCLEAR_INTERRUPT_MASK_FROM_ISR( irqStatus );
420 }
421
vPortCPUAcquireMutexTimeout(portMUX_TYPE * mux,int timeout_cycles,const char * fnName,int line)422 bool vPortCPUAcquireMutexTimeout( portMUX_TYPE * mux,
423 int timeout_cycles,
424 const char * fnName,
425 int line )
426 {
427 unsigned int irqStatus = portSET_INTERRUPT_MASK_FROM_ISR();
428 bool result = vPortCPUAcquireMutexIntsDisabled( mux, timeout_cycles, fnName, line );
429
430 portCLEAR_INTERRUPT_MASK_FROM_ISR( irqStatus );
431 return result;
432 }
433
434 #else /* ifdef CONFIG_FREERTOS_PORTMUX_DEBUG */
vPortCPUAcquireMutex(portMUX_TYPE * mux)435 void vPortCPUAcquireMutex( portMUX_TYPE * mux )
436 {
437 unsigned int irqStatus = portSET_INTERRUPT_MASK_FROM_ISR();
438
439 vPortCPUAcquireMutexIntsDisabled( mux, portMUX_NO_TIMEOUT );
440 portCLEAR_INTERRUPT_MASK_FROM_ISR( irqStatus );
441 }
442
vPortCPUAcquireMutexTimeout(portMUX_TYPE * mux,int timeout_cycles)443 bool vPortCPUAcquireMutexTimeout( portMUX_TYPE * mux,
444 int timeout_cycles )
445 {
446 unsigned int irqStatus = portSET_INTERRUPT_MASK_FROM_ISR();
447 bool result = vPortCPUAcquireMutexIntsDisabled( mux, timeout_cycles );
448
449 portCLEAR_INTERRUPT_MASK_FROM_ISR( irqStatus );
450 return result;
451 }
452 #endif /* ifdef CONFIG_FREERTOS_PORTMUX_DEBUG */
453
454
455 /*
456 * For kernel use: Release a per-CPU mux
457 *
458 * Mux must be already locked by this core
459 */
460 #ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
vPortCPUReleaseMutex(portMUX_TYPE * mux,const char * fnName,int line)461 void vPortCPUReleaseMutex( portMUX_TYPE * mux,
462 const char * fnName,
463 int line )
464 {
465 unsigned int irqStatus = portSET_INTERRUPT_MASK_FROM_ISR();
466
467 vPortCPUReleaseMutexIntsDisabled( mux, fnName, line );
468 portCLEAR_INTERRUPT_MASK_FROM_ISR( irqStatus );
469 }
470 #else
vPortCPUReleaseMutex(portMUX_TYPE * mux)471 void vPortCPUReleaseMutex( portMUX_TYPE * mux )
472 {
473 unsigned int irqStatus = portSET_INTERRUPT_MASK_FROM_ISR();
474
475 vPortCPUReleaseMutexIntsDisabled( mux );
476 portCLEAR_INTERRUPT_MASK_FROM_ISR( irqStatus );
477 }
478 #endif /* ifdef CONFIG_FREERTOS_PORTMUX_DEBUG */
479
480 #define STACK_WATCH_AREA_SIZE ( 32 )
481 #define STACK_WATCH_POINT_NUMBER ( SOC_CPU_WATCHPOINTS_NUM - 1 )
482
vPortSetStackWatchpoint(void * pxStackStart)483 void vPortSetStackWatchpoint( void * pxStackStart )
484 {
485 /*Set watchpoint 1 to watch the last 32 bytes of the stack. */
486 /*Unfortunately, the Xtensa watchpoints can't set a watchpoint on a random [base - base+n] region because */
487 /*the size works by masking off the lowest address bits. For that reason, we futz a bit and watch the lowest 32 */
488 /*bytes of the stack we can actually watch. In general, this can cause the watchpoint to be triggered at most */
489 /*28 bytes early. The value 32 is chosen because it's larger than the stack canary, which in FreeRTOS is 20 bytes. */
490 /*This way, we make sure we trigger before/when the stack canary is corrupted, not after. */
491 int addr = ( int ) pxStackStart;
492
493 addr = ( addr + 31 ) & ( ~31 );
494 esp_cpu_set_watchpoint( STACK_WATCH_POINT_NUMBER, (char*)addr, 32, ESP_WATCHPOINT_STORE );
495 }
496
497 #if (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 2, 0))
498
499 #if defined( CONFIG_SPIRAM_SUPPORT )
500
501 /*
502 * Compare & set (S32C1) does not work in external RAM. Instead, this routine uses a mux (in internal memory) to fake it.
503 */
504 static portMUX_TYPE extram_mux = portMUX_INITIALIZER_UNLOCKED;
505
uxPortCompareSetExtram(volatile uint32_t * addr,uint32_t compare,uint32_t * set)506 void uxPortCompareSetExtram( volatile uint32_t * addr,
507 uint32_t compare,
508 uint32_t * set )
509 {
510 uint32_t prev;
511
512 uint32_t oldlevel = portSET_INTERRUPT_MASK_FROM_ISR();
513
514 #ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
515 vPortCPUAcquireMutexIntsDisabled( &extram_mux, portMUX_NO_TIMEOUT, __FUNCTION__, __LINE__ );
516 #else
517 vPortCPUAcquireMutexIntsDisabled( &extram_mux, portMUX_NO_TIMEOUT );
518 #endif
519 prev = *addr;
520
521 if( prev == compare )
522 {
523 *addr = *set;
524 }
525
526 *set = prev;
527 #ifdef CONFIG_FREERTOS_PORTMUX_DEBUG
528 vPortCPUReleaseMutexIntsDisabled( &extram_mux, __FUNCTION__, __LINE__ );
529 #else
530 vPortCPUReleaseMutexIntsDisabled( &extram_mux );
531 #endif
532
533 portCLEAR_INTERRUPT_MASK_FROM_ISR(oldlevel);
534 }
535 #endif //defined(CONFIG_SPIRAM_SUPPORT)
536
537 #endif /* ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 2, 0) */
538
539
xPortGetTickRateHz(void)540 uint32_t xPortGetTickRateHz( void )
541 {
542 return ( uint32_t ) configTICK_RATE_HZ;
543 }
544
545 // For now, running FreeRTOS on one core and a bare metal on the other (or other OSes)
546 // is not supported. For now CONFIG_FREERTOS_UNICORE and CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
547 // should mirror each other's values.
548 //
549 // And since this should be true, we can just check for CONFIG_FREERTOS_UNICORE.
550 #if CONFIG_FREERTOS_UNICORE != CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
551 #error "FreeRTOS and system configuration mismatch regarding the use of multiple cores."
552 #endif
553
554 extern void esp_startup_start_app_common(void);
555
esp_startup_start_app(void)556 void esp_startup_start_app(void)
557 {
558 #if !CONFIG_ESP_INT_WDT
559 #if CONFIG_ESP32_ECO3_CACHE_LOCK_FIX
560 assert(!soc_has_cache_lock_bug() && "ESP32 Rev 3 + Dual Core + PSRAM requires INT WDT enabled in project config!");
561 #endif
562 #endif
563
564 esp_startup_start_app_common();
565
566 ESP_LOGI("cpu_start", "Starting scheduler on PRO CPU.");
567 vTaskStartScheduler();
568 }
569