µ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++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2016 Liviu Ionescu.
5 * Copyright (c) 2013-2014 ARM Ltd.
6 *
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation
9 * files (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use,
11 * copy, modify, merge, publish, distribute, sublicense, and/or
12 * sell copies of the Software, and to permit persons to whom
13 * the Software is furnished to do so, subject to the following
14 * conditions:
15 *
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
27 */
28
29/*
30 * The code is inspired by ARM CMSIS Driver_Common.h file, v2.00,
31 * and tries to remain functionally close to the CMSIS specifications.
32 */
33
34#ifndef CMSIS_PLUS_DRIVER_COMMON_H_
35#define CMSIS_PLUS_DRIVER_COMMON_H_
36
37// ----------------------------------------------------------------------------
38
39#ifdef __cplusplus
40
41// ----------------------------------------------------------------------------
42
43#include <cstdint>
44
45// ----------------------------------------------------------------------------
46
47#pragma GCC diagnostic push
48
49#if defined(__clang__)
50#pragma clang diagnostic ignored "-Wc++98-compat"
51#endif
52
53// ----------------------------------------------------------------------------
54
55namespace os
56{
57 namespace driver
58 {
59 // ----------------------------------------------------------------------
60
61 using version_t = uint16_t;
62 using event_t = uint32_t;
63 using return_t = int32_t;
64 using power_t = uint32_t;
65
66 // ----- Return & error codes -----
67
69 constexpr return_t RETURN_OK = 0;
70
72 constexpr return_t ERROR = -1;
74 constexpr return_t ERROR_BUSY = -2;
76 constexpr return_t ERROR_TIMEOUT = -3;
80 constexpr return_t ERROR_PARAMETER = -5;
82 constexpr return_t ERROR_SPECIFIC = -6;
83
84 typedef void
85 (*signal_event_t) (const void* object, event_t event);
86
87 // ----------------------------------------------------------------------
88
89 enum class Power
90 : power_t
91 {
92 //
93
94 // Completely power off the device.
95 off,
96 // Low power mode.
97 low,
98 // Fully power on the
99 full
100 };
101
102 // ======================================================================
103
105 {
106 public:
107
108 // --------------------------------------------------------------------
109
110 constexpr
111 Version () noexcept;
112
113 constexpr
114 Version (version_t api, version_t drv) noexcept;
115
116 Version (const Version&) = default;
117
118 Version&
119 operator= (const Version&) = default;
120
121 ~Version () noexcept = default;
122
123 // --------------------------------------------------------------------
124
126 get_api (void) const noexcept;
127
129 get_drv (void) const noexcept;
130
131 // --------------------------------------------------------------------
132
133 private:
134
137 };
138
139 inline constexpr
140 Version::Version () noexcept :
141 api_ (0), //
142 drv_ (0)
143 {
144 ;
145 }
146
147 inline constexpr
149 api_ (api), //
150 drv_ (drv)
151 {
152 ;
153 }
154
155 inline version_t
156 Version::get_api (void) const noexcept
157 {
158 return api_;
159 }
160
161 inline version_t
162 Version::get_drv (void) const noexcept
163 {
164 return drv_;
165 }
166
167 // ========================================================================
168
169 class Base
170 {
171
172 public:
173
174 // --------------------------------------------------------------------
175
176 Base () noexcept = default;
177
178 virtual
179 ~Base () noexcept;
180
181 // --------------------------------------------------------------------
182
187 const Version&
188 get_version (void) noexcept;
189
196 power (Power state) noexcept;
197
198 // --------------------------------------------------------------------
199
200 protected:
201
202 virtual const Version&
203 do_get_version (void) noexcept = 0;
204
205 virtual return_t
206 do_power (Power state) noexcept = 0;
207
208 };
209
210 // ----------------------------------------------------------------------
211
212 inline const Version&
213 Base::get_version (void) noexcept
214 {
215 return do_get_version ();
216 }
217
218 inline return_t
219 Base::power (Power state) noexcept
220 {
221 return do_power (state);
222 }
223
224 } /* namespace driver */
225} /* namespace os */
226
227#pragma GCC diagnostic pop
228
229// ----------------------------------------------------------------------------
230
231#endif /* __cplusplus */
232
233// ----------------------------------------------------------------------------
234
235#endif /* CMSIS_PLUS_DRIVER_COMMON_H_ */
Base() noexcept=default
version_t get_api(void) const noexcept
Definition common.h:156
version_t drv_
Driver version.
Definition common.h:136
Version & operator=(const Version &)=default
version_t get_drv(void) const noexcept
Definition common.h:162
~Version() noexcept=default
version_t api_
API version.
Definition common.h:135
Version(const Version &)=default
constexpr Version() noexcept
Definition common.h:140
uint16_t version_t
Definition common.h:61
uint32_t power_t
Definition common.h:64
constexpr return_t ERROR_SPECIFIC
Definition common.h:82
constexpr return_t ERROR_UNSUPPORTED
Parameter error.
Definition common.h:78
constexpr return_t RETURN_OK
< Operation succeeded
Definition common.h:69
constexpr return_t ERROR
Driver is busy.
Definition common.h:72
constexpr return_t ERROR_PARAMETER
Start of driver specific errors.
Definition common.h:80
constexpr return_t ERROR_TIMEOUT
Operation not supported.
Definition common.h:76
constexpr return_t ERROR_BUSY
Timeout occurred.
Definition common.h:74
int32_t return_t
Definition common.h:63
uint32_t event_t
Definition common.h:62
void(* signal_event_t)(const void *object, event_t event)
Definition common.h:85
System namespace.