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 Sierra Wireless AR 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_swar.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_host_class_swar_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 swar 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_get Get protection semaphore */
64 /* _ux_host_semaphore_delete Delete protection semaphore */
65 /* _ux_utility_thread_schedule_other Schedule other threads */
66 /* */
67 /* CALLED BY */
68 /* */
69 /* _ux_host_class_swar_entry Entry of swar class */
70 /* */
71 /* RELEASE HISTORY */
72 /* */
73 /* DATE NAME DESCRIPTION */
74 /* */
75 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
76 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
77 /* resulting in version 6.1 */
78 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
79 /* refined macros names, */
80 /* resulting in version 6.1.10 */
81 /* */
82 /**************************************************************************/
_ux_host_class_swar_deactivate(UX_HOST_CLASS_COMMAND * command)83 UINT _ux_host_class_swar_deactivate(UX_HOST_CLASS_COMMAND *command)
84 {
85
86 UX_HOST_CLASS_SWAR *swar;
87 UINT status;
88
89
90 /* Get the instance for this class. */
91 swar = (UX_HOST_CLASS_SWAR *) command -> ux_host_class_command_instance;
92
93 /* The swar is being shut down. */
94 swar -> ux_host_class_swar_state = UX_HOST_CLASS_INSTANCE_SHUTDOWN;
95
96 /* Protect thread reentry to this instance. */
97 status = _ux_host_semaphore_get(&swar -> ux_host_class_swar_semaphore, UX_WAIT_FOREVER);
98 if (status != UX_SUCCESS)
99 {
100
101 /* Error trap. */
102 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
103
104 /* If trace is enabled, insert this event into the trace buffer. */
105 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, swar, 0, 0, UX_TRACE_ERRORS, 0, 0)
106
107 return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
108 }
109
110 /* We need to abort transactions on the bulk Out pipe. */
111 _ux_host_stack_endpoint_transfer_abort(swar -> ux_host_class_swar_bulk_out_endpoint);
112
113 /* We need to abort transactions on the bulk In pipe. */
114 _ux_host_stack_endpoint_transfer_abort(swar -> ux_host_class_swar_bulk_in_endpoint);
115
116 /* The enumeration thread needs to sleep a while to allow the application or the class that may be using
117 endpoints to exit properly. */
118 _ux_host_thread_schedule_other(UX_THREAD_PRIORITY_ENUM);
119
120 /* Destroy the instance. */
121 _ux_host_stack_class_instance_destroy(swar -> ux_host_class_swar_class, (VOID *) swar);
122
123 /* Destroy the semaphore. */
124 _ux_host_semaphore_delete(&swar -> ux_host_class_swar_semaphore);
125
126 /* Before we free the device resources, we need to inform the application
127 that the device is removed. */
128 if (_ux_system_host -> ux_system_host_change_function != UX_NULL)
129 {
130
131 /* Inform the application the device is removed. */
132 _ux_system_host -> ux_system_host_change_function(UX_DEVICE_REMOVAL, swar -> ux_host_class_swar_class, (VOID *) swar);
133 }
134 /* If trace is enabled, insert this event into the trace buffer. */
135 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_SWAR_DEACTIVATE, swar, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
136
137 /* If trace is enabled, register this object. */
138 UX_TRACE_OBJECT_UNREGISTER(swar);
139
140 /* Free the swar instance memory. */
141 _ux_utility_memory_free(swar);
142
143 /* Return successful status. */
144 return(UX_SUCCESS);
145 }
146
147