1 // Copyright 2023 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 "pw_thread/thread.h" 16 #include "pw_thread_zephyr/config.h" 17 #include "pw_thread_zephyr/options.h" 18 19 namespace pw::system { 20 21 using namespace pw::thread::zephyr::config; 22 23 // Low to high priorities. 24 enum class ThreadPriority : int { 25 kWorkQueue = kDefaultPriority, 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 constexpr size_t kLogThreadStackWords = 34 CONFIG_PIGWEED_SYSTEM_TARGET_HOOKS_LOG_STACK_SIZE; 35 static thread::zephyr::StaticContextWithStack<kLogThreadStackWords> 36 log_thread_context; LogThreadOptions()37const thread::Options& LogThreadOptions() { 38 static constexpr auto options = 39 pw::thread::zephyr::Options(log_thread_context) 40 .set_priority(static_cast<int>(ThreadPriority::kLog)); 41 return options; 42 } 43 44 static constexpr size_t kRpcThreadStackWords = 45 CONFIG_PIGWEED_SYSTEM_TARGET_HOOKS_RPC_STACK_SIZE; 46 static thread::zephyr::StaticContextWithStack<kRpcThreadStackWords> 47 rpc_thread_context; RpcThreadOptions()48const thread::Options& RpcThreadOptions() { 49 static constexpr auto options = 50 pw::thread::zephyr::Options(rpc_thread_context) 51 .set_priority(static_cast<int>(ThreadPriority::kRpc)); 52 return options; 53 } 54 55 static constexpr size_t kWorkQueueThreadStackWords = 56 CONFIG_PIGWEED_SYSTEM_TARGET_HOOKS_WORK_QUEUE_STACK_SIZE; 57 static thread::zephyr::StaticContextWithStack<kWorkQueueThreadStackWords> 58 work_queue_thread_context; 59 WorkQueueThreadOptions()60const thread::Options& WorkQueueThreadOptions() { 61 static constexpr auto options = 62 pw::thread::zephyr::Options(work_queue_thread_context) 63 .set_priority(static_cast<int>(ThreadPriority::kWorkQueue)); 64 return options; 65 } 66 67 } // namespace pw::system