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_class_call                           PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function will call all the registered classes to the USBX      */
45 /*    stack. Each class will have the possibility to own the device or    */
46 /*    one of the interfaces of a device.                                  */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    class_command                         Class command structure       */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    Number of owners                                                    */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    (ux_host_class_entry_function)        Class entry function          */
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 /*                                            optimized based on compile  */
71 /*                                            definitions,                */
72 /*                                            resulting in version 6.1    */
73 /*                                                                        */
74 /**************************************************************************/
_ux_host_stack_class_call(UX_HOST_CLASS_COMMAND * class_command)75 UX_HOST_CLASS  *_ux_host_stack_class_call(UX_HOST_CLASS_COMMAND *class_command)
76 {
77 
78 UINT            status = UX_NO_CLASS_MATCH;
79 UX_HOST_CLASS   *class_inst;
80 #if UX_MAX_CLASS_DRIVER > 1
81 ULONG           class_index;
82 #endif
83 
84     /* Start from the 1st registered classes with USBX.  */
85     class_inst =  _ux_system_host -> ux_system_host_class_array;
86 
87     /* Parse all the class drivers.  */
88 #if UX_MAX_CLASS_DRIVER > 1
89     for (class_index = 0; class_index < _ux_system_host -> ux_system_host_max_class; class_index++)
90     {
91 #endif
92 
93         /* Check if this class driver is used.  */
94         if (class_inst -> ux_host_class_status == UX_USED)
95         {
96 
97             /* We have found a potential candidate. Call this registered class entry function.  */
98             status = class_inst -> ux_host_class_entry_function(class_command);
99 
100             /* The status tells us if the registered class wants to own this class.  */
101             if (status == UX_SUCCESS)
102             {
103 
104                 /* Yes, return this class pointer.  */
105                 return(class_inst);
106             }
107         }
108 #if UX_MAX_CLASS_DRIVER > 1
109         /* Move to the next registered class. */
110         class_inst ++;
111     }
112 #endif
113 
114     /* There is no driver who want to own this class!  */
115     return(UX_NULL);
116 }
117