µ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.h
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
13#ifndef CMSIS_PLUS_DRIVER_USART_WRAPPER_H_
14#define CMSIS_PLUS_DRIVER_USART_WRAPPER_H_
15
17
18// ----------------------------------------------------------------------------
19
20#pragma GCC diagnostic push
21#if defined(__clang__)
22#pragma clang diagnostic ignored "-Wc++98-compat"
23#endif
24
25// ----------------------------------------------------------------------------
26
27extern "C"
28{
29 // Avoid to include <Driver_USART.h>
30 typedef void
31 (*ARM_USART_SignalEvent_t) (uint32_t event);
32
33 typedef struct _ARM_DRIVER_USART const ARM_DRIVER_USART;
34}
35
36namespace os
37{
38 namespace driver
39 {
40 // ======================================================================
41
42#pragma GCC diagnostic push
43#if defined(__clang__)
44#pragma clang diagnostic ignored "-Wpadded"
45#elif defined(__GNUC__)
46#pragma GCC diagnostic ignored "-Wpadded"
47#endif
48
49 // This wrapper makes a CMSIS USART Keil driver behave like a
50 // µOS++ Serial driver.
51
52 class usart_wrapper : public Serial
53 {
54 public:
55
56 // --------------------------------------------------------------------
57
59 ARM_USART_SignalEvent_t c_cb_func) noexcept;
60
61 usart_wrapper (const usart_wrapper&) = delete;
62
64
66 operator= (const usart_wrapper&) = delete;
67
70
71 virtual
72 ~usart_wrapper () noexcept override;
73
74 // --------------------------------------------------------------------
75
76 protected:
77
78 virtual const Version&
79 do_get_version (void) noexcept override;
80
81 virtual const serial::Capabilities&
82 do_get_capabilities (void) noexcept override;
83
84 virtual return_t
85 do_power (Power state) noexcept override;
86
87 virtual return_t
88 do_send (const void* data, std::size_t num) noexcept override;
89
90 virtual return_t
91 do_receive (void* data, std::size_t num) noexcept override;
92
93 virtual return_t
94 do_transfer (const void* data_out, void* data_in, std::size_t num)
95 noexcept override;
96
97 virtual std::size_t
98 do_get_tx_count (void) noexcept override;
99
100 virtual std::size_t
101 do_get_rx_count (void) noexcept override;
102
103 virtual return_t
104 do_configure (serial::config_t ctrl, serial::config_arg_t arg)
105 noexcept override;
106
107 virtual return_t
108 do_control (serial::control_t ctrl) noexcept override;
109
110 virtual serial::Status&
111 do_get_status (void) noexcept override;
112
113 virtual return_t
114 do_control_modem_line (serial::Modem_control ctrl) noexcept override;
115
116 virtual serial::Modem_status&
117 do_get_modem_status (void) noexcept override;
118
119 // --------------------------------------------------------------------
120
121 private:
122
125
129
130 // Attempts to somehow use && failed, since the Keil driver
131 // functions return temporary objects. So the only portable
132 // solution was to copy these objects here and return
133 // references to these objects.
134 // (Not particularly proud of this solution, but could not find
135 // a better one.)
136
138 { 0, 0 };
140 // serial::Status status_;
141 // serial::Modem_status modem_status_;
142
143 };
144
145#pragma GCC diagnostic pop
146
147 } /* namespace driver */
148} /* namespace os */
149
150#pragma GCC diagnostic pop
151
152// ----------------------------------------------------------------------------
153
154#endif /* CMSIS_PLUS_DRIVER_USART_WRAPPER_H_ */
Serial device driver capabilities.
Definition serial.h:454
usart_wrapper(usart_wrapper &&)=delete
virtual std::size_t do_get_rx_count(void) noexcept override
usart_wrapper & operator=(const usart_wrapper &)=delete
serial::Capabilities capa_
virtual ~usart_wrapper() noexcept override
ARM_USART_SignalEvent_t c_cb_func_
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
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
usart_wrapper(const usart_wrapper &)=delete
int32_t return_t
Definition common.h:47
System namespace.
Standard std namespace.
struct _ARM_DRIVER_USART const ARM_DRIVER_USART
void(* ARM_USART_SignalEvent_t)(uint32_t event)