1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** USBX Component */
16 /** */
17 /** Host Stack */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22
23 /* Include necessary system files. */
24
25 #define UX_SOURCE_CODE
26
27 #include "ux_api.h"
28 #include "ux_host_stack.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _ux_host_stack_endpoint_instance_delete PORTABLE C */
36 /* 6.1.10 */
37 /* AUTHOR */
38 /* */
39 /* Chaoqiong Xiao, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function will delete an endpoint instance. It does not delete */
44 /* the endpoint container but it removes the HCD endpoint and reclaims */
45 /* the bandwidth. */
46 /* */
47 /* INPUT */
48 /* */
49 /* endpoint Endpoint to delete */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* None */
54 /* */
55 /* CALLS */
56 /* */
57 /* _ux_host_stack_bandwidth_release Release bandwidth */
58 /* _ux_utility_semaphore_delete Semaphore delete */
59 /* (ux_hcd_entry_function) HCD entry function */
60 /* */
61 /* CALLED BY */
62 /* */
63 /* USBX Components */
64 /* */
65 /* RELEASE HISTORY */
66 /* */
67 /* DATE NAME DESCRIPTION */
68 /* */
69 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
70 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
71 /* optimized based on compile */
72 /* definitions, */
73 /* resulting in version 6.1 */
74 /* 06-02-2021 Chaoqiong Xiao Modified comment(s), */
75 /* fixed trace enabled error, */
76 /* resulting in version 6.1.7 */
77 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
78 /* added standalone support, */
79 /* resulting in version 6.1.10 */
80 /* */
81 /**************************************************************************/
_ux_host_stack_endpoint_instance_delete(UX_ENDPOINT * endpoint)82 VOID _ux_host_stack_endpoint_instance_delete(UX_ENDPOINT *endpoint)
83 {
84
85 UX_HCD *hcd;
86
87
88 /* Obtain the HCD for this endpoint. */
89 hcd = UX_DEVICE_HCD_GET(endpoint -> ux_endpoint_device);
90
91 /* If trace is enabled, insert this event into the trace buffer. */
92 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_ENDPOINT_INSTANCE_DELETE, endpoint -> ux_endpoint_device, endpoint, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
93
94 /* Ensure the endpoint had its physical ED allocated. */
95 if (endpoint -> ux_endpoint_ed != UX_NULL)
96 {
97
98 /* Destroy this endpoint. */
99 hcd -> ux_hcd_entry_function(hcd, UX_HCD_DESTROY_ENDPOINT, (VOID *) endpoint);
100
101 /* Free the semaphore previously attached to the transfer_request of this endpoint. */
102 _ux_host_semaphore_delete(&endpoint -> ux_endpoint_transfer_request.ux_transfer_request_semaphore);
103 }
104
105 /* If the endpoint requested guaranteed bandwidth, free it now. */
106 switch ((endpoint -> ux_endpoint_descriptor.bmAttributes) & UX_MASK_ENDPOINT_TYPE)
107 {
108
109 case UX_CONTROL_ENDPOINT:
110 case UX_BULK_ENDPOINT:
111
112 break;
113
114 default:
115
116 /* Reclaim its bandwidth. */
117 _ux_host_stack_bandwidth_release(hcd, endpoint);
118 }
119
120 /* If trace is enabled, register this object. */
121 UX_TRACE_OBJECT_UNREGISTER(endpoint);
122
123 /* Return to caller. */
124 return;
125 }
126
127