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_close PORTABLE C */
38 /* 6.1 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function closes a session with the PIMA device. */
46 /* */
47 /* INPUT */
48 /* */
49 /* pima Pointer to pima class */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* Completion Status */
54 /* */
55 /* CALLS */
56 /* */
57 /* _ux_host_class_pima_command Pima command function */
58 /* */
59 /* CALLED BY */
60 /* */
61 /* USB application */
62 /* */
63 /* RELEASE HISTORY */
64 /* */
65 /* DATE NAME DESCRIPTION */
66 /* */
67 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
68 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
69 /* resulting in version 6.1 */
70 /* */
71 /**************************************************************************/
_ux_host_class_pima_session_close(UX_HOST_CLASS_PIMA * pima,UX_HOST_CLASS_PIMA_SESSION * pima_session)72 UINT _ux_host_class_pima_session_close(UX_HOST_CLASS_PIMA *pima, UX_HOST_CLASS_PIMA_SESSION *pima_session)
73 {
74
75 UX_HOST_CLASS_PIMA_COMMAND command;
76 UINT status;
77
78 /* If trace is enabled, insert this event into the trace buffer. */
79 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_PIMA_SESSION_CLOSE, pima, pima_session, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
80
81 /* Check if this session is valid or not. */
82 if (pima_session -> ux_host_class_pima_session_magic != UX_HOST_CLASS_PIMA_MAGIC_NUMBER)
83 return (UX_HOST_CLASS_PIMA_RC_SESSION_NOT_OPEN);
84
85 /* Check if this session is opened or not. */
86 if (pima_session -> ux_host_class_pima_session_state != UX_HOST_CLASS_PIMA_SESSION_STATE_OPENED)
87 return (UX_HOST_CLASS_PIMA_RC_SESSION_NOT_OPEN);
88
89 /* The transaction ID in the PIMA instance should be reset. */
90 pima -> ux_host_class_pima_transaction_id = 0;
91
92 /* Issue command to close the session with the PIMA device. No parameter. */
93 command.ux_host_class_pima_command_nb_parameters = 0;
94
95 /* Then set the command to CLOSE_SESSION. */
96 command.ux_host_class_pima_command_operation_code = UX_HOST_CLASS_PIMA_OC_CLOSE_SESSION;
97
98 /* Other parameters unused. */
99 command.ux_host_class_pima_command_parameter_1 = 0;
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 closed properly. */
109 if (status == UX_SUCCESS)
110 {
111
112 /* Reset the PIMA session in the pima instance. */
113 pima -> ux_host_class_pima_session = UX_NULL;
114
115 /* Reset the magic field. */
116 pima_session -> ux_host_class_pima_session_magic = 0;
117
118 /* Mark the session as closed. */
119 pima_session -> ux_host_class_pima_session_state = UX_HOST_CLASS_PIMA_SESSION_STATE_CLOSED;
120 }
121
122 /* Return completion status. */
123 return(status);
124 }
125
126