1 /*
2  * SPDX-FileCopyrightText: 2022 Amazon.com, Inc. or its affiliates
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * SPDX-FileContributor: 2016-2022 Espressif Systems (Shanghai) CO LTD
7  */
8 /*
9  * FreeRTOS Kernel V10.6.2
10  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of
13  * this software and associated documentation files (the "Software"), to deal in
14  * the Software without restriction, including without limitation the rights to
15  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
16  * the Software, and to permit persons to whom the Software is furnished to do so,
17  * subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included in all
20  * copies or substantial portions of the Software. If you wish to use our Amazon
21  * FreeRTOS name, please do so in a fair use way that does not cause confusion.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
25  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
26  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
27  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29  *
30  * https://www.FreeRTOS.org
31  * https://github.com/FreeRTOS
32  *
33  * 1 tab == 4 spaces!
34  */
35 
36 #ifndef FREERTOS_CONFIG_XTENSA_H
37 #define FREERTOS_CONFIG_XTENSA_H
38 
39 #include "sdkconfig.h"
40 
41 /* enable use of optimized task selection by the scheduler */
42 #if defined (CONFIG_FREERTOS_OPTIMIZED_SCHEDULER) && !defined(configUSE_PORT_OPTIMISED_TASK_SELECTION)
43 #define configUSE_PORT_OPTIMISED_TASK_SELECTION         1
44 #endif
45 
46 #define XT_USE_THREAD_SAFE_CLIB                         0
47 #undef XT_USE_SWPRI
48 
49 #if CONFIG_FREERTOS_CORETIMER_0
50 #define XT_TIMER_INDEX                                  0
51 #elif CONFIG_FREERTOS_CORETIMER_1
52 #define XT_TIMER_INDEX                                  1
53 #endif
54 
55 #ifndef __ASSEMBLER__
56 /**
57  * This function is defined to provide a deprecation warning whenever
58  * XT_CLOCK_FREQ macro is used.
59  * Update the code to use esp_clk_cpu_freq function instead.
60  * @return current CPU clock frequency, in Hz
61  */
62 int xt_clock_freq(void) __attribute__((deprecated));
63 
64 #define XT_CLOCK_FREQ   (xt_clock_freq())
65 
66 #endif // __ASSEMBLER__
67 
68 /* Required for configuration-dependent settings */
69 #include <xtensa_config.h>
70 
71 /* configASSERT behaviour */
72 #ifndef __ASSEMBLER__
73 #include <assert.h>
74 #include "esp_rom_sys.h"
75 #if CONFIG_IDF_TARGET_ESP32
76 #include "esp32/rom/ets_sys.h"  // will be removed in idf v5.0
77 #elif CONFIG_IDF_TARGET_ESP32S2
78 #include "esp32s2/rom/ets_sys.h"
79 #elif CONFIG_IDF_TARGET_ESP32S3
80 #include "esp32s3/rom/ets_sys.h"
81 #endif
82 #endif // __ASSEMBLER__
83 
84 // If CONFIG_FREERTOS_ASSERT_DISABLE is set then configASSERT is defined empty later in FreeRTOS.h and the macro
85 // configASSERT_DEFINED remains unset (meaning some warnings are avoided)
86 #ifdef configASSERT
87 #undef configASSERT
88 #if defined(CONFIG_FREERTOS_ASSERT_FAIL_PRINT_CONTINUE)
89 #define configASSERT(a) if (unlikely(!(a))) {                           \
90         esp_rom_printf("%s:%d (%s)- assert failed!\n", __FILE__, __LINE__,  \
91                    __FUNCTION__);                                           \
92     }
93 #elif defined(CONFIG_FREERTOS_ASSERT_FAIL_ABORT)
94 #define configASSERT(a) assert(a)
95 #endif
96 #endif
97 
98 #if CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION
99 #define UNTESTED_FUNCTION() { esp_rom_printf("Untested FreeRTOS function %s\r\n", __FUNCTION__); configASSERT(false); } while(0)
100 #else
101 #define UNTESTED_FUNCTION()
102 #endif
103 
104 #define configXT_BOARD                                  1   /* Board mode */
105 #define configXT_SIMULATOR                              0
106 
107 /* The maximum interrupt priority from which FreeRTOS.org API functions can
108    be called.  Only API functions that end in ...FromISR() can be used within
109    interrupts. */
110 #define configMAX_SYSCALL_INTERRUPT_PRIORITY    XCHAL_EXCM_LEVEL
111 
112 /* Stack alignment, architecture specifc. Must be a power of two. */
113 #define configSTACK_ALIGNMENT                           16
114 
115 
116 /* The Xtensa port uses a separate interrupt stack. Adjust the stack size
117  * to suit the needs of your specific application.
118  * Size needs to be aligned to the stack increment, since the location of
119  * the stack for the 2nd CPU will be calculated using configISR_STACK_SIZE.
120  */
121 #ifndef configISR_STACK_SIZE
122 #define configISR_STACK_SIZE                            ((CONFIG_FREERTOS_ISR_STACKSIZE + configSTACK_ALIGNMENT - 1) & (~(configSTACK_ALIGNMENT - 1)))
123 #endif
124 
125 #ifndef __ASSEMBLER__
126 #if CONFIG_APPTRACE_SV_ENABLE
127 extern uint32_t port_switch_flag[];
128 #define os_task_switch_is_pended(_cpu_) (port_switch_flag[_cpu_])
129 #else
130 #define os_task_switch_is_pended(_cpu_) (false)
131 #endif
132 #endif
133 
134 #endif // FREERTOS_CONFIG_XTENSA_H
135