Mistake on this page?
Report an issue in GitHub or email us
EndpointResolver.h
1 /*
2  * Copyright (c) 2018-2019, Arm Limited and affiliates.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may 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,
13  * WITHOUT 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 ENDPOINT_RESOLVER_H
19 #define ENDPOINT_RESOLVER_H
20 
21 #include "USBPhy.h"
22 
23 /**
24  * Utility class for resolving endpoints
25  *
26  * This class is intended to make the process of
27  * selecting the correct endpoint from a device endpoint
28  * table easier. It also provides a verification function
29  * to check if the device has enough resources for the
30  * given configuration.
31  *
32  * @ingroup usb_device_core
33  */
35 public:
36  EndpointResolver(const usb_ep_table_t *table);
38 
39  /**
40  * Add control endpoint size
41  *
42  * @param size Space reserved for control in and control out
43  */
44  void endpoint_ctrl(uint32_t size);
45 
46  /**
47  * Return a free IN endpoint of the given size
48  *
49  * @param type Desired endpoint type
50  * @param size Space to reserve for this endpoint
51  * @return Endpoint index or 0 if there are not enough resources
52  */
53  usb_ep_t endpoint_in(usb_ep_type_t type, uint32_t size);
54 
55  /**
56  * Return a free OUT endpoint of the given size
57  *
58  * @param type Desired endpoint type
59  * @param size Space to reserve for this endpoint
60  * @return Endpoint index or 0 if there are not enough resources
61  */
62  usb_ep_t endpoint_out(usb_ep_type_t type, uint32_t size);
63 
64  /**
65  * Get next free endpoint
66  */
67  usb_ep_t next_free_endpoint(bool in_not_out, usb_ep_type_t type, uint32_t size);
68 
69  /**
70  * Check if the endpoint configuration created so far is valid
71  *
72  * @return true if all endpoint sizes are available and fit, false otherwise
73  */
74  bool valid();
75 
76  /**
77  * Reset this class's state to when it was constructed
78  */
79  void reset();
80 
81 private:
82 
83  usb_ep_t index_to_endpoint(int index);
84  int next_index(usb_ep_type_t type, bool in_not_out);
85 
86  const usb_ep_table_t *_table;
87  uint32_t _cost;
88  uint32_t _used;
89  bool _valid;
90 };
91 
92 
93 #endif
usb_ep_t endpoint_out(usb_ep_type_t type, uint32_t size)
Return a free OUT endpoint of the given size.
usb_ep_t next_free_endpoint(bool in_not_out, usb_ep_type_t type, uint32_t size)
Get next free endpoint.
bool valid()
Check if the endpoint configuration created so far is valid.
void endpoint_ctrl(uint32_t size)
Add control endpoint size.
Utility class for resolving endpoints.
usb_ep_t endpoint_in(usb_ep_type_t type, uint32_t size)
Return a free IN endpoint of the given size.
void reset()
Reset this class's state to when it was constructed.
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.