1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
10 |
|
|
**************************************************************************/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/**************************************************************************/ |
15 |
|
|
/** */ |
16 |
|
|
/** USBX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** HID Class */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
/**************************************************************************/ |
22 |
|
|
|
23 |
|
|
|
24 |
|
|
/* Include necessary system files. */ |
25 |
|
|
|
26 |
|
|
#define UX_SOURCE_CODE |
27 |
|
|
|
28 |
|
|
#include "ux_api.h" |
29 |
|
|
#include "ux_host_class_hid.h" |
30 |
|
|
#include "ux_host_stack.h" |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _ux_host_class_hid_deactivate PORTABLE C */ |
38 |
|
|
/* 6.1.10 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function is called when this instance of the HID has been */ |
46 |
|
|
/* removed from the bus either directly or indirectly. The interrupt */ |
47 |
|
|
/* pipe will be destroyed and the instanced removed. */ |
48 |
|
|
/* */ |
49 |
|
|
/* INPUT */ |
50 |
|
|
/* */ |
51 |
|
|
/* command Pointer to command */ |
52 |
|
|
/* */ |
53 |
|
|
/* OUTPUT */ |
54 |
|
|
/* */ |
55 |
|
|
/* Completion Status */ |
56 |
|
|
/* */ |
57 |
|
|
/* CALLS */ |
58 |
|
|
/* */ |
59 |
|
|
/* (ux_host_class_hid_client_handler) HID client handler */ |
60 |
|
|
/* _ux_host_class_hid_instance_clean HID instance clean */ |
61 |
|
|
/* _ux_host_stack_class_instance_destroy Destroy the class instance */ |
62 |
|
|
/* _ux_host_stack_endpoint_transfer_abort */ |
63 |
|
|
/* Abort transfer */ |
64 |
|
|
/* _ux_utility_memory_free Release memory block */ |
65 |
|
|
/* _ux_host_semaphore_delete Delete semaphore */ |
66 |
|
|
/* _ux_host_semaphore_get Get semaphore */ |
67 |
|
|
/* */ |
68 |
|
|
/* CALLED BY */ |
69 |
|
|
/* */ |
70 |
|
|
/* HID Class */ |
71 |
|
|
/* */ |
72 |
|
|
/**************************************************************************/ |
73 |
|
168 |
UINT _ux_host_class_hid_deactivate(UX_HOST_CLASS_COMMAND *command) |
74 |
|
|
{ |
75 |
|
|
|
76 |
|
|
UX_HOST_CLASS_HID *hid; |
77 |
|
|
UX_HOST_CLASS_HID_CLIENT_COMMAND hid_client_command; |
78 |
|
|
UX_TRANSFER *transfer_request; |
79 |
|
|
#if !defined(UX_HOST_STANDALONE) |
80 |
|
|
UINT status; |
81 |
|
|
#endif |
82 |
|
|
|
83 |
|
|
|
84 |
|
|
/* Get the instance for this class. */ |
85 |
|
168 |
hid = (UX_HOST_CLASS_HID *) command -> ux_host_class_command_instance; |
86 |
|
|
|
87 |
|
|
/* The HID is being shut down. */ |
88 |
|
168 |
hid -> ux_host_class_hid_state = UX_HOST_CLASS_INSTANCE_SHUTDOWN; |
89 |
|
|
|
90 |
|
|
#if !defined(UX_HOST_STANDALONE) |
91 |
|
|
|
92 |
|
|
/* Protect thread reentry to this instance. */ |
93 |
|
168 |
status = _ux_host_semaphore_get(&hid -> ux_host_class_hid_semaphore, UX_WAIT_FOREVER); |
94 |
✓✓ |
168 |
if (status != UX_SUCCESS) |
95 |
|
|
|
96 |
|
|
/* Return error. */ |
97 |
|
1 |
return(status); |
98 |
|
|
#endif |
99 |
|
|
|
100 |
|
|
#if defined(UX_HOST_STANDALONE) |
101 |
|
|
if (hid -> ux_host_class_hid_interrupt_endpoint) |
102 |
|
|
#endif |
103 |
|
|
{ |
104 |
|
|
|
105 |
|
|
/* We need to abort transactions on the interrupt pipe. */ |
106 |
|
167 |
_ux_host_stack_endpoint_transfer_abort(hid -> ux_host_class_hid_interrupt_endpoint); |
107 |
|
|
|
108 |
|
|
/* If the Hid class instance has a interrupt pipe with a data payload associated with it |
109 |
|
|
it must be freed. */ |
110 |
|
167 |
transfer_request = &hid -> ux_host_class_hid_interrupt_endpoint -> ux_endpoint_transfer_request; |
111 |
|
|
|
112 |
|
|
/* Then de allocate the memory. */ |
113 |
|
167 |
_ux_utility_memory_free(transfer_request -> ux_transfer_request_data_pointer); |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
#if defined(UX_HOST_CLASS_HID_INTERRUPT_OUT_SUPPORT) |
117 |
|
|
if (hid -> ux_host_class_hid_interrupt_out_endpoint) |
118 |
|
|
{ |
119 |
|
|
|
120 |
|
|
/* We need to abort transactions on the interrupt pipe. */ |
121 |
|
|
_ux_host_stack_endpoint_transfer_abort(hid -> ux_host_class_hid_interrupt_out_endpoint); |
122 |
|
|
|
123 |
|
|
/* If the Hid class instance has a interrupt pipe with a data payload associated with it |
124 |
|
|
it must be freed. */ |
125 |
|
|
transfer_request = &hid -> ux_host_class_hid_interrupt_out_endpoint -> ux_endpoint_transfer_request; |
126 |
|
|
|
127 |
|
|
/* Then de allocate the memory. */ |
128 |
|
|
_ux_utility_memory_free(transfer_request -> ux_transfer_request_data_pointer); |
129 |
|
|
} |
130 |
|
|
#endif |
131 |
|
|
|
132 |
|
|
#if defined(UX_HOST_STANDALONE) |
133 |
|
|
if (hid -> ux_host_class_hid_allocated) |
134 |
|
|
_ux_utility_memory_free(hid -> ux_host_class_hid_allocated); |
135 |
|
|
#endif |
136 |
|
|
|
137 |
|
|
/* We need to inform the HID client, if any, of the deactivation. */ |
138 |
|
167 |
hid_client_command.ux_host_class_hid_client_command_instance = (VOID *) hid; |
139 |
|
167 |
hid_client_command.ux_host_class_hid_client_command_container = (VOID *) hid -> ux_host_class_hid_class; |
140 |
|
167 |
hid_client_command.ux_host_class_hid_client_command_request = UX_HOST_CLASS_COMMAND_DEACTIVATE; |
141 |
|
|
|
142 |
|
|
/* Call the HID client with a deactivate command if there was a client registered. */ |
143 |
✓✓ |
167 |
if (hid -> ux_host_class_hid_client != UX_NULL) |
144 |
|
121 |
hid -> ux_host_class_hid_client -> ux_host_class_hid_client_handler(&hid_client_command); |
145 |
|
|
|
146 |
|
|
/* Clean all the HID memory fields. */ |
147 |
|
167 |
_ux_host_class_hid_instance_clean(hid); |
148 |
|
|
|
149 |
|
|
/* The enumeration thread needs to sleep a while to allow the application or the class that may be using |
150 |
|
|
endpoints to exit properly. */ |
151 |
|
167 |
_ux_host_thread_schedule_other(UX_THREAD_PRIORITY_ENUM); |
152 |
|
|
|
153 |
|
|
/* Destroy the instance. */ |
154 |
|
167 |
_ux_host_stack_class_instance_destroy(hid -> ux_host_class_hid_class, (VOID *) hid); |
155 |
|
|
|
156 |
|
|
/* Destroy the semaphore. */ |
157 |
|
167 |
_ux_host_semaphore_delete(&hid -> ux_host_class_hid_semaphore); |
158 |
|
|
|
159 |
|
|
/* Before we free the device resources, we need to inform the application |
160 |
|
|
that the device is removed. */ |
161 |
✓✓ |
167 |
if (_ux_system_host -> ux_system_host_change_function != UX_NULL) |
162 |
|
|
{ |
163 |
|
|
|
164 |
|
|
/* Inform the application the device is removed. */ |
165 |
|
151 |
_ux_system_host -> ux_system_host_change_function(UX_DEVICE_REMOVAL, hid -> ux_host_class_hid_class, (VOID *) hid); |
166 |
|
|
} |
167 |
|
|
|
168 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
169 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_HID_DEACTIVATE, hid, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0) |
170 |
|
|
|
171 |
|
|
/* If trace is enabled, register this object. */ |
172 |
|
|
UX_TRACE_OBJECT_UNREGISTER(hid); |
173 |
|
|
|
174 |
|
|
/* The HID is now free again. */ |
175 |
|
167 |
_ux_utility_memory_free(hid); |
176 |
|
|
|
177 |
|
|
/* Return successful completion. */ |
178 |
|
167 |
return(UX_SUCCESS); |
179 |
|
|
} |