µ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-2023 Liviu Ionescu. All rights reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software
7 * for any purpose is hereby granted, under the terms of the MIT license.
8 *
9 * If a copy of the license was not distributed with this file, it can
10 * be obtained from https://opensource.org/licenses/mit/.
11 */
12
15#include <Driver_USART.h>
16
17#include <utility>
18#include <stdio.h>
19
20// ----------------------------------------------------------------------------
21
22namespace os
23{
24 namespace driver
25 {
26 // ----------------------------------------------------------------------
27
29 ARM_USART_SignalEvent_t c_cb_func) noexcept :
30 driver_ (driver),
31 c_cb_func_ (c_cb_func)
32 {
33 trace::printf("%s() %p\n", __func__, this);
34 }
35
37 {
38 trace::printf ("%s() %p\n", __func__, this);
39
40 driver_ = nullptr;
41 }
42
43 // ----------------------------------------------------------------------
44
45#pragma GCC diagnostic push
46#if defined(__clang__)
47#elif defined(__GNUC__)
48#pragma GCC diagnostic ignored "-Waggregate-return"
49#endif
50#pragma GCC diagnostic ignored "-Wstrict-aliasing"
51
52 const Version&
54 {
55 // Overwrite the C++ instance. Assume same layout.
56 *(reinterpret_cast<ARM_DRIVER_VERSION*> (&version_)) =
57 driver_->GetVersion ();
58 return version_;
59 }
60
63 {
64 // Overwrite the C++ instance. Assume same layout.
65 *(reinterpret_cast<ARM_USART_CAPABILITIES*> (&capa_)) =
66 driver_->GetCapabilities ();
67 return capa_;
68 }
69
72 {
73 // Overwrite the C++ instance. Assume same layout.
74 *(reinterpret_cast<ARM_USART_STATUS*> (&status_)) = driver_->GetStatus ();
75 return status_;
76 }
77
80 {
81 // Overwrite the C++ instance. Assume same layout.
82 *(reinterpret_cast<ARM_USART_MODEM_STATUS*> (&modem_status_)) =
83 driver_->GetModemStatus ();
84 return modem_status_;
85 }
86
87#pragma GCC diagnostic pop
88
91 {
92 return_t status;
93
94 if (state == Power::full)
95 {
96 status = driver_->Initialize (c_cb_func_);
97 if (status != ARM_DRIVER_OK)
98 {
99 return status;
100 }
101 }
102
103 status = driver_->PowerControl (static_cast<ARM_POWER_STATE> (state));
104
105 if (state == Power::off)
106 {
107 driver_->Uninitialize ();
108 }
109
110 return status;
111 }
112
114 usart_wrapper::do_send (const void* data, std::size_t num) noexcept
115 {
116 return driver_->Send (data, static_cast<uint32_t> (num));
117 }
118
120 usart_wrapper::do_receive (void* data, std::size_t num) noexcept
121 {
122 return driver_->Receive (data, static_cast<uint32_t> (num));
123 }
124
126 usart_wrapper::do_transfer (const void* data_out, void* data_in,
127 std::size_t num) noexcept
128 {
129 return driver_->Transfer (data_out, data_in, static_cast<uint32_t> (num));
130 }
131
132 std::size_t
134 {
135 return driver_->GetTxCount ();
136 }
137
138 std::size_t
140 {
141 return driver_->GetRxCount ();
142 }
143
146 {
147 return driver_->Control (cfg, arg);
148 }
149
152 {
153 switch (ctrl)
154 {
158 return driver_->Control (
160 0);
161 }
162 return driver_->Control (ctrl, 1);
163 }
164
167 {
168 return driver_->SetModemControl (
169 static_cast<ARM_USART_MODEM_CONTROL> (ctrl));
170 }
171
172 } /* namespace driver */
173} /* namespace os */
174
175// ----------------------------------------------------------------------------
Serial device driver capabilities.
Definition serial.h:454
Serial modem status
Definition serial.h:351
Serial port status
Definition serial.h:257
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:60
uint32_t config_arg_t
Definition serial.h:52
uint32_t config_t
Definition serial.h:51
@ disable_tx
Disable Receiver.
Definition serial.h:207
@ enable_tx
Enable Transmitter.
Definition serial.h:189
@ disable_rx
Disable Continuous Break transmission;.
Definition serial.h:210
uint32_t control_t
Definition serial.h:53
Modem_control
Configuration to change the serial modem lines.
Definition serial.h:322
int32_t return_t
Definition common.h:47
System namespace.
struct _ARM_DRIVER_USART const ARM_DRIVER_USART
void(* ARM_USART_SignalEvent_t)(uint32_t event)