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_command                     PORTABLE C      */
38 /*                                                           6.3.0        */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Chaoqiong Xiao, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function will send a command to the Prolific device.           */
46 /*    The command can be one of the following :                           */
47 /*    SET_CONTROL                                                         */
48 /*    SET_LINE                                                            */
49 /*    SEND_BREAK                                                          */
50 /*                                                                        */
51 /*                                                                        */
52 /*  INPUT                                                                 */
53 /*                                                                        */
54 /*    prolific                              Pointer to prolific class     */
55 /*    command                               command value                 */
56 /*    value                                 value to be sent in the       */
57 /*                                          command request               */
58 /*    data_buffer                           buffer to be sent             */
59 /*    data_length                           length of the buffer to send  */
60 /*                                                                        */
61 /*                                                                        */
62 /*  OUTPUT                                                                */
63 /*                                                                        */
64 /*    Completion Status                                                   */
65 /*                                                                        */
66 /*  CALLS                                                                 */
67 /*                                                                        */
68 /*    _ux_host_stack_transfer_request       Process transfer request      */
69 /*    _ux_host_semaphore_get                Get semaphore                 */
70 /*                                                                        */
71 /*  CALLED BY                                                             */
72 /*                                                                        */
73 /*    Application                                                         */
74 /*                                                                        */
75 /*  RELEASE HISTORY                                                       */
76 /*                                                                        */
77 /*    DATE              NAME                      DESCRIPTION             */
78 /*                                                                        */
79 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
80 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
81 /*                                            resulting in version 6.1    */
82 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
83 /*                                            refined macros names,       */
84 /*                                            resulting in version 6.1.10 */
85 /*  10-31-2023     Yajun xia                Modified comment(s),          */
86 /*                                            resulting in version 6.3.0  */
87 /*                                                                        */
88 /**************************************************************************/
_ux_host_class_prolific_command(UX_HOST_CLASS_PROLIFIC * prolific,ULONG command,ULONG value,UCHAR * data_buffer,ULONG data_length)89 UINT  _ux_host_class_prolific_command(UX_HOST_CLASS_PROLIFIC *prolific, ULONG command,
90                                     ULONG value, UCHAR *data_buffer, ULONG data_length)
91 {
92 
93 UX_ENDPOINT     *control_endpoint;
94 UX_TRANSFER     *transfer_request;
95 UINT            status;
96 
97 
98     /* We need to get the default control endpoint transfer request pointer.  */
99     control_endpoint =  &prolific -> ux_host_class_prolific_device -> ux_device_control_endpoint;
100     transfer_request =  &control_endpoint -> ux_endpoint_transfer_request;
101 
102     /* Protect the control endpoint semaphore here.  It will be unprotected in the
103        transfer request function.  */
104     status =  _ux_host_semaphore_get(&prolific -> ux_host_class_prolific_device -> ux_device_protection_semaphore, UX_WAIT_FOREVER);
105 
106     /* Check for status.  */
107     if (status != UX_SUCCESS)
108 
109         /* Something went wrong. */
110         return(status);
111 
112     /* Create a transfer_request for the request.  */
113     transfer_request -> ux_transfer_request_data_pointer     =  data_buffer;
114     transfer_request -> ux_transfer_request_requested_length =  data_length;
115     transfer_request -> ux_transfer_request_function         =  command;
116     transfer_request -> ux_transfer_request_type             =  UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
117     transfer_request -> ux_transfer_request_value            =  value;
118     transfer_request -> ux_transfer_request_index            =  prolific -> ux_host_class_prolific_interface -> ux_interface_descriptor.bInterfaceNumber;
119 
120     /* Send request to HCD layer.  */
121     status =  _ux_host_stack_transfer_request(transfer_request);
122 
123     /* Return completion status.  */
124     return(status);
125 }
126 
127 
128 /**************************************************************************/
129 /*                                                                        */
130 /*  FUNCTION                                               RELEASE        */
131 /*                                                                        */
132 /*    _uxe_host_class_prolific_command                     PORTABLE C     */
133 /*                                                            6.3.0       */
134 /*  AUTHOR                                                                */
135 /*                                                                        */
136 /*    Chaoqiong Xiao, Microsoft Corporation                               */
137 /*                                                                        */
138 /*  DESCRIPTION                                                           */
139 /*                                                                        */
140 /*    This function checks errors in PROLIFIC command function call.      */
141 /*                                                                        */
142 /*  INPUT                                                                 */
143 /*                                                                        */
144 /*    prolific                              Pointer to prolific class     */
145 /*    command                               command value                 */
146 /*    value                                 value to be sent in the       */
147 /*                                          command request               */
148 /*    data_buffer                           buffer to be sent             */
149 /*    data_length                           length of the buffer to send  */
150 /*                                                                        */
151 /*  OUTPUT                                                                */
152 /*                                                                        */
153 /*    Status                                                              */
154 /*                                                                        */
155 /*  CALLS                                                                 */
156 /*                                                                        */
157 /*    _ux_host_class_prolific_command        PROLIFIC command             */
158 /*                                                                        */
159 /*  CALLED BY                                                             */
160 /*                                                                        */
161 /*    Application                                                         */
162 /*                                                                        */
163 /*  RELEASE HISTORY                                                       */
164 /*                                                                        */
165 /*    DATE              NAME                      DESCRIPTION             */
166 /*                                                                        */
167 /*  10-31-2023     Chaoqiong Xiao           Initial Version 6.3.0         */
168 /*                                                                        */
169 /**************************************************************************/
_uxe_host_class_prolific_command(UX_HOST_CLASS_PROLIFIC * prolific,ULONG command,ULONG value,UCHAR * data_buffer,ULONG data_length)170 UINT  _uxe_host_class_prolific_command(UX_HOST_CLASS_PROLIFIC *prolific, ULONG command,
171                                     ULONG value, UCHAR *data_buffer, ULONG data_length)
172 {
173 
174     /* Sanity check.  */
175     if (prolific == UX_NULL)
176         return(UX_INVALID_PARAMETER);
177 
178     /* Invoke PROLIFIC command function.  */
179     return(_ux_host_class_prolific_command(prolific, command, value, data_buffer, data_length));
180 }
181