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 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   Device CDC 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_acm.h"
29 #include "ux_device_stack.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_device_class_cdc_acm_uninitialize               PORTABLE C      */
37 /*                                                           6.1.12       */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function uninitialize the cdc-acm class.                       */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    command                               Pointer to a class command    */
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    Completion Status                                                   */
53 /*                                                                        */
54 /*  CALLS                                                                 */
55 /*                                                                        */
56 /*    _ux_device_mutex_delete               Delete Mutex                  */
57 /*    _ux_utility_memory_free               Free used local memory        */
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    CDC Class                                                           */
62 /*                                                                        */
63 /*  RELEASE HISTORY                                                       */
64 /*                                                                        */
65 /*    DATE              NAME                      DESCRIPTION             */
66 /*                                                                        */
67 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
68 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
69 /*                                            resulting in version 6.1    */
70 /*  04-02-2021     Chaoqiong Xiao           Modified comment(s),          */
71 /*                                            added macro to disable      */
72 /*                                            transmission support,       */
73 /*                                            moved transmission resource */
74 /*                                            free to here (uninit),      */
75 /*                                            resulting in version 6.1.6  */
76 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
77 /*                                            added standalone support,   */
78 /*                                            resulting in version 6.1.10 */
79 /*  04-25-2022     Chaoqiong Xiao           Modified comment(s),          */
80 /*                                            resulting in version 6.1.11 */
81 /*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
82 /*                                            fixed parameter/variable    */
83 /*                                            names conflict C++ keyword, */
84 /*                                            resulting in version 6.1.12 */
85 /*                                                                        */
86 /**************************************************************************/
_ux_device_class_cdc_acm_uninitialize(UX_SLAVE_CLASS_COMMAND * command)87 UINT  _ux_device_class_cdc_acm_uninitialize(UX_SLAVE_CLASS_COMMAND *command)
88 {
89 
90 UX_SLAVE_CLASS_CDC_ACM      *cdc_acm;
91 UX_SLAVE_CLASS              *class_ptr;
92 
93     /* Get the class container.  */
94     class_ptr =  command -> ux_slave_class_command_class_ptr;
95 
96     /* Get the class instance in the container.  */
97     cdc_acm = (UX_SLAVE_CLASS_CDC_ACM *) class_ptr -> ux_slave_class_instance;
98 
99     /* Sanity check.  */
100     if (cdc_acm != UX_NULL)
101     {
102 
103 #if !defined(UX_DEVICE_STANDALONE)
104 
105         /* Delete the IN endpoint mutex.  */
106         _ux_device_mutex_delete(&cdc_acm -> ux_slave_class_cdc_acm_endpoint_in_mutex);
107 
108         /* Out Mutex. */
109         _ux_device_mutex_delete(&cdc_acm -> ux_slave_class_cdc_acm_endpoint_out_mutex);
110 
111 #ifndef UX_DEVICE_CLASS_CDC_ACM_TRANSMISSION_DISABLE
112 
113         /* Free resources and return error.  */
114         _ux_utility_thread_delete(&cdc_acm -> ux_slave_class_cdc_acm_bulkin_thread);
115         _ux_utility_thread_delete(&cdc_acm -> ux_slave_class_cdc_acm_bulkout_thread);
116         _ux_utility_event_flags_delete(&cdc_acm -> ux_slave_class_cdc_acm_event_flags_group);
117         _ux_utility_memory_free(cdc_acm -> ux_slave_class_cdc_acm_bulkout_thread_stack);
118 #endif
119 #endif
120 
121         /* Free the resources.  */
122         _ux_utility_memory_free(cdc_acm);
123 
124     }
125 
126     /* Return completion status.  */
127     return(UX_SUCCESS);
128 }
129 
130