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_stop PORTABLE C */
38 /* 6.1.12 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function stops the video channel. */
46 /* */
47 /* INPUT */
48 /* */
49 /* video Pointer to video class */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* Completion Status */
54 /* */
55 /* CALLS */
56 /* */
57 /* _ux_host_stack_endpoint_transfer_abort */
58 /* Abort outstanding transfer */
59 /* _ux_host_stack_interface_setting_select */
60 /* Select interface */
61 /* _ux_host_semaphore_get Get semaphore */
62 /* _ux_host_semaphore_put Release semaphore */
63 /* */
64 /* CALLED BY */
65 /* */
66 /* Video Class */
67 /* */
68 /* RELEASE HISTORY */
69 /* */
70 /* DATE NAME DESCRIPTION */
71 /* */
72 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
73 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
74 /* resulting in version 6.1 */
75 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
76 /* refined macros names, */
77 /* resulting in version 6.1.10 */
78 /* 04-25-2022 Chaoqiong Xiao Modified comment(s), */
79 /* fixed standalone compile, */
80 /* resulting in version 6.1.11 */
81 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
82 /* fixed parameter/variable */
83 /* names conflict C++ keyword, */
84 /* resulting in version 6.1.12 */
85 /* */
86 /**************************************************************************/
_ux_host_class_video_stop(UX_HOST_CLASS_VIDEO * video)87 UINT _ux_host_class_video_stop(UX_HOST_CLASS_VIDEO *video)
88 {
89
90 UINT status;
91 UX_CONFIGURATION *configuration;
92 UX_INTERFACE *interface_ptr;
93 UINT streaming_interface;
94
95
96 /* Protect thread reentry to this instance. */
97 status = _ux_host_semaphore_get(&video -> ux_host_class_video_semaphore, UX_WAIT_FOREVER);
98
99 /* Get the interface number of the video streaming interface. */
100 streaming_interface = video -> ux_host_class_video_streaming_interface -> ux_interface_descriptor.bInterfaceNumber;
101
102 /* We need to abort transactions on the iso pipe. */
103 if (video -> ux_host_class_video_isochronous_endpoint != UX_NULL)
104 {
105
106 /* Abort the iso transfer. */
107 _ux_host_stack_endpoint_transfer_abort(video -> ux_host_class_video_isochronous_endpoint);
108 }
109
110 /* We found the alternate setting for the sampling values demanded, now we need
111 to search its container. */
112 configuration = video -> ux_host_class_video_streaming_interface -> ux_interface_configuration;
113 interface_ptr = configuration -> ux_configuration_first_interface;
114
115 /* Scan all interfaces. */
116 while (interface_ptr != UX_NULL)
117 {
118
119 /* We search for both the right interface and alternate setting. */
120 if ((interface_ptr -> ux_interface_descriptor.bInterfaceNumber == streaming_interface) &&
121 (interface_ptr -> ux_interface_descriptor.bAlternateSetting == 0))
122 {
123
124 /* We have found the right interface/alternate setting combination
125 The stack will select it for us. */
126 status = _ux_host_stack_interface_setting_select(interface_ptr);
127
128 /* If the alternate setting for the streaming interface could be selected, we memorize it. */
129 if (status == UX_SUCCESS)
130 {
131
132 /* Memorize the interface. */
133 video -> ux_host_class_video_streaming_interface = interface_ptr;
134
135 /* There is no endpoint for the alternate setting 0. */
136 video -> ux_host_class_video_isochronous_endpoint = UX_NULL;
137
138 /* Unprotect thread reentry to this instance. */
139 _ux_host_semaphore_put(&video -> ux_host_class_video_semaphore);
140
141 /* Return successful completion. */
142 return(UX_SUCCESS);
143 }
144 }
145
146 /* Move to next interface. */
147 interface_ptr = interface_ptr -> ux_interface_next_interface;
148 }
149
150 /* Unprotect thread reentry to this instance. */
151 _ux_host_semaphore_put(&video -> ux_host_class_video_semaphore);
152
153 /* Return completion status. */
154 return(status);
155 }
156
157