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 /**   Host Stack                                                          */
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_stack.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_host_stack_configuration_instance_create        PORTABLE C      */
37 /*                                                           6.2.0        */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function will create a configuration instance. It scan all the */
45 /*    interfaces hooked to the configuration and enable each interface    */
46 /*    with the alternate setting 0.                                       */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    configuration                         Pointer to configuration      */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    Completion Status                                                   */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    _ux_host_stack_interface_instance_create  Create interface instance */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    USBX Components                                                     */
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 /*  10-31-2022     Chaoqiong Xiao           Modified comment(s),          */
76 /*                                            added interface instance    */
77 /*                                            creation strategy control,  */
78 /*                                            resulting in version 6.2.0  */
79 /*                                                                        */
80 /**************************************************************************/
_ux_host_stack_configuration_instance_create(UX_CONFIGURATION * configuration)81 UINT  _ux_host_stack_configuration_instance_create(UX_CONFIGURATION *configuration)
82 {
83 
84 UX_INTERFACE    *interface_ptr;
85 UINT            status;
86 
87     /* If trace is enabled, insert this event into the trace buffer.  */
88     UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_CONFIGURATION_INSTANCE_CREATE, configuration, 0, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
89 
90     /* Obtain the first interface for this configuration.  */
91     interface_ptr =  configuration -> ux_configuration_first_interface;
92 
93     /* Each selected alternate setting 0 for each interface must be created.  */
94     while (interface_ptr != UX_NULL)
95     {
96 
97         /* Check if we are dealing with the first alternate setting.  */
98         if (interface_ptr -> ux_interface_descriptor.bAlternateSetting == 0)
99         {
100 
101 #if UX_HOST_STACK_CONFIGURATION_INSTANCE_CREATE_CONTROL == UX_HOST_STACK_CONFIGURATION_INSTANCE_CREATE_OWNED
102 
103             /* Create the interface, if it's usable. */
104             if (interface_ptr -> ux_interface_class || configuration -> ux_configuration_device -> ux_device_class)
105 #endif
106             {
107                 status = _ux_host_stack_interface_instance_create(interface_ptr);
108 
109                 /* Check status, the controller may have refused the endpoint creation.  */
110                 if (status != UX_SUCCESS)
111 
112                     /* An error occurred.  The interface cannot be mounted.  */
113                     return(status);
114             }
115         }
116 
117         /* Next interface.  */
118         interface_ptr =  interface_ptr -> ux_interface_next_interface;
119     }
120 
121     /* Return successful completion.  */
122     return(UX_SUCCESS);
123 }
124 
125