µ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++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2016-2025 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can
9 * be obtained from https://opensource.org/licenses/mit.
10 */
11
14#include <Driver_USART.h>
15
16#include <utility>
17#include <stdio.h>
18
19// ----------------------------------------------------------------------------
20
21namespace os
22{
23 namespace driver
24 {
25 // ------------------------------------------------------------------------
26
28 ARM_USART_SignalEvent_t c_cb_func) noexcept
29 : driver_ (driver), c_cb_func_ (c_cb_func)
30 {
31 trace::printf ("%s() %p\n", __func__, this);
32 }
33
35 {
36 trace::printf ("%s() %p\n", __func__, this);
37
38 driver_ = nullptr;
39 }
40
41 // ------------------------------------------------------------------------
42
43#pragma GCC diagnostic push
44#if defined(__clang__)
45#elif defined(__GNUC__)
46#pragma GCC diagnostic ignored "-Waggregate-return"
47#endif
48#pragma GCC diagnostic ignored "-Wstrict-aliasing"
49
50 const Version&
52 {
53 // Overwrite the C++ instance. Assume same layout.
54 *(reinterpret_cast<ARM_DRIVER_VERSION*> (&version_))
55 = driver_->GetVersion ();
56 return version_;
57 }
58
61 {
62 // Overwrite the C++ instance. Assume same layout.
63 *(reinterpret_cast<ARM_USART_CAPABILITIES*> (&capa_))
64 = driver_->GetCapabilities ();
65 return capa_;
66 }
67
70 {
71 // Overwrite the C++ instance. Assume same layout.
72 *(reinterpret_cast<ARM_USART_STATUS*> (&status_))
73 = driver_->GetStatus ();
74 return status_;
75 }
76
79 {
80 // Overwrite the C++ instance. Assume same layout.
81 *(reinterpret_cast<ARM_USART_MODEM_STATUS*> (&modem_status_))
82 = driver_->GetModemStatus ();
83 return modem_status_;
84 }
85
86#pragma GCC diagnostic pop
87
90 {
91 return_t status;
92
93 if (state == Power::full)
94 {
95 status = driver_->Initialize (c_cb_func_);
96 if (status != ARM_DRIVER_OK)
97 {
98 return status;
99 }
100 }
101
102 status = driver_->PowerControl (static_cast<ARM_POWER_STATE> (state));
103
104 if (state == Power::off)
105 {
106 driver_->Uninitialize ();
107 }
108
109 return status;
110 }
111
113 usart_wrapper::do_send (const void* data, std::size_t num) noexcept
114 {
115 return driver_->Send (data, static_cast<uint32_t> (num));
116 }
117
119 usart_wrapper::do_receive (void* data, std::size_t num) noexcept
120 {
121 return driver_->Receive (data, static_cast<uint32_t> (num));
122 }
123
125 usart_wrapper::do_transfer (const void* data_out, void* data_in,
126 std::size_t num) noexcept
127 {
128 return driver_->Transfer (data_out, data_in,
129 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 serial::config_arg_t arg) noexcept
147 {
148 return driver_->Control (cfg, arg);
149 }
150
153 {
154 switch (ctrl)
155 {
159 return driver_->Control (
160 ctrl
162 0);
163 }
164 return driver_->Control (ctrl, 1);
165 }
166
169 {
170 return driver_->SetModemControl (
171 static_cast<ARM_USART_MODEM_CONTROL> (ctrl));
172 }
173
174 } /* namespace driver */
175} /* namespace os */
176
177// ----------------------------------------------------------------------------
Serial device driver capabilities.
Definition serial.h:455
Serial modem status
Definition serial.h:355
Serial port status
Definition serial.h:259
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:59
uint32_t config_arg_t
Definition serial.h:51
uint32_t config_t
Definition serial.h:50
@ disable_break
Disable Continuous Break transmission;.
Definition serial.h:215
@ disable_tx
Disable Transmitter.
Definition serial.h:209
@ enable_tx
Enable Transmitter.
Definition serial.h:191
@ disable_rx
Disable Receiver.
Definition serial.h:212
uint32_t control_t
Definition serial.h:52
Modem_control
Configuration to change the serial modem lines.
Definition serial.h:326
int32_t return_t
Definition common.h:46
System namespace.
struct _ARM_DRIVER_USART const ARM_DRIVER_USART
void(* ARM_USART_SignalEvent_t)(uint32_t event)