µ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++.
usb-host.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_USBH.h file, v2.01,
31  * and tries to remain functionally close to the CMSIS specifications.
32  */
33 
35 #include <cmsis-plus/diag/trace.h>
36 #include <cassert>
37 
38 // ----------------------------------------------------------------------------
39 
40 namespace os
41 {
42  namespace driver
43  {
44  namespace usb
45  {
46  // ----------------------------------------------------------------------
47 
48  Host::Host () noexcept
49  {
50  trace::printf ("%s() %p\n", __func__, this);
51 
52  cb_port_func_ = nullptr;
53  cb_port_object_ = nullptr;
54 
55  cb_pipe_func_ = nullptr;
56  cb_pipe_object_ = nullptr;
57  }
58 
59  Host::~Host () noexcept
60  {
61  trace::printf ("%s() %p\n", __func__, this);
62  }
63 
64  void
66  const void* cb_object) noexcept
67  {
68  cb_port_func_ = cb_func;
69  cb_port_object_ = cb_object;
70  }
71 
72  void
74  const void* cb_object) noexcept
75  {
76  cb_pipe_func_ = cb_func;
77  cb_pipe_object_ = cb_object;
78  }
79 
80  // ----------------------------------------------------------------------
81 
82  return_t
83  Host::transfer (pipe_t pipe, uint32_t packet, uint8_t* data,
84  std::size_t num) noexcept
85  {
86  assert (data != nullptr);
87  if (num == 0)
88  {
89  return RETURN_OK;
90  }
91  return do_transfer (pipe, packet, data, num);
92  }
93 
94  // ----------------------------------------------------------------------
95 
96  void
97  Host::signal_port_event (port_t port, event_t event) noexcept
98  {
99  if (cb_port_func_ != nullptr)
100  {
101  // Forward event to registered callback.
102  cb_port_func_ (cb_port_object_, port, event);
103  }
104  }
105 
106  void
107  Host::signal_pipe_event (pipe_t pipe, event_t event) noexcept
108  {
109  if (cb_pipe_func_ != nullptr)
110  {
111  // Forward event to registered callback.
112  cb_pipe_func_ (cb_pipe_object_, pipe, event);
113  }
114  }
115 
116  } /* namespace usb */
117  } /* namespace driver */
118 } /* namespace os */
119 
120 // ----------------------------------------------------------------------------
uint8_t port_t
Definition: usb.h:116
host::signal_pipe_event_t cb_pipe_func_
Pointer to static function that implements the pipe callback.
Definition: usb-host.h:365
constexpr return_t RETURN_OK
< Operation succeeded
Definition: common.h:57
void register_port_callback(host::signal_port_event_t cb_func, const void *cb_object=nullptr) noexcept
Register port event callback.
Definition: usb-host.cpp:65
const void * cb_port_object_
Pointer to object instance associated with the port callback.
Definition: usb-host.h:362
System namespace.
uint32_t event_t
Definition: common.h:50
virtual ~Host() noexcept
Definition: usb-host.cpp:59
virtual return_t do_transfer(pipe_t pipe, uint32_t packet, uint8_t *data, std::size_t num) noexcept=0
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition: trace.cpp:74
const void * cb_pipe_object_
Pointer to object instance associated with the pipe callback.
Definition: usb-host.h:368
void(* signal_port_event_t)(const void *object, port_t port, event_t event)
Definition: usb-host.h:198
void register_pipe_callback(host::signal_pipe_event_t cb_func, const void *cb_object=nullptr) noexcept
Definition: usb-host.cpp:73
void signal_port_event(port_t port, event_t event) noexcept
Definition: usb-host.cpp:97
void(* signal_pipe_event_t)(const void *object, pipe_t pipe, event_t event)
Definition: usb-host.h:201
uint32_t pipe_t
Definition: usb.h:115
void signal_pipe_event(pipe_t pipe, event_t event) noexcept
Definition: usb-host.cpp:107
int32_t return_t
Definition: common.h:51
host::signal_port_event_t cb_port_func_
Pointer to static function that implements the port callback.
Definition: usb-host.h:359
return_t transfer(pipe_t pipe, uint32_t packet, uint8_t *data, std::size_t num) noexcept
Definition: usb-host.cpp:83