1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   PIMA Class                                                          */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 
23 /* Include necessary system files.  */
24 
25 #define UX_SOURCE_CODE
26 
27 #include "ux_api.h"
28 #include "ux_host_class_pima.h"
29 #include "ux_host_stack.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_host_class_pima_device_reset                    PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function resets the device.                                    */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    pima                                       Pointer to pima class    */
48 /*                                                                        */
49 /*  OUTPUT                                                                */
50 /*                                                                        */
51 /*    Completion Status                                                   */
52 /*                                                                        */
53 /*  CALLS                                                                 */
54 /*                                                                        */
55 /*    _ux_host_stack_transfer_request            Transfer request         */
56 /*                                                                        */
57 /*  CALLED BY                                                             */
58 /*                                                                        */
59 /*    USB application                                                     */
60 /*                                                                        */
61 /*  RELEASE HISTORY                                                       */
62 /*                                                                        */
63 /*    DATE              NAME                      DESCRIPTION             */
64 /*                                                                        */
65 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
66 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
67 /*                                            resulting in version 6.1    */
68 /*                                                                        */
69 /**************************************************************************/
_ux_host_class_pima_device_reset(UX_HOST_CLASS_PIMA * pima)70 UINT  _ux_host_class_pima_device_reset(UX_HOST_CLASS_PIMA *pima)
71 {
72 
73 UX_TRANSFER                         *transfer_request;
74 UX_ENDPOINT                         *control_endpoint;
75 UINT                                status;
76 
77     /* If trace is enabled, insert this event into the trace buffer.  */
78     UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_PIMA_DEVICE_RESET, pima, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
79 
80     /* We need to get the default control endpoint transfer request pointer.  */
81     control_endpoint =  &pima -> ux_host_class_pima_device -> ux_device_control_endpoint;
82     transfer_request =  &control_endpoint -> ux_endpoint_transfer_request;
83 
84     /* Create a transfer_request for the CANCEL request.  */
85     transfer_request -> ux_transfer_request_data_pointer =      UX_NULL;
86     transfer_request -> ux_transfer_request_requested_length =  0;
87     transfer_request -> ux_transfer_request_function =          UX_HOST_CLASS_PIMA_REQUEST_RESET_DEVICE;
88     transfer_request -> ux_transfer_request_type =              UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
89     transfer_request -> ux_transfer_request_value =             0;
90     transfer_request -> ux_transfer_request_index  =            0;
91 
92     /* Send request to HCD layer.  */
93     status =  _ux_host_stack_transfer_request(transfer_request);
94 
95     /* Reset the session pointer if it was opened.  A device reset closes the session.  */
96     pima -> ux_host_class_pima_session = UX_NULL;
97 
98     /* Return completion status.  */
99     return(status);
100 
101 }
102 
103