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 /**   Generic Serial Host module 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_gser.h"
30 #include "ux_host_stack.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _ux_host_class_gser_reception_stop                  PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Chaoqiong Xiao, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function starts a reception with the generic modem. This way   */
46 /*    allows for non blocking calls based on a packet orientated round    */
47 /*    robbin buffer. When a packet is fully or partially received, an     */
48 /*    application callback function is invoked and a new transfer request */
49 /*    is rescheduled.                                                     */
50 /*                                                                        */
51 /*  INPUT                                                                 */
52 /*                                                                        */
53 /*    gser                               Pointer to gser class            */
54 /*    gser_reception                     Pointer to reception struct      */
55 /*                                                                        */
56 /*  OUTPUT                                                                */
57 /*                                                                        */
58 /*    Completion Status                                                   */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*    _ux_host_stack_endpoint_transfer_abort                              */
63 /*                                       Abort transfer request           */
64 /*                                                                        */
65 /*  CALLED BY                                                             */
66 /*                                                                        */
67 /*    Application                                                         */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
74 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
_ux_host_class_gser_reception_stop(UX_HOST_CLASS_GSER * gser,UX_HOST_CLASS_GSER_RECEPTION * gser_reception)78 UINT  _ux_host_class_gser_reception_stop (UX_HOST_CLASS_GSER *gser,
79                                     UX_HOST_CLASS_GSER_RECEPTION *gser_reception)
80 {
81 
82 ULONG           interface_index;
83 
84     /* If trace is enabled, insert this event into the trace buffer.  */
85     UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_GSER_RECEPTION_STOP, gser, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
86 
87     /* Ensure the instance is valid.  */
88     if (gser -> ux_host_class_gser_state !=  UX_HOST_CLASS_INSTANCE_LIVE)
89     {
90 
91         /* If trace is enabled, insert this event into the trace buffer.  */
92         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, gser, 0, 0, UX_TRACE_ERRORS, 0, 0)
93 
94         return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
95     }
96 
97     /* Check if we do have transfers for this application. If none, nothing to do. */
98     if (gser_reception -> ux_host_class_gser_reception_state ==  UX_HOST_CLASS_GSER_RECEPTION_STATE_STOPPED)
99         return(UX_SUCCESS);
100 
101     /* Get the interface index.  */
102     interface_index = gser_reception -> ux_host_class_gser_reception_interface_index;
103 
104     /* We need to abort transactions on the bulk In pipe.  */
105     _ux_host_stack_endpoint_transfer_abort(gser -> ux_host_class_gser_interface_array[interface_index].ux_host_class_gser_bulk_in_endpoint);
106 
107     /* Declare the reception stopped.  */
108     gser_reception -> ux_host_class_gser_reception_state =  UX_HOST_CLASS_GSER_RECEPTION_STATE_STOPPED;
109 
110     /* This function never really fails.  */
111     return(UX_SUCCESS);
112 }
113 
114