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 /**   PIMA 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_pima.h"
30 #include "ux_host_stack.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _ux_host_class_pima_num_objects_get                 PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Chaoqiong Xiao, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function returns the number of objects for a specific storage. */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    pima                                       Pointer to pima class    */
50 /*    pima_session                               Pointer to pima session  */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    Completion Status                                                   */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*  _ux_host_class_pima_command                 Pima command function     */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    USB application                                                     */
63 /*                                                                        */
64 /*  RELEASE HISTORY                                                       */
65 /*                                                                        */
66 /*    DATE              NAME                      DESCRIPTION             */
67 /*                                                                        */
68 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
69 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
70 /*                                            resulting in version 6.1    */
71 /*                                                                        */
72 /**************************************************************************/
_ux_host_class_pima_num_objects_get(UX_HOST_CLASS_PIMA * pima,UX_HOST_CLASS_PIMA_SESSION * pima_session,ULONG storage_id,ULONG object_format_code)73 UINT  _ux_host_class_pima_num_objects_get(UX_HOST_CLASS_PIMA *pima,
74                                         UX_HOST_CLASS_PIMA_SESSION *pima_session,
75                                         ULONG storage_id,
76                                         ULONG object_format_code)
77 {
78 
79 UX_HOST_CLASS_PIMA_COMMAND             command;
80 UINT                                status;
81 
82     /* If trace is enabled, insert this event into the trace buffer.  */
83     UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_PIMA_NUM_OBJECTS_GET, pima, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
84 
85     /* Check if this session is valid or not.  */
86     if (pima_session -> ux_host_class_pima_session_magic != UX_HOST_CLASS_PIMA_MAGIC_NUMBER)
87         return (UX_HOST_CLASS_PIMA_RC_SESSION_NOT_OPEN);
88 
89     /* Check if this session is opened or not.  */
90     if (pima_session -> ux_host_class_pima_session_state != UX_HOST_CLASS_PIMA_SESSION_STATE_OPENED)
91         return (UX_HOST_CLASS_PIMA_RC_SESSION_NOT_OPEN);
92 
93     /* Issue command to get the storage IDs.  2 parameter.  */
94     command.ux_host_class_pima_command_nb_parameters =  2;
95 
96     /* Parameter 1 is the Storage ID.  */
97     command.ux_host_class_pima_command_parameter_1 =  storage_id;
98 
99     /* Parameter 2 is the Object Format Code.  */
100     command.ux_host_class_pima_command_parameter_2 =  object_format_code;
101 
102     /* Other parameters unused.  */
103     command.ux_host_class_pima_command_parameter_3 =  0;
104     command.ux_host_class_pima_command_parameter_4 =  0;
105     command.ux_host_class_pima_command_parameter_5 =  0;
106 
107     /* Then set the command to GET_NUM_OBJETCS.  */
108     command.ux_host_class_pima_command_operation_code =  UX_HOST_CLASS_PIMA_OC_GET_NUM_OBJECTS;
109 
110     /* Issue the command.  */
111     status = _ux_host_class_pima_command(pima, &command, 0 , UX_NULL, 0, 0);
112 
113     /* Check the result. If the result is OK, the parameter1 has the number of objects. */
114     if (status == UX_SUCCESS)
115 
116         /* Store the number of objects into the current pima session.  */
117         pima_session -> ux_host_class_pima_session_nb_objects =  command.ux_host_class_pima_command_parameter_1;
118 
119     /* Return completion status.  */
120     return(status);
121 }
122 
123