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_session_open PORTABLE C */
38 /* 6.1 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function opens a session with the PIMA device. The session */
46 /* is maintained in this state until the session is closed or the */
47 /* device is unmounted. */
48 /* */
49 /* INPUT */
50 /* */
51 /* pima Pointer to pima class */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* Completion Status */
56 /* */
57 /* CALLS */
58 /* */
59 /* _ux_host_class_pima_command Pima command function */
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_session_open(UX_HOST_CLASS_PIMA * pima,UX_HOST_CLASS_PIMA_SESSION * pima_session)74 UINT _ux_host_class_pima_session_open(UX_HOST_CLASS_PIMA *pima, UX_HOST_CLASS_PIMA_SESSION *pima_session)
75 {
76
77 UX_HOST_CLASS_PIMA_COMMAND command;
78 ULONG status;
79
80 /* If trace is enabled, insert this event into the trace buffer. */
81 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_PIMA_SESSION_OPEN, pima, pima_session, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
82
83 /* Check if there is already a session opened. */
84 if (pima -> ux_host_class_pima_session != UX_NULL)
85 return (UX_HOST_CLASS_PIMA_RC_SESSION_ALREADY_OPENED);
86
87 /* The transaction ID in the PIMA instance should be reset. */
88 pima -> ux_host_class_pima_transaction_id = 0;
89
90 /* Issue command to open the session with the PIMA device. First set the number of parameters. */
91 command.ux_host_class_pima_command_nb_parameters = 1;
92
93 /* Then set the command to OPEN_SESSION. */
94 command.ux_host_class_pima_command_operation_code = UX_HOST_CLASS_PIMA_OC_OPEN_SESSION;
95
96 /* The session ID is the handle to the session. */
97 command.ux_host_class_pima_command_parameter_1 = (ULONG) (ALIGN_TYPE) pima_session;
98
99 /* Other parameters unused. */
100 command.ux_host_class_pima_command_parameter_2 = 0;
101 command.ux_host_class_pima_command_parameter_3 = 0;
102 command.ux_host_class_pima_command_parameter_4 = 0;
103 command.ux_host_class_pima_command_parameter_5 = 0;
104
105 /* Issue the command. */
106 status = _ux_host_class_pima_command(pima, &command, 0 , UX_NULL, 0, 0);
107
108 /* Check the result. If OK, the session was opened properly. */
109 if (status == UX_SUCCESS)
110 {
111
112 /* Store the session pointer in the PIMA instance. The PIMA class instance
113 only supports one opened session at a time at this stage. */
114 pima -> ux_host_class_pima_session = pima_session;
115
116 /* Save the session ID in the session container. This is not too useful since
117 the session ID is the session structure address. */
118 pima_session -> ux_host_class_pima_session_id = (ALIGN_TYPE) pima_session;
119
120 /* Put the magic number in the session instance. */
121 pima_session -> ux_host_class_pima_session_magic = UX_HOST_CLASS_PIMA_MAGIC_NUMBER;
122
123 /* Mark the session as opened. */
124 pima_session -> ux_host_class_pima_session_state = UX_HOST_CLASS_PIMA_SESSION_STATE_OPENED;
125 }
126
127 /* Return completion status. */
128 return(status);
129 }
130
131