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_lock                   PORTABLE C      */
39 /*                                                           6.1.10       */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Chaoqiong Xiao, Microsoft Corporation                               */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function lock storage and select storage media for read/write. */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    storage_media                         Pointer to storage media to   */
51 /*                                          select                        */
52 /*    wait                                  Wait option                   */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    Completion Status                                                   */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    Storage Class                                                       */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  09-30-2020     Chaoqiong Xiao           Initial Version 6.1           */
70 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
71 /*                                            added standalone support,   */
72 /*                                            resulting in version 6.1.10 */
73 /*                                                                        */
74 /**************************************************************************/
_ux_host_class_storage_media_lock(UX_HOST_CLASS_STORAGE_MEDIA * storage_media,ULONG wait)75 UINT    _ux_host_class_storage_media_lock(UX_HOST_CLASS_STORAGE_MEDIA *storage_media, ULONG wait)
76 {
77 #if !defined(UX_HOST_CLASS_STORAGE_NO_FILEX)
78     UX_PARAMETER_NOT_USED(storage_media);
79     UX_PARAMETER_NOT_USED(wait);
80     return(UX_FUNCTION_NOT_SUPPORTED);
81 #else
82 
83 UX_HOST_CLASS_STORAGE           *storage;
84 UINT                            status;
85 
86 
87     /* Get storage instance.  */
88     storage = storage_media -> ux_host_class_storage_media_storage;
89     if (storage == UX_NULL)
90         return(UX_ERROR);
91 
92     /* Protect thread reentry to this instance.  */
93     status = _ux_host_class_storage_lock(storage, wait);
94     if (status != UX_SUCCESS)
95         return(status);
96 
97     /* Select the media if success.  */
98     storage -> ux_host_class_storage_lun = storage_media -> ux_host_class_storage_media_lun;
99     storage -> ux_host_class_storage_sector_size = storage_media -> ux_host_class_storage_media_sector_size;
100     storage -> ux_host_class_storage_last_sector_number = storage_media -> ux_host_class_storage_media_number_sectors - 1;
101 
102     /* Return success.  */
103     return(UX_SUCCESS);
104 #endif
105 }
106 #endif
107