µ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.cpp
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
30#include <Driver_USART.h>
31
32#include <utility>
33#include <stdio.h>
34
35// ----------------------------------------------------------------------------
36
37namespace os
38{
39 namespace driver
40 {
41 // ----------------------------------------------------------------------
42
44 ARM_USART_SignalEvent_t c_cb_func) noexcept :
45 driver_ (driver),
46 c_cb_func_ (c_cb_func)
47 {
48 trace::printf("%s() %p\n", __func__, this);
49 }
50
52 {
53 trace::printf ("%s() %p\n", __func__, this);
54
55 driver_ = nullptr;
56 }
57
58 // ----------------------------------------------------------------------
59
60#pragma GCC diagnostic push
61#pragma GCC diagnostic ignored "-Waggregate-return"
62#pragma GCC diagnostic ignored "-Wstrict-aliasing"
63
64 const Version&
66 {
67 // Overwrite the C++ instance. Assume same layout.
68 *(reinterpret_cast<ARM_DRIVER_VERSION*> (&version_)) =
69 driver_->GetVersion ();
70 return version_;
71 }
72
75 {
76 // Overwrite the C++ instance. Assume same layout.
77 *(reinterpret_cast<ARM_USART_CAPABILITIES*> (&capa_)) =
78 driver_->GetCapabilities ();
79 return capa_;
80 }
81
84 {
85 // Overwrite the C++ instance. Assume same layout.
86 *(reinterpret_cast<ARM_USART_STATUS*> (&status_)) = driver_->GetStatus ();
87 return status_;
88 }
89
92 {
93 // Overwrite the C++ instance. Assume same layout.
94 *(reinterpret_cast<ARM_USART_MODEM_STATUS*> (&modem_status_)) =
95 driver_->GetModemStatus ();
96 return modem_status_;
97 }
98
99#pragma GCC diagnostic pop
100
103 {
104 return_t status;
105
106 if (state == Power::full)
107 {
108 status = driver_->Initialize (c_cb_func_);
109 if (status != ARM_DRIVER_OK)
110 {
111 return status;
112 }
113 }
114
115 status = driver_->PowerControl (static_cast<ARM_POWER_STATE> (state));
116
117 if (state == Power::off)
118 {
119 driver_->Uninitialize ();
120 }
121
122 return status;
123 }
124
126 usart_wrapper::do_send (const void* data, std::size_t num) noexcept
127 {
128 return driver_->Send (data, static_cast<uint32_t> (num));
129 }
130
132 usart_wrapper::do_receive (void* data, std::size_t num) noexcept
133 {
134 return driver_->Receive (data, static_cast<uint32_t> (num));
135 }
136
138 usart_wrapper::do_transfer (const void* data_out, void* data_in,
139 std::size_t num) noexcept
140 {
141 return driver_->Transfer (data_out, data_in, static_cast<uint32_t> (num));
142 }
143
144 std::size_t
146 {
147 return driver_->GetTxCount ();
148 }
149
150 std::size_t
152 {
153 return driver_->GetRxCount ();
154 }
155
158 {
159 return driver_->Control (cfg, arg);
160 }
161
164 {
165 switch (ctrl)
166 {
170 return driver_->Control (
172 0);
173 }
174 return driver_->Control (ctrl, 1);
175 }
176
179 {
180 return driver_->SetModemControl (
181 static_cast<ARM_USART_MODEM_CONTROL> (ctrl));
182 }
183
184 } /* namespace driver */
185} /* namespace os */
186
187// ----------------------------------------------------------------------------
Serial device driver capabilities.
Definition serial.h:458
Serial modem status
Definition serial.h:359
Serial port status
Definition serial.h:269
virtual std::size_t do_get_rx_count(void) noexcept override
virtual ~usart_wrapper() noexcept override
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
usart_wrapper(ARM_DRIVER_USART *driver, ARM_USART_SignalEvent_t c_cb_func) noexcept
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
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:74
uint32_t config_arg_t
Definition serial.h:68
uint32_t config_t
Definition serial.h:67
@ disable_tx
Disable Receiver.
Definition serial.h:223
@ enable_tx
Enable Transmitter.
Definition serial.h:205
@ disable_rx
Disable Continuous Break transmission;.
Definition serial.h:226
uint32_t control_t
Definition serial.h:69
Modem_control
Configuration to change the serial modem lines.
Definition serial.h:334
int32_t return_t
Definition common.h:63
System namespace.
struct _ARM_DRIVER_USART const ARM_DRIVER_USART
void(* ARM_USART_SignalEvent_t)(uint32_t event)