µ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-2023 Liviu Ionescu. All rights reserved.
5 * Copyright (c) 2013-2014 ARM Ltd.
6 *
7 * Permission to use, copy, modify, and/or distribute this software
8 * for any purpose is hereby granted, under the terms of the MIT license.
9 *
10 * If a copy of the license was not distributed with this file, it can
11 * be obtained from https://opensource.org/licenses/mit/.
12 */
13
14/*
15 * The code is inspired by ARM CMSIS Driver_USART.h file, v2.02,
16 * and tries to remain functionally close to the CMSIS specifications.
17 */
18
21
22#include <cassert>
23
24// ----------------------------------------------------------------------------
25
26#if defined(__clang__)
27#pragma clang diagnostic ignored "-Wc++98-compat"
28#endif
29
30// ----------------------------------------------------------------------------
31
32namespace os
33{
34 namespace driver
35 {
36 // ----------------------------------------------------------------------
37
38 Serial::Serial () noexcept
39 {
40 trace::printf ("%s() %p\n", __func__, this);
41
42 cb_func_ = nullptr;
43 cb_object_ = nullptr;
44
45 clean ();
46 }
47
48 Serial::~Serial () noexcept
49 {
50 trace::printf ("%s() %p\n", __func__, this);
51 }
52
53 // ----------------------------------------------------------------------
54
55 void
56 Serial::clean (void) noexcept
57 {
58 status_.rx_break = false;
59 status_.rx_busy = false;
60 status_.rx_framing_error = false;
61 status_.rx_overflow = false;
62 status_.rx_parity_error = false;
63 status_.tx_busy = false;
64 status_.tx_underflow = false;
65
66 modem_status_.cts = false;
67 modem_status_.dsr = false;
68 modem_status_.dcd = false;
69 modem_status_.ri = false;
70 }
71
72 // ----------------------------------------------------------------------
73
74 void
75 Serial::register_callback (signal_event_t cb_func, const void* cb_object) noexcept
76 {
77 cb_func_ = cb_func;
78 cb_object_ = cb_object;
79 }
80
82 Serial::send (const void* data, std::size_t num) noexcept
83 {
84 assert (data != nullptr);
85 if (num == 0)
86 {
87 return RETURN_OK;
88 }
89 return do_send (data, num);
90 }
91
93 Serial::receive (void* data, std::size_t num) noexcept
94 {
95 assert (data != nullptr);
96 if (num == 0)
97 {
98 return RETURN_OK;
99 }
100 return do_receive (data, num);
101 }
102
104 Serial::transfer (const void* data_out, void* data_in, std::size_t num) noexcept
105 {
106 assert (data_out != nullptr);
107 assert (data_in != nullptr);
108 if (num == 0)
109 {
110 return RETURN_OK;
111 }
112 return do_transfer (data_out, data_in, num);
113 }
114
115 } /* namespace driver */
116} /* namespace os */
117
118// ----------------------------------------------------------------------------
Serial() noexcept
Definition serial.cpp:38
void clean(void) noexcept
Definition serial.cpp:56
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:93
signal_event_t cb_func_
Pointer to static function that implements the callback.
Definition serial.h:716
virtual ~Serial() noexcept override
Definition serial.cpp:48
return_t send(const void *data, std::size_t num) noexcept
Start the serial transmitter.
Definition serial.cpp:82
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:104
void register_callback(signal_event_t cb_func, const void *cb_object=nullptr) noexcept
Register event callback.
Definition serial.cpp:75
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:60
constexpr return_t RETURN_OK
< Operation succeeded
Definition common.h:53
int32_t return_t
Definition common.h:47
void(* signal_event_t)(const void *object, event_t event)
Definition common.h:69
System namespace.