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 Storage 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_storage.h"
30 #include "ux_device_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_device_class_storage_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 storage 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 Storage 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 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
71 /* added standalone support, */
72 /* resulting in version 6.1.10 */
73 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
74 /* fixed parameter/variable */
75 /* names conflict C++ keyword, */
76 /* resulting in version 6.1.12 */
77 /* */
78 /**************************************************************************/
_ux_device_class_storage_deactivate(UX_SLAVE_CLASS_COMMAND * command)79 UINT _ux_device_class_storage_deactivate(UX_SLAVE_CLASS_COMMAND *command)
80 {
81
82 UX_SLAVE_CLASS_STORAGE *storage;
83 UX_SLAVE_ENDPOINT *endpoint_in;
84 UX_SLAVE_ENDPOINT *endpoint_out;
85 UX_SLAVE_CLASS *class_ptr;
86
87 /* Get the class container. */
88 class_ptr = command -> ux_slave_class_command_class_ptr;
89
90 /* Get the class instance in the container. */
91 storage = (UX_SLAVE_CLASS_STORAGE *)class_ptr -> ux_slave_class_instance;
92
93 #if defined(UX_DEVICE_STANDALONE)
94
95 endpoint_in = storage -> ux_device_class_storage_ep_in;
96 endpoint_out = storage -> ux_device_class_storage_ep_out;
97 _ux_device_stack_transfer_all_request_abort(endpoint_in, UX_TRANSFER_BUS_RESET);
98 _ux_device_stack_transfer_all_request_abort(endpoint_out, UX_TRANSFER_BUS_RESET);
99 endpoint_out -> ux_slave_endpoint_transfer_request.ux_slave_transfer_request_data_pointer =
100 storage -> ux_device_class_storage_buffer[0];
101 endpoint_in -> ux_slave_endpoint_transfer_request.ux_slave_transfer_request_data_pointer =
102 storage -> ux_device_class_storage_buffer[1];
103 #else
104
105 /* Locate the endpoints. */
106 endpoint_in = storage -> ux_slave_class_storage_interface -> ux_slave_interface_first_endpoint;
107
108 /* Check the endpoint direction, if IN we have the correct endpoint. */
109 if ((endpoint_in -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) != UX_ENDPOINT_IN)
110 {
111
112 /* Wrong direction, we found the OUT endpoint first. */
113 endpoint_out = endpoint_in;
114
115 /* So the next endpoint has to be the IN endpoint. */
116 endpoint_in = endpoint_out -> ux_slave_endpoint_next_endpoint;
117 }
118 else
119 {
120
121 /* We found the endpoint IN first, so next endpoint is OUT. */
122 endpoint_out = endpoint_in -> ux_slave_endpoint_next_endpoint;
123 }
124
125 /* Terminate the transactions pending on the endpoints. */
126 _ux_device_stack_transfer_all_request_abort(endpoint_in, UX_TRANSFER_BUS_RESET);
127 _ux_device_stack_transfer_all_request_abort(endpoint_out, UX_TRANSFER_BUS_RESET);
128 #endif
129
130 /* If there is a deactivate function call it. */
131 if (storage -> ux_slave_class_storage_instance_deactivate != UX_NULL)
132 {
133
134 /* Invoke the application. */
135 storage -> ux_slave_class_storage_instance_deactivate(storage);
136 }
137
138 /* If trace is enabled, insert this event into the trace buffer. */
139 UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_STORAGE_DEACTIVATE, storage, 0, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
140
141 /* If trace is enabled, register this object. */
142 UX_TRACE_OBJECT_UNREGISTER(storage);
143
144 /* Return completion status. */
145 return(UX_SUCCESS);
146 }
147
148