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 /** Generic Serial Host module 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_gser.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_host_class_gser_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 gser 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 Swar 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 */
61 /* Abort endpoint transfer */
62 /* _ux_utility_memory_free Free memory block */
63 /* _ux_host_semaphore_delete Delete protection semaphore */
64 /* _ux_utility_thread_schedule_other Schedule other threads */
65 /* */
66 /* CALLED BY */
67 /* */
68 /* _ux_host_class_gser_entry Entry of gser 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 /* refined macros names, */
79 /* resulting in version 6.1.10 */
80 /* */
81 /**************************************************************************/
_ux_host_class_gser_deactivate(UX_HOST_CLASS_COMMAND * command)82 UINT _ux_host_class_gser_deactivate(UX_HOST_CLASS_COMMAND *command)
83 {
84
85 UX_HOST_CLASS_GSER *gser;
86 ULONG interface_index;
87
88 /* Get the instance for this class. */
89 gser = (UX_HOST_CLASS_GSER *) command -> ux_host_class_command_instance;
90
91 /* The gser class is being shut down. */
92 gser -> ux_host_class_gser_state = UX_HOST_CLASS_INSTANCE_SHUTDOWN;
93
94 for (interface_index = 0; interface_index < UX_HOST_CLASS_GSER_INTERFACE_NUMBER; interface_index++)
95 {
96
97 /* We need to abort transactions on the bulk Out pipes. */
98 _ux_host_stack_endpoint_transfer_abort(gser -> ux_host_class_gser_interface_array[interface_index].ux_host_class_gser_bulk_out_endpoint);
99
100 /* We need to abort transactions on the bulk In pipes. */
101 _ux_host_stack_endpoint_transfer_abort(gser -> ux_host_class_gser_interface_array[interface_index].ux_host_class_gser_bulk_in_endpoint);
102
103 /* The enumeration thread needs to sleep a while to allow the application or the class that may be using
104 endpoints to exit properly. */
105 _ux_host_thread_schedule_other(UX_THREAD_PRIORITY_ENUM);
106
107 /* Destroy the semaphore. */
108 _ux_host_semaphore_delete(&gser -> ux_host_class_gser_interface_array[interface_index].ux_host_class_gser_semaphore);
109
110 }
111
112 /* Destroy the instance. */
113 _ux_host_stack_class_instance_destroy(gser -> ux_host_class_gser_class, (VOID *) gser);
114
115 /* Before we free the device resources, we need to inform the application
116 that the device is removed. */
117 if (_ux_system_host -> ux_system_host_change_function != UX_NULL)
118 {
119
120 /* Inform the application the device is removed. */
121 _ux_system_host -> ux_system_host_change_function(UX_DEVICE_REMOVAL, gser -> ux_host_class_gser_class, (VOID *) gser);
122 }
123 /* If trace is enabled, insert this event into the trace buffer. */
124 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_GSER_DEACTIVATE, gser, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
125
126 /* If trace is enabled, register this object. */
127 UX_TRACE_OBJECT_UNREGISTER(gser);
128
129 /* Free the gser instance memory. */
130 _ux_utility_memory_free(gser);
131
132 /* Return successful status. */
133 return(UX_SUCCESS);
134 }
135
136