µOS++ IIIe Reference  v6.3.15
“Perfekt ist nicht gut genug”
The third edition of µOS++, a POSIX inspired open source system, written in C++.
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 
35 #include <cmsis-plus/diag/trace.h>
36 
37 #include <cassert>
38 
39 // ----------------------------------------------------------------------------
40 
41 namespace os
42 {
43  namespace driver
44  {
45  // ----------------------------------------------------------------------
46 
47  Serial::Serial () noexcept
48  {
49  trace::printf ("%s() %p\n", __func__, this);
50 
51  cb_func_ = nullptr;
52  cb_object_ = nullptr;
53 
54  clean ();
55  }
56 
57  Serial::~Serial () noexcept
58  {
59  trace::printf ("%s() %p\n", __func__, this);
60  }
61 
62  // ----------------------------------------------------------------------
63 
64  void
65  Serial::clean (void) noexcept
66  {
67  status_.rx_break = false;
68  status_.rx_busy = false;
69  status_.rx_framing_error = false;
70  status_.rx_overflow = false;
71  status_.rx_parity_error = false;
72  status_.tx_busy = false;
73  status_.tx_underflow = false;
74 
75  modem_status_.cts = false;
76  modem_status_.dsr = false;
77  modem_status_.dcd = false;
78  modem_status_.ri = false;
79  }
80 
81  // ----------------------------------------------------------------------
82 
83  void
84  Serial::register_callback (signal_event_t cb_func, const void* cb_object) noexcept
85  {
86  cb_func_ = cb_func;
87  cb_object_ = cb_object;
88  }
89 
90  return_t
91  Serial::send (const void* data, std::size_t num) noexcept
92  {
93  assert (data != nullptr);
94  if (num == 0)
95  {
96  return RETURN_OK;
97  }
98  return do_send (data, num);
99  }
100 
101  return_t
102  Serial::receive (void* data, std::size_t num) noexcept
103  {
104  assert (data != nullptr);
105  if (num == 0)
106  {
107  return RETURN_OK;
108  }
109  return do_receive (data, num);
110  }
111 
112  return_t
113  Serial::transfer (const void* data_out, void* data_in, std::size_t num) noexcept
114  {
115  assert (data_out != nullptr);
116  assert (data_in != nullptr);
117  if (num == 0)
118  {
119  return RETURN_OK;
120  }
121  return do_transfer (data_out, data_in, num);
122  }
123 
124  } /* namespace driver */
125 } /* namespace os */
126 
127 // ----------------------------------------------------------------------------
virtual return_t do_transfer(const void *data_out, void *data_in, std::size_t num) noexcept=0
const void * cb_object_
Pointer to object instance associated with this driver.
Definition: serial.h:705
constexpr return_t RETURN_OK
< Operation succeeded
Definition: common.h:57
signal_event_t cb_func_
Pointer to static function that implements the callback.
Definition: serial.h:702
virtual return_t do_receive(void *data, std::size_t num) noexcept=0
return_t receive(void *data, std::size_t num) noexcept
Start the serial receiver.
Definition: serial.cpp:102
bool cts
< CTS state: true=Active, false=Inactive
Definition: serial.h:369
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:113
System namespace.
bool tx_busy
< Transmitter busy flag
Definition: serial.h:289
return_t send(const void *data, std::size_t num) noexcept
Start the serial transmitter.
Definition: serial.cpp:91
void register_callback(signal_event_t cb_func, const void *cb_object=nullptr) noexcept
Register event callback.
Definition: serial.cpp:84
bool rx_busy
Transmit data underflow detected (cleared on start of next send operation)
Definition: serial.h:292
bool rx_overflow
Break detected on receive (cleared on start of next receive operation)
Definition: serial.h:298
bool tx_underflow
Receive data overflow detected (cleared on start of next receive operation)
Definition: serial.h:295
virtual ~Serial() noexcept
Definition: serial.cpp:57
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition: trace.cpp:74
bool rx_framing_error
Parity error detected on receive (cleared on start of next receive operation)
Definition: serial.h:304
bool rx_break
Framing error detected on receive (cleared on start of next receive operation)
Definition: serial.h:301
void clean(void) noexcept
Definition: serial.cpp:65
Serial() noexcept
Definition: serial.cpp:47
serial::Modem_status modem_status_
Definition: serial.h:708
void(* signal_event_t)(const void *object, event_t event)
Definition: common.h:73
serial::Status status_
Definition: serial.h:707
virtual return_t do_send(const void *data, std::size_t num) noexcept=0
int32_t return_t
Definition: common.h:51
bool dsr
DCD state: true=Active, false=Inactive.
Definition: serial.h:372
bool dcd
RI state: true=Active, false=Inactive.
Definition: serial.h:375