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