µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
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#pragma GCC diagnostic push
36
37#if defined(__clang__)
38#pragma clang diagnostic ignored "-Wc++98-compat"
39#endif
40
41// ----------------------------------------------------------------------------
42
43extern "C"
44{
45 // Avoid to include <Driver_USART.h>
46 typedef void
47 (*ARM_USART_SignalEvent_t) (uint32_t event);
48
49 typedef struct _ARM_DRIVER_USART const ARM_DRIVER_USART;
50}
51
52namespace os
53{
54 namespace driver
55 {
56 // ======================================================================
57
58#pragma GCC diagnostic push
59#pragma GCC diagnostic ignored "-Wpadded"
60
61 // This wrapper makes a CMSIS USART Keil driver behave like a
62 // µOS++ Serial driver.
63
64 class usart_wrapper : public Serial
65 {
66 public:
67
68 // --------------------------------------------------------------------
69
71 ARM_USART_SignalEvent_t c_cb_func) noexcept;
72
73 usart_wrapper (const usart_wrapper&) = delete;
74
76
78 operator= (const usart_wrapper&) = delete;
79
82
83 virtual
84 ~usart_wrapper () noexcept override;
85
86 // --------------------------------------------------------------------
87
88 protected:
89
90 virtual const Version&
91 do_get_version (void) noexcept override;
92
93 virtual const serial::Capabilities&
94 do_get_capabilities (void) noexcept override;
95
96 virtual return_t
97 do_power (Power state) noexcept override;
98
99 virtual return_t
100 do_send (const void* data, std::size_t num) noexcept override;
101
102 virtual return_t
103 do_receive (void* data, std::size_t num) noexcept override;
104
105 virtual return_t
106 do_transfer (const void* data_out, void* data_in, std::size_t num)
107 noexcept override;
108
109 virtual std::size_t
110 do_get_tx_count (void) noexcept override;
111
112 virtual std::size_t
113 do_get_rx_count (void) noexcept override;
114
115 virtual return_t
116 do_configure (serial::config_t ctrl, serial::config_arg_t arg)
117 noexcept override;
118
119 virtual return_t
120 do_control (serial::control_t ctrl) noexcept override;
121
122 virtual serial::Status&
123 do_get_status (void) noexcept override;
124
125 virtual return_t
126 do_control_modem_line (serial::Modem_control ctrl) noexcept override;
127
128 virtual serial::Modem_status&
129 do_get_modem_status (void) noexcept override;
130
131 // --------------------------------------------------------------------
132
133 private:
134
137
141
142 // Attempts to somehow use && failed, since the Keil driver
143 // functions return temporary objects. So the only portable
144 // solution was to copy these objects here and return
145 // references to these objects.
146 // (Not particularly proud of this solution, but could not find
147 // a better one.)
148
150 { 0, 0 };
152 // serial::Status status_;
153 // serial::Modem_status modem_status_;
154
155 };
156
157#pragma GCC diagnostic pop
158
159 } /* namespace driver */
160} /* namespace os */
161
162#pragma GCC diagnostic pop
163
164// ----------------------------------------------------------------------------
165
166#endif /* CMSIS_PLUS_DRIVER_USART_WRAPPER_H_ */
Serial device driver capabilities.
Definition serial.h:458
usart_wrapper(usart_wrapper &&)=delete
virtual std::size_t do_get_rx_count(void) noexcept override
usart_wrapper & operator=(const usart_wrapper &)=delete
serial::Capabilities capa_
virtual ~usart_wrapper() noexcept override
ARM_USART_SignalEvent_t c_cb_func_
virtual serial::Status & do_get_status(void) noexcept override
virtual const Version & do_get_version(void) noexcept override
virtual return_t do_receive(void *data, std::size_t num) noexcept override
virtual return_t do_transfer(const void *data_out, void *data_in, std::size_t num) noexcept override
ARM_DRIVER_USART * driver_
Pointer to CMSIS USART Keil driver.
virtual std::size_t do_get_tx_count(void) noexcept override
virtual const serial::Capabilities & do_get_capabilities(void) noexcept override
virtual serial::Modem_status & do_get_modem_status(void) noexcept override
virtual return_t do_control(serial::control_t ctrl) noexcept override
virtual return_t do_power(Power state) noexcept override
virtual return_t do_configure(serial::config_t ctrl, serial::config_arg_t arg) noexcept override
virtual return_t do_send(const void *data, std::size_t num) noexcept override
virtual return_t do_control_modem_line(serial::Modem_control ctrl) noexcept override
usart_wrapper(const usart_wrapper &)=delete
int32_t return_t
Definition common.h:63
System namespace.
Standard std namespace.
struct _ARM_DRIVER_USART const ARM_DRIVER_USART
void(* ARM_USART_SignalEvent_t)(uint32_t event)