1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** USBX Component */
17 /** */
18 /** Host Data Pump 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_dpump.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_host_class_dpump_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 dpump has been */
46 /* removed from the bus either directly or indirectly. The bulk in\out */
47 /* pipes will be destroyed and the instanced removed. */
48 /* */
49 /* INPUT */
50 /* */
51 /* command Data Pump class command pointer */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* Completion Status */
56 /* */
57 /* CALLS */
58 /* */
59 /* _ux_host_stack_class_instance_destroy Destroy the class instance */
60 /* _ux_host_stack_endpoint_transfer_abort Abort endpoint transfer */
61 /* _ux_utility_memory_free Free memory block */
62 /* _ux_utility_semaphore_get Get protection semaphore */
63 /* _ux_utility_semaphore_delete Delete protection semaphore */
64 /* _ux_utility_thread_sleep Sleep thread */
65 /* */
66 /* CALLED BY */
67 /* */
68 /* _ux_host_class_dpump_entry Entry of dpump class */
69 /* */
70 /* RELEASE HISTORY */
71 /* */
72 /* DATE NAME DESCRIPTION */
73 /* */
74 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
75 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
76 /* resulting in version 6.1 */
77 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
78 /* added standalone support, */
79 /* resulting in version 6.1.10 */
80 /* */
81 /**************************************************************************/
_ux_host_class_dpump_deactivate(UX_HOST_CLASS_COMMAND * command)82 UINT _ux_host_class_dpump_deactivate(UX_HOST_CLASS_COMMAND *command)
83 {
84
85 UX_HOST_CLASS_DPUMP *dpump;
86 UINT status;
87
88
89 /* Get the instance for this class. */
90 dpump = (UX_HOST_CLASS_DPUMP *) command -> ux_host_class_command_instance;
91
92 /* The dpump is being shut down. */
93 dpump -> ux_host_class_dpump_state = UX_HOST_CLASS_INSTANCE_SHUTDOWN;
94
95 /* Protect thread reentry to this instance. */
96 status = _ux_host_semaphore_get(&dpump -> ux_host_class_dpump_semaphore, UX_WAIT_FOREVER);
97 if (status != UX_SUCCESS)
98 {
99
100 /* If trace is enabled, insert this event into the trace buffer. */
101 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, dpump, 0, 0, UX_TRACE_ERRORS, 0, 0)
102
103 return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
104 }
105
106 /* We need to abort transactions on the bulk Out pipe. */
107 _ux_host_stack_endpoint_transfer_abort(dpump -> ux_host_class_dpump_bulk_out_endpoint);
108
109 /* We need to abort transactions on the bulk In pipe. */
110 _ux_host_stack_endpoint_transfer_abort(dpump -> ux_host_class_dpump_bulk_in_endpoint);
111
112 /* If the class instance was busy, let it finish properly and not return. */
113 _ux_host_thread_sleep(UX_ENUMERATION_THREAD_WAIT);
114
115 /* Destroy the instance. */
116 _ux_host_stack_class_instance_destroy(dpump -> ux_host_class_dpump_class, (VOID *) dpump);
117
118 /* Destroy the semaphore. */
119 _ux_host_semaphore_delete(&dpump -> ux_host_class_dpump_semaphore);
120
121 /* Before we free the device resources, we need to inform the application
122 that the device is removed. */
123 if (_ux_system_host -> ux_system_host_change_function != UX_NULL)
124 {
125
126 /* Inform the application the device is removed. */
127 _ux_system_host -> ux_system_host_change_function(UX_DEVICE_REMOVAL, dpump -> ux_host_class_dpump_class, (VOID *) dpump);
128 }
129 /* If trace is enabled, insert this event into the trace buffer. */
130 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_DPUMP_DEACTIVATE, dpump, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
131
132 /* If trace is enabled, register this object. */
133 UX_TRACE_OBJECT_UNREGISTER(dpump);
134
135 /* Free the dpump instance memory. */
136 _ux_utility_memory_free(dpump);
137
138 /* Return successful status. */
139 return(UX_SUCCESS);
140 }
141
142