ZPP


Zephyr C++ Framework
/img/zpp_logo.png

Warning: ZPP is very much experimental/alpha quality, and non backwards compatible changes can (and will) be made at any time.

ZPP is a C++ wrapper for Zephyr so the OS API’s can be used more easily from C++.

It is not the intention of ZPP to implement a std:: library for Zephyr. ZPP tries to wrap the Zephyr C-API in C++20 without causing to much runtime and/or memory overhead.

ZPP tries to use RAII for things like locking and unlocking mutex’s comparable to the standard C++ library. Different from the standard C++ library ZPP does not use exceptions and it tries to not use dynamic memory allocation.


zpp::mutex lock;

static void foo(void)
{
  zpp::lock_guard<zpp::mutex> lg(lock);

  do_something_that_needs_a_lock();

  // lock will be automatically unlock
}

ZPP Also tries to use modern C++ features like lambda functions, instead of raw function pointers like the C API. The example below shows the use of a lambda functions as the starting point for a new thread, and passing a semaphore as a reference.


ZPP_THREAD_STACK_DEFINE(tstack, 1024);

zpp::thread_data tcb;

static void foo(void)
{
  const zpp::thread_attr attr(
          zpp::thread_prio::preempt(0),
          zpp::thread_inherit_perms::no,
          zpp::thread_essential::no,
          zpp::thread_suspend::no );

  auto t = zpp::thread(tcb, tstack(), attr,
    []() noexcept {
      zpp::print("Hello from thread tid={}\n", zpp::this_thread::get_id());
    });

  t.join(); // wait until the thread is done
}

The source code has several tests and examples that can be used to better understand the ZPP API.

API Documentation

The code is (being) documented with doxygen and the latest automatically generated version can be found on github https://lowlander.github.io/zpp/

Getting the Source Code

When you are using west to build and checkout zephyr, you can add zpp to your zephyr project as a module by adding the following to your west.yaml file;

manifest:
  projects:
    - name: zpp
      remote: https://github.com/lowlander
      revision: master
      path: modules/zpp

The code is hosted as zpp on GitHub. You can use the following git command to clone and compile the sources

git clone git://github.com/lowlander/zpp.git


See also