Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. OS abstraction layers
  5. pw_thread
  6. OS abstraction layers
  7. Backends
  8. Eclipse ThreadX
  9. pw_thread_threadx

Overview

Classes

class  pw::thread::threadx::Context
 
class  pw::thread::threadx::ContextWithStack< kStackSizeWords >
 
class  pw::thread::threadx::Options
 

Macros

#define PW_THREAD_THREADX_CONFIG_JOINING_ENABLED   0
 
#define PW_THREAD_THREADX_CONFIG_DEFAULT_STACK_SIZE_WORDS    (TX_MINIMUM_STACK / sizeof(ULONG))
 
#define PW_THREAD_THREADX_CONFIG_MAX_THREAD_NAME_LEN   15
 
#define PW_THREAD_THREADX_CONFIG_DEFAULT_TIME_SLICE_INTERVAL   TX_NO_TIME_SLICE
 
#define PW_THREAD_THREADX_CONFIG_MIN_PRIORITY   (TX_MAX_PRIORITIES - 1)
 
#define PW_THREAD_THREADX_CONFIG_DEFAULT_PRIORITY    PW_THREAD_THREADX_CONFIG_MIN_PRIORITY
 
#define PW_THREAD_THREADX_CONFIG_LOG_LEVEL   PW_LOG_LEVEL_DEBUG
 The log level to use for this module. Logs below this level are omitted.
 

Typedefs

using pw::thread::threadx::ThreadCallback = pw::Function< bool(const TX_THREAD &)>
 

Functions

Status pw::thread::threadx::SnapshotThreads (void *running_thread_stack_pointer, proto::SnapshotThreadInfo::StreamEncoder &encoder, ProcessThreadStackCallback &thread_stack_callback)
 
Status pw::thread::threadx::SnapshotThread (const TX_THREAD &thread, void *running_thread_stack_pointer, proto::Thread::StreamEncoder &encoder, ProcessThreadStackCallback &thread_stack_callback)
 
Status pw::thread::threadx::ForEachThread (const ThreadCallback &cb)
 

Variables

constexpr size_t pw::thread::threadx::config::kMaximumNameLength
 Maximum length of a thread's name, not including null termination.
 
constexpr size_t pw::thread::threadx::config::kMinimumStackSizeWords
 Minimum ThreadX stack size in words (ULONG elements).
 
constexpr size_t pw::thread::threadx::config::kDefaultStackSizeWords
 Default stack size in words (ULONG elements).
 
constexpr UINT pw::thread::threadx::config::kMinimumPriority = (TX_MAX_PRIORITIES - 1)
 Minimum ThreadX priority level (numerically highest value).
 
constexpr UINT pw::thread::threadx::config::kDefaultPriority
 Default ThreadX priority level.
 
constexpr ULONG pw::thread::threadx::config::kDefaultTimeSliceInterval
 

Macro Definition Documentation

◆ PW_THREAD_THREADX_CONFIG_DEFAULT_PRIORITY

#define PW_THREAD_THREADX_CONFIG_DEFAULT_PRIORITY    PW_THREAD_THREADX_CONFIG_MIN_PRIORITY

The default priority level. By default this uses the minimal ThreadX priority level, given that 0 is the highest priority.

◆ PW_THREAD_THREADX_CONFIG_DEFAULT_STACK_SIZE_WORDS

#define PW_THREAD_THREADX_CONFIG_DEFAULT_STACK_SIZE_WORDS    (TX_MINIMUM_STACK / sizeof(ULONG))

The default stack size in words (ULONG elements). By default this uses the minimal ThreadX stack size.

◆ PW_THREAD_THREADX_CONFIG_DEFAULT_TIME_SLICE_INTERVAL

#define PW_THREAD_THREADX_CONFIG_DEFAULT_TIME_SLICE_INTERVAL   TX_NO_TIME_SLICE

The round-robin time slice tick interval for threads at the same priority. By default this is disabled as not all ports support this, using a value of 0 ticks.

◆ PW_THREAD_THREADX_CONFIG_JOINING_ENABLED

#define PW_THREAD_THREADX_CONFIG_JOINING_ENABLED   0

Whether thread joining is enabled. By default this is disabled.

We suggest only enabling this when thread joining is required to minimize the RAM and ROM cost of threads.

Enabling this grows the RAM footprint of every pw::Thread as it adds a TX_EVENT_FLAGS_GROUP to every thread's pw::thread::threadx::Context. In addition, there is a minute ROM cost to construct and destroy this added object.

PW_THREAD_JOINING_ENABLED gets set to this value.

◆ PW_THREAD_THREADX_CONFIG_MAX_THREAD_NAME_LEN

#define PW_THREAD_THREADX_CONFIG_MAX_THREAD_NAME_LEN   15

The maximum length of a thread's name, not including null termination. By default this is arbitrarily set to 15. This results in an array of characters which is this length + 1 bytes in every pw::Thread's context.

◆ PW_THREAD_THREADX_CONFIG_MIN_PRIORITY

#define PW_THREAD_THREADX_CONFIG_MIN_PRIORITY   (TX_MAX_PRIORITIES - 1)

The minimum priority level (numerically highest value, since 0 is the highest priority in ThreadX). Normally based on the number of priority levels.

