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