1 // Copyright 2020 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 // Configuration macros for the tokenizer module. 15 #pragma once 16 17 #include "FreeRTOS.h" 18 #include "task.h" 19 20 // Whether thread joining is enabled. By default this is disabled. 21 // 22 // We suggest only enabling this when thread joining is required to minimize 23 // the RAM and ROM cost of threads. 24 // 25 // Enabling this grows the RAM footprint of every pw::Thread as it adds 26 // a StaticEventGroup_t to every thread's pw::thread::freertos::Context. In 27 // addition, there is a minute ROM cost to construct and destroy this added 28 // object. 29 // 30 // PW_THREAD_JOINING_ENABLED gets set to this value. 31 #ifndef PW_THREAD_FREERTOS_CONFIG_JOINING_ENABLED 32 #define PW_THREAD_FREERTOS_CONFIG_JOINING_ENABLED 0 33 #endif // PW_THREAD_FREERTOS_CONFIG_JOINING_ENABLED 34 #define PW_THREAD_JOINING_ENABLED PW_THREAD_FREERTOS_CONFIG_JOINING_ENABLED 35 36 // Whether dynamic allocation for thread contexts is enabled. By default this 37 // matches the FreeRTOS configuration on whether dynamic allocations are 38 // enabled. Note that static contexts _must_ be provided if dynamic allocations 39 // are disabled. 40 #ifndef PW_THREAD_FREERTOS_CONFIG_DYNAMIC_ALLOCATION_ENABLED 41 #if configSUPPORT_DYNAMIC_ALLOCATION == 1 42 #define PW_THREAD_FREERTOS_CONFIG_DYNAMIC_ALLOCATION_ENABLED 1 43 #else 44 #define PW_THREAD_FREERTOS_CONFIG_DYNAMIC_ALLOCATION_ENABLED 0 45 #endif // configSUPPORT_DYNAMIC_ALLOCATION 46 #endif // PW_THREAD_FREERTOS_CONFIG_DYNAMIC_ALLOCATION_ENABLED 47 48 // The default stack size in words. By default this uses the minimal FreeRTOS 49 // stack size. 50 #ifndef PW_THREAD_FREERTOS_CONFIG_DEFAULT_STACK_SIZE_WORDS 51 #define PW_THREAD_FREERTOS_CONFIG_DEFAULT_STACK_SIZE_WORDS \ 52 configMINIMAL_STACK_SIZE 53 #endif // PW_THREAD_FREERTOS_CONFIG_DEFAULT_STACK_SIZE_WORDS 54 static_assert(PW_THREAD_FREERTOS_CONFIG_DEFAULT_STACK_SIZE_WORDS >= 55 configMINIMAL_STACK_SIZE); 56 57 // The default thread priority. By default this uses the minimal FreeRTOS 58 // priority level above the idle priority. 59 #ifndef PW_THREAD_FREERTOS_CONFIG_DEFAULT_PRIORITY 60 #define PW_THREAD_FREERTOS_CONFIG_DEFAULT_PRIORITY (tskIDLE_PRIORITY + 1) 61 #endif // PW_THREAD_FREERTOS_CONFIG_DEFAULT_PRIORITY 62 static_assert(PW_THREAD_FREERTOS_CONFIG_DEFAULT_PRIORITY >= 63 tskIDLE_PRIORITY + 1); 64 65 // The maximum thread priority defined by the FreeRTOS configuration. 66 #ifndef PW_THREAD_FREERTOS_CONFIG_MAXIMUM_PRIORITY 67 #define PW_THREAD_FREERTOS_CONFIG_MAXIMUM_PRIORITY (configMAX_PRIORITIES - 1) 68 #endif // PW_THREAD_FREERTOS_CONFIG_MAXIMUM_PRIORITY 69 static_assert(PW_THREAD_FREERTOS_CONFIG_MAXIMUM_PRIORITY <= 70 configMAX_PRIORITIES - 1); 71 72 // The log level to use for this module. Logs below this level are omitted. 73 #ifndef PW_THREAD_FREERTOS_CONFIG_LOG_LEVEL 74 #define PW_THREAD_FREERTOS_CONFIG_LOG_LEVEL PW_LOG_LEVEL_DEBUG 75 #endif // PW_THREAD_FREERTOS_CONFIG_LOG_LEVEL 76 77 namespace pw::thread::freertos::config { 78 79 inline constexpr size_t kMinimumStackSizeWords = configMINIMAL_STACK_SIZE; 80 inline constexpr size_t kDefaultStackSizeWords = 81 PW_THREAD_FREERTOS_CONFIG_DEFAULT_STACK_SIZE_WORDS; 82 inline constexpr UBaseType_t kDefaultPriority = 83 PW_THREAD_FREERTOS_CONFIG_DEFAULT_PRIORITY; 84 inline constexpr UBaseType_t kMaximumPriority = 85 PW_THREAD_FREERTOS_CONFIG_MAXIMUM_PRIORITY; 86 87 } // namespace pw::thread::freertos::config 88