1 // Copyright 2021 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 15 #include "FreeRTOS.h" 16 #include "pw_system/init.h" 17 #include "pw_thread/detached_thread.h" 18 #include "pw_thread/thread.h" 19 #include "pw_thread_freertos/context.h" 20 #include "pw_thread_freertos/options.h" 21 22 namespace pw::system { 23 24 // Low to high priorities. 25 enum class ThreadPriority : UBaseType_t { 26 kWorkQueue = tskIDLE_PRIORITY + 1, 27 // TODO(amontanez): These should ideally be at different priority levels, but 28 // there's synchronization issues when they are. 29 kLog = kWorkQueue, 30 kRpc = kWorkQueue, 31 kNumPriorities, 32 }; 33 34 static_assert(static_cast<UBaseType_t>(ThreadPriority::kNumPriorities) <= 35 configMAX_PRIORITIES); 36 37 static constexpr size_t kLogThreadStackWorkds = 1024; 38 static thread::freertos::StaticContextWithStack<kLogThreadStackWorkds> 39 log_thread_context; LogThreadOptions()40const thread::Options& LogThreadOptions() { 41 static constexpr auto options = 42 pw::thread::freertos::Options() 43 .set_name("LogThread") 44 .set_static_context(log_thread_context) 45 .set_priority(static_cast<UBaseType_t>(ThreadPriority::kLog)); 46 return options; 47 } 48 49 static constexpr size_t kRpcThreadStackWorkds = 512; 50 static thread::freertos::StaticContextWithStack<kRpcThreadStackWorkds> 51 rpc_thread_context; RpcThreadOptions()52const thread::Options& RpcThreadOptions() { 53 static constexpr auto options = 54 pw::thread::freertos::Options() 55 .set_name("RpcThread") 56 .set_static_context(rpc_thread_context) 57 .set_priority(static_cast<UBaseType_t>(ThreadPriority::kRpc)); 58 return options; 59 } 60 61 static constexpr size_t kWorkQueueThreadStackWorkds = 512; 62 static thread::freertos::StaticContextWithStack<kWorkQueueThreadStackWorkds> 63 work_queue_thread_context; WorkQueueThreadOptions()64const thread::Options& WorkQueueThreadOptions() { 65 static constexpr auto options = 66 pw::thread::freertos::Options() 67 .set_name("WorkQueueThread") 68 .set_static_context(work_queue_thread_context) 69 .set_priority(static_cast<UBaseType_t>(ThreadPriority::kWorkQueue)); 70 return options; 71 } 72 73 } // namespace pw::system 74