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_destroy PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function destroys a class instance for a class container. */
45 /* */
46 /* INPUT */
47 /* */
48 /* class Pointer to class */
49 /* class_instance Pointer to class instance */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* Completion Status */
54 /* */
55 /* CALLS */
56 /* */
57 /* None */
58 /* */
59 /* CALLED BY */
60 /* */
61 /* Application */
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 /* */
72 /**************************************************************************/
_ux_host_stack_class_instance_destroy(UX_HOST_CLASS * host_class,VOID * class_instance)73 UINT _ux_host_stack_class_instance_destroy(UX_HOST_CLASS *host_class, VOID *class_instance)
74 {
75
76 VOID **current_class_instance;
77 VOID **next_class_instance;
78
79 /* If trace is enabled, insert this event into the trace buffer. */
80 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_CLASS_INSTANCE_DESTROY, host_class, class_instance, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
81
82 /* If trace is enabled, register this object. */
83 UX_TRACE_OBJECT_UNREGISTER(class_instance);
84
85 /* Get the pointer to the instance pointed by the instance to destroy. */
86 next_class_instance = class_instance;
87 next_class_instance = *next_class_instance;
88
89 /* Start with the first class instance attached to the class container. */
90 current_class_instance = host_class -> ux_host_class_first_instance;
91
92 /* Check if there are any instances attached. */
93 if (current_class_instance == UX_NULL)
94 {
95
96 /* Error trap. */
97 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_HOST_CLASS_INSTANCE_UNKNOWN);
98
99 /* If trace is enabled, insert this event into the trace buffer. */
100 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, class_instance, 0, 0, UX_TRACE_ERRORS, 0, 0)
101
102 return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
103 }
104
105 /* The first instance is a special case because it is attached to the class
106 container. */
107 if (current_class_instance == class_instance)
108 {
109
110 /* Point to next class instance. */
111 host_class -> ux_host_class_first_instance = next_class_instance;
112
113 /* Return success. */
114 return(UX_SUCCESS);
115 }
116
117 /* Traverse the list of the class instances until we found the right one. */
118 while (*current_class_instance != UX_NULL)
119 {
120
121 /* Check to see if this class is the one we need to destroy. */
122 if(*current_class_instance == class_instance)
123 {
124
125 /* Point to next class instance. */
126 *current_class_instance = next_class_instance;
127
128 /* Return success. */
129 return(UX_SUCCESS);
130 }
131
132 /* Points to the next class instance. */
133 current_class_instance = *current_class_instance;
134 }
135
136 /* Error trap. */
137 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_HOST_CLASS_INSTANCE_UNKNOWN);
138
139 /* If trace is enabled, insert this event into the trace buffer. */
140 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, class_instance, 0, 0, UX_TRACE_ERRORS, 0, 0)
141
142 /* Return error to caller. */
143 return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
144 }
145
146