1.. _module-pw_thread_zephyr: 2 3================ 4pw_thread_zephyr 5================ 6This is a set of backends for pw_thread based on the Zephyr RTOS. 7 8.. Warning:: 9 This module is still under construction, the API is not yet stable and 10 documentation is incomplete. 11 12----------------------- 13Thread Creation Backend 14----------------------- 15A backend for ``pw::Thread`` is offered using ``k_thread_create()``. 16This backend only supports threads with static contexts (which are passed via 17Options). 18All created threads support joining and detaching. 19To enable this backend, add ``CONFIG_PIGWEED_THREAD=y`` to the Zephyr 20project`s configuration. 21 22.. code-block:: cpp 23 24 #include "pw_thread/detached_thread.h" 25 #include "pw_thread_zephyr/config.h" 26 #include "pw_thread_zephyr/context.h" 27 #include "pw_thread_zephyr/options.h" 28 29 constexpr int kFooPriority = 30 pw::thread::zephyr::config::kDefaultPriority; 31 constexpr size_t kFooStackSizeBytes = 512; 32 33 pw::thread::zephyr::StaticContextWithStack<kFooStackSizeBytes> 34 example_thread_context; 35 void StartExampleThread() { 36 pw::thread::DetachedThread( 37 pw::thread::zephyr::Options(example_thread_context) 38 .set_priority(kFooPriority), 39 example_thread_function, example_arg); 40 } 41 42-------------------- 43Thread Sleep Backend 44-------------------- 45A backend for ``pw::thread::sleep_for()`` and ``pw::thread::sleep_until()``. 46To enable this backend, add ``CONFIG_PIGWEED_THREAD_SLEEP=y`` 47to the Zephyr project`s configuration. 48