pw_thread_zephyr#

Pigweed AI summary: The "pw_thread_zephyr" module provides backends for pw_thread based on the Zephyr RTOS. However, it is still under construction, with an unstable API and incomplete documentation. One backend offered is for creating threads using "k_thread_create()", which only supports threads with static contexts. The backend also supports joining and detaching threads. To enable this backend, "CONFIG_PIGWEED_THREAD=y" should be added to the Zephyr project's configuration. Another backend is

This is a set of backends for pw_thread based on the Zephyr RTOS.

Warning

This module is still under construction, the API is not yet stable and documentation is incomplete.

Thread Creation Backend#

Pigweed AI summary: This article discusses the Thread Creation Backend, which is a backend for pw::thread::Thread that uses k_thread_create(). This backend only supports threads with static contexts and all created threads support joining and detaching. To enable this backend, CONFIG_PIGWEED_THREAD=y must be added to the Zephyr project's configuration. The article also includes a code snippet demonstrating how to use this backend.

A backend for pw::thread::Thread is offered using k_thread_create(). This backend only supports threads with static contexts (which are passed via Options). All created threads support joining and detaching. To enable this backend, add CONFIG_PIGWEED_THREAD=y to the Zephyr project`s configuration.

#include "pw_thread/detached_thread.h"
#include "pw_thread_zephyr/config.h"
#include "pw_thread_zephyr/context.h"
#include "pw_thread_zephyr/options.h"

constexpr int kFooPriority =
    pw::thread::zephyr::config::kDefaultPriority;
constexpr size_t kFooStackSizeBytes = 512;

pw::thread::zephyr::StaticContextWithStack<kFooStackSizeBytes>
    example_thread_context;
void StartExampleThread() {
  pw::thread::DetachedThread(
      pw::thread::zephyr::Options(example_thread_context)
          .set_priority(kFooPriority),
      example_thread_function, example_arg);
}

Thread Sleep Backend#

Pigweed AI summary: This paragraph describes a backend for the pw::thread::sleep_for() and pw::thread::sleep_until() functions. To enable this backend, the CONFIG_PIGWEED_THREAD_SLEEP=y must be added to the Zephyr project's configuration.

A backend for pw::thread::sleep_for() and pw::thread::sleep_until(). To enable this backend, add CONFIG_PIGWEED_THREAD_SLEEP=y to the Zephyr project`s configuration.