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 /** Device CDC-ECM Class */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define UX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "ux_api.h"
28 #include "ux_device_class_cdc_ecm.h"
29 #include "ux_device_stack.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _ux_device_class_cdc_ecm_uninitialize PORTABLE C */
37 /* 6.3.0 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function deinitializes the resources for the specified CDC-ECM */
45 /* instance. */
46 /* */
47 /* INPUT */
48 /* */
49 /* command Pointer to storage command */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* Completion Status */
54 /* */
55 /* CALLS */
56 /* */
57 /* _ux_device_mutex_delete Delete mutex */
58 /* _ux_device_thread_delete Delete thread */
59 /* _ux_utility_memory_free Free memory */
60 /* _ux_utility_event_flags_delete Delete event flags */
61 /* _ux_device_semaphore_delete Delete semaphore */
62 /* */
63 /* CALLED BY */
64 /* */
65 /* Device CDC-ECM Class */
66 /* */
67 /* RELEASE HISTORY */
68 /* */
69 /* DATE NAME DESCRIPTION */
70 /* */
71 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
72 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
73 /* resulting in version 6.1 */
74 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
75 /* refined macros names, */
76 /* resulting in version 6.1.10 */
77 /* 04-25-2022 Chaoqiong Xiao Modified comment(s), */
78 /* fixed standalone compile, */
79 /* resulting in version 6.1.11 */
80 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
81 /* fixed parameter/variable */
82 /* names conflict C++ keyword, */
83 /* resulting in version 6.1.12 */
84 /* 10-31-2022 Chaoqiong Xiao Modified comment(s), */
85 /* removed internal NX pool, */
86 /* resulting in version 6.2.0 */
87 /* 10-31-2023 Chaoqiong Xiao Modified comment(s), */
88 /* added a new mode to manage */
89 /* endpoint buffer in classes, */
90 /* resulting in version 6.3.0 */
91 /* */
92 /**************************************************************************/
_ux_device_class_cdc_ecm_uninitialize(UX_SLAVE_CLASS_COMMAND * command)93 UINT _ux_device_class_cdc_ecm_uninitialize(UX_SLAVE_CLASS_COMMAND *command)
94 {
95
96 UX_SLAVE_CLASS_CDC_ECM *cdc_ecm;
97 UX_SLAVE_CLASS *class_ptr;
98
99
100 /* Get the class container. */
101 class_ptr = command -> ux_slave_class_command_class_ptr;
102
103 /* Get the class instance in the container. */
104 cdc_ecm = (UX_SLAVE_CLASS_CDC_ECM *) class_ptr -> ux_slave_class_instance;
105
106 /* Sanity check. */
107 if (cdc_ecm != UX_NULL)
108 {
109
110 /* Deinitialize resources. We do not check if they have been allocated
111 because if they weren't, the class register (called by the application)
112 would have failed. */
113
114 #if !defined(UX_DEVICE_STANDALONE)
115
116 /* Delete the xmit queue mutex. */
117 _ux_device_mutex_delete(&cdc_ecm -> ux_slave_class_cdc_ecm_mutex);
118
119 /* Delete bulk out thread . */
120 _ux_device_thread_delete(&cdc_ecm -> ux_slave_class_cdc_ecm_bulkout_thread);
121
122 /* Free bulk out thread stack. */
123 _ux_utility_memory_free(cdc_ecm -> ux_slave_class_cdc_ecm_bulkout_thread_stack);
124
125 /* Delete interrupt thread. */
126 _ux_device_thread_delete(&cdc_ecm -> ux_slave_class_cdc_ecm_interrupt_thread);
127
128 /* Free interrupt thread stack. */
129 _ux_utility_memory_free(cdc_ecm -> ux_slave_class_cdc_ecm_interrupt_thread_stack);
130
131 /* Delete bulk in thread. */
132 _ux_device_thread_delete(&cdc_ecm -> ux_slave_class_cdc_ecm_bulkin_thread);
133
134 /* Free bulk in thread stack. */
135 _ux_utility_memory_free(cdc_ecm -> ux_slave_class_cdc_ecm_bulkin_thread_stack);
136
137 /* Delete the interrupt thread sync event flags group. */
138 _ux_device_event_flags_delete(&cdc_ecm -> ux_slave_class_cdc_ecm_event_flags_group);
139
140 #endif
141
142 /* Free the resources. */
143 #if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1
144 _ux_utility_memory_free(cdc_ecm -> ux_device_class_cdc_ecm_endpoint_buffer);
145 #endif
146 _ux_utility_memory_free(cdc_ecm);
147 }
148
149 /* Return completion status. */
150 return(UX_SUCCESS);
151 }
152