µ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++.
usart-wrapper.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  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without
9  * restriction, including without limitation the rights to use,
10  * copy, modify, merge, publish, distribute, sublicense, and/or
11  * sell copies of the Software, and to permit persons to whom
12  * the Software is furnished to do so, subject to the following
13  * conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  */
27 
28 #ifndef CMSIS_PLUS_DRIVER_USART_WRAPPER_H_
29 #define CMSIS_PLUS_DRIVER_USART_WRAPPER_H_
30 
32 
33 // ----------------------------------------------------------------------------
34 
35 extern "C"
36 {
37  // Avoid to include <Driver_USART.h>
38  typedef void
39  (*ARM_USART_SignalEvent_t) (uint32_t event);
40 
41  typedef struct _ARM_DRIVER_USART const ARM_DRIVER_USART;
42 }
43 
44 namespace os
45 {
46  namespace driver
47  {
48  // ======================================================================
49 
50 #pragma GCC diagnostic push
51 #pragma GCC diagnostic ignored "-Wpadded"
52 
53  // This wrapper makes a CMSIS USART Keil driver behave like a
54  // µOS++ Serial driver.
55 
56  class usart_wrapper : public Serial
57  {
58  public:
59 
60  // --------------------------------------------------------------------
61 
63  ARM_USART_SignalEvent_t c_cb_func) noexcept;
64 
65  usart_wrapper (const usart_wrapper&) = delete;
66 
67  usart_wrapper (usart_wrapper&&) = delete;
68 
70  operator= (const usart_wrapper&) = delete;
71 
73  operator= (usart_wrapper&&) = delete;
74 
75  virtual
76  ~usart_wrapper () noexcept;
77 
78  // --------------------------------------------------------------------
79 
80  protected:
81 
82  virtual const Version&
83  do_get_version (void) noexcept override;
84 
85  virtual const serial::Capabilities&
86  do_get_capabilities (void) noexcept override;
87 
88  virtual return_t
89  do_power (Power state) noexcept override;
90 
91  virtual return_t
92  do_send (const void* data, std::size_t num) noexcept override;
93 
94  virtual return_t
95  do_receive (void* data, std::size_t num) noexcept override;
96 
97  virtual return_t
98  do_transfer (const void* data_out, void* data_in, std::size_t num)
99  noexcept override;
100 
101  virtual std::size_t
102  do_get_tx_count (void) noexcept override;
103 
104  virtual std::size_t
105  do_get_rx_count (void) noexcept override;
106 
107  virtual return_t
109  noexcept override;
110 
111  virtual return_t
112  do_control (serial::control_t ctrl) noexcept override;
113 
114  virtual serial::Status&
115  do_get_status (void) noexcept override;
116 
117  virtual return_t
118  do_control_modem_line (serial::Modem_control ctrl) noexcept override;
119 
120  virtual serial::Modem_status&
121  do_get_modem_status (void) noexcept override;
122 
123  // --------------------------------------------------------------------
124 
125  private:
126 
129 
133 
134  // Attempts to somehow use && failed, since the Keil driver
135  // functions return temporary objects. So the only portable
136  // solution was to copy these objects here and return
137  // references to these objects.
138  // (Not particularly proud of this solution, but could not find
139  // a better one.)
140 
142  { 0, 0 };
146 
147  };
148 
149 #pragma GCC diagnostic pop
150 
151  } /* namespace driver */
152 } /* namespace os */
153 
154 // ----------------------------------------------------------------------------
155 
156 #endif /* CMSIS_PLUS_DRIVER_USART_WRAPPER_H_ */
serial::Modem_status modem_status_
virtual ~usart_wrapper() noexcept
ARM_USART_SignalEvent_t c_cb_func_
virtual serial::Status & do_get_status(void) noexcept override
System namespace.
uint32_t config_t
Definition: serial.h:55
Serial device driver capabilities.
Definition: serial.h:445
serial::Capabilities capa_
usart_wrapper(ARM_DRIVER_USART *driver, ARM_USART_SignalEvent_t c_cb_func) noexcept
ARM_DRIVER_USART * driver_
Pointer to CMSIS USART Keil driver.
virtual return_t do_transfer(const void *data_out, void *data_in, std::size_t num) noexcept override
uint32_t config_arg_t
Definition: serial.h:56
void(* ARM_USART_SignalEvent_t)(uint32_t event)
Definition: usart-wrapper.h:39
struct _ARM_DRIVER_USART const ARM_DRIVER_USART
Definition: usart-wrapper.h:41
virtual const serial::Capabilities & do_get_capabilities(void) noexcept override
virtual std::size_t do_get_tx_count(void) noexcept override
virtual serial::Modem_status & do_get_modem_status(void) noexcept override
virtual const Version & do_get_version(void) noexcept override
virtual return_t do_send(const void *data, std::size_t num) noexcept override
virtual return_t do_configure(serial::config_t ctrl, serial::config_arg_t arg) noexcept override
Modem_control
Configuration to change the serial modem lines.
Definition: serial.h:320
virtual return_t do_control_modem_line(serial::Modem_control ctrl) noexcept override
usart_wrapper & operator=(const usart_wrapper &)=delete
Serial modem status
Definition: serial.h:346
Serial port status
Definition: serial.h:256
int32_t return_t
Definition: common.h:51
uint32_t control_t
Definition: serial.h:57
virtual return_t do_control(serial::control_t ctrl) noexcept override
virtual return_t do_receive(void *data, std::size_t num) noexcept override
virtual return_t do_power(Power state) noexcept override
virtual std::size_t do_get_rx_count(void) noexcept override