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_ioctl PORTABLE C */
38 /* 6.1.12 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function is the ioctl entry point for the application to */
46 /* configure the video class based device. */
47 /* */
48 /* */
49 /* INPUT */
50 /* */
51 /* video Pointer to video class */
52 /* ioctl_function Ioctl function */
53 /* parameter Pointer to structure */
54 /* */
55 /* OUTPUT */
56 /* */
57 /* Completion Status */
58 /* */
59 /* CALLS */
60 /* */
61 /* _ux_host_class_video_format_data_get Get video format data. */
62 /* _ux_host_class_video_frame_data_get Get video frame data */
63 /* _ux_host_class_video_frame_interval_get */
64 /* Get video frame internal data.*/
65 /* _ux_host_class_video_channel_start Start the video. */
66 /* _ux_host_class_video_stop Stop the video. */
67 /* _ux_host_stack_endpoint_transfer_abort */
68 /* Abort the transfer */
69 /* _ux_system_error_handler Log system error */
70 /* */
71 /* CALLED BY */
72 /* */
73 /* Storage Class */
74 /* */
75 /* RELEASE HISTORY */
76 /* */
77 /* DATE NAME DESCRIPTION */
78 /* */
79 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
80 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
81 /* resulting in version 6.1 */
82 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
83 /* reset indexes of requests */
84 /* ring when it is aborted, */
85 /* resulting in version 6.1.12 */
86 /* */
87 /**************************************************************************/
_ux_host_class_video_ioctl(UX_HOST_CLASS_VIDEO * video,ULONG ioctl_function,VOID * parameter)88 UINT _ux_host_class_video_ioctl(UX_HOST_CLASS_VIDEO *video, ULONG ioctl_function,
89 VOID *parameter)
90 {
91
92 UINT status;
93 UX_HOST_CLASS_VIDEO_PARAMETER_INPUT_TERMINAL *input_terminal;
94 UX_HOST_CLASS_VIDEO_PARAMETER_NUMBER_FORMATS *number_formats;
95 UX_HOST_CLASS_VIDEO_PARAMETER_FORMAT_DATA *format_parameter;
96 UX_HOST_CLASS_VIDEO_PARAMETER_FRAME_DATA *frame_parameter;
97 UX_HOST_CLASS_VIDEO_PARAMETER_CHANNEL *channel_parameter;
98 UX_HOST_CLASS_VIDEO_PARAMETER_FRAME_INTERVAL *interval_parameter;
99
100 /* Ensure the instance is valid. */
101 if ((video -> ux_host_class_video_state != UX_HOST_CLASS_INSTANCE_LIVE) &&
102 (video -> ux_host_class_video_state != UX_HOST_CLASS_INSTANCE_MOUNTING))
103 {
104
105 /* If trace is enabled, insert this event into the trace buffer. */
106 //UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, video, 0, 0, UX_TRACE_ERRORS, 0, 0)
107
108 return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
109 }
110
111 /* The command request will tell us what we need to do here. */
112 switch (ioctl_function)
113 {
114
115 case UX_HOST_CLASS_VIDEO_IOCTL_GET_INPUT_TERMINAL:
116
117 /* Set status to error by default. */
118 status = UX_ERROR;
119
120 /* Is the video terminal defined ? */
121 if (video -> ux_host_class_video_terminal_id != 0)
122 {
123
124 /* Cast answer. */
125 input_terminal = (UX_HOST_CLASS_VIDEO_PARAMETER_INPUT_TERMINAL *) parameter;
126
127 /* Return input terminal id. */
128 input_terminal -> ux_host_class_video_parameter_input_terminal_id = video -> ux_host_class_video_terminal_id;
129
130 /* Return input terminal type. */
131 input_terminal -> ux_host_class_video_parameter_input_terminal_type = video -> ux_host_class_video_terminal_type;
132
133 /* Status ok. */
134 status = UX_SUCCESS;
135 }
136
137 break;
138
139 case UX_HOST_CLASS_VIDEO_IOCTL_GET_FORMAT_NUMBER:
140
141 /* Cast answer. */
142 number_formats = (UX_HOST_CLASS_VIDEO_PARAMETER_NUMBER_FORMATS *) parameter;
143
144 /* Save the number of formats. */
145 number_formats -> ux_host_class_video_parameter_number_formats = video -> ux_host_class_video_number_formats;
146
147 /* Status ok. */
148 status = UX_SUCCESS;
149
150 break;
151
152 case UX_HOST_CLASS_VIDEO_IOCTL_GET_FORMAT_DATA:
153
154 /* Cast answer. */
155 format_parameter = (UX_HOST_CLASS_VIDEO_PARAMETER_FORMAT_DATA *) parameter;
156
157 /* Get the format data for the format index requested. */
158 status = _ux_host_class_video_format_data_get(video, format_parameter);
159 break;
160
161 case UX_HOST_CLASS_VIDEO_IOCTL_GET_FRAME_DATA:
162
163 /* Cast answer. */
164 frame_parameter = (UX_HOST_CLASS_VIDEO_PARAMETER_FRAME_DATA *) parameter;
165
166 /* Get the frame data for the frame index requested. */
167 status = _ux_host_class_video_frame_data_get(video, frame_parameter);
168 break;
169
170 case UX_HOST_CLASS_VIDEO_IOCTL_GET_FRAME_INTERVAL:
171
172 /* Cast answer. */
173 interval_parameter = (UX_HOST_CLASS_VIDEO_PARAMETER_FRAME_INTERVAL *) parameter;
174
175 /* Get the frame intervals for the frame index requested. */
176 status = _ux_host_class_video_frame_interval_get(video, interval_parameter);
177 break;
178
179 case UX_HOST_CLASS_VIDEO_IOCTL_CHANNEL_START:
180
181 /* Cast answer. */
182 channel_parameter = (UX_HOST_CLASS_VIDEO_PARAMETER_CHANNEL *) parameter;
183
184 /* Start the channel for reading video input. */
185 status = _ux_host_class_video_channel_start(video, channel_parameter);
186 break;
187
188 case UX_HOST_CLASS_VIDEO_IOCTL_CHANNEL_STOP:
189
190 /* Stop the channel. */
191 status = _ux_host_class_video_stop(video);
192 break;
193
194
195 case UX_HOST_CLASS_VIDEO_IOCTL_ABORT_IN_PIPE :
196
197 /* If trace is enabled, insert this event into the trace buffer. */
198 //UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_VIDEO_IOCTL_ABORT_IN_PIPE, video, video -> ux_host_class_video_isochronous_endpoint, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
199
200 /* We need to abort transactions on the bulk In pipe. */
201 _ux_host_stack_endpoint_transfer_abort(video -> ux_host_class_video_isochronous_endpoint);
202
203 /* All linked requests are aborted, reset indexes. */
204 video -> ux_host_class_video_transfer_request_start_index = 0;
205 video -> ux_host_class_video_transfer_request_end_index = 0;
206
207 /* Status is successful. */
208 status = UX_SUCCESS;
209 break;
210
211 default:
212
213 /* Error trap. */
214 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED);
215
216 /* If trace is enabled, insert this event into the trace buffer. */
217 //UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
218
219 /* Function not supported. Return an error. */
220 status = UX_FUNCTION_NOT_SUPPORTED;
221 }
222
223 /* Return status to caller. */
224 return(status);
225 }
226
227