Skip to content

Commit f8422a6

Browse files
committed
Terminate the hid out interrupt out endpoint on deactivate
1 parent 1249abe commit f8422a6

File tree

1 file changed

+60
-46
lines changed

1 file changed

+60
-46
lines changed

common/usbx_host_classes/src/ux_host_class_hid_deactivate.c

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/***************************************************************************
2-
* Copyright (c) 2024 Microsoft Corporation
3-
*
2+
* Copyright (c) 2024 Microsoft Corporation
3+
*
44
* This program and the accompanying materials are made available under the
55
* terms of the MIT License which is available at
66
* https://opensource.org/licenses/MIT.
7-
*
7+
*
88
* SPDX-License-Identifier: MIT
99
**************************************************************************/
1010

1111

1212
/**************************************************************************/
1313
/**************************************************************************/
14-
/** */
15-
/** USBX Component */
14+
/** */
15+
/** USBX Component */
1616
/** */
1717
/** HID Class */
1818
/** */
@@ -29,50 +29,49 @@
2929
#include "ux_host_stack.h"
3030

3131

32-
/**************************************************************************/
33-
/* */
34-
/* FUNCTION RELEASE */
35-
/* */
36-
/* _ux_host_class_hid_deactivate PORTABLE C */
32+
/**************************************************************************/
33+
/* */
34+
/* FUNCTION RELEASE */
35+
/* */
36+
/* _ux_host_class_hid_deactivate PORTABLE C */
3737
/* 6.1.10 */
3838
/* AUTHOR */
3939
/* */
4040
/* Chaoqiong Xiao, Microsoft Corporation */
4141
/* */
4242
/* DESCRIPTION */
43-
/* */
43+
/* */
4444
/* This function is called when this instance of the HID has been */
45-
/* removed from the bus either directly or indirectly. The interrupt */
46-
/* pipe will be destroyed and the instanced removed. */
47-
/* */
48-
/* INPUT */
49-
/* */
50-
/* command Pointer to command */
51-
/* */
52-
/* OUTPUT */
53-
/* */
54-
/* Completion Status */
55-
/* */
56-
/* CALLS */
57-
/* */
58-
/* (ux_host_class_hid_client_handler) HID client handler */
59-
/* _ux_host_class_hid_instance_clean HID instance clean */
60-
/* _ux_host_stack_class_instance_destroy Destroy the class instance */
45+
/* removed from the bus either directly or indirectly. The interrupt */
46+
/* pipe will be destroyed and the instanced removed. */
47+
/* */
48+
/* INPUT */
49+
/* */
50+
/* command Pointer to command */
51+
/* */
52+
/* OUTPUT */
53+
/* */
54+
/* Completion Status */
55+
/* */
56+
/* CALLS */
57+
/* */
58+
/* (ux_host_class_hid_client_handler) HID client handler */
59+
/* _ux_host_class_hid_instance_clean HID instance clean */
60+
/* _ux_host_stack_class_instance_destroy Destroy the class instance */
6161
/* _ux_host_stack_endpoint_transfer_abort */
62-
/* Abort transfer */
63-
/* _ux_utility_memory_free Release memory block */
64-
/* _ux_host_semaphore_delete Delete semaphore */
65-
/* _ux_host_semaphore_get Get semaphore */
66-
/* _ux_utility_thread_schedule_other Schedule other threads */
67-
/* */
68-
/* CALLED BY */
69-
/* */
70-
/* HID Class */
71-
/* */
72-
/* RELEASE HISTORY */
73-
/* */
74-
/* DATE NAME DESCRIPTION */
75-
/* */
62+
/* Abort transfer */
63+
/* _ux_utility_memory_free Release memory block */
64+
/* _ux_host_semaphore_delete Delete semaphore */
65+
/* _ux_host_semaphore_get Get semaphore */
66+
/* */
67+
/* CALLED BY */
68+
/* */
69+
/* HID Class */
70+
/* */
71+
/* RELEASE HISTORY */
72+
/* */
73+
/* DATE NAME DESCRIPTION */
74+
/* */
7675
/* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
7776
/* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
7877
/* resulting in version 6.1 */
@@ -124,6 +123,22 @@ UINT status;
124123
_ux_utility_memory_free(transfer_request -> ux_transfer_request_data_pointer);
125124
}
126125

126+
#if defined(UX_HOST_CLASS_HID_INTERRUPT_OUT_SUPPORT)
127+
if (hid -> ux_host_class_hid_interrupt_out_endpoint)
128+
{
129+
130+
/* We need to abort transactions on the interrupt pipe. */
131+
_ux_host_stack_endpoint_transfer_abort(hid -> ux_host_class_hid_interrupt_out_endpoint);
132+
133+
/* If the Hid class instance has a interrupt pipe with a data payload associated with it
134+
it must be freed. */
135+
transfer_request = &hid -> ux_host_class_hid_interrupt_out_endpoint -> ux_endpoint_transfer_request;
136+
137+
/* Then de allocate the memory. */
138+
_ux_utility_memory_free(transfer_request -> ux_transfer_request_data_pointer);
139+
}
140+
#endif
141+
127142
#if defined(UX_HOST_STANDALONE)
128143
if (hid -> ux_host_class_hid_allocated)
129144
_ux_utility_memory_free(hid -> ux_host_class_hid_allocated);
@@ -133,7 +148,7 @@ UINT status;
133148
hid_client_command.ux_host_class_hid_client_command_instance = (VOID *) hid;
134149
hid_client_command.ux_host_class_hid_client_command_container = (VOID *) hid -> ux_host_class_hid_class;
135150
hid_client_command.ux_host_class_hid_client_command_request = UX_HOST_CLASS_COMMAND_DEACTIVATE;
136-
151+
137152
/* Call the HID client with a deactivate command if there was a client registered. */
138153
if (hid -> ux_host_class_hid_client != UX_NULL)
139154
hid -> ux_host_class_hid_client -> ux_host_class_hid_client_handler(&hid_client_command);
@@ -143,7 +158,7 @@ UINT status;
143158

144159
/* The enumeration thread needs to sleep a while to allow the application or the class that may be using
145160
endpoints to exit properly. */
146-
_ux_host_thread_schedule_other(UX_THREAD_PRIORITY_ENUM);
161+
_ux_host_thread_schedule_other(UX_THREAD_PRIORITY_ENUM);
147162

148163
/* Destroy the instance. */
149164
_ux_host_stack_class_instance_destroy(hid -> ux_host_class_hid_class, (VOID *) hid);
@@ -155,7 +170,7 @@ UINT status;
155170
that the device is removed. */
156171
if (_ux_system_host -> ux_system_host_change_function != UX_NULL)
157172
{
158-
173+
159174
/* Inform the application the device is removed. */
160175
_ux_system_host -> ux_system_host_change_function(UX_DEVICE_REMOVAL, hid -> ux_host_class_hid_class, (VOID *) hid);
161176
}
@@ -170,6 +185,5 @@ UINT status;
170185
_ux_utility_memory_free(hid);
171186

172187
/* Return successful completion. */
173-
return(UX_SUCCESS);
188+
return(UX_SUCCESS);
174189
}
175-

0 commit comments

Comments
 (0)