blob: 5cfd84fb502bf34bd35ea03e3b2af9025d219cfe [file] [log] [blame]
Ewout van Bekkumfe5b4a72021-02-01 17:03:58 -08001.. _module-pw_thread_threadx:
2
Ewout van Bekkumf4da4892021-03-05 15:05:37 -08003=================
Ewout van Bekkumfe5b4a72021-02-01 17:03:58 -08004pw_thread_threadx
Ewout van Bekkumf4da4892021-03-05 15:05:37 -08005=================
6This is a set of backends for pw_thread based on ThreadX.
Ewout van Bekkumfe5b4a72021-02-01 17:03:58 -08007
Ewout van Bekkumf4da4892021-03-05 15:05:37 -08008.. Warning::
9 This module is still under construction, the API is not yet stable.
10
11.. list-table::
12
13 * - :ref:`module-pw_thread` Facade
14 - Backend Target
15 - Description
16 * - ``pw_thread:id``
17 - ``pw_thread_threadx:id``
18 - Thread identification.
19 * - ``pw_thread:yield``
20 - ``pw_thread_threadx:yield``
21 - Thread scheduler yielding.
22 * - ``pw_thread:sleep``
23 - ``pw_thread_threadx:sleep``
24 - Thread scheduler sleeping.
25 * - ``pw_thread:thread``
26 - ``pw_thread_threadx:thread``
27 - Thread creation.
Armando Montanezfec572b2021-06-28 12:13:57 -070028
29---------
30utilities
31---------
32In cases where an operation must be performed for every thread,
33``ForEachThread()`` can be used to iterate over all the created thread TCBs.
34Note that it's only safe to use this while the scheduler is disabled.
35
36--------------------
37Snapshot integration
38--------------------
39This ``pw_thread`` backend provides helper functions that capture ThreadX thread
40state to a ``pw::thread::Thread`` proto.
41
42SnapshotThread()/SnapshotThreads()
43==================================
44``SnapshotThread()`` captures the thread name, state, and stack information for
45the provided RTX TCB to a ``pw::thread::Thread`` protobuf encoder. To ensure
46the most up-to-date information is captured, the stack pointer for the currently
47running thread must be provided for cases where the running thread is being
48captured. For ARM Cortex-M CPUs, you can do something like this:
49
50.. Code:: cpp
51
52 // Capture PSP.
53 void* stack_ptr = 0;
54 asm volatile("mrs %0, psp\n" : "=r"(stack_ptr));
55 pw::thread::ProcessThreadStackCallback cb =
56 [](pw::thread::Thread::StreamEncoder& encoder,
57 pw::ConstByteSpan stack) -> pw::Status {
58 return encoder.WriteRawStack(stack);
59 };
60 pw::thread::threadx::SnapshotThread(my_thread, stack_ptr,
61 snapshot_encoder, cb);
62
63``SnapshotThreads()`` wraps the singular thread capture to instead captures
64all created threads to a ``pw::thread::SnapshotThreadInfo`` message. This proto
65message overlays a snapshot, so it is safe to static cast a
66``pw::snapshot::Snapshot::StreamEncoder`` to a
67``pw::thread::SnapshotThreadInfo::StreamEncoder`` when calling this function.