1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
10 |
|
|
**************************************************************************/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/**************************************************************************/ |
15 |
|
|
/** */ |
16 |
|
|
/** USBX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** Device Stack */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
/**************************************************************************/ |
22 |
|
|
|
23 |
|
|
#define UX_SOURCE_CODE |
24 |
|
|
|
25 |
|
|
|
26 |
|
|
/* Include necessary system files. */ |
27 |
|
|
|
28 |
|
|
#include "ux_api.h" |
29 |
|
|
#include "ux_device_stack.h" |
30 |
|
|
|
31 |
|
|
/**************************************************************************/ |
32 |
|
|
/* */ |
33 |
|
|
/* FUNCTION RELEASE */ |
34 |
|
|
/* */ |
35 |
|
|
/* _ux_device_stack_uninitialize PORTABLE C */ |
36 |
|
|
/* 6.3.0 */ |
37 |
|
|
/* AUTHOR */ |
38 |
|
|
/* */ |
39 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
40 |
|
|
/* */ |
41 |
|
|
/* DESCRIPTION */ |
42 |
|
|
/* */ |
43 |
|
|
/* This function uninitializes the generic portion of the device side */ |
44 |
|
|
/* of USBX. */ |
45 |
|
|
/* */ |
46 |
|
|
/* INPUT */ |
47 |
|
|
/* */ |
48 |
|
|
/* OUTPUT */ |
49 |
|
|
/* */ |
50 |
|
|
/* Completion Status */ |
51 |
|
|
/* */ |
52 |
|
|
/* CALLS */ |
53 |
|
|
/* */ |
54 |
|
|
/* _ux_utility_memory_free Free */ |
55 |
|
|
/* _ux_utility_semaphore_delete Delete semaphore */ |
56 |
|
|
/* */ |
57 |
|
|
/* CALLED BY */ |
58 |
|
|
/* */ |
59 |
|
|
/* Application */ |
60 |
|
|
/* */ |
61 |
|
|
/**************************************************************************/ |
62 |
|
220 |
UINT _ux_device_stack_uninitialize(VOID) |
63 |
|
|
{ |
64 |
|
|
UX_SLAVE_DEVICE *device; |
65 |
|
|
UX_SLAVE_ENDPOINT *endpoints_pool; |
66 |
|
|
UX_SLAVE_TRANSFER *transfer_request; |
67 |
|
|
ULONG endpoints_found; |
68 |
|
|
|
69 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
70 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_STACK_INITIALIZE, 0, 0, 0, 0, UX_TRACE_DEVICE_STACK_EVENTS, 0, 0) |
71 |
|
|
|
72 |
|
|
/* Get the pointer to the device. */ |
73 |
|
220 |
device = &_ux_system_slave -> ux_system_slave_device; |
74 |
|
|
|
75 |
|
|
/* Free class memory. */ |
76 |
|
220 |
_ux_utility_memory_free(_ux_system_slave -> ux_system_slave_class_array); |
77 |
|
|
|
78 |
|
|
/* Allocate some memory for the Control Endpoint. First get the address of the transfer request for the |
79 |
|
|
control endpoint. */ |
80 |
|
220 |
transfer_request = &device -> ux_slave_device_control_endpoint.ux_slave_endpoint_transfer_request; |
81 |
|
|
|
82 |
|
|
/* Free memory for the control endpoint buffer. */ |
83 |
|
220 |
_ux_utility_memory_free(transfer_request -> ux_slave_transfer_request_data_pointer); |
84 |
|
|
|
85 |
|
|
/* Get the number of endpoints found in the device framework. */ |
86 |
|
220 |
endpoints_found = device -> ux_slave_device_endpoints_pool_number; |
87 |
|
|
|
88 |
|
|
/* Get the endpoint pool address in the device container. */ |
89 |
|
220 |
endpoints_pool = device -> ux_slave_device_endpoints_pool; |
90 |
|
|
|
91 |
|
|
/* Parse all endpoints and fee memory and semaphore. */ |
92 |
✓✓ |
594 |
while (endpoints_found-- != 0) |
93 |
|
|
{ |
94 |
|
|
|
95 |
|
|
#if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 0 |
96 |
|
|
|
97 |
|
|
/* Free the memory for endpoint data pointer. */ |
98 |
|
374 |
_ux_utility_memory_free(endpoints_pool -> ux_slave_endpoint_transfer_request.ux_slave_transfer_request_data_pointer); |
99 |
|
|
#endif |
100 |
|
|
|
101 |
|
|
/* Remove the TX semaphore for the endpoint. */ |
102 |
|
374 |
_ux_device_semaphore_delete(&endpoints_pool -> ux_slave_endpoint_transfer_request.ux_slave_transfer_request_semaphore); |
103 |
|
|
|
104 |
|
|
/* Next endpoint. */ |
105 |
|
374 |
endpoints_pool++; |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
/* Free the endpoint pool address in the device container. */ |
109 |
✓✓ |
220 |
if (device -> ux_slave_device_endpoints_pool) |
110 |
|
217 |
_ux_utility_memory_free(device -> ux_slave_device_endpoints_pool); |
111 |
|
|
|
112 |
|
|
/* Free memory for interface pool. */ |
113 |
|
220 |
_ux_utility_memory_free(device -> ux_slave_device_interfaces_pool); |
114 |
|
|
|
115 |
|
|
/* Return successful completion. */ |
116 |
|
220 |
return(UX_SUCCESS); |
117 |
|
|
} |
118 |
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
|