µOS++ IIIe Reference  v6.3.15
“Perfekt ist nicht gut genug”
The third edition of µOS++, a POSIX inspired open source system, written in C++.
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 #include <cstdint>
42 
43 namespace os
44 {
45  namespace driver
46  {
47  // ----------------------------------------------------------------------
48 
49  using version_t = uint16_t;
50  using event_t = uint32_t;
51  using return_t = int32_t;
52  using power_t = uint32_t;
53 
54  // ----- Return & error codes -----
55 
57  constexpr return_t RETURN_OK = 0;
58 
60  constexpr return_t ERROR = -1;
62  constexpr return_t ERROR_BUSY = -2;
64  constexpr return_t ERROR_TIMEOUT = -3;
66  constexpr return_t ERROR_UNSUPPORTED = -4;
68  constexpr return_t ERROR_PARAMETER = -5;
70  constexpr return_t ERROR_SPECIFIC = -6;
71 
72  typedef void
73  (*signal_event_t) (const void* object, event_t event);
74 
75  // ----------------------------------------------------------------------
76 
77  enum class Power
78  : power_t
79  {
80  //
81 
82  // Completely power off the device.
83  off,
84  // Low power mode.
85  low,
86  // Fully power on the
87  full
88  };
89 
90  // ======================================================================
91 
92  class Version
93  {
94  public:
95 
96  // --------------------------------------------------------------------
97 
98  constexpr
99  Version () noexcept;
100 
101  constexpr
102  Version (version_t api, version_t drv) noexcept;
103 
104  Version (const Version&) = default;
105 
106  Version&
107  operator= (const Version&) = default;
108 
109  ~Version () noexcept = default;
110 
111  // --------------------------------------------------------------------
112 
113  version_t
114  get_api (void) const noexcept;
115 
116  version_t
117  get_drv (void) const noexcept;
118 
119  // --------------------------------------------------------------------
120 
121  private:
122 
125  };
126 
127  inline constexpr
128  Version::Version () noexcept :
129  api_ (0), //
130  drv_ (0)
131  {
132  ;
133  }
134 
135  inline constexpr
136  Version::Version (version_t api, version_t drv) noexcept :
137  api_ (api), //
138  drv_ (drv)
139  {
140  ;
141  }
142 
143  inline version_t
144  Version::get_api (void) const noexcept
145  {
146  return api_;
147  }
148 
149  inline version_t
150  Version::get_drv (void) const noexcept
151  {
152  return drv_;
153  }
154 
155  // ========================================================================
156 
157  class Base
158  {
159 
160  public:
161 
162  // --------------------------------------------------------------------
163 
164  Base () noexcept = default;
165 
166  virtual
167  ~Base () noexcept;
168 
169  // --------------------------------------------------------------------
170 
175  const Version&
176  get_version (void) noexcept;
177 
183  return_t
184  power (Power state) noexcept;
185 
186  // --------------------------------------------------------------------
187 
188  protected:
189 
190  virtual const Version&
191  do_get_version (void) noexcept = 0;
192 
193  virtual return_t
194  do_power (Power state) noexcept = 0;
195 
196  };
197 
198  // ----------------------------------------------------------------------
199 
200  inline const Version&
201  Base::get_version (void) noexcept
202  {
203  return do_get_version ();
204  }
205 
206  inline return_t
207  Base::power (Power state) noexcept
208  {
209  return do_power (state);
210  }
211 
212  } /* namespace driver */
213 } /* namespace os */
214 
215 #endif /* __cplusplus */
216 
217 // ----------------------------------------------------------------------------
218 
219 #endif /* CMSIS_PLUS_DRIVER_COMMON_H_ */
uint32_t power_t
Definition: common.h:52
constexpr return_t RETURN_OK
< Operation succeeded
Definition: common.h:57
constexpr return_t ERROR_PARAMETER
Start of driver specific errors.
Definition: common.h:68
uint16_t version_t
Definition: common.h:49
System namespace.
constexpr return_t ERROR_SPECIFIC
Definition: common.h:70
version_t get_drv(void) const noexcept
Definition: common.h:150
return_t power(Power state) noexcept
Power up/down device.
Definition: common.h:207
uint32_t event_t
Definition: common.h:50
constexpr Version() noexcept
Definition: common.h:128
version_t api_
API version.
Definition: common.h:123
version_t get_api(void) const noexcept
Definition: common.h:144
constexpr return_t ERROR_UNSUPPORTED
Parameter error.
Definition: common.h:66
constexpr return_t ERROR_TIMEOUT
Operation not supported.
Definition: common.h:64
constexpr return_t ERROR_BUSY
Timeout occurred.
Definition: common.h:62
void(* signal_event_t)(const void *object, event_t event)
Definition: common.h:73
constexpr return_t ERROR
Driver is busy.
Definition: common.h:60
int32_t return_t
Definition: common.h:51
const Version & get_version(void) noexcept
Get driver version.
Definition: common.h:201
version_t drv_
Driver version.
Definition: common.h:124