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