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_device_reset                    PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Chaoqiong Xiao, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function resets the device.                                    */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    pima                                       Pointer to pima class    */
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    Completion Status                                                   */
53 /*                                                                        */
54 /*  CALLS                                                                 */
55 /*                                                                        */
56 /*    _ux_host_stack_transfer_request            Transfer request         */
57 /*                                                                        */
58 /*  CALLED BY                                                             */
59 /*                                                                        */
60 /*    USB application                                                     */
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 /*                                                                        */
70 /**************************************************************************/
_ux_host_class_pima_device_reset(UX_HOST_CLASS_PIMA * pima)71 UINT  _ux_host_class_pima_device_reset(UX_HOST_CLASS_PIMA *pima)
72 {
73 
74 UX_TRANSFER                         *transfer_request;
75 UX_ENDPOINT                         *control_endpoint;
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_DEVICE_RESET, pima, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
80 
81     /* We need to get the default control endpoint transfer request pointer.  */
82     control_endpoint =  &pima -> ux_host_class_pima_device -> ux_device_control_endpoint;
83     transfer_request =  &control_endpoint -> ux_endpoint_transfer_request;
84 
85     /* Create a transfer_request for the CANCEL request.  */
86     transfer_request -> ux_transfer_request_data_pointer =      UX_NULL;
87     transfer_request -> ux_transfer_request_requested_length =  0;
88     transfer_request -> ux_transfer_request_function =          UX_HOST_CLASS_PIMA_REQUEST_RESET_DEVICE;
89     transfer_request -> ux_transfer_request_type =              UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
90     transfer_request -> ux_transfer_request_value =             0;
91     transfer_request -> ux_transfer_request_index  =            0;
92 
93     /* Send request to HCD layer.  */
94     status =  _ux_host_stack_transfer_request(transfer_request);
95 
96     /* Reset the session pointer if it was opened.  A device reset closes the session.  */
97     pima -> ux_host_class_pima_session = UX_NULL;
98 
99     /* Return completion status.  */
100     return(status);
101 
102 }
103 
104