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 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_activate PORTABLE C */ |
38 |
|
|
/* 6.3.0 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function activates the USB storage device. */ |
46 |
|
|
/* */ |
47 |
|
|
/* INPUT */ |
48 |
|
|
/* */ |
49 |
|
|
/* command Pointer to storage command */ |
50 |
|
|
/* */ |
51 |
|
|
/* OUTPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* Completion Status */ |
54 |
|
|
/* */ |
55 |
|
|
/* CALLS */ |
56 |
|
|
/* */ |
57 |
|
|
/* _ux_device_thread_resume Resume thread */ |
58 |
|
|
/* */ |
59 |
|
|
/* CALLED BY */ |
60 |
|
|
/* */ |
61 |
|
|
/* Device Storage Class */ |
62 |
|
|
/* */ |
63 |
|
|
/**************************************************************************/ |
64 |
|
140 |
UINT _ux_device_class_storage_activate(UX_SLAVE_CLASS_COMMAND *command) |
65 |
|
|
{ |
66 |
|
|
|
67 |
|
140 |
UINT status = UX_SUCCESS; |
68 |
|
|
UX_SLAVE_INTERFACE *interface_ptr; |
69 |
|
|
UX_SLAVE_CLASS *class_ptr; |
70 |
|
|
UX_SLAVE_CLASS_STORAGE *storage; |
71 |
|
|
ULONG lun_index; |
72 |
|
|
#if defined(UX_DEVICE_STANDALONE) |
73 |
|
|
UX_SLAVE_ENDPOINT *endpoint; |
74 |
|
|
#endif |
75 |
|
|
|
76 |
|
|
|
77 |
|
|
/* Get the class container. */ |
78 |
|
140 |
class_ptr = command -> ux_slave_class_command_class_ptr; |
79 |
|
|
|
80 |
|
|
/* Get the class instance in the container. */ |
81 |
|
140 |
storage = (UX_SLAVE_CLASS_STORAGE *)class_ptr -> ux_slave_class_instance; |
82 |
|
|
|
83 |
|
|
/* Get the interface that owns this instance. */ |
84 |
|
140 |
interface_ptr = (UX_SLAVE_INTERFACE *) command -> ux_slave_class_command_interface; |
85 |
|
|
|
86 |
|
|
/* Store the class instance into the interface. */ |
87 |
|
140 |
interface_ptr -> ux_slave_interface_class_instance = (VOID *)storage; |
88 |
|
|
|
89 |
|
|
/* Now the opposite, store the interface in the class instance. */ |
90 |
|
140 |
storage -> ux_slave_class_storage_interface = interface_ptr; |
91 |
|
|
|
92 |
|
|
#if !defined(UX_DEVICE_STANDALONE) |
93 |
|
|
|
94 |
|
|
/* Resume thread. */ |
95 |
|
140 |
_ux_device_thread_resume(&class_ptr -> ux_slave_class_thread); |
96 |
|
|
|
97 |
|
|
#else |
98 |
|
|
|
99 |
|
|
/* Locate the endpoints. */ |
100 |
|
|
/* Check the first endpoint direction, if IN we have the correct endpoint. */ |
101 |
|
|
endpoint = interface_ptr -> ux_slave_interface_first_endpoint; |
102 |
|
|
if ((endpoint -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) != UX_ENDPOINT_IN) |
103 |
|
|
{ |
104 |
|
|
|
105 |
|
|
/* Wrong direction, we found the OUT endpoint first. */ |
106 |
|
|
storage -> ux_device_class_storage_ep_out = endpoint; |
107 |
|
|
|
108 |
|
|
/* So the next endpoint has to be the IN endpoint. */ |
109 |
|
|
storage -> ux_device_class_storage_ep_in = endpoint -> ux_slave_endpoint_next_endpoint; |
110 |
|
|
} |
111 |
|
|
else |
112 |
|
|
{ |
113 |
|
|
|
114 |
|
|
/* We found the IN endpoint first. */ |
115 |
|
|
storage -> ux_device_class_storage_ep_in = endpoint; |
116 |
|
|
|
117 |
|
|
/* So the next endpoint has to be the OUT endpoint. */ |
118 |
|
|
storage -> ux_device_class_storage_ep_out = endpoint -> ux_slave_endpoint_next_endpoint; |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
#if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1 |
122 |
|
|
|
123 |
|
|
/* Assign endpoint buffers. */ |
124 |
|
|
storage -> ux_device_class_storage_ep_in -> ux_slave_endpoint_transfer_request. |
125 |
|
|
ux_slave_transfer_request_data_pointer = UX_DEVICE_CLASS_STORAGE_BULKIN_BUFFER(storage); |
126 |
|
|
storage -> ux_device_class_storage_ep_out -> ux_slave_endpoint_transfer_request. |
127 |
|
|
ux_slave_transfer_request_data_pointer = UX_DEVICE_CLASS_STORAGE_BULKOUT_BUFFER(storage); |
128 |
|
|
#endif |
129 |
|
|
|
130 |
|
|
/* Reset states. */ |
131 |
|
|
storage -> ux_device_class_storage_buffer[0] = storage -> ux_device_class_storage_ep_out -> |
132 |
|
|
ux_slave_endpoint_transfer_request.ux_slave_transfer_request_data_pointer; |
133 |
|
|
storage -> ux_device_class_storage_buffer[1] = storage -> ux_device_class_storage_ep_in -> |
134 |
|
|
ux_slave_endpoint_transfer_request.ux_slave_transfer_request_data_pointer; |
135 |
|
|
storage -> ux_device_class_storage_data_buffer = UX_NULL; |
136 |
|
|
storage -> ux_device_class_storage_state = UX_STATE_RESET; |
137 |
|
|
storage -> ux_device_class_storage_disk_state = UX_DEVICE_CLASS_STORAGE_DISK_IDLE; |
138 |
|
|
storage -> ux_device_class_storage_buffer_state[0] = UX_DEVICE_CLASS_STORAGE_BUFFER_IDLE; |
139 |
|
|
storage -> ux_device_class_storage_buffer_state[1] = UX_DEVICE_CLASS_STORAGE_BUFFER_IDLE; |
140 |
|
|
storage -> ux_device_class_storage_buffer_usb = 0; |
141 |
|
|
storage -> ux_device_class_storage_buffer_disk = 0; |
142 |
|
|
UX_SLAVE_TRANSFER_STATE_RESET(&storage -> ux_device_class_storage_ep_out -> ux_slave_endpoint_transfer_request); |
143 |
|
|
UX_SLAVE_TRANSFER_STATE_RESET(&storage -> ux_device_class_storage_ep_in -> ux_slave_endpoint_transfer_request); |
144 |
|
|
|
145 |
|
|
status = UX_SUCCESS; |
146 |
|
|
#endif |
147 |
|
|
|
148 |
|
|
/* Default when activating storage device: media removal is allowed (not prevented) and loaded. */ |
149 |
✓✓ |
314 |
for (lun_index = 0; lun_index < storage -> ux_slave_class_storage_number_lun; lun_index++) |
150 |
|
|
{ |
151 |
|
174 |
storage -> ux_slave_class_storage_lun[lun_index].ux_slave_class_storage_prevent_medium_removal = 0; |
152 |
|
174 |
storage -> ux_slave_class_storage_lun[lun_index].ux_slave_class_storage_medium_loaded_status = 1; |
153 |
|
|
} |
154 |
|
|
|
155 |
|
|
/* If there is a activate function call it. */ |
156 |
✓✓ |
140 |
if (storage -> ux_slave_class_storage_instance_activate != UX_NULL) |
157 |
|
|
{ |
158 |
|
|
/* Invoke the application. */ |
159 |
|
77 |
storage -> ux_slave_class_storage_instance_activate(storage); |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
163 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_STORAGE_ACTIVATE, storage, 0, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0) |
164 |
|
|
|
165 |
|
|
/* If trace is enabled, register this object. */ |
166 |
|
|
UX_TRACE_OBJECT_REGISTER(UX_TRACE_DEVICE_OBJECT_TYPE_INTERFACE, storage, 0, 0, 0) |
167 |
|
|
|
168 |
|
|
/* Return completion status. */ |
169 |
|
140 |
return(status); |
170 |
|
|
} |
171 |
|
|
|