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 Stack */
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_stack.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _ux_host_stack_uninitialize PORTABLE C */
37 /* 6.1.10 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function uninitializes all the host code for USBX to work on a */
45 /* specific platform. */
46 /* */
47 /* Note following steps must be done before host stack uninitialize: */
48 /* All HCDs must be unregistered (devices also removed). */
49 /* All classes unregistered (clients attached also removed). */
50 /* */
51 /* INPUT */
52 /* */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* Completion Status */
57 /* UX_SUCCESS Uninitialized success */
58 /* */
59 /* */
60 /* CALLS */
61 /* */
62 /* _ux_utility_memory_free Free host memory */
63 /* _ux_utility_thread_delete Delete host thread */
64 /* _ux_utility_semaphore_delete Delete host semaphore */
65 /* */
66 /* CALLED BY */
67 /* */
68 /* Application */
69 /* */
70 /* RELEASE HISTORY */
71 /* */
72 /* DATE NAME DESCRIPTION */
73 /* */
74 /* 09-30-2020 Chaoqiong Xiao Initial Version 6.1 */
75 /* 08-02-2021 Xiuwen Cai Modified comment(s), */
76 /* fixed compile issue, */
77 /* resulting in version 6.1.8 */
78 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
79 /* added standalone support, */
80 /* resulting in version 6.1.10 */
81 /* */
82 /**************************************************************************/
_ux_host_stack_uninitialize(VOID)83 UINT _ux_host_stack_uninitialize(VOID)
84 {
85
86 /* If trace is enabled, insert this event into the trace buffer. */
87 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_UNINITIALIZE, 0, 0, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
88
89 #if !defined(UX_HOST_STANDALONE)
90 /* Delete enumeration thread. */
91 _ux_utility_thread_delete(&_ux_system_host -> ux_system_host_enum_thread);
92
93 /* Delete enumeration semaphore. */
94 _ux_utility_semaphore_delete(&_ux_system_host -> ux_system_host_enum_semaphore);
95
96 /* Free enumeration thread stack. */
97 _ux_utility_memory_free(_ux_system_host -> ux_system_host_enum_thread_stack);
98
99 /* Delete HCD thread. */
100 _ux_utility_thread_delete(&_ux_system_host -> ux_system_host_hcd_thread);
101
102 /* Delete HCD semaphore. */
103 _ux_utility_semaphore_delete(&_ux_system_host -> ux_system_host_hcd_semaphore);
104
105 /* Free HCD thread stack. */
106 _ux_utility_memory_free(_ux_system_host -> ux_system_host_hcd_thread_stack);
107 #endif
108
109 #if defined(UX_OTG_SUPPORT) && !defined(UX_OTG_STANDALONE)
110
111 /* Delete HNP thread. */
112 _ux_utility_thread_delete(&_ux_system_host -> ux_system_host_hnp_polling_thread);
113
114 /* Free HNP thread stack. */
115 _ux_utility_memory_free(_ux_system_host -> ux_system_host_hnp_polling_thread_stack);
116 #endif
117
118 /* Free HCD array. */
119 _ux_utility_memory_free(_ux_system_host -> ux_system_host_hcd_array);
120
121 /* Free Class array. */
122 _ux_utility_memory_free(_ux_system_host -> ux_system_host_class_array);
123
124 /* Free Device array. */
125 _ux_utility_memory_free(_ux_system_host -> ux_system_host_device_array);
126
127 /* Return success to caller. */
128 return(UX_SUCCESS);
129 }
130