1 /*
2  * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef FREERTOS_CONFIG_H
8 #define FREERTOS_CONFIG_H
9 
10 #include "sdkconfig.h"
11 
12 /*
13 This file get's pulled into assembly sources. Therefore, some includes need to be wrapped in #ifndef __ASSEMBLER__
14 */
15 
16 #ifndef __ASSEMBLER__
17 #include <assert.h> //For configASSERT()
18 #endif              /* def __ASSEMBLER__ */
19 
20 #ifdef CONFIG_FREERTOS_SMP
21 
22 // Pull in the SMP configuration
23 #include "freertos/FreeRTOSConfig_smp.h"
24 
25 #else // CONFIG_FREERTOS_SMP
26 
27 // The arch-specific FreeRTOSConfig_arch.h in port/<arch>/include.
28 #include "freertos/FreeRTOSConfig_arch.h"
29 
30 #if !(defined(FREERTOS_CONFIG_XTENSA_H) || defined(FREERTOS_CONFIG_RISCV_H) || defined(FREERTOS_CONFIG_LINUX_H))
31 #error "Needs architecture-speific FreeRTOSConfig.h!"
32 #endif
33 
34 /* ----------------------------------------------------- Helpers -------------------------------------------------------
35  * - Macros that the FreeRTOS configuration macros depend on
36  * ------------------------------------------------------------------------------------------------------------------ */
37 
38 /* Higher stack checker modes cause overhead on each function call */
39 #if CONFIG_STACK_CHECK_ALL || CONFIG_STACK_CHECK_STRONG
40 #define STACK_OVERHEAD_CHECKER 256
41 #else
42 #define STACK_OVERHEAD_CHECKER 0
43 #endif
44 
45 /* with optimizations disabled, scheduler uses additional stack */
46 #if CONFIG_COMPILER_OPTIMIZATION_NONE
47 #define STACK_OVERHEAD_OPTIMIZATION 320
48 #else
49 #define STACK_OVERHEAD_OPTIMIZATION 0
50 #endif
51 
52 /* apptrace mdule increases minimum stack usage */
53 #if CONFIG_APPTRACE_ENABLE
54 #define STACK_OVERHEAD_APPTRACE 1280
55 #else
56 #define STACK_OVERHEAD_APPTRACE 0
57 #endif
58 
59 /* Stack watchpoint decreases minimum usable stack size by up to 60 bytes.
60    See FreeRTOS FREERTOS_WATCHPOINT_END_OF_STACK option in Kconfig. */
61 #if CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK
62 #define STACK_OVERHEAD_WATCHPOINT 60
63 #else
64 #define STACK_OVERHEAD_WATCHPOINT 0
65 #endif
66 
67 #define configSTACK_OVERHEAD_TOTAL ( \
68     STACK_OVERHEAD_CHECKER +         \
69     STACK_OVERHEAD_OPTIMIZATION +    \
70     STACK_OVERHEAD_APPTRACE +        \
71     STACK_OVERHEAD_WATCHPOINT)
72 
73 /* ------------------------------------------------- FreeRTOS Config ---------------------------------------------------
74  * - All Vanilla FreeRTOS configuration goes into this section
75  * - Keep this section in-sync with the corresponding version of single-core upstream version of FreeRTOS
76  * - Don't put any SMP or ESP-IDF exclusive FreeRTOS configurations here. Those go into the next section
77  * - Not all FreeRTOS configuration are listed. Some configurations have default values set in FreeRTOS.h thus don't
78  *   need to be explicitly defined.
79  * ------------------------------------------------------------------------------------------------------------------ */
80 
81 /*-----------------------------------------------------------
82  * Application specific definitions.
83  *
84  * These definitions should be adjusted for your particular hardware and
85  * application requirements.
86  *
87  * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
88  * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
89  *
90  * See http://www.freertos.org/a00110.html
91  *----------------------------------------------------------*/
92 
93 // ------------------ Scheduler Related --------------------
94 
95 // #define configUSE_PREEMPTION 1
96 // #define configUSE_TICKLESS_IDLE                         CONFIG_FREERTOS_USE_TICKLESS_IDLE
97 #if configUSE_TICKLESS_IDLE
98 #define configEXPECTED_IDLE_TIME_BEFORE_SLEEP CONFIG_FREERTOS_IDLE_TIME_BEFORE_SLEEP
99 #endif // configUSE_TICKLESS_IDLE
100 #define configCPU_CLOCK_HZ (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 1000000)
101 // #define configTICK_RATE_HZ                              CONFIG_FREERTOS_HZ
102 // #define configMAX_PRIORITIES                            ( 25 )  //This has impact on speed of search for highest priority
103 // #define configMINIMAL_STACK_SIZE                        ( 768 + configSTACK_OVERHEAD_TOTAL )
104 // #define configUSE_TIME_SLICING 1
105 // #define configUSE_16_BIT_TICKS 0
106 #define configIDLE_SHOULD_YIELD 0
107 #define configKERNEL_INTERRUPT_PRIORITY 1 // Todo: This currently isn't used anywhere
108 
109 // ------------- Synchronization Primitives ----------------
110 
111 // #define configUSE_MUTEXES                               1
112 // #define configUSE_RECURSIVE_MUTEXES                     1
113 #define configUSE_COUNTING_SEMAPHORES 1
114 // #define configUSE_QUEUE_SETS                            1
115 // #define configQUEUE_REGISTRY_SIZE                       CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE
116 #define configUSE_TASK_NOTIFICATIONS 1
117 // #define configTASK_NOTIFICATION_ARRAY_ENTRIES           1
118 
119 // ----------------------- System --------------------------
120 
121 // #define configMAX_TASK_NAME_LEN                         CONFIG_FREERTOS_MAX_TASK_NAME_LEN
122 #define configNUM_THREAD_LOCAL_STORAGE_POINTERS         CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS
123 #ifndef CONFIG_IDF_TARGET_LINUX
124 #define configSTACK_DEPTH_TYPE uint32_t
125 #define configUSE_NEWLIB_REENTRANT                      1
126 #endif
127 #if CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY
128 #define configENABLE_BACKWARD_COMPATIBILITY 1
129 #else
130 #define configENABLE_BACKWARD_COMPATIBILITY 0
131 #endif
132 // #define configASSERT(a) assert(a)
133 #define configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H 1
134 
135 // ----------------------- Memory  -------------------------
136 
137 #define configSUPPORT_STATIC_ALLOCATION 1
138 #define configSUPPORT_DYNAMIC_ALLOCATION 1
139 // We define the heap to span all of the non-statically-allocated shared RAM. ToDo: Make sure there
140 // is some space left for the app and main cpu when running outside of a thread.
141 //  #define configTOTAL_HEAP_SIZE                           (&_heap_end - &_heap_start)//( ( size_t ) (64 * 1024) )
142 //  #define configAPPLICATION_ALLOCATED_HEAP                1
143 #define configSTACK_ALLOCATION_FROM_SEPARATE_HEAP 0
144 
145 // ------------------------ Hooks --------------------------
146 
147 // #define configUSE_IDLE_HOOK                             CONFIG_FREERTOS_USE_IDLE_HOOK
148 // #define configUSE_TICK_HOOK                             CONFIG_FREERTOS_USE_TICK_HOOK
149 #if CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE
150 #define configCHECK_FOR_STACK_OVERFLOW 0
151 #elif CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL
152 #define configCHECK_FOR_STACK_OVERFLOW 1
153 #elif CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY
154 #define configCHECK_FOR_STACK_OVERFLOW 2
155 #endif
156 #define configRECORD_STACK_HIGH_ADDRESS 1
157 
158 // ------------------- Run-time Stats ----------------------
159 
160 #ifdef CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
161 #define configGENERATE_RUN_TIME_STATS 1 /* Used by vTaskGetRunTimeStats() */
162 #endif
163 #ifdef CONFIG_FREERTOS_USE_TRACE_FACILITY
164 #define configUSE_TRACE_FACILITY 1 /* Used by uxTaskGetSystemState(), and other trace facility functions */
165 #endif
166 #ifdef CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS
167 #define configUSE_STATS_FORMATTING_FUNCTIONS 1 /* Used by vTaskList() */
168 #endif
169 
170 // -------------------- Co-routines  -----------------------
171 
172 #define configUSE_CO_ROUTINES 0
173 #define configMAX_CO_ROUTINE_PRIORITIES 2
174 
175 // ------------------- Software Timer ----------------------
176 
177 // #define configUSE_TIMERS                                1
178 // #define configTIMER_TASK_PRIORITY                       CONFIG_FREERTOS_TIMER_TASK_PRIORITY
179 // #define configTIMER_QUEUE_LENGTH                        CONFIG_FREERTOS_TIMER_QUEUE_LENGTH
180 // #define configTIMER_TASK_STACK_DEPTH                    CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH
181 
182 // -------------------- API Includes -----------------------
183 
184 #if CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY
185 #define configENABLE_BACKWARD_COMPATIBILITY 1
186 #else
187 #define configENABLE_BACKWARD_COMPATIBILITY 0
188 #endif
189 
190 #define INCLUDE_vTaskPrioritySet 1
191 #define INCLUDE_uxTaskPriorityGet 1
192 #define INCLUDE_vTaskDelete 1
193 #define INCLUDE_vTaskSuspend 1
194 #define INCLUDE_xTaskDelayUntil 1
195 #define INCLUDE_vTaskDelay 1
196 #define INCLUDE_xTaskGetIdleTaskHandle 1
197 #define INCLUDE_xTaskAbortDelay 1
198 #define INCLUDE_xSemaphoreGetMutexHolder 1
199 #define INCLUDE_xTaskGetHandle 1
200 #define INCLUDE_uxTaskGetStackHighWaterMark 1
201 #define INCLUDE_uxTaskGetStackHighWaterMark2 1
202 #define INCLUDE_eTaskGetState 1
203 #define INCLUDE_xTaskResumeFromISR 1
204 // #define INCLUDE_xTimerPendFunctionCall                  1
205 #define INCLUDE_xTaskGetSchedulerState 1
206 #define INCLUDE_xTaskGetCurrentTaskHandle 1
207 // Unlisted
208 #define INCLUDE_pxTaskGetStackStart 1
209 
210 // -------------------- Trace Macros -----------------------
211 
212 /*
213 For trace macros.
214 Note: Include trace macros here and not above as trace macros are dependent on some of the FreeRTOS configs
215 */
216 #ifndef __ASSEMBLER__
217 #if CONFIG_SYSVIEW_ENABLE
218 #include "SEGGER_SYSVIEW_FreeRTOS.h"
219 #undef INLINE // to avoid redefinition
220 #endif        // CONFIG_SYSVIEW_ENABLE
221 #endif        /* def __ASSEMBLER__ */
222 
223 /* ------------------------------------------------ ESP-IDF Additions --------------------------------------------------
224  * - All FreeRTOS related configurations no part of Vanilla FreeRTOS goes into this section
225  * - FreeRTOS configurations related to SMP and ESP-IDF additions go into this section
226  * ------------------------------------------------------------------------------------------------------------------ */
227 
228 // ------------------------- SMP ---------------------------
229 
230 #ifndef CONFIG_FREERTOS_UNICORE
231 #define portNUM_PROCESSORS 2
232 #else
233 #define portNUM_PROCESSORS 1
234 #endif
235 #define configNUM_CORES portNUM_PROCESSORS
236 #ifdef CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID
237 #define configTASKLIST_INCLUDE_COREID 1
238 #endif
239 
240 // ---------------------- Features -------------------------
241 
242 #define configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS 1
243 #ifndef configIDLE_TASK_STACK_SIZE
244 #define configIDLE_TASK_STACK_SIZE CONFIG_FREERTOS_IDLE_TASK_STACKSIZE
245 #endif
246 
247 #if CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER
248 #define configCHECK_MUTEX_GIVEN_BY_OWNER 1
249 #else
250 #define configCHECK_MUTEX_GIVEN_BY_OWNER 0
251 #endif
252 
253 #ifndef __ASSEMBLER__
254 #if CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP
255 extern void vPortCleanUpTCB(void *pxTCB);
256 #define portCLEAN_UP_TCB(pxTCB) vPortCleanUpTCB(pxTCB)
257 #endif
258 #endif
259 
260 // -------------------- Compatibility ----------------------
261 
262 // backward compatibility for 4.4
263 #define xTaskRemoveFromUnorderedEventList vTaskRemoveFromUnorderedEventList
264 
265 #endif // CONFIG_FREERTOS_SMP
266 
267 #endif /* FREERTOS_CONFIG_H */
268