Typedef Documentation

◆ ThreadCallback

using pw::thread::threadx::ThreadCallback = typedef pw::Function<bool(const TX_THREAD&)>

A callback that is executed for each thread when using ForEachThread(). The callback should return true if thread iteration should continue. When this callback returns false, ForEachThread() ceases iteration of threads and returns an ABORTED error code.

Function Documentation

◆ ForEachThread()

Status pw::thread::threadx::ForEachThread ( const ThreadCallback &  cb)

Iterates through all threads that haven't been deleted, calling the provided callback on each thread.

Precondition
This is only safe to use when the scheduler is disabled.
Parameters
[in]cbCallback invoked for each non-deleted thread.
Returns
  • OK: Successfully iterated over all threads.
  • ABORTED: The callback requested early termination of thread iteration.

◆ SnapshotThread()

Status pw::thread::threadx::SnapshotThread ( const TX_THREAD &  thread,
void *  running_thread_stack_pointer,
proto::Thread::StreamEncoder &  encoder,
ProcessThreadStackCallback &  thread_stack_callback 
)

Captures only the provided thread handle as a pw.thread.Thread proto message. After thread info capture, thread_stack_callback is called to capture either the raw_stack or raw_backtrace.

An updated running_thread_stack_pointer must be provided in order for the running thread's context to reflect the current state. If the thread being captured is not the running thread, the value is ignored. Note that the stack pointer in the thread handle is almost always stale on the running thread.

Captures the following pw.thread.Thread proto fields:

  • name
  • id
  • state
  • stack_start_pointer
  • stack_end_pointer
  • stack_pointer
Precondition
Interrupts and the ThreadX scheduler must be disabled.
Warning
SMP ports are not yet supported.
Parameters
[in]threadThreadX TCB to capture.
[in]running_thread_stack_pointerUpdated stack pointer of the currently running thread (ignored if thread is not the running thread).
[in,out]encoderProtobuf encoder to write the captured thread into.
[in,out]thread_stack_callbackCallback invoked to capture either the raw_stack or raw_backtrace.
Returns
  • OK: The thread was captured successfully.
  • OUT_OF_RANGE: The thread's stack pointer underflowed past the stack start.
  • Any error status returned by thread_stack_callback or encoder.

◆ SnapshotThreads()

Status pw::thread::threadx::SnapshotThreads ( void *  running_thread_stack_pointer,
proto::SnapshotThreadInfo::StreamEncoder &  encoder,
ProcessThreadStackCallback &  thread_stack_callback 
)

Captures all ThreadX threads in a system as part of a snapshot.

An updated running_thread_stack_pointer must be provided in order for the running thread's context to reflect the running state. For ARM, you might do something like this:

// Capture PSP.
void* stack_ptr = 0;
asm volatile("mrs %0, psp\n" : "=r"(stack_ptr));
pw::thread::ProcessThreadStackCallback cb =
[](pw::thread::proto::Thread::StreamEncoder& encoder,
return encoder.WriteRawStack(stack);
};
pw::thread::threadx::SnapshotThreads(stack_ptr, snapshot_encoder, cb);
Definition: status.h:200
Status SnapshotThreads(void *running_thread_stack_pointer, proto::SnapshotThreadInfo::StreamEncoder &encoder, ProcessThreadStackCallback &thread_stack_callback)
Precondition
Interrupts and the ThreadX scheduler must be disabled.
Warning
SMP ports are not yet supported.
Parameters
[in]running_thread_stack_pointerUpdated stack pointer of the currently running thread.
[in,out]encoderProtobuf encoder to write captured threads into.
[in,out]thread_stack_callbackCallback invoked for each thread to capture either its raw_stack or raw_backtrace.
Returns
  • OK: All threads were captured successfully.
  • OUT_OF_RANGE: A thread's stack pointer underflowed past the stack start.
  • Any error status returned by thread_stack_callback or encoder.

Variable Documentation

◆ kDefaultPriority

constexpr UINT pw::thread::threadx::config::kDefaultPriority
inlineconstexpr
Initial value:
=
(TX_MAX_PRIORITIES - 1)

Default ThreadX priority level.

◆ kDefaultStackSizeWords

constexpr size_t pw::thread::threadx::config::kDefaultStackSizeWords
inlineconstexpr
Initial value:
=
(TX_MINIMUM_STACK / sizeof(ULONG))

Default stack size in words (ULONG elements).

◆ kDefaultTimeSliceInterval

constexpr ULONG pw::thread::threadx::config::kDefaultTimeSliceInterval
inlineconstexpr
Initial value:
=
TX_NO_TIME_SLICE

Default round-robin time slice tick interval for threads at the same priority.

◆ kMaximumNameLength

constexpr size_t pw::thread::threadx::config::kMaximumNameLength
inlineconstexpr
Initial value:
=
15

Maximum length of a thread's name, not including null termination.

◆ kMinimumStackSizeWords

constexpr size_t pw::thread::threadx::config::kMinimumStackSizeWords
inlineconstexpr
Initial value:
=
TX_MINIMUM_STACK / sizeof(ULONG)

Minimum ThreadX stack size in words (ULONG elements).