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_entry PORTABLE C */ |
38 |
|
|
/* 6.x */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function is the entry point of the device storage class. It */ |
46 |
|
|
/* will be called by the device stack enumeration module when the */ |
47 |
|
|
/* host has sent a SET_CONFIGURATION command and the storage interface */ |
48 |
|
|
/* needs to be mounted. */ |
49 |
|
|
/* */ |
50 |
|
|
/* INPUT */ |
51 |
|
|
/* */ |
52 |
|
|
/* command Pointer to class command */ |
53 |
|
|
/* */ |
54 |
|
|
/* OUTPUT */ |
55 |
|
|
/* */ |
56 |
|
|
/* Completion Status */ |
57 |
|
|
/* */ |
58 |
|
|
/* CALLS */ |
59 |
|
|
/* */ |
60 |
|
|
/* _ux_device_class_storage_initialize Initialize storage class */ |
61 |
|
|
/* _ux_device_class_storage_uninitialize Uninitialize storage class */ |
62 |
|
|
/* _ux_device_class_storage_activate Activate storage class */ |
63 |
|
|
/* _ux_device_class_storage_deactivate Deactivate storage class */ |
64 |
|
|
/* _ux_device_class_storage_control_request */ |
65 |
|
|
/* Request control */ |
66 |
|
|
/* */ |
67 |
|
|
/* CALLED BY */ |
68 |
|
|
/* */ |
69 |
|
|
/* Device Storage Class */ |
70 |
|
|
/* */ |
71 |
|
|
/**************************************************************************/ |
72 |
|
918 |
UINT _ux_device_class_storage_entry(UX_SLAVE_CLASS_COMMAND *command) |
73 |
|
|
{ |
74 |
|
|
|
75 |
|
|
UINT status; |
76 |
|
|
|
77 |
|
|
|
78 |
|
|
/* The command request will tell us we need to do here, either a enumeration |
79 |
|
|
query, an activation or a deactivation. */ |
80 |
✓✓✓✓ ✓✓✓ |
918 |
switch (command -> ux_slave_class_command_request) |
81 |
|
|
{ |
82 |
|
|
|
83 |
|
51 |
case UX_SLAVE_CLASS_COMMAND_INITIALIZE: |
84 |
|
|
|
85 |
|
|
/* Call the init function of the Storage class. */ |
86 |
|
|
#if defined(UX_DEVICE_CLASS_STORAGE_ENABLE_ERROR_CHECKING) |
87 |
|
|
status = _uxe_device_class_storage_initialize(command); |
88 |
|
|
#else |
89 |
|
51 |
status = _ux_device_class_storage_initialize(command); |
90 |
|
|
#endif |
91 |
|
|
|
92 |
|
|
/* Return the completion status. */ |
93 |
|
51 |
return(status); |
94 |
|
|
|
95 |
|
41 |
case UX_SLAVE_CLASS_COMMAND_UNINITIALIZE: |
96 |
|
|
|
97 |
|
|
/* Call the uninit function of the Storage class. */ |
98 |
|
41 |
status = _ux_device_class_storage_uninitialize(command); |
99 |
|
|
|
100 |
|
|
/* Return the completion status. */ |
101 |
|
41 |
return(status); |
102 |
|
|
|
103 |
|
|
|
104 |
|
141 |
case UX_SLAVE_CLASS_COMMAND_QUERY: |
105 |
|
|
|
106 |
|
|
/* Check the CLASS definition in the interface descriptor. */ |
107 |
✓✓ |
141 |
if (command -> ux_slave_class_command_class == UX_SLAVE_CLASS_STORAGE_CLASS) |
108 |
|
140 |
return(UX_SUCCESS); |
109 |
|
|
else |
110 |
|
1 |
return(UX_NO_CLASS_MATCH); |
111 |
|
|
|
112 |
|
140 |
case UX_SLAVE_CLASS_COMMAND_ACTIVATE: |
113 |
|
|
|
114 |
|
|
/* The activate command is used when the host has sent a SET_CONFIGURATION command |
115 |
|
|
and this interface has to be mounted. Both Bulk endpoints have to be mounted |
116 |
|
|
and the storage thread needs to be activated. */ |
117 |
|
140 |
status = _ux_device_class_storage_activate(command); |
118 |
|
|
|
119 |
|
|
/* Return the completion status. */ |
120 |
|
140 |
return(status); |
121 |
|
|
|
122 |
|
137 |
case UX_SLAVE_CLASS_COMMAND_DEACTIVATE: |
123 |
|
|
|
124 |
|
|
/* The deactivate command is used when the device has been extracted. |
125 |
|
|
The device endpoints have to be dismounted and the storage thread canceled. */ |
126 |
|
137 |
status = _ux_device_class_storage_deactivate(command); |
127 |
|
|
|
128 |
|
|
/* Return the completion status. */ |
129 |
|
137 |
return(status); |
130 |
|
|
|
131 |
|
407 |
case UX_SLAVE_CLASS_COMMAND_REQUEST: |
132 |
|
|
|
133 |
|
|
/* The request command is used when the host sends a command on the control endpoint. */ |
134 |
|
407 |
status = _ux_device_class_storage_control_request(command); |
135 |
|
|
|
136 |
|
|
/* Return the completion status. */ |
137 |
|
407 |
return(status); |
138 |
|
|
|
139 |
|
1 |
default: |
140 |
|
|
|
141 |
|
|
/* Error trap. */ |
142 |
|
1 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED); |
143 |
|
|
|
144 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
145 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0) |
146 |
|
|
|
147 |
|
|
/* Return an error. */ |
148 |
|
1 |
return(UX_FUNCTION_NOT_SUPPORTED); |
149 |
|
|
} |
150 |
|
|
} |
151 |
|
|
|