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 /** Video Class */
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_class_video.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_host_class_video_deactivate PORTABLE C */
38 /* 6.1.10 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function is called when this instance of the video has been */
46 /* removed from the bus either directly or indirectly. The iso pipes */
47 /* will be destroyed and the instanced removed. */
48 /* */
49 /* INPUT */
50 /* */
51 /* command Pointer to command */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* Completion Status */
56 /* */
57 /* CALLS */
58 /* */
59 /* _ux_host_stack_class_instance_destroy Destroy class instance */
60 /* _ux_host_stack_endpoint_transfer_abort */
61 /* Abort outstanding transfer */
62 /* _ux_host_semaphore_get Get semaphore */
63 /* _ux_host_semaphore_delete Delete semaphore */
64 /* _ux_utility_memory_free Release memory block */
65 /* _ux_utility_thread_schedule_other Schedule other threads */
66 /* */
67 /* CALLED BY */
68 /* */
69 /* Video Class */
70 /* */
71 /* RELEASE HISTORY */
72 /* */
73 /* DATE NAME DESCRIPTION */
74 /* */
75 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
76 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
77 /* fixed issue of aborting */
78 /* transfer without endpoint */
79 /* ready, deleted new semaphore*/
80 /* for control requests, */
81 /* resulting in version 6.1 */
82 /* 11-09-2020 Chaoqiong Xiao Modified comment(s), */
83 /* freed descriptor memory, */
84 /* resulting in version 6.1.2 */
85 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
86 /* refined macros names, */
87 /* resulting in version 6.1.10 */
88 /* */
89 /**************************************************************************/
_ux_host_class_video_deactivate(UX_HOST_CLASS_COMMAND * command)90 UINT _ux_host_class_video_deactivate(UX_HOST_CLASS_COMMAND *command)
91 {
92
93 UX_HOST_CLASS_VIDEO *video;
94 UINT status;
95
96 /* Get the instance for this class. */
97 video= (UX_HOST_CLASS_VIDEO *) command -> ux_host_class_command_instance;
98
99 /* The video is being shut down. */
100 video -> ux_host_class_video_state = UX_HOST_CLASS_INSTANCE_SHUTDOWN;
101
102 /* Protect thread reentry to this instance. */
103 status = _ux_host_semaphore_get(&video -> ux_host_class_video_semaphore, UX_WAIT_FOREVER);
104 if (status != UX_SUCCESS)
105
106 /* Return error. */
107 return(status);
108
109 /* We need to abort transactions on the iso out pipe. */
110 if (video -> ux_host_class_video_isochronous_endpoint)
111 _ux_host_stack_endpoint_transfer_abort(video -> ux_host_class_video_isochronous_endpoint);
112
113 /* The enumeration thread needs to sleep a while to allow the application or the class that may be using
114 endpoints to exit properly. */
115 _ux_host_thread_schedule_other(UX_THREAD_PRIORITY_ENUM);
116
117 /* Free descriptor memory. */
118 if (video -> ux_host_class_video_configuration_descriptor)
119 _ux_utility_memory_free(video -> ux_host_class_video_configuration_descriptor);
120
121 /* Destroy the instance. */
122 _ux_host_stack_class_instance_destroy(video -> ux_host_class_video_class, (VOID *) video);
123
124 /* Destroy the semaphores. */
125 _ux_host_semaphore_delete(&video -> ux_host_class_video_semaphore);
126 _ux_host_semaphore_delete(&video -> ux_host_class_video_semaphore_control_request);
127
128 /* Before we free the device resources, we need to inform the application
129 that the device is removed. */
130 if (_ux_system_host -> ux_system_host_change_function != UX_NULL)
131 {
132
133 /* Inform the application the device is removed. */
134 _ux_system_host -> ux_system_host_change_function(UX_DEVICE_REMOVAL, video -> ux_host_class_video_class, (VOID *) video);
135 }
136
137 /* If trace is enabled, insert this event into the trace buffer. */
138 //UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_VIDEO_DEACTIVATE, video, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
139
140 /* If trace is enabled, register this object. */
141 //UX_TRACE_OBJECT_UNREGISTER(video);
142
143 /* Free the video instance memory. */
144 _ux_utility_memory_free(video);
145
146 /* Return successful completion. */
147 return(UX_SUCCESS);
148 }
149
150