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_instance_create                PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function creates a new class instance for a class container.   */
45 /*    The instance of a class is not contained in the class code to       */
46 /*    reduce the class driver complexity. Rather, each class instance is  */
47 /*    attached to class container.                                        */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    class                                 Pointer to class              */
52 /*    class_instance                        Pointer to class instance     */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    Completion Status                                                   */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    None                                                                */
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    Application                                                         */
65 /*    USBX Components                                                     */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
72 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
73 /*                                            resulting in version 6.1    */
74 /*                                                                        */
75 /**************************************************************************/
_ux_host_stack_class_instance_create(UX_HOST_CLASS * host_class,VOID * class_instance)76 UINT  _ux_host_stack_class_instance_create(UX_HOST_CLASS *host_class, VOID *class_instance)
77 {
78 
79 VOID    **current_class_instance;
80 
81     /* If trace is enabled, insert this event into the trace buffer.  */
82     UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_CLASS_INSTANCE_CREATE, host_class, class_instance, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
83 
84     /* If trace is enabled, register this object.  */
85     UX_TRACE_OBJECT_REGISTER(UX_TRACE_HOST_OBJECT_TYPE_CLASS_INSTANCE, class_instance, 0, 0, 0)
86 
87     /* Start with the first class instance attached to the class container.  */
88     current_class_instance =  host_class -> ux_host_class_first_instance;
89 
90     /* Check if there are any instances attached.  */
91     if (current_class_instance == UX_NULL)
92     {
93 
94         /* Since it is the first class, attach it to the class container.  */
95         host_class -> ux_host_class_first_instance =  class_instance;
96 
97         /* Return successful completion.  */
98         return(UX_SUCCESS);
99     }
100 
101     /* Traverse the list of the class instances until we find the last class.  */
102     while (*current_class_instance != UX_NULL)
103     {
104 
105         /* Point to the next class instance.  */
106         current_class_instance =  *current_class_instance;
107     }
108 
109     /* We have reached the last class, hook the new class to the end. This way, we preserve
110        the chronological order of the class instances.  */
111     *current_class_instance =  class_instance;
112 
113     /* Return successful completion to caller.  */
114     return(UX_SUCCESS);
115 }
116 
117