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