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 /** Generic Serial Host module class */
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_class_gser.h"
29 #include "ux_host_stack.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _ux_host_class_gser_deactivate PORTABLE C */
37 /* 6.1.10 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function is called when this instance of the gser has been */
45 /* removed from the bus either directly or indirectly. The bulk in\out */
46 /* pipes will be destroyed and the instanced removed. */
47 /* */
48 /* INPUT */
49 /* */
50 /* command Swar class command pointer */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* Completion Status */
55 /* */
56 /* CALLS */
57 /* */
58 /* _ux_host_stack_class_instance_destroy Destroy the class instance */
59 /* _ux_host_stack_endpoint_transfer_abort */
60 /* Abort endpoint transfer */
61 /* _ux_utility_memory_free Free memory block */
62 /* _ux_host_semaphore_delete Delete protection semaphore */
63 /* _ux_utility_thread_schedule_other Schedule other threads */
64 /* */
65 /* CALLED BY */
66 /* */
67 /* _ux_host_class_gser_entry Entry of gser class */
68 /* */
69 /* RELEASE HISTORY */
70 /* */
71 /* DATE NAME DESCRIPTION */
72 /* */
73 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
74 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
75 /* resulting in version 6.1 */
76 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
77 /* refined macros names, */
78 /* resulting in version 6.1.10 */
79 /* */
80 /**************************************************************************/
_ux_host_class_gser_deactivate(UX_HOST_CLASS_COMMAND * command)81 UINT _ux_host_class_gser_deactivate(UX_HOST_CLASS_COMMAND *command)
82 {
83
84 UX_HOST_CLASS_GSER *gser;
85 ULONG interface_index;
86
87 /* Get the instance for this class. */
88 gser = (UX_HOST_CLASS_GSER *) command -> ux_host_class_command_instance;
89
90 /* The gser class is being shut down. */
91 gser -> ux_host_class_gser_state = UX_HOST_CLASS_INSTANCE_SHUTDOWN;
92
93 for (interface_index = 0; interface_index < UX_HOST_CLASS_GSER_INTERFACE_NUMBER; interface_index++)
94 {
95
96 /* We need to abort transactions on the bulk Out pipes. */
97 _ux_host_stack_endpoint_transfer_abort(gser -> ux_host_class_gser_interface_array[interface_index].ux_host_class_gser_bulk_out_endpoint);
98
99 /* We need to abort transactions on the bulk In pipes. */
100 _ux_host_stack_endpoint_transfer_abort(gser -> ux_host_class_gser_interface_array[interface_index].ux_host_class_gser_bulk_in_endpoint);
101
102 /* The enumeration thread needs to sleep a while to allow the application or the class that may be using
103 endpoints to exit properly. */
104 _ux_host_thread_schedule_other(UX_THREAD_PRIORITY_ENUM);
105
106 /* Destroy the semaphore. */
107 _ux_host_semaphore_delete(&gser -> ux_host_class_gser_interface_array[interface_index].ux_host_class_gser_semaphore);
108
109 }
110
111 /* Destroy the instance. */
112 _ux_host_stack_class_instance_destroy(gser -> ux_host_class_gser_class, (VOID *) gser);
113
114 /* Before we free the device resources, we need to inform the application
115 that the device is removed. */
116 if (_ux_system_host -> ux_system_host_change_function != UX_NULL)
117 {
118
119 /* Inform the application the device is removed. */
120 _ux_system_host -> ux_system_host_change_function(UX_DEVICE_REMOVAL, gser -> ux_host_class_gser_class, (VOID *) gser);
121 }
122 /* If trace is enabled, insert this event into the trace buffer. */
123 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_GSER_DEACTIVATE, gser, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
124
125 /* If trace is enabled, register this object. */
126 UX_TRACE_OBJECT_UNREGISTER(gser);
127
128 /* Free the gser instance memory. */
129 _ux_utility_memory_free(gser);
130
131 /* Return successful status. */
132 return(UX_SUCCESS);
133 }
134
135