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 /** Storage Class */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23
24 /* Include necessary system files. */
25
26 #define UX_SOURCE_CODE
27
28 #include "ux_api.h"
29 #include "ux_host_class_storage.h"
30 #include "ux_host_stack.h"
31
32
33 #if defined(UX_HOST_CLASS_STORAGE_NO_FILEX)
34 /**************************************************************************/
35 /* */
36 /* FUNCTION RELEASE */
37 /* */
38 /* _ux_host_class_storage_media_get PORTABLE C */
39 /* 6.1.12 */
40 /* AUTHOR */
41 /* */
42 /* Chaoqiong Xiao, Microsoft Corporation */
43 /* */
44 /* DESCRIPTION */
45 /* */
46 /* This function retrieves storage media from the storage device. */
47 /* */
48 /* INPUT */
49 /* */
50 /* storage Pointer to storage class */
51 /* media_lun Media logical unit No. (LUN) */
52 /* storage_media Holds returned storage media */
53 /* pointer */
54 /* */
55 /* OUTPUT */
56 /* */
57 /* Completion Status */
58 /* */
59 /* CALLS */
60 /* */
61 /* */
62 /* CALLED BY */
63 /* */
64 /* Storage Class */
65 /* */
66 /* RELEASE HISTORY */
67 /* */
68 /* DATE NAME DESCRIPTION */
69 /* */
70 /* 09-30-2020 Chaoqiong Xiao Initial Version 6.1 */
71 /* 08-02-2021 Wen Wang Modified comment(s), */
72 /* fixed spelling error, */
73 /* resulting in version 6.1.8 */
74 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
75 /* refined media to search, */
76 /* resulting in version 6.1.10 */
77 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
78 /* cleared CSTAT warning, */
79 /* resulting in version 6.1.12 */
80 /* */
81 /**************************************************************************/
_ux_host_class_storage_media_get(UX_HOST_CLASS_STORAGE * storage,ULONG media_lun,UX_HOST_CLASS_STORAGE_MEDIA ** storage_media)82 UINT _ux_host_class_storage_media_get(UX_HOST_CLASS_STORAGE *storage,
83 ULONG media_lun,
84 UX_HOST_CLASS_STORAGE_MEDIA **storage_media)
85 {
86 #if !defined(UX_HOST_CLASS_STORAGE_NO_FILEX)
87 UX_PARAMETER_NOT_USED(storage);
88 UX_PARAMETER_NOT_USED(media_index);
89 UX_PARAMETER_NOT_USED(storage_media);
90 return(UX_FUNCTION_NOT_SUPPORTED);
91 #else
92
93 UX_HOST_CLASS_STORAGE_MEDIA *storage_medias;
94 UX_HOST_CLASS_STORAGE_MEDIA *storage_media_inst;
95 UX_HOST_CLASS *class_inst;
96 UINT scan_index;
97
98
99 /* If storage is not live, media is not ready. */
100 if (storage -> ux_host_class_storage_state != UX_HOST_CLASS_INSTANCE_LIVE)
101 return(UX_ERROR);
102
103 /* Get storage class instance. */
104 class_inst = storage -> ux_host_class_storage_class;
105
106 /* Get shared storage media array. */
107 storage_medias = (UX_HOST_CLASS_STORAGE_MEDIA *)class_inst -> ux_host_class_media;
108
109 /* Search media to find the right one. */
110 for(scan_index = 0; scan_index < UX_HOST_CLASS_STORAGE_MAX_MEDIA; scan_index ++)
111 {
112 storage_media_inst = &storage_medias[scan_index];
113
114 /* Skip storage media not used. */
115 if (storage_media_inst -> ux_host_class_storage_media_status != UX_USED)
116 continue;
117
118 /* Skip storage media not belong to the storage. */
119 if (storage_media_inst -> ux_host_class_storage_media_storage != storage)
120 continue;
121
122 /* Skip storage media with different LUN. */
123 if (storage_media_inst -> ux_host_class_storage_media_lun != media_lun)
124 continue;
125
126 /* Store the media instance. */
127 {
128 *storage_media = storage_media_inst;
129 return(UX_SUCCESS);
130 }
131 }
132
133 /* Media not found. */
134 return(UX_ERROR);
135 #endif
136 }
137 #endif
138