Mistake on this page?
Report an issue in GitHub or email us
USBEndpointTester.h
1 /*
2  * Copyright (c) 2018-2018, ARM Limited, All Rights Reserved
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may
6  * not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef USB_ENDPOINT_TESTER_H
19 #define USB_ENDPOINT_TESTER_H
20 
21 /* These headers are included for child class. */
22 #include "USBDescriptor.h"
23 #include "USBDevice_Types.h"
24 #include "EventQueue.h"
25 #include "EventFlags.h"
26 #include "platform/NonCopyable.h"
27 
28 #include "USBDevice.h"
29 
30 #define NUM_ENDPOINTS 6 // Not including CTRL OUT/IN
31 
32 class USBEndpointTester: public USBDevice, private mbed::NonCopyable<USBEndpointTester> {
33 
34 public:
35  USBEndpointTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release,
36  bool abort_transfer_test);
37  virtual ~USBEndpointTester();
38  const char *get_serial_desc_string();
39  void start_ep_in_abort_test();
40 
41  uint32_t get_cnt_cb_set_conf() const
42  {
43  return _cnt_cb_set_conf;
44  }
45  uint32_t get_cnt_cb_set_intf() const
46  {
47  return _cnt_cb_set_intf;
48  }
49  uint32_t get_cnt_cb_bulk_out() const
50  {
51  return _cnt_cb_bulk_out;
52  }
53  uint32_t get_cnt_cb_bulk_in() const
54  {
55  return _cnt_cb_bulk_in;
56  }
57  uint32_t get_cnt_cb_int_out() const
58  {
59  return _cnt_cb_int_out;
60  }
61  uint32_t get_cnt_cb_int_in() const
62  {
63  return _cnt_cb_int_in;
64  }
65  uint32_t get_cnt_cb_iso_out() const
66  {
67  return _cnt_cb_iso_out;
68  }
69  uint32_t get_cnt_cb_iso_in() const
70  {
71  return _cnt_cb_iso_in;
72  }
73 
74  struct ep_config_t {
75  bool dir_in;
76  usb_ep_type_t type;
77  uint32_t max_packet;
78  ep_cb_t callback;
79  };
80 
81 protected:
82  events::EventQueue *queue;
83  rtos::EventFlags flags;
84  uint8_t *ctrl_buf;
85 
86  bool _abort_transfer_test;
87  usb_ep_t _endpoints[NUM_ENDPOINTS];
88  uint8_t *_endpoint_buffs[NUM_ENDPOINTS];
89  ep_config_t (*_endpoint_configs)[NUM_ENDPOINTS];
90 
91  static ep_config_t _intf_config_max[NUM_ENDPOINTS];
92  static ep_config_t _intf_config0[NUM_ENDPOINTS];
93  static ep_config_t _intf_config1[NUM_ENDPOINTS];
94  static ep_config_t _intf_config2[NUM_ENDPOINTS];
95  static ep_config_t _intf_config3[NUM_ENDPOINTS];
96  static ep_config_t _intf_config4[NUM_ENDPOINTS];
97 
98  volatile uint32_t _cnt_cb_set_conf;
99  volatile uint32_t _cnt_cb_set_intf;
100  volatile uint32_t _cnt_cb_bulk_out;
101  volatile uint32_t _cnt_cb_bulk_in;
102  volatile uint32_t _cnt_cb_int_out;
103  volatile uint32_t _cnt_cb_int_in;
104  volatile uint32_t _cnt_cb_iso_out;
105  volatile uint32_t _cnt_cb_iso_in;
106 
107  volatile uint32_t _num_packets_bulk_out_abort;
108  volatile uint32_t _num_packets_bulk_in_abort;
109  volatile uint32_t _num_packets_int_out_abort;
110  volatile uint32_t _num_packets_int_in_abort;
111 
112  virtual const uint8_t *configuration_desc(uint8_t index);
113  virtual void callback_state_change(DeviceState new_state);
114  virtual void callback_request(const setup_packet_t *setup);
115  virtual void callback_request_xfer_done(const setup_packet_t *setup, bool aborted);
116  virtual void callback_set_configuration(uint8_t configuration);
117  virtual void callback_set_interface(uint16_t interface, uint8_t alternate);
118 
119  void _setup_non_zero_endpoints();
120  bool _setup_interface(uint16_t interface, uint8_t alternate);
121 
122  virtual void _cb_bulk_out();
123  virtual void _cb_bulk_in();
124  virtual void _cb_int_out();
125  virtual void _cb_int_in();
126  virtual void _cb_iso_out();
127  virtual void _cb_iso_in();
128 
129 private:
130  const char *get_desc_string(const uint8_t *desc);
131  bool _request_rw_restart(const setup_packet_t *setup);
132  bool _request_abort_buff_check(const setup_packet_t *setup);
133 };
134 
135 #endif
virtual void callback_request_xfer_done(const setup_packet_t *setup, bool aborted)
Called by USBDevice on data stage completion.
virtual void callback_request(const setup_packet_t *setup)
Called by USBDevice on Endpoint0 request.
The EventFlags class is used to control event flags or wait for event flags other threads control...
Definition: EventFlags.h:51
EventQueue.
Definition: EventQueue.h:60
Prevents generation of copy constructor and copy assignment operator in derived classes.
Definition: NonCopyable.h:169
Abstract interface to physical USB hardware.
Definition: USBPhy.h:82
Core USB Device driver.
Definition: USBDevice.h:38
virtual void callback_state_change(DeviceState new_state)
Called when USB changes state.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.