µ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-2023 Liviu Ionescu. All rights reserved.
5 * Copyright (c) 2013-2014 ARM Ltd.
6 *
7 * Permission to use, copy, modify, and/or distribute this software
8 * for any purpose is hereby granted, under the terms of the MIT license.
9 *
10 * If a copy of the license was not distributed with this file, it can
11 * be obtained from https://opensource.org/licenses/mit/.
12 */
13
14/*
15 * The code is inspired by ARM CMSIS Driver_Common.h file, v2.00,
16 * and tries to remain functionally close to the CMSIS specifications.
17 */
18
19#ifndef CMSIS_PLUS_DRIVER_COMMON_H_
20#define CMSIS_PLUS_DRIVER_COMMON_H_
21
22// ----------------------------------------------------------------------------
23
24#ifdef __cplusplus
25
26// ----------------------------------------------------------------------------
27
28#include <cstdint>
29
30// ----------------------------------------------------------------------------
31
32#pragma GCC diagnostic push
33#if defined(__clang__)
34#pragma clang diagnostic ignored "-Wc++98-compat"
35#endif
36
37// ----------------------------------------------------------------------------
38
39namespace os
40{
41 namespace driver
42 {
43 // ----------------------------------------------------------------------
44
45 using version_t = uint16_t;
46 using event_t = uint32_t;
47 using return_t = int32_t;
48 using power_t = uint32_t;
49
50 // ----- Return & error codes -----
51
53 constexpr return_t RETURN_OK = 0;
54
56 constexpr return_t ERROR = -1;
58 constexpr return_t ERROR_BUSY = -2;
60 constexpr return_t ERROR_TIMEOUT = -3;
64 constexpr return_t ERROR_PARAMETER = -5;
66 constexpr return_t ERROR_SPECIFIC = -6;
67
68 typedef void
69 (*signal_event_t) (const void* object, event_t event);
70
71 // ----------------------------------------------------------------------
72
73 enum class Power
74 : power_t
75 {
76 //
77
78 // Completely power off the device.
79 off,
80 // Low power mode.
81 low,
82 // Fully power on the
83 full
84 };
85
86 // ======================================================================
87
88 class Version
89 {
90 public:
91
92 // --------------------------------------------------------------------
93
94 constexpr
95 Version () noexcept;
96
97 constexpr
98 Version (version_t api, version_t drv) noexcept;
99
100 Version (const Version&) = default;
101
102 Version&
103 operator= (const Version&) = default;
104
105 ~Version () noexcept = default;
106
107 // --------------------------------------------------------------------
108
110 get_api (void) const noexcept;
111
113 get_drv (void) const noexcept;
114
115 // --------------------------------------------------------------------
116
117 private:
118
121 };
122
123 inline constexpr
124 Version::Version () noexcept :
125 api_ (0), //
126 drv_ (0)
127 {
128 }
129
130 inline constexpr
132 api_ (api), //
133 drv_ (drv)
134 {
135 }
136
137 inline version_t
138 Version::get_api (void) const noexcept
139 {
140 return api_;
141 }
142
143 inline version_t
144 Version::get_drv (void) const noexcept
145 {
146 return drv_;
147 }
148
149 // ========================================================================
150
151 class Base
152 {
153
154 public:
155
156 // --------------------------------------------------------------------
157
158 Base () noexcept = default;
159
160 virtual
161 ~Base () noexcept;
162
163 // --------------------------------------------------------------------
164
169 const Version&
170 get_version (void) noexcept;
171
178 power (Power state) noexcept;
179
180 // --------------------------------------------------------------------
181
182 protected:
183
184 virtual const Version&
185 do_get_version (void) noexcept = 0;
186
187 virtual return_t
188 do_power (Power state) noexcept = 0;
189
190 };
191
192 // ----------------------------------------------------------------------
193
194 inline const Version&
195 Base::get_version (void) noexcept
196 {
197 return do_get_version ();
198 }
199
200 inline return_t
201 Base::power (Power state) noexcept
202 {
203 return do_power (state);
204 }
205
206 } /* namespace driver */
207} /* namespace os */
208
209#pragma GCC diagnostic pop
210
211// ----------------------------------------------------------------------------
212
213#endif /* __cplusplus */
214
215// ----------------------------------------------------------------------------
216
217#endif /* CMSIS_PLUS_DRIVER_COMMON_H_ */
Base() noexcept=default
version_t get_api(void) const noexcept
Definition common.h:138
version_t drv_
Driver version.
Definition common.h:120
Version & operator=(const Version &)=default
version_t get_drv(void) const noexcept
Definition common.h:144
~Version() noexcept=default
version_t api_
API version.
Definition common.h:119
Version(const Version &)=default
constexpr Version() noexcept
Definition common.h:124
uint16_t version_t
Definition common.h:45
uint32_t power_t
Definition common.h:48
constexpr return_t ERROR_SPECIFIC
Definition common.h:66
constexpr return_t ERROR_UNSUPPORTED
Parameter error.
Definition common.h:62
constexpr return_t RETURN_OK
< Operation succeeded
Definition common.h:53
constexpr return_t ERROR
Driver is busy.
Definition common.h:56
constexpr return_t ERROR_PARAMETER
Start of driver specific errors.
Definition common.h:64
constexpr return_t ERROR_TIMEOUT
Operation not supported.
Definition common.h:60
constexpr return_t ERROR_BUSY
Timeout occurred.
Definition common.h:58
int32_t return_t
Definition common.h:47
uint32_t event_t
Definition common.h:46
void(* signal_event_t)(const void *object, event_t event)
Definition common.h:69
System namespace.