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 /** Device Data Pump Class */
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_class_dpump.h"
30 #include "ux_device_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_device_class_dpump_deactivate PORTABLE C */
38 /* 6.1.12 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function deactivate an instance of the dpump class. */
46 /* */
47 /* INPUT */
48 /* */
49 /* command Pointer to a class command */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* Completion Status */
54 /* */
55 /* CALLS */
56 /* */
57 /* _ux_device_stack_transfer_all_request_abort Abort all transfers */
58 /* */
59 /* CALLED BY */
60 /* */
61 /* Device Data Pump 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 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
71 /* fixed parameter/variable */
72 /* names conflict C++ keyword, */
73 /* resulting in version 6.1.12 */
74 /* */
75 /**************************************************************************/
_ux_device_class_dpump_deactivate(UX_SLAVE_CLASS_COMMAND * command)76 UINT _ux_device_class_dpump_deactivate(UX_SLAVE_CLASS_COMMAND *command)
77 {
78
79 UX_SLAVE_INTERFACE *interface_ptr;
80 UX_SLAVE_CLASS *class_ptr;
81 UX_SLAVE_CLASS_DPUMP *dpump;
82 UX_SLAVE_ENDPOINT *endpoint_in;
83 UX_SLAVE_ENDPOINT *endpoint_out;
84
85 /* Get the class container. */
86 class_ptr = command -> ux_slave_class_command_class_ptr;
87
88 /* Store the class instance in the container. */
89 dpump = (UX_SLAVE_CLASS_DPUMP *) class_ptr -> ux_slave_class_instance;
90
91 /* We need the interface to the class. */
92 interface_ptr = dpump -> ux_slave_class_dpump_interface;
93
94 /* Locate the endpoints. */
95 endpoint_in = interface_ptr -> ux_slave_interface_first_endpoint;
96
97 /* Check the endpoint direction, if IN we have the correct endpoint. */
98 if ((endpoint_in -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) != UX_ENDPOINT_IN)
99 {
100
101 /* Wrong direction, we found the OUT endpoint first. */
102 endpoint_out = endpoint_in;
103
104 /* So the next endpoint has to be the IN endpoint. */
105 endpoint_in = endpoint_out -> ux_slave_endpoint_next_endpoint;
106 }
107 else
108 {
109
110 /* We found the endpoint IN first, so next endpoint is OUT. */
111 endpoint_out = endpoint_in -> ux_slave_endpoint_next_endpoint;
112 }
113
114 /* Terminate the transactions pending on the endpoints. */
115 _ux_device_stack_transfer_all_request_abort(endpoint_in, UX_TRANSFER_BUS_RESET);
116 _ux_device_stack_transfer_all_request_abort(endpoint_out, UX_TRANSFER_BUS_RESET);
117
118 /* If there is a deactivate function call it. */
119 if (dpump -> ux_slave_class_dpump_parameter.ux_slave_class_dpump_instance_deactivate != UX_NULL)
120 {
121
122 /* Invoke the application. */
123 dpump -> ux_slave_class_dpump_parameter.ux_slave_class_dpump_instance_deactivate(dpump);
124 }
125
126 /* If trace is enabled, insert this event into the trace buffer. */
127 UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_DPUMP_DEACTIVATE, dpump, 0, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
128
129 /* If trace is enabled, register this object. */
130 UX_TRACE_OBJECT_UNREGISTER(dpump);
131
132 /* Return completion status. */
133 return(UX_SUCCESS);
134 }
135
136