zpp
Zephyr C++20 Framework
main.cpp File Reference
#include <zephyr/ztest.h>
#include <zephyr/kernel.h>
#include <zpp/fifo.hpp>
#include <zpp/thread.hpp>
#include <zpp/sem.hpp>
#include <array>
Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

 ZTEST_SUITE (test_zpp_fifo, NULL, NULL, NULL, NULL, NULL)
 
 ZTEST (test_zpp_fifo, test_fifo)
 

Function Documentation

◆ ZTEST()

ZTEST ( test_zpp_fifo  ,
test_fifo   
)

Definition at line 36 of file main.cpp.

37 {
38  using namespace zpp;
39  using namespace std::chrono;
40 
41  const thread_attr attr(
46  );
47 
48  //
49  // Put items into fifo
50  //
51  for (auto& item: g_item_array) {
52  item.data = 0x1234;
53  item.more_data = 0x5678;
54  g_fifo.push_back(&item);
55  }
56 
57  auto t = thread(
58  tcb, tstack(), attr,
59  []() noexcept {
60  //
61  // Get items from fifo
62  //
63  for (auto& item: g_item_array) {
64  auto res = g_fifo.try_pop_front();
65  zassert_equal(res->data, 0x1234, nullptr);
66  zassert_equal(res->more_data, 0x5678, nullptr);
67  zassert_equal(res, &item, nullptr);
68  }
69 
70  //
71  // Put items into fifo
72  //
73  for (auto& item: g_item_array) {
74  g_fifo.push_back(&item);
75  }
76  });
77 
78  //
79  // Let the child thread run
80  //
81  auto res = t.join();
82  zassert_equal(!!res, true, "");
83 
84  //
85  // Get items from fifo
86  //
87  for (auto& item: g_item_array) {
88  auto res = g_fifo.try_pop_front();
89  zassert_equal(res->data, 0x1234, nullptr);
90  zassert_equal(res->more_data, 0x5678, nullptr);
91  zassert_equal(res, &item, nullptr);
92  }
93 }
Thread creation attributes.
Definition: thread_attr.hpp:35
static constexpr thread_prio preempt(int prio) noexcept
Create a preemptive priority value.
The class thread repecents a single Zephyr thread.
Definition: thread.hpp:147
auto join() noexcept
join the thread this object mamages.
Definition: thread.hpp:483

References zpp::thread::join(), zpp::no, zpp::thread_prio::preempt(), and zpp::yes.

◆ ZTEST_SUITE()

ZTEST_SUITE ( test_zpp_fifo  ,
NULL  ,
NULL  ,
NULL  ,
NULL  ,
NULL   
)