zpp
Zephyr C++20 Framework
main.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2019 Erwin Rol <erwin@erwinrol.com>
3
*
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
#include <zephyr/ztest.h>
8
9
#include <zephyr/kernel.h>
10
11
#include <
zpp/timer.hpp
>
12
#include <
zpp/thread.hpp
>
13
#include <
zpp/fmt.hpp
>
14
15
ZTEST_SUITE
(zpp_timer_tests, NULL, NULL, NULL, NULL, NULL);
16
17
namespace
{
18
19
auto
g_t =
zpp::make_timer
();
20
21
void
timer_callback(
zpp::timer_base
* t) noexcept
22
{
23
zpp::print
(
"Hello from timer tid={}\n"
,
zpp::this_thread::get_id
());
24
}
25
26
}
// namespace
27
28
ZTEST
(zpp_timer_tests, test_timer_creation_function)
29
{
30
using namespace
zpp
;
31
using namespace
std::chrono;
32
33
auto
t =
make_timer
(timer_callback);
34
t.start(100ms, 1s);
35
36
this_thread::sleep_for
(5s);
37
}
38
39
ZTEST
(zpp_timer_tests, test_timer_creation_lambda)
40
{
41
using namespace
zpp
;
42
using namespace
std::chrono;
43
44
auto
t =
make_timer
(
45
[] (
auto
t) {
46
print
(
"Hello from timer tid={}\n"
,
47
this_thread::get_id
());
48
} );
49
50
t.start(100ms, 1s);
51
52
this_thread::sleep_for
(5s);
53
}
zpp::timer_base
base class for the timer class
Definition:
timer.hpp:24
fmt.hpp
zpp::this_thread::get_id
auto get_id() noexcept
Get the thread ID of the current thread.
Definition:
thread.hpp:42
zpp::this_thread::sleep_for
auto sleep_for(const std::chrono::duration< T_Rep, T_Period > &sleep_duration)
Suspend the current thread for a specified time duration.
Definition:
thread.hpp:77
zpp
Definition:
atomic_bitset.hpp:15
zpp::print
void print(const char *fmt, T_Args &&... args) noexcept
simple typesafe print function
Definition:
fmt.hpp:157
zpp::make_timer
auto make_timer() noexcept
create sync_timer object
Definition:
timer.hpp:233
ZTEST
ZTEST(zpp_atomic_tests, test_atomic_bitset)
Definition:
main.cpp:23
ZTEST_SUITE
ZTEST_SUITE(zpp_atomic_tests, NULL, NULL, NULL, NULL, NULL)
thread.hpp
timer.hpp
tests
timer
src
main.cpp
Generated by
1.9.1