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 /**   Device Stack                                                        */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define UX_SOURCE_CODE
24 
25 
26 /* Include necessary system files.  */
27 
28 #include "ux_api.h"
29 #include "ux_device_stack.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_device_stack_interface_start                    PORTABLE C      */
37 /*                                                           6.1.12       */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function starts an interface associated with the enabled       */
45 /*    configuration.                                                      */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    interface                             Pointer to interface          */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    Completion Status                                                   */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    (ux_slave_class_entry_function)       Device class entry function   */
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    Application                                                         */
62 /*    Device Stack                                                        */
63 /*                                                                        */
64 /*  RELEASE HISTORY                                                       */
65 /*                                                                        */
66 /*    DATE              NAME                      DESCRIPTION             */
67 /*                                                                        */
68 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
69 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
70 /*                                            resulting in version 6.1    */
71 /*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
72 /*                                            fixed parameter/variable    */
73 /*                                            names conflict C++ keyword, */
74 /*                                            resulting in version 6.1.12 */
75 /*                                                                        */
76 /**************************************************************************/
_ux_device_stack_interface_start(UX_SLAVE_INTERFACE * interface_ptr)77 UINT  _ux_device_stack_interface_start(UX_SLAVE_INTERFACE *interface_ptr)
78 {
79 
80 UX_SLAVE_DEVICE             *device;
81 UX_SLAVE_CLASS              *class_ptr;
82 UINT                        status;
83 UX_SLAVE_CLASS_COMMAND      class_command;
84 
85 
86     /* Get the class for the interface.  */
87     class_ptr =  _ux_system_slave -> ux_system_slave_interface_class_array[interface_ptr -> ux_slave_interface_descriptor.bInterfaceNumber];
88 
89     /* Check if class driver is available. */
90     if (class_ptr == UX_NULL)
91 
92         /* There is no class driver supported. */
93         return (UX_NO_CLASS_MATCH);
94 
95     /* Get the pointer to the device.  */
96     device =  &_ux_system_slave -> ux_system_slave_device;
97 
98     /* Build all the fields of the Class Command.  */
99     class_command.ux_slave_class_command_request   =    UX_SLAVE_CLASS_COMMAND_QUERY;
100     class_command.ux_slave_class_command_interface =   (VOID *)interface_ptr;
101     class_command.ux_slave_class_command_class     =   interface_ptr -> ux_slave_interface_descriptor.bInterfaceClass;
102     class_command.ux_slave_class_command_subclass  =   interface_ptr -> ux_slave_interface_descriptor.bInterfaceSubClass;
103     class_command.ux_slave_class_command_protocol  =   interface_ptr -> ux_slave_interface_descriptor.bInterfaceProtocol;
104     class_command.ux_slave_class_command_vid       =   device -> ux_slave_device_descriptor.idVendor;
105     class_command.ux_slave_class_command_pid       =   device -> ux_slave_device_descriptor.idProduct;
106 
107     /* We can now memorize the interface pointer associated with this class.  */
108     class_ptr -> ux_slave_class_interface = interface_ptr;
109 
110     /* We have found a potential candidate. Call this registered class entry function.  */
111     status = class_ptr -> ux_slave_class_entry_function(&class_command);
112 
113     /* The status tells us if the registered class wants to own this class.  */
114     if (status == UX_SUCCESS)
115     {
116 
117         /* Store the class container. */
118         class_command.ux_slave_class_command_class_ptr =  class_ptr;
119 
120         /* Store the command.  */
121         class_command.ux_slave_class_command_request =  UX_SLAVE_CLASS_COMMAND_ACTIVATE;
122 
123         /* Activate the class.  */
124         status = class_ptr -> ux_slave_class_entry_function(&class_command);
125 
126         /* If the class was successfully activated, set the class for the interface.  */
127         if(status == UX_SUCCESS)
128             interface_ptr -> ux_slave_interface_class =  class_ptr;
129 
130         return(status);
131     }
132 
133     /* There is no driver who want to own this class!  */
134     return(UX_NO_CLASS_MATCH);
135 }
136 
137