µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2016-2025 Liviu Ionescu. All rights reserved.
4 * Copyright (c) 2013-2014 ARM Ltd.
5 *
6 * Permission to use, copy, modify, and/or distribute this software
7 * for any purpose is hereby granted, under the terms of the MIT license.
8 *
9 * If a copy of the license was not distributed with this file, it can
10 * be obtained from https://opensource.org/licenses/mit.
11 */
12
13/*
14 * The code is inspired by ARM CMSIS Driver_Common.h file, v2.00,
15 * and tries to remain functionally close to the CMSIS specifications.
16 */
17
18#ifndef CMSIS_PLUS_DRIVER_COMMON_H_
19#define CMSIS_PLUS_DRIVER_COMMON_H_
20
21// ----------------------------------------------------------------------------
22
23#ifdef __cplusplus
24
25// ----------------------------------------------------------------------------
26
27#include <cstdint>
28
29// ----------------------------------------------------------------------------
30
31#pragma GCC diagnostic push
32#if defined(__clang__)
33#pragma clang diagnostic ignored "-Wc++98-compat"
34#endif
35
36// ----------------------------------------------------------------------------
37
38namespace os
39{
40 namespace driver
41 {
42 // ------------------------------------------------------------------------
43
44 using version_t = uint16_t;
45 using event_t = uint32_t;
46 using return_t = int32_t;
47 using power_t = uint32_t;
48
49 // ----- Return & error codes -----
50
52 constexpr return_t RETURN_OK = 0;
53
55 constexpr return_t ERROR = -1;
57 constexpr return_t ERROR_BUSY = -2;
59 constexpr return_t ERROR_TIMEOUT = -3;
63 constexpr return_t ERROR_PARAMETER = -5;
65 constexpr return_t ERROR_SPECIFIC = -6;
66
67 typedef void (*signal_event_t) (const void* object, event_t event);
68
69 // ------------------------------------------------------------------------
70
71 enum class Power : power_t
72 {
73 //
74
75 // Completely power off the device.
76 off,
77 // Low power mode.
78 low,
79 // Fully power on the
80 full
81 };
82
83 // ========================================================================
84
85 class Version
86 {
87 public:
88 // ----------------------------------------------------------------------
89
90 constexpr Version () noexcept;
91
92 constexpr Version (version_t api, version_t drv) noexcept;
93
94 Version (const Version&) = default;
95
96 Version&
98 = default;
99
100 ~Version () noexcept = default;
101
102 // ----------------------------------------------------------------------
103
105 get_api (void) const noexcept;
106
108 get_drv (void) const noexcept;
109
110 // ----------------------------------------------------------------------
111
112 private:
115 };
116
117 inline constexpr Version::Version () noexcept
118 : api_ (0), //
119 drv_ (0)
120 {
121 }
122
123 inline constexpr Version::Version (version_t api, version_t drv) noexcept
124 : api_ (api), //
125 drv_ (drv)
126 {
127 }
128
129 inline version_t
130 Version::get_api (void) const noexcept
131 {
132 return api_;
133 }
134
135 inline version_t
136 Version::get_drv (void) const noexcept
137 {
138 return drv_;
139 }
140
141 // ========================================================================
142
143 class Base
144 {
145
146 public:
147 // ----------------------------------------------------------------------
148
149 Base () noexcept = default;
150
151 virtual ~Base () noexcept;
152
153 // ----------------------------------------------------------------------
154
159 const Version&
160 get_version (void) noexcept;
161
168 power (Power state) noexcept;
169
170 // ----------------------------------------------------------------------
171
172 protected:
173 virtual const Version&
174 do_get_version (void) noexcept
175 = 0;
176
177 virtual return_t
178 do_power (Power state) noexcept
179 = 0;
180 };
181
182 // ------------------------------------------------------------------------
183
184 inline const Version&
185 Base::get_version (void) noexcept
186 {
187 return do_get_version ();
188 }
189
190 inline return_t
191 Base::power (Power state) noexcept
192 {
193 return do_power (state);
194 }
195
196 } /* namespace driver */
197} /* namespace os */
198
199#pragma GCC diagnostic pop
200
201// ----------------------------------------------------------------------------
202
203#endif /* __cplusplus */
204
205// ----------------------------------------------------------------------------
206
207#endif /* CMSIS_PLUS_DRIVER_COMMON_H_ */
Base() noexcept=default
version_t get_api(void) const noexcept
Definition common.h:130
version_t drv_
Definition common.h:114
Version & operator=(const Version &)=default
version_t get_drv(void) const noexcept
Definition common.h:136
~Version() noexcept=default
version_t api_
Definition common.h:113
Version(const Version &)=default
constexpr Version() noexcept
Definition common.h:117
uint16_t version_t
Definition common.h:44
uint32_t power_t
Definition common.h:47
constexpr return_t ERROR_SPECIFIC
Definition common.h:65
constexpr return_t ERROR_UNSUPPORTED
Definition common.h:61
constexpr return_t RETURN_OK
Definition common.h:52
constexpr return_t ERROR
Definition common.h:55
constexpr return_t ERROR_PARAMETER
Definition common.h:63
constexpr return_t ERROR_TIMEOUT
Definition common.h:59
constexpr return_t ERROR_BUSY
Definition common.h:57
int32_t return_t
Definition common.h:46
uint32_t event_t
Definition common.h:45
void(* signal_event_t)(const void *object, event_t event)
Definition common.h:67
System namespace.