1 /*
2  * Copyright (c) 2006-2021, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2021-04-27     flybreak     the first version.
9  */
10 
11 #pragma once
12 
13 #include <cstdlib>
14 #include <system_error>
15 #include <chrono>
16 #include <ratio>
17 
18 #include <rtthread.h>
19 
throw_system_error(int err,const char * what_msg)20 inline void throw_system_error(int err, const char *what_msg)
21 {
22 #ifdef RT_USING_CPP_EXCEPTIONS
23     throw std::system_error(std::error_code(err, std::system_category()), what_msg);
24 #else
25     (void)err;
26     (void)what_msg;
27     ::abort();
28 #endif
29 }
30 
31 class tick_clock
32 {
33 public:
34     typedef clock_t rep;
35     typedef std::ratio<1, RT_TICK_PER_SECOND> period;
36 
37     typedef std::chrono::duration<tick_clock::rep, tick_clock::period> duration;
38     typedef std::chrono::time_point<tick_clock> time_point;
39 
40     constexpr static bool is_ready = true;
41 
42     static time_point now();
43 };
44 
45 class real_time_clock
46 {
47 public:
48     typedef std::chrono::nanoseconds duration;
49     typedef duration::rep rep;
50     typedef duration::period period;
51     typedef std::chrono::time_point<real_time_clock, duration> time_point;
52 
53     static constexpr bool is_steady = true;
54 
55     static time_point
56     now() noexcept;
57 };
58