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 /**   PROLIFIC 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_prolific.h"
30 #include "ux_host_stack.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _ux_host_class_prolific_transfer_request_completed  PORTABLE C      */
38 /*                                                           6.1.9        */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Chaoqiong Xiao, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function is called by the completion thread when a transfer    */
46 /*    request has been completed either because the transfer is           */
47 /*    successful or there was an error.                                   */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    transfer_request                      Pointer to transfer request   */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    None                                                                */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _ux_host_stack_transfer_request       Transfer request              */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    USBX stack                                                          */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
70 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*  10-15-2021     Chaoqiong Xiao           Modified comment(s),          */
73 /*                                            use pre-calculated value    */
74 /*                                            instead of wMaxPacketSize,  */
75 /*                                            resulting in version 6.1.9  */
76 /*                                                                        */
77 /**************************************************************************/
_ux_host_class_prolific_transfer_request_completed(UX_TRANSFER * transfer_request)78 VOID  _ux_host_class_prolific_transfer_request_completed(UX_TRANSFER *transfer_request)
79 {
80 
81 UX_HOST_CLASS_PROLIFIC                   *prolific;
82 
83 
84     /* Get the class instance for this transfer request.  */
85     prolific =  (UX_HOST_CLASS_PROLIFIC *) transfer_request -> ux_transfer_request_class_instance;
86 
87     /* Check the state of the transfer.  If there is an error, we do not proceed with this notification.  */
88     if (transfer_request -> ux_transfer_request_completion_code != UX_SUCCESS)
89 
90         /* We do not proceed.  */
91         return;
92 
93     /* Check if the class is in shutdown.  */
94     if (prolific -> ux_host_class_prolific_state ==  UX_HOST_CLASS_INSTANCE_SHUTDOWN)
95 
96         /* We do not proceed.  */
97         return;
98 
99     /* Increment the notification count.   */
100     prolific -> ux_host_class_prolific_notification_count++;
101 
102     /* Look at what the the status is.  First ensure the length of our interrupt pipe data is correct.  */
103     if (transfer_request -> ux_transfer_request_actual_length ==
104                     transfer_request -> ux_transfer_request_requested_length)
105     {
106 
107         /* Check if device is present.  */
108         if ((*(transfer_request -> ux_transfer_request_data_pointer + UX_HOST_CLASS_PROLIFIC_DEVICE_STATE_OFFSET) &
109                 UX_HOST_CLASS_PROLIFIC_DEVICE_STATE_MASK) == 0)
110 
111             /* Device is not present.  */
112             prolific -> ux_host_class_prolific_device_state =  UX_HOST_CLASS_PROLIFIC_DEVICE_NOT_PRESENT;
113 
114         else
115 
116             /* Device is present.  */
117             prolific -> ux_host_class_prolific_device_state =  UX_HOST_CLASS_PROLIFIC_DEVICE_PRESENT;
118 
119         /* If there is a callback present, invoke it.  */
120         if (prolific -> ux_host_class_prolific_device_status_change_callback != UX_NULL)
121 
122             /* There is a callback, send the status change to the application.  */
123             prolific -> ux_host_class_prolific_device_status_change_callback(prolific, prolific -> ux_host_class_prolific_device_state);
124 
125     }
126 
127     /* Reactivate the PROLIFIC interrupt pipe.  */
128     _ux_host_stack_transfer_request(transfer_request);
129 
130     /* Return to caller.  */
131     return;
132 }
133 
134