µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
serial.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 * Copyright (c) 2013-2014 ARM Ltd.
6 *
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation
9 * files (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use,
11 * copy, modify, merge, publish, distribute, sublicense, and/or
12 * sell copies of the Software, and to permit persons to whom
13 * the Software is furnished to do so, subject to the following
14 * conditions:
15 *
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
27 */
28
29/*
30 * The code is inspired by ARM CMSIS Driver_USART.h file, v2.02,
31 * and tries to remain functionally close to the CMSIS specifications.
32 */
33
36
37#include <cassert>
38
39// ----------------------------------------------------------------------------
40
41#if defined(__clang__)
42#pragma clang diagnostic ignored "-Wc++98-compat"
43#endif
44
45// ----------------------------------------------------------------------------
46
47namespace os
48{
49 namespace driver
50 {
51 // ----------------------------------------------------------------------
52
53 Serial::Serial () noexcept
54 {
55 trace::printf ("%s() %p\n", __func__, this);
56
57 cb_func_ = nullptr;
58 cb_object_ = nullptr;
59
60 clean ();
61 }
62
63 Serial::~Serial () noexcept
64 {
65 trace::printf ("%s() %p\n", __func__, this);
66 }
67
68 // ----------------------------------------------------------------------
69
70 void
71 Serial::clean (void) noexcept
72 {
73 status_.rx_break = false;
74 status_.rx_busy = false;
75 status_.rx_framing_error = false;
76 status_.rx_overflow = false;
77 status_.rx_parity_error = false;
78 status_.tx_busy = false;
79 status_.tx_underflow = false;
80
81 modem_status_.cts = false;
82 modem_status_.dsr = false;
83 modem_status_.dcd = false;
84 modem_status_.ri = false;
85 }
86
87 // ----------------------------------------------------------------------
88
89 void
90 Serial::register_callback (signal_event_t cb_func, const void* cb_object) noexcept
91 {
92 cb_func_ = cb_func;
93 cb_object_ = cb_object;
94 }
95
97 Serial::send (const void* data, std::size_t num) noexcept
98 {
99 assert (data != nullptr);
100 if (num == 0)
101 {
102 return RETURN_OK;
103 }
104 return do_send (data, num);
105 }
106
108 Serial::receive (void* data, std::size_t num) noexcept
109 {
110 assert (data != nullptr);
111 if (num == 0)
112 {
113 return RETURN_OK;
114 }
115 return do_receive (data, num);
116 }
117
119 Serial::transfer (const void* data_out, void* data_in, std::size_t num) noexcept
120 {
121 assert (data_out != nullptr);
122 assert (data_in != nullptr);
123 if (num == 0)
124 {
125 return RETURN_OK;
126 }
127 return do_transfer (data_out, data_in, num);
128 }
129
130 } /* namespace driver */
131} /* namespace os */
132
133// ----------------------------------------------------------------------------
Serial() noexcept
Definition serial.cpp:53
void clean(void) noexcept
Definition serial.cpp:71
const void * cb_object_
Pointer to object instance associated with this driver.
Definition serial.h:719
return_t receive(void *data, std::size_t num) noexcept
Start the serial receiver.
Definition serial.cpp:108
signal_event_t cb_func_
Pointer to static function that implements the callback.
Definition serial.h:716
virtual ~Serial() noexcept override
Definition serial.cpp:63
return_t send(const void *data, std::size_t num) noexcept
Start the serial transmitter.
Definition serial.cpp:97
return_t transfer(const void *data_out, void *data_in, std::size_t num) noexcept
Start sending/receiving data to/from the serial transmitter/receiver.
Definition serial.cpp:119
void register_callback(signal_event_t cb_func, const void *cb_object=nullptr) noexcept
Register event callback.
Definition serial.cpp:90
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:74
constexpr return_t RETURN_OK
< Operation succeeded
Definition common.h:69
int32_t return_t
Definition common.h:63
void(* signal_event_t)(const void *object, event_t event)
Definition common.h:85
System namespace.