1 /* This test is designed to test the ux_utility_descriptor_pack. */
2
3 #include <stdio.h>
4 #include "tx_api.h"
5 #include "ux_api.h"
6 #include "ux_system.h"
7 #include "ux_utility.h"
8
9 #include "ux_host_stack.h"
10 #include "ux_device_stack.h"
11 #include "ux_host_class_video.h"
12 #include "ux_host_class_dummy.h"
13
14 #include "ux_device_class_video.h"
15
16 #include "ux_test.h"
17
18 /* Define USBX test constants. */
19
20 #define UX_TEST_STACK_SIZE 4096
21 #define UX_TEST_BUFFER_SIZE 2048
22 #define UX_TEST_MEMORY_SIZE (64*1024)
23
24
25 /* Define the counters used in the test application... */
26
27 static ULONG error_counter = 0;
28
29 /* Define USBX test global variables. */
30
31
32 /* Define prototypes for external Host Controller's (HCDs), classes and clients. */
33
34 static TX_THREAD ux_test_thread_simulation_0;
35 static void ux_test_thread_simulation_0_entry(ULONG);
36
37
38 /* Prototype for test control return. */
39
40 void test_control_return(UINT status);
41
42 /* Define constants. */
43
44 #define UX_DEMO_REQUEST_MAX_LENGTH \
45 ((UX_HCD_SIM_HOST_MAX_PAYLOAD) > (UX_SLAVE_REQUEST_DATA_MAX_LENGTH) ? \
46 (UX_HCD_SIM_HOST_MAX_PAYLOAD) : (UX_SLAVE_REQUEST_DATA_MAX_LENGTH))
47
48 #define UX_DEMO_DEBUG_SIZE (4096*8)
49 #define UX_DEMO_STACK_SIZE 1024
50 #define UX_DEMO_BUFFER_SIZE (UX_DEMO_REQUEST_MAX_LENGTH + 1)
51 #define UX_DEMO_MEMORY_SIZE (128*1024)
52 #define UX_DEMO_ENDPOINT_SIZE 480
53
54 #define UX_TEST_LOG_SIZE (64)
55
56
57 /* Define local/extern function prototypes. */
58 static void test_thread_entry(ULONG);
59 static TX_THREAD tx_test_thread_host_simulation;
60 static TX_THREAD tx_test_thread_slave_simulation;
61 static void tx_test_thread_host_simulation_entry(ULONG);
62 static void tx_test_thread_slave_simulation_entry(ULONG);
63
64
65 /* Define global data structures. */
66 static UCHAR usbx_memory[UX_DEMO_MEMORY_SIZE + (UX_DEMO_STACK_SIZE * 2)];
67
68 static UX_HOST_CLASS_DUMMY *dummy_control;
69 static UX_HOST_CLASS_DUMMY *dummy_tx;
70 static UX_HOST_CLASS_DUMMY *dummy_rx;
71
72 static UX_DEVICE_CLASS_VIDEO *device_video;
73 static UX_DEVICE_CLASS_VIDEO_STREAM *device_video_tx_stream;
74 static UX_DEVICE_CLASS_VIDEO_STREAM *device_video_rx_stream;
75 static UX_DEVICE_CLASS_VIDEO_PARAMETER device_video_parameter;
76 static UX_DEVICE_CLASS_VIDEO_STREAM_PARAMETER device_video_stream_parameter[2];
77
78 static UX_SLAVE_TRANSFER *device_video_tx_transfer;
79 static UX_SLAVE_TRANSFER *device_video_rx_transfer;
80
81 static UX_HOST_CLASS_VIDEO *video;
82
83 static ULONG error_counter;
84
85 static ULONG set_cfg_counter;
86
87 static ULONG rsc_mem_free_on_set_cfg;
88 static ULONG rsc_sem_on_set_cfg;
89 static ULONG rsc_sem_get_on_set_cfg;
90 static ULONG rsc_mutex_on_set_cfg;
91
92 static ULONG rsc_enum_sem_usage;
93 static ULONG rsc_enum_sem_get_count;
94 static ULONG rsc_enum_mutex_usage;
95 static ULONG rsc_enum_mem_usage;
96
97 static ULONG rsc_video_sem_usage;
98 static ULONG rsc_video_sem_get_count;
99 static ULONG rsc_video_mutex_usage;
100 static ULONG rsc_video_mem_usage;
101
102 static ULONG interaction_count;
103
104 static UCHAR error_callback_ignore = UX_TRUE;
105 static ULONG error_callback_counter;
106
107 static struct BUFFER_LOG_STRUCT {
108 ULONG length;
109 UCHAR data[256];
110 } buffer_log[UX_TEST_LOG_SIZE];
111 static ULONG buffer_log_count = 0;
112 #define SAVE_BUFFER_LOG(buf,siz) do { \
113 if (buffer_log_count < UX_TEST_LOG_SIZE) { \
114 ULONG __local_size__ = ((siz) > 256) ? 256 : (siz); \
115 buffer_log[buffer_log_count].length = (siz); \
116 _ux_utility_memory_copy(buffer_log[buffer_log_count].data, (buf), __local_size__); \
117 } \
118 buffer_log_count ++; \
119 } while(0)
120
121 static ULONG test_tx_ack_count = 0xFFFFFFFF;
122 static ULONG test_tx_ins_count = 0;
123 static ULONG test_tx_ins_way = 0;
124
125 static struct CALLBACK_INVOKE_LOG_STRUCT {
126 VOID *func;
127 VOID *param1;
128 VOID *param2;
129 VOID *param3;
130 } callback_invoke_log[UX_TEST_LOG_SIZE];
131 static ULONG callback_invoke_count = 0;
132
133 #define SAVE_CALLBACK_INVOKE_LOG(f,p1,p2,p3) do { \
134 if (callback_invoke_count < UX_TEST_LOG_SIZE) { \
135 callback_invoke_log[callback_invoke_count].func = (VOID *)(f); \
136 callback_invoke_log[callback_invoke_count].param1 = (VOID *)(p1); \
137 callback_invoke_log[callback_invoke_count].param2 = (VOID *)(p2); \
138 callback_invoke_log[callback_invoke_count].param3 = (VOID *)(p3); \
139 callback_invoke_count++; \
140 } \
141 } while(0)
142 #define RESET_CALLBACK_INVOKE_LOG() do { \
143 callback_invoke_count = 0; \
144 } while(0)
145
146 /* Define device framework. */
147
148 #define W(d) UX_DW0(d), UX_DW1(d)
149 #define DW(d) UX_DW0(d), UX_DW1(d), UX_DW2(d), UX_DW3(d)
150
151 #define _DEVICE_DESCRIPTOR() \
152 /* --------------------------------------- Device Descriptor */ \
153 /* 0 bLength, bDescriptorType */ 18, 0x01, \
154 /* 2 bcdUSB */ UX_DW0(0x200),UX_DW1(0x200), \
155 /* 4 bDeviceClass, bDeviceSubClass, bDeviceProtocol */ 0x00, 0x00, 0x00, \
156 /* 7 bMaxPacketSize0 */ 0x08, \
157 /* 8 idVendor, idProduct */ 0x84, 0x84, 0x01, 0x00, \
158 /* 12 bcdDevice */ UX_DW0(0x100),UX_DW1(0x100), \
159 /* 14 iManufacturer, iProduct, iSerialNumber */ 0, 0, 0, \
160 /* 17 bNumConfigurations */ 1,
161
162 #define _DEVICE_QUALIFIER_DESCRIPTOR() \
163 /* ----------------------------- Device Qualifier Descriptor */ \
164 /* 0 bLength, bDescriptorType */ 10, 0x06, \
165 /* 2 bcdUSB */ UX_DW0(0x200),UX_DW1(0x200), \
166 /* 4 bDeviceClass, bDeviceSubClass, bDeviceProtocol */ 0x00, 0x00, 0x00, \
167 /* 7 bMaxPacketSize0 */ 8, \
168 /* 8 bNumConfigurations */ 1, \
169 /* 9 bReserved */ 0,
170
171 #define _CONFIGURE_DESCRIPTOR(total_len,n_ifc,cfg_v) \
172 /* -------------------------------- Configuration Descriptor */ \
173 /* 0 bLength, bDescriptorType */ 9, 0x02, \
174 /* 2 wTotalLength */ UX_DW0(total_len),UX_DW1(total_len),\
175 /* 4 bNumInterfaces, bConfigurationValue */ (n_ifc), (cfg_v), \
176 /* 6 iConfiguration */ 0, \
177 /* 7 bmAttributes, bMaxPower */ 0x80, 50,
178
179 #define _IAD_DESCRIPTOR(ifc_0,ifc_cnt,cls,sub,protocol) \
180 /* ------------------------ Interface Association Descriptor */ \
181 /* 0 bLength, bDescriptorType */ 8, 0x0B, \
182 /* 2 bFirstInterface, bInterfaceCount */ (ifc_0), (ifc_cnt), \
183 /* 4 bFunctionClass, bFunctionSubClass, bFunctionProtocol */ (cls), (sub), (protocol), \
184 /* 7 iFunction */ 0,
185
186 #define _INTERFACE_DESCRIPTOR(ifc,alt,n_ep,cls,sub,protocol) \
187 /* ------------------------------------ Interface Descriptor */ \
188 /* 0 bLength, bDescriptorType */ 9, 0x04, \
189 /* 2 bInterfaceNumber, bAlternateSetting */ (ifc), (alt), \
190 /* 4 bNumEndpoints */ (n_ep), \
191 /* 5 bInterfaceClass, bInterfaceSubClass, bInterfaceProtocol */ (cls), (sub), (protocol), \
192 /* 8 iInterface */ 0,
193
194 #define _ENDPOINT_DESCRIPTOR(addr,attr,pkt_siz,interval) \
195 /* ------------------------------------- Endpoint Descriptor */ \
196 /* 0 bLength, bDescriptorType */ 7, 0x05, \
197 /* 2 bEndpointAddress, bmAttributes */ (addr), (attr), \
198 /* 4 wMaxPacketSize, bInterval */ UX_DW0(pkt_siz),UX_DW1(pkt_siz),(interval),
199
200 #define _VC_DESCRIPTORS_LEN (14+17+9+17+9)
201 #define _VC_DESCRIPTORS() \
202 /*--------------------------- Class VC Interface Descriptor (VC_HEADER). */ \
203 14, 0x24, 0x01, W(0x150), \
204 W(_VC_DESCRIPTORS_LEN), /* wTotalLength. */ \
205 DW(6000000), /* dwClockFrequency. */ \
206 2, /* bInCollection. */ \
207 1, 2, /* BaInterfaceNr(2). */ \
208 /*--------------------------- Input Terminal (VC_INPUT_TERMINAL, Camera) */ \
209 17, 0x24, 0x02, \
210 0x01, /* bTerminalID, ITT_CAMERA */ \
211 W(0x201), /* wTerminalType */ \
212 0x00, 0x00, W(0), W(0), W(0), \
213 0x02, W(0), /* bControlSize, bmControls */ \
214 /*---------------------------- Output Terminal (VC_OUTPUT_TERMINAL, USB) */ \
215 9, 0x24, 0x03, \
216 0x02, /* bTerminalID */ \
217 W(0x0101), /* wTerminalType, TT_STREAMING */ \
218 0x00, 0x01/* bSourceID */, 0x00, \
219 /*--------------------------- Input Terminal (VC_INPUT_TERMINAL, USB) */ \
220 17, 0x24, 0x02, \
221 0x03, /* bTerminalID */ \
222 W(0x101), /* wTerminalType, TT_STREAMING */ \
223 0x00, 0x00, W(0), W(0), W(0), \
224 0x02, W(0), /* bControlSize, bmControls */ \
225 /*---------------------------- Output Terminal (VC_OUTPUT_TERMINAL, DISPLAY) */ \
226 9, 0x24, 0x03, \
227 0x04, /* bTerminalID */ \
228 W(0x0301), /* wTerminalType, OTT_DISPLAY */ \
229 0x00, 0x03/* bSourceID */, 0x00,
230
231 #if 0
232 /*--------------------------------- Processing Unit (VC_PROCESSING_UNIT) */ \
233 12, 0x24, 0x05, \
234 , /* bUnitID */ \
235 , /* bSourceID */ \
236 W(0), \
237 3 /* bControlSize */, 0, 0, 0 /*bmControls */, \
238 0x00, 0x00, \
239 /*--------------------------------- Processing Unit (VC_PROCESSING_UNIT) */ \
240 12, 0x24, 0x05, \
241 , /* bUnitID */ \
242 , /* bSourceID */ \
243 W(0), \
244 3 /* bControlSize */, 0, 0, 0 /*bmControls */, \
245 0x00, 0x00, \
246
247 #endif
248
249 #define _VS_IN_DESCRIPTORS_LEN (14+11+38)
250 #define _VS_IN_DESCRIPTORS() \
251 /*------------------------- Class VS Header Descriptor (VS_INPUT_HEADER) */ \
252 14, 0x24, 0x01, \
253 0X01, /* bNumFormats */ \
254 W(_VS_IN_DESCRIPTORS_LEN), /* wTotalLength */ \
255 0x81, /* bEndpointAddress */ \
256 0x00, \
257 0x02, /* bTerminalLink */ \
258 0x00, /* bStillCaptureMethod */ \
259 0x00, 0x00, /* bTriggerSupport, bTriggerUsage */ \
260 0x01, 0x00, /* bControlSize, bmaControls */ \
261 /*------------------------------- VS Format Descriptor (VS_FORMAT_MJPEG) */ \
262 11, 0x24, 0x06, \
263 0x01, /* bFormatIndex */ \
264 0x01, /* bNumFrameDescriptors */ \
265 0x01, /* bmFlags */ \
266 0x01, /* bDefaultFrameIndex */ \
267 0x00, 0x00, 0x00, 0x00, \
268 /*--------------------------------- VS Frame Descriptor (VS_FRAME_MJPEG) */ \
269 38, 0x24, 0x07, \
270 0x01, /* bFrameIndex */ \
271 0x03, /* bmCapabilities */ \
272 W(176), W(144), /* wWidth, wHeight */ \
273 DW(912384), DW(912384), /* dwMinBitRate, dwMaxBitRate */ \
274 DW(38016), /* dwMaxVideoFrameBufSize */ \
275 DW(666666), /* dwDefaultFrameInterval */ \
276 0x00, /* bFrameIntervalType */ \
277 DW(666666), DW(666666), DW(0), /* dwMinFrameInterval, dwMaxFrameInterval, dwFrameIntervalStep */
278
279 #define _VS_OUT_DESCRIPTORS_LEN (11+11+38)
280 #define _VS_OUT_DESCRIPTORS() \
281 /*------------------------- Class VS Header Descriptor (VS_OUTPUT_HEADER) */ \
282 11, 0x24, 0x02, \
283 0x01, /* bNumFormats */ \
284 W(_VS_OUT_DESCRIPTORS_LEN), /* wTotalLength */ \
285 0x02, /* bEndpointAddress */ \
286 0x00, \
287 0x03, /* bTerminalLink */ \
288 0x01, 0x00, /* bControlSize, bmaControls */ \
289 /*------------------------------- VS Format Descriptor (VS_FORMAT_MJPEG) */ \
290 11, 0x24, 0x06, \
291 0x01, /* bFormatIndex */ \
292 0x01, /* bNumFrameDescriptors */ \
293 0x01, /* bmFlags */ \
294 0x01, /* bDefaultFrameIndex */ \
295 0x00, 0x00, 0x00, 0x00, \
296 /*--------------------------------- VS Frame Descriptor (VS_FRAME_MJPEG) */ \
297 38, 0x24, 0x07, \
298 0x01, /* bFrameIndex */ \
299 0x03, /* bmCapabilities */ \
300 W(176), W(144), /* wWidth, wHeight */ \
301 DW(912384), DW(912384), /* dwMinBitRate, dwMaxBitRate */ \
302 DW(38016), /* dwMaxVideoFrameBufSize */ \
303 DW(666666), /* dwDefaultFrameInterval */ \
304 0x00, /* bFrameIntervalType */ \
305 DW(666666), DW(666666), DW(0), /* dwMinFrameInterval, dwMaxFrameInterval, dwFrameIntervalStep */
306
307
308 #define _CONFIGURE_DESCRIPTORS_LEN (9+ 8+ 9+_VC_DESCRIPTORS_LEN+ 9+_VS_IN_DESCRIPTORS_LEN+9+7+ 9+_VS_OUT_DESCRIPTORS_LEN+9+7)
309
310 static unsigned char device_framework_full_speed[] = {
311 _DEVICE_DESCRIPTOR()
312 _CONFIGURE_DESCRIPTOR(_CONFIGURE_DESCRIPTORS_LEN,3,1)
313 _IAD_DESCRIPTOR(0,3,0x0E,0x03,0x00)
314
315 _INTERFACE_DESCRIPTOR(0,0,0,0x0E,0x01,0x01)
316 _VC_DESCRIPTORS()
317
318 _INTERFACE_DESCRIPTOR(1,0,0,0x0E,0x02,0x00)
319 _VS_IN_DESCRIPTORS()
320 _INTERFACE_DESCRIPTOR(1,1,1,0x0E,0x02,0x00)
321 _ENDPOINT_DESCRIPTOR(0x81,0x05,UX_DEMO_ENDPOINT_SIZE,0x01)
322
323 _INTERFACE_DESCRIPTOR(2,0,0,0x0E,0x02,0x00)
324 _VS_OUT_DESCRIPTORS()
325 _INTERFACE_DESCRIPTOR(2,1,1,0x0E,0x02,0x00)
326 _ENDPOINT_DESCRIPTOR(0x02,0x05,UX_DEMO_ENDPOINT_SIZE,0x01)
327 };
328 #define DEVICE_FRAMEWORK_LENGTH_FULL_SPEED sizeof(device_framework_full_speed)
329
330 static unsigned char device_framework_high_speed[] = {
331 _DEVICE_DESCRIPTOR()
332 _DEVICE_QUALIFIER_DESCRIPTOR()
333 _CONFIGURE_DESCRIPTOR(_CONFIGURE_DESCRIPTORS_LEN,3,1)
334 _IAD_DESCRIPTOR(0,3,0x0E,0x03,0x00)
335
336 _INTERFACE_DESCRIPTOR(0,0,0,0x0E,0x01,0x01)
337 _VC_DESCRIPTORS()
338
339 _INTERFACE_DESCRIPTOR(1,0,0,0x0E,0x02,0x00)
340 _VS_IN_DESCRIPTORS()
341 _INTERFACE_DESCRIPTOR(1,1,1,0x0E,0x02,0x00)
342 _ENDPOINT_DESCRIPTOR(0x81,0x05,UX_DEMO_ENDPOINT_SIZE,0x01)
343
344 _INTERFACE_DESCRIPTOR(2,0,0,0x0E,0x02,0x00)
345 _VS_OUT_DESCRIPTORS()
346 _INTERFACE_DESCRIPTOR(2,1,1,0x0E,0x02,0x00)
347 _ENDPOINT_DESCRIPTOR(0x02,0x05,UX_DEMO_ENDPOINT_SIZE,0x01)
348 };
349 #define DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED sizeof(device_framework_high_speed)
350
351 static unsigned char string_framework[] = {
352
353 /* Manufacturer string descriptor : Index 1 - "Express Logic" */
354 0x09, 0x04, 0x01, 0x0c,
355 0x45, 0x78, 0x70, 0x72,0x65, 0x73, 0x20, 0x4c,
356 0x6f, 0x67, 0x69, 0x63,
357
358 /* Product string descriptor : Index 2 - "EL Composite device" */
359 0x09, 0x04, 0x02, 0x13,
360 0x45, 0x4c, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x6f,
361 0x73, 0x69, 0x74, 0x65, 0x20, 0x64, 0x65, 0x76,
362 0x69, 0x63, 0x65,
363
364 /* Serial Number string descriptor : Index 3 - "0001" */
365 0x09, 0x04, 0x03, 0x04,
366 0x30, 0x30, 0x30, 0x31
367 };
368 #define STRING_FRAMEWORK_LENGTH sizeof(string_framework)
369
370
371 /* Multiple languages are supported on the device, to add
372 a language besides English, the Unicode language code must
373 be appended to the language_id_framework array and the length
374 adjusted accordingly. */
375 static unsigned char language_id_framework[] = {
376
377 /* English. */
378 0x09, 0x04
379 };
380 #define LANGUAGE_ID_FRAMEWORK_LENGTH sizeof(language_id_framework)
381
device_video_activate(VOID * video_instance)382 static VOID device_video_activate(VOID *video_instance)
383 {
384 device_video = (UX_DEVICE_CLASS_VIDEO *)video_instance;
385 ux_device_class_video_stream_get(device_video, 0, &device_video_tx_stream);
386 ux_device_class_video_stream_get(device_video, 1, &device_video_rx_stream);
387 // printf("sVID:%p,%p,%p\n", video_instance, device_video_tx_stream, device_video_rx_stream);
388 }
device_video_deactivate(VOID * video_instance)389 static VOID device_video_deactivate(VOID *video_instance)
390 {
391 if ((VOID *)device_video == video_instance)
392 {
393 device_video = UX_NULL;
394 device_video_tx_stream = UX_NULL;
395 device_video_rx_stream = UX_NULL;
396 }
397 }
device_video_tx_stream_change(UX_DEVICE_CLASS_VIDEO_STREAM * video,ULONG alt)398 static VOID device_video_tx_stream_change(UX_DEVICE_CLASS_VIDEO_STREAM *video, ULONG alt)
399 {
400 SAVE_CALLBACK_INVOKE_LOG(device_video_tx_stream_change, video, (ALIGN_TYPE)alt, 0);
401 }
device_video_rx_stream_change(UX_DEVICE_CLASS_VIDEO_STREAM * video,ULONG alt)402 static VOID device_video_rx_stream_change(UX_DEVICE_CLASS_VIDEO_STREAM *video, ULONG alt)
403 {
404 SAVE_CALLBACK_INVOKE_LOG(device_video_rx_stream_change, video, (ALIGN_TYPE)alt, 0);
405
406 device_video_rx_transfer = UX_NULL;
407 }
device_video_vc_control_process(UX_DEVICE_CLASS_VIDEO * video,UX_SLAVE_TRANSFER * transfer)408 static UINT device_video_vc_control_process(UX_DEVICE_CLASS_VIDEO *video, UX_SLAVE_TRANSFER *transfer)
409 {
410 SAVE_CALLBACK_INVOKE_LOG(device_video_vc_control_process, video, transfer, 0);
411 return(UX_ERROR);
412 }
device_video_vs_control_process(UX_DEVICE_CLASS_VIDEO_STREAM * video,UX_SLAVE_TRANSFER * transfer)413 static UINT device_video_vs_control_process(UX_DEVICE_CLASS_VIDEO_STREAM *video, UX_SLAVE_TRANSFER *transfer)
414 {
415 SAVE_CALLBACK_INVOKE_LOG(device_video_vs_control_process, video, transfer, 0);
416 return(UX_ERROR);
417 }
device_video_tx_done(UX_DEVICE_CLASS_VIDEO_STREAM * video,ULONG length)418 static VOID device_video_tx_done(UX_DEVICE_CLASS_VIDEO_STREAM *video, ULONG length)
419 {
420 SAVE_CALLBACK_INVOKE_LOG(device_video_tx_done, video, (ALIGN_TYPE)length, 0);
421 }
device_video_rx_done(UX_DEVICE_CLASS_VIDEO_STREAM * video,ULONG length)422 static VOID device_video_rx_done(UX_DEVICE_CLASS_VIDEO_STREAM *video, ULONG length)
423 {
424 SAVE_CALLBACK_INVOKE_LOG(device_video_rx_done, video, (ALIGN_TYPE)length, 0);
425 }
426
427 /* Define what the initial system looks like. */
428
429 #ifdef CTEST
test_application_define(void * first_unused_memory)430 void test_application_define(void *first_unused_memory)
431 #else
432 void usbx_uxe_device_video_test_application_define(void *first_unused_memory)
433 #endif
434 {
435
436 UINT status;
437 CHAR *stack_pointer;
438 CHAR *memory_pointer;
439
440 /* Inform user. */
441 printf("Running uxe_device_video APIs Test.................................. ");
442 #if !defined(UX_DEVICE_CLASS_VIDEO_ENABLE_ERROR_CHECKING)
443 #warning Tests skipped due to compile option!
444 printf("SKIP SUCCESS!\n");
445 test_control_return(0);
446 return;
447 #endif /* UX_DEVICE_CLASS_VIDEO_ENABLE_ERROR_CHECKING */
448
449 /* Initialize the free memory pointer. */
450 stack_pointer = (CHAR *) first_unused_memory;
451 memory_pointer = stack_pointer + (UX_TEST_STACK_SIZE * 2);
452
453 /* Initialize USBX Memory. */
454 status = ux_system_initialize(memory_pointer, UX_TEST_MEMORY_SIZE, UX_NULL, 0);
455
456 /* Check for error. */
457 if (status != UX_SUCCESS)
458 {
459
460 printf("ERROR #%d\n", __LINE__);
461 test_control_return(1);
462 }
463
464 /* The code below is required for installing the device portion of USBX. No call back for
465 device status change in this example. */
466 status = ux_device_stack_initialize(device_framework_high_speed, DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED,
467 device_framework_full_speed, DEVICE_FRAMEWORK_LENGTH_FULL_SPEED,
468 string_framework, STRING_FRAMEWORK_LENGTH,
469 language_id_framework, LANGUAGE_ID_FRAMEWORK_LENGTH,UX_NULL);
470
471 UX_TEST_CHECK_SUCCESS(status);
472
473 /* Set the parameters for callback when insertion/extraction of a Video device, with IAD. */
474 #if defined(UX_DEVICE_STANDALONE)
475 device_video_stream_parameter[0].ux_device_class_video_stream_parameter_task_function = ux_device_class_video_write_task_function;
476 #else
477 device_video_stream_parameter[0].ux_device_class_video_stream_parameter_thread_entry = ux_device_class_video_write_thread_entry;
478 #endif
479 device_video_stream_parameter[0].ux_device_class_video_stream_parameter_callbacks.ux_device_class_video_stream_change = device_video_tx_stream_change;
480 device_video_stream_parameter[0].ux_device_class_video_stream_parameter_callbacks.ux_device_class_video_stream_payload_done = device_video_tx_done;
481 device_video_stream_parameter[0].ux_device_class_video_stream_parameter_callbacks.ux_device_class_video_stream_request = device_video_vs_control_process;
482 device_video_stream_parameter[0].ux_device_class_video_stream_parameter_max_payload_buffer_size = UX_DEMO_ENDPOINT_SIZE;
483 device_video_stream_parameter[0].ux_device_class_video_stream_parameter_max_payload_buffer_nb = 8;
484 #if defined(UX_DEVICE_STANDALONE)
485 device_video_stream_parameter[1].ux_device_class_video_stream_parameter_task_function = ux_device_class_video_read_task_function;
486 #else
487 device_video_stream_parameter[1].ux_device_class_video_stream_parameter_thread_entry = ux_device_class_video_read_thread_entry;
488 #endif
489 device_video_stream_parameter[1].ux_device_class_video_stream_parameter_callbacks.ux_device_class_video_stream_change = device_video_rx_stream_change;
490 device_video_stream_parameter[1].ux_device_class_video_stream_parameter_callbacks.ux_device_class_video_stream_payload_done = device_video_rx_done;
491 device_video_stream_parameter[1].ux_device_class_video_stream_parameter_callbacks.ux_device_class_video_stream_request = device_video_vs_control_process;
492 device_video_stream_parameter[1].ux_device_class_video_stream_parameter_max_payload_buffer_size = UX_DEMO_ENDPOINT_SIZE;
493 device_video_stream_parameter[1].ux_device_class_video_stream_parameter_max_payload_buffer_nb = 8;
494 // device_video_parameter.ux_device_class_video_parameter_streams = device_video_stream_parameter;
495 device_video_parameter.ux_device_class_video_parameter_streams_nb = 2;
496 device_video_parameter.ux_device_class_video_parameter_callbacks.ux_slave_class_video_instance_activate = device_video_activate;
497 device_video_parameter.ux_device_class_video_parameter_callbacks.ux_slave_class_video_instance_deactivate = device_video_deactivate;
498 device_video_parameter.ux_device_class_video_parameter_callbacks.ux_device_class_video_request = device_video_vc_control_process;
499 device_video_parameter.ux_device_class_video_parameter_callbacks.ux_device_class_video_arg = UX_NULL;
500
501 status = ux_device_stack_class_register(_ux_system_device_class_video_name, ux_device_class_video_entry,
502 1, 0, UX_NULL);
503 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER ,status);
504
505 device_video_parameter.ux_device_class_video_parameter_streams = UX_NULL;
506 status = ux_device_stack_class_register(_ux_system_device_class_video_name, ux_device_class_video_entry,
507 1, 0, &device_video_parameter);
508 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER ,status);
509
510 device_video_parameter.ux_device_class_video_parameter_streams = device_video_stream_parameter;
511 device_video_parameter.ux_device_class_video_parameter_streams_nb = 0;
512 status = ux_device_stack_class_register(_ux_system_device_class_video_name, ux_device_class_video_entry,
513 1, 0, &device_video_parameter);
514 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER ,status);
515
516 device_video_parameter.ux_device_class_video_parameter_streams = device_video_stream_parameter;
517 device_video_parameter.ux_device_class_video_parameter_streams_nb = 2;
518 device_video_stream_parameter[0].ux_device_class_video_stream_parameter_max_payload_buffer_size = 0;
519 status = ux_device_stack_class_register(_ux_system_device_class_video_name, ux_device_class_video_entry,
520 1, 0, &device_video_parameter);
521 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER ,status);
522
523 device_video_parameter.ux_device_class_video_parameter_streams = device_video_stream_parameter;
524 device_video_parameter.ux_device_class_video_parameter_streams_nb = 2;
525 device_video_stream_parameter[0].ux_device_class_video_stream_parameter_max_payload_buffer_size = UX_DEMO_ENDPOINT_SIZE;
526 device_video_stream_parameter[1].ux_device_class_video_stream_parameter_max_payload_buffer_nb = 0;
527 status = ux_device_stack_class_register(_ux_system_device_class_video_name, ux_device_class_video_entry,
528 1, 0, &device_video_parameter);
529 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER ,status);
530
531 /* Create the simulation thread. */
532 status = tx_thread_create(&ux_test_thread_simulation_0, "test simulation", ux_test_thread_simulation_0_entry, 0,
533 stack_pointer, UX_TEST_STACK_SIZE,
534 20, 20, 1, TX_AUTO_START);
535
536 /* Check for error. */
537 if (status != TX_SUCCESS)
538 {
539
540 printf("ERROR #%d\n", __LINE__);
541 test_control_return(1);
542 }
543 }
544
545
ux_test_thread_simulation_0_entry(ULONG arg)546 static void ux_test_thread_simulation_0_entry(ULONG arg)
547 {
548 UINT status;
549 UX_DEVICE_CLASS_VIDEO_STREAM dummy_video_stream;
550 ULONG dummy_length;
551 UCHAR payload_data[64];
552 ULONG payload_length;
553 UCHAR **dummy_payload = &payload_data;
554
555 dummy_length = ux_device_class_video_max_payload_length(UX_NULL);
556 if (dummy_length != 0)
557 {
558 printf("ERROR #%d\n", __LINE__);
559 test_control_return(1);
560 }
561
562 status = ux_device_class_video_reception_start(UX_NULL);
563 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
564
565 status = ux_device_class_video_read_payload_get(UX_NULL, dummy_payload, &payload_length);
566 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
567
568 status = ux_device_class_video_read_payload_get(&dummy_video_stream, UX_NULL, &payload_length);
569 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
570
571 status = ux_device_class_video_read_payload_get(&dummy_video_stream, dummy_payload, UX_NULL);
572 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
573
574 status = ux_device_class_video_read_payload_free(UX_NULL);
575 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
576
577 status = ux_device_class_video_transmission_start(UX_NULL);
578 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
579
580 status = ux_device_class_video_write_payload_get(UX_NULL, dummy_payload, &payload_length);
581 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
582
583 status = ux_device_class_video_write_payload_get(&dummy_video_stream, UX_NULL, &payload_length);
584 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
585
586 status = ux_device_class_video_write_payload_get(&dummy_video_stream, dummy_payload, UX_NULL);
587 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
588
589 status = ux_device_class_video_write_payload_commit(UX_NULL, 8);
590 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
591
592 status = ux_device_class_video_write_payload_commit(&dummy_video_stream, 0);
593 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
594
595 status = ux_device_class_video_ioctl(UX_NULL, 0, 0);
596 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
597
598 /* Sleep for a tick to make sure everything is complete. */
599 tx_thread_sleep(1);
600
601 /* Check for errors from other threads. */
602 if (error_counter)
603 {
604
605 /* Test error. */
606 printf("ERROR #%d: total %ld errors\n", __LINE__, error_counter);
607 test_control_return(1);
608 }
609 else
610 {
611
612 /* Successful test. */
613 printf("SUCCESS!\n");
614 test_control_return(0);
615 }
616 }
617