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 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   Device PIMA Class                                                   */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define UX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "ux_api.h"
28 #include "ux_device_class_pima.h"
29 #include "ux_device_stack.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_device_class_pima_deactivate                    PORTABLE C      */
37 /*                                                           6.3.0        */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function deactivate an instance of the pima class.             */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    command                               Pointer to a class command    */
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    Completion Status                                                   */
53 /*                                                                        */
54 /*  CALLS                                                                 */
55 /*                                                                        */
56 /*    _ux_device_stack_transfer_all_request_abort Abort all transfers     */
57 /*                                                                        */
58 /*  CALLED BY                                                             */
59 /*                                                                        */
60 /*    PIMA Class                                                          */
61 /*                                                                        */
62 /*  RELEASE HISTORY                                                       */
63 /*                                                                        */
64 /*    DATE              NAME                      DESCRIPTION             */
65 /*                                                                        */
66 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
67 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
68 /*                                            resulting in version 6.1    */
69 /*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
70 /*                                            fixed parameter/variable    */
71 /*                                            names conflict C++ keyword, */
72 /*                                            resulting in version 6.1.12 */
73 /*  10-31-2023     Chaoqiong Xiao           Modified comment(s),          */
74 /*                                            supported optional INT EP,  */
75 /*                                            resulting in version 6.3.0  */
76 /*                                                                        */
77 /**************************************************************************/
_ux_device_class_pima_deactivate(UX_SLAVE_CLASS_COMMAND * command)78 UINT  _ux_device_class_pima_deactivate(UX_SLAVE_CLASS_COMMAND *command)
79 {
80 
81 UX_SLAVE_CLASS_PIMA         *pima;
82 UX_SLAVE_CLASS              *class_ptr;
83 
84     /* Get the class container.  */
85     class_ptr =  command -> ux_slave_class_command_class_ptr;
86 
87     /* Store the class instance in the container.  */
88     pima = (UX_SLAVE_CLASS_PIMA *) class_ptr -> ux_slave_class_instance;
89 
90     /* Terminate the transactions pending on the endpoints.  */
91     _ux_device_stack_transfer_all_request_abort(pima -> ux_device_class_pima_bulk_in_endpoint, UX_TRANSFER_BUS_RESET);
92     _ux_device_stack_transfer_all_request_abort(pima -> ux_device_class_pima_bulk_out_endpoint, UX_TRANSFER_BUS_RESET);
93     if (pima -> ux_device_class_pima_interrupt_endpoint)
94         _ux_device_stack_transfer_all_request_abort(pima -> ux_device_class_pima_interrupt_endpoint, UX_TRANSFER_BUS_RESET);
95 
96     /* Session is now closed.  */
97     pima -> ux_device_class_pima_session_id = 0;
98 
99     /* If there is a deactivate function call it.  */
100     if (pima -> ux_device_class_pima_instance_deactivate != UX_NULL)
101     {
102         /* Invoke the application.  */
103         pima -> ux_device_class_pima_instance_deactivate(pima);
104     }
105 
106     /* If trace is enabled, insert this event into the trace buffer.  */
107     UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_PIMA_DEACTIVATE, pima, 0, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
108 
109     /* If trace is enabled, register this object.  */
110     UX_TRACE_OBJECT_UNREGISTER(pima);
111 
112     /* Return completion status.  */
113     return(UX_SUCCESS);
114 }
115 
116