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