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.1.10       */
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 /*    Storage Class                                                       */
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 /*                                                                        */
86 /**************************************************************************/
_ux_host_class_prolific_command(UX_HOST_CLASS_PROLIFIC * prolific,ULONG command,ULONG value,UCHAR * data_buffer,ULONG data_length)87 UINT  _ux_host_class_prolific_command(UX_HOST_CLASS_PROLIFIC *prolific, ULONG command,
88                                     ULONG value, UCHAR *data_buffer, ULONG data_length)
89 {
90 
91 UX_ENDPOINT     *control_endpoint;
92 UX_TRANSFER     *transfer_request;
93 UINT            status;
94 
95 
96     /* We need to get the default control endpoint transfer request pointer.  */
97     control_endpoint =  &prolific -> ux_host_class_prolific_device -> ux_device_control_endpoint;
98     transfer_request =  &control_endpoint -> ux_endpoint_transfer_request;
99 
100     /* Protect the control endpoint semaphore here.  It will be unprotected in the
101        transfer request function.  */
102     status =  _ux_host_semaphore_get(&prolific -> ux_host_class_prolific_device -> ux_device_protection_semaphore, UX_WAIT_FOREVER);
103 
104     /* Check for status.  */
105     if (status != UX_SUCCESS)
106 
107         /* Something went wrong. */
108         return(status);
109 
110     /* Create a transfer_request for the request.  */
111     transfer_request -> ux_transfer_request_data_pointer     =  data_buffer;
112     transfer_request -> ux_transfer_request_requested_length =  data_length;
113     transfer_request -> ux_transfer_request_function         =  command;
114     transfer_request -> ux_transfer_request_type             =  UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
115     transfer_request -> ux_transfer_request_value            =  value;
116     transfer_request -> ux_transfer_request_index            =  prolific -> ux_host_class_prolific_interface -> ux_interface_descriptor.bInterfaceNumber;
117 
118     /* Send request to HCD layer.  */
119     status =  _ux_host_stack_transfer_request(transfer_request);
120 
121     /* Return completion status.  */
122     return(status);
123 }
124 
125