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_object_open                     PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Chaoqiong Xiao, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function opens an object for a read or write operation         */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    pima                                       Pointer to pima class    */
49 /*    pima_session                               Pointer to pima session  */
50 /*    object_handle                              The object handle        */
51 /*    object                                     Pointer to object info   */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    Completion Status                                                   */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    None                                                                */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    USB application                                                     */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
70 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*                                                                        */
73 /**************************************************************************/
_ux_host_class_pima_object_open(UX_HOST_CLASS_PIMA * pima,UX_HOST_CLASS_PIMA_SESSION * pima_session,ULONG object_handle,UX_HOST_CLASS_PIMA_OBJECT * object)74 UINT  _ux_host_class_pima_object_open(UX_HOST_CLASS_PIMA *pima,
75                                         UX_HOST_CLASS_PIMA_SESSION *pima_session,
76                                         ULONG object_handle, UX_HOST_CLASS_PIMA_OBJECT *object)
77 {
78 
79     UX_PARAMETER_NOT_USED(object_handle);
80     UX_PARAMETER_NOT_USED(pima);
81 
82     /* Check if this session is valid or not.  */
83     if (pima_session -> ux_host_class_pima_session_magic != UX_HOST_CLASS_PIMA_MAGIC_NUMBER)
84         return (UX_HOST_CLASS_PIMA_RC_SESSION_NOT_OPEN);
85 
86     /* Check if this session is opened or not.  */
87     if (pima_session -> ux_host_class_pima_session_state != UX_HOST_CLASS_PIMA_SESSION_STATE_OPENED)
88         return (UX_HOST_CLASS_PIMA_RC_SESSION_NOT_OPEN);
89 
90     /* Check if the object is already opened.  */
91     if (object -> ux_host_class_pima_object_state != UX_HOST_CLASS_PIMA_OBJECT_STATE_CLOSED)
92         return (UX_HOST_CLASS_PIMA_RC_OBJECT_ALREADY_OPENED);
93 
94     /* Open the object.  */
95     object -> ux_host_class_pima_object_state = UX_HOST_CLASS_PIMA_OBJECT_STATE_OPENED;
96 
97     /* Reset the object offset.  */
98     object -> ux_host_class_pima_object_offset =  0;
99 
100     /* Set the object transfer status to inactive.  */
101     object -> ux_host_class_pima_object_transfer_status = UX_HOST_CLASS_PIMA_OBJECT_TRANSFER_STATUS_INACTIVE;
102 
103     /* Return completion status.  */
104     return(UX_SUCCESS);
105 }
106 
107