1 /* This test is designed to test the simple dpump host/device class operation. */
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 #include "ux_hcd_sim_host.h"
9
10 #include "fx_api.h"
11
12 #include "ux_device_class_audio.h"
13 #include "ux_device_class_audio20.h"
14 #include "ux_device_stack.h"
15
16 #include "ux_host_class_audio.h"
17 #include "ux_host_class_dummy.h"
18
19 #include "ux_test_dcd_sim_slave.h"
20 #include "ux_test_hcd_sim_host.h"
21 #include "ux_test_utility_sim.h"
22
23
24 /* Define constants. */
25
26 #define UX_DEMO_REQUEST_MAX_LENGTH \
27 ((UX_HCD_SIM_HOST_MAX_PAYLOAD) > (UX_SLAVE_REQUEST_DATA_MAX_LENGTH) ? \
28 (UX_HCD_SIM_HOST_MAX_PAYLOAD) : (UX_SLAVE_REQUEST_DATA_MAX_LENGTH))
29
30 #define UX_DEMO_DEBUG_SIZE (4096*8)
31 #define UX_DEMO_STACK_SIZE 1024
32 #define UX_DEMO_BUFFER_SIZE (UX_DEMO_REQUEST_MAX_LENGTH + 1)
33 #define UX_DEMO_MEMORY_SIZE (128*1024)
34
35 #define UX_TEST_LOG_SIZE (64)
36
37
38 /* Define local/extern function prototypes. */
39 static void test_thread_entry(ULONG);
40 static TX_THREAD tx_test_thread_host_simulation;
41 static TX_THREAD tx_test_thread_slave_simulation;
42 static void tx_test_thread_host_simulation_entry(ULONG);
43 static void tx_test_thread_slave_simulation_entry(ULONG);
44
45
46 /* Define global data structures. */
47 static UCHAR usbx_memory[UX_DEMO_MEMORY_SIZE + (UX_DEMO_STACK_SIZE * 2)];
48 static UCHAR buffer[64];
49
50 static UX_HOST_CLASS_DUMMY *dummy_control;
51 static UX_HOST_CLASS_DUMMY *dummy_tx;
52 static UX_HOST_CLASS_DUMMY *dummy_rx;
53
54 static UX_DEVICE_CLASS_AUDIO *slave_audio;
55 static UX_DEVICE_CLASS_AUDIO_PARAMETER slave_audio_parameter;
56 static UX_DEVICE_CLASS_AUDIO_STREAM_PARAMETER slave_audio_stream_parameter[2];
57
58 static UX_DEVICE_CLASS_AUDIO_STREAM *slave_audio_tx_stream;
59
60 static UX_DEVICE_CLASS_AUDIO_STREAM *slave_audio_rx_stream;
61 static UX_SLAVE_TRANSFER *slave_audio_rx_transfer;
62
63 static UX_HOST_CLASS_AUDIO *audio;
64
65 static UX_DEVICE_CLASS_AUDIO20_CONTROL g_slave_audio20_control[2];
66
67 static ULONG error_counter;
68
69 static ULONG set_cfg_counter;
70
71 static ULONG rsc_mem_free_on_set_cfg;
72 static ULONG rsc_sem_on_set_cfg;
73 static ULONG rsc_sem_get_on_set_cfg;
74 static ULONG rsc_mutex_on_set_cfg;
75
76 static ULONG rsc_enum_sem_usage;
77 static ULONG rsc_enum_sem_get_count;
78 static ULONG rsc_enum_mutex_usage;
79 static ULONG rsc_enum_mem_usage;
80
81 static ULONG rsc_audio_sem_usage;
82 static ULONG rsc_audio_sem_get_count;
83 static ULONG rsc_audio_mutex_usage;
84 static ULONG rsc_audio_mem_usage;
85
86 static ULONG interaction_count;
87
88 static UCHAR error_callback_ignore = UX_TRUE;
89 static ULONG error_callback_counter;
90
91 static struct BUFFER_LOG_STRUCT {
92 ULONG length;
93 UCHAR data[256];
94 } buffer_log[UX_TEST_LOG_SIZE];
95 static ULONG buffer_log_count = 0;
96 #define SAVE_BUFFER_LOG(buf,siz) do { \
97 if (buffer_log_count < UX_TEST_LOG_SIZE) { \
98 ULONG __local_size__ = ((siz) > 256) ? 256 : (siz); \
99 buffer_log[buffer_log_count].length = (siz); \
100 _ux_utility_memory_copy(buffer_log[buffer_log_count].data, (buf), __local_size__); \
101 } \
102 buffer_log_count ++; \
103 } while(0)
104
105 static ULONG test_tx_ack_count = 0xFFFFFFFF;
106 static ULONG test_tx_ins_count = 0;
107 static ULONG test_tx_ins_way = 0;
108
109 static struct CALLBACK_INVOKE_LOG_STRUCT {
110 VOID *func;
111 VOID *param1;
112 VOID *param2;
113 VOID *param3;
114 } callback_invoke_log[UX_TEST_LOG_SIZE];
115 static ULONG callback_invoke_count = 0;
116
117 #define SAVE_CALLBACK_INVOKE_LOG(f,p1,p2,p3) do { \
118 if (callback_invoke_count < UX_TEST_LOG_SIZE) { \
119 callback_invoke_log[callback_invoke_count].func = (VOID *)(f); \
120 callback_invoke_log[callback_invoke_count].param1 = (VOID *)(p1); \
121 callback_invoke_log[callback_invoke_count].param2 = (VOID *)(p2); \
122 callback_invoke_log[callback_invoke_count].param3 = (VOID *)(p3); \
123 callback_invoke_count++; \
124 } \
125 } while(0)
126 #define RESET_CALLBACK_INVOKE_LOG() do { \
127 callback_invoke_count = 0; \
128 } while(0)
129
130 /* Define device framework. */
131
132 #define D3(d) ((UCHAR)((d) >> 24))
133 #define D2(d) ((UCHAR)((d) >> 16))
134 #define D1(d) ((UCHAR)((d) >> 8))
135 #define D0(d) ((UCHAR)((d) >> 0))
136
137 static unsigned char device_framework_full_speed[] = {
138
139 /* --------------------------------------- Device Descriptor */
140 /* 0 bLength, bDescriptorType */ 18, 0x01,
141 /* 2 bcdUSB */ D0(0x200),D1(0x200),
142 /* 4 bDeviceClass, bDeviceSubClass, bDeviceProtocol */ 0x00, 0x00, 0x00,
143 /* 7 bMaxPacketSize0 */ 8,
144 /* 8 idVendor, idProduct */ 0x84, 0x84, 0x02, 0x00,
145 /* 12 bcdDevice */ D0(0x200),D1(0x200),
146 /* 14 iManufacturer, iProduct, iSerialNumber */ 0, 0, 0,
147 /* 17 bNumConfigurations */ 1,
148
149 /* ----------------------------- Device Qualifier Descriptor */
150 /* 0 bLength, bDescriptorType */ 10, 0x06,
151 /* 2 bcdUSB */ D0(0x200),D1(0x200),
152 /* 4 bDeviceClass, bDeviceSubClass, bDeviceProtocol */ 0x00, 0x00, 0x00,
153 /* 7 bMaxPacketSize0 */ 8,
154 /* 8 bNumConfigurations */ 1,
155 /* 9 bReserved */ 0,
156
157 /* -------------------------------- Configuration Descriptor *//* 9+8+120+55*2=247 */
158 /* 0 bLength, bDescriptorType */ 9, 0x02,
159 /* 2 wTotalLength */ D0(247),D1(247),
160 /* 4 bNumInterfaces, bConfigurationValue */ 3, 1,
161 /* 6 iConfiguration */ 0,
162 /* 7 bmAttributes, bMaxPower */ 0x80, 50,
163
164 /* ------------------------ Interface Association Descriptor */
165 /* 0 bLength, bDescriptorType */ 8, 0x0B,
166 /* 2 bFirstInterface, bInterfaceCount */ 0, 3,
167 /* 4 bFunctionClass, bFunctionSubClass, bFunctionProtocol */ 0x01, 0x00, 0x20,
168 /* 7 iFunction */ 0,
169
170 /* ------------------------------------ Interface Descriptor *//* 0 Control (9+111=120) */
171 /* 0 bLength, bDescriptorType */ 9, 0x04,
172 /* 2 bInterfaceNumber, bAlternateSetting */ 0, 0,
173 /* 4 bNumEndpoints */ 0,
174 /* 5 bInterfaceClass, bInterfaceSubClass, bInterfaceProtocol */ 0x01, 0x01, 0x20,
175 /* 8 iInterface */ 0,
176 /* ---------------- Audio 2.0 AC Interface Header Descriptor *//* (9+8+17*2+18*2+12*2=111) */
177 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 9, 0x24, 0x01,
178 /* 3 bcdADC, bCategory */ D0(0x200),D1(0x200), 0x08,
179 /* 6 wTotalLength */ D0(111),D1(111),
180 /* 8 bmControls */ 0x00,
181 /* -------------------- Audio 2.0 AC Clock Source Descriptor */
182 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 8, 0x24, 0x0A,
183 /* 3 bClockID, bmAttributes, bmControls */ 0x10, 0x05, 0x01,
184 /* 6 bAssocTerminal, iClockSource */ 0x00, 0,
185 /* ------------------- Audio 2.0 AC Input Terminal Descriptor */
186 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 17, 0x24, 0x02,
187 /* 3 bTerminalID, wTerminalType */ 0x01, D0(0x0201),D1(0x0201),
188 /* 6 bAssocTerminal, bCSourceID */ 0x00, 0x10,
189 /* 8 bNrChannels, bmChannelConfig */ 0x02, D0(0),D1(0),D2(0),D3(0),
190 /* 13 iChannelNames, bmControls, iTerminal */ 0, D0(0),D1(0), 0,
191 /* --------------------- Audio 2.0 AC Feature Unit Descriptor */
192 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 18, 0x24, 0x06,
193 /* 3 bUnitID, bSourceID */ 0x02, 0x01,
194 /* 5 bmaControls(0), bmaControls(...) ... */ D0(0xF),D1(0xF),D2(0xF),D3(0xF), D0(0),D1(0),D2(0),D3(0), D0(0),D1(0),D2(0),D3(0),
195 /* . iFeature */ 0,
196 /* ------------------ Audio 2.0 AC Output Terminal Descriptor */
197 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 12, 0x24, 0x03,
198 /* 3 bTerminalID, wTerminalType */ 0x03, D0(0x0101),D1(0x0101),
199 /* 6 bAssocTerminal, bSourceID, bCSourceID */ 0x00, 0x02, 0x10,
200 /* 9 bmControls, iTerminal */ D0(0),D1(0), 0,
201 /* ------------------- Audio 2.0 AC Input Terminal Descriptor */
202 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 17, 0x24, 0x02,
203 /* 3 bTerminalID, wTerminalType */ 0x04, D0(0x0101),D1(0x0101),
204 /* 6 bAssocTerminal, bCSourceID */ 0x00, 0x10,
205 /* 8 bNrChannels, bmChannelConfig */ 0x02, D0(0),D1(0),D2(0),D3(0),
206 /* 13 iChannelNames, bmControls, iTerminal */ 0, D0(0),D1(0), 0,
207 /* --------------------- Audio 2.0 AC Feature Unit Descriptor */
208 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 18, 0x24, 0x06,
209 /* 3 bUnitID, bSourceID */ 0x05, 0x04,
210 /* 5 bmaControls(0), bmaControls(...) ... */ D0(0xF),D1(0xF),D2(0xF),D3(0xF), D0(0),D1(0),D2(0),D3(0), D0(0),D1(0),D2(0),D3(0),
211 /* . iFeature */ 0,
212 /* ------------------ Audio 2.0 AC Output Terminal Descriptor */
213 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 12, 0x24, 0x03,
214 /* 3 bTerminalID, wTerminalType */ 0x06, D0(0x0301),D1(0x0301),
215 /* 6 bAssocTerminal, bSourceID, bCSourceID */ 0x00, 0x05, 0x10,
216 /* 9 bmControls, iTerminal */ D0(0),D1(0), 0,
217
218 /* ------------------------------------ Interface Descriptor *//* 1 Stream IN (9+9+16+6+7+8=55) */
219 /* 0 bLength, bDescriptorType */ 9, 0x04,
220 /* 2 bInterfaceNumber, bAlternateSetting */ 1, 0,
221 /* 4 bNumEndpoints */ 0,
222 /* 5 bInterfaceClass, bInterfaceSubClass, bInterfaceProtocol */ 0x01, 0x02, 0x20,
223 /* 8 iInterface */ 0,
224 /* ------------------------------------ Interface Descriptor */
225 /* 0 bLength, bDescriptorType */ 9, 0x04,
226 /* 2 bInterfaceNumber, bAlternateSetting */ 1, 1,
227 /* 4 bNumEndpoints */ 1,
228 /* 5 bInterfaceClass, bInterfaceSubClass, bInterfaceProtocol */ 0x01, 0x02, 0x20,
229 /* 8 iInterface */ 0,
230 /* ------------------------ Audio 2.0 AS Interface Descriptor */
231 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 16, 0x24, 0x01,
232 /* 3 bTerminalLink, bmControls */ 0x03,0x00,
233 /* 5 bFormatType, bmFormats */ 0x01,D0(1),D1(1),D2(1),D3(1),
234 /* 10 bNrChannels, bmChannelConfig */ 2, D0(0),D1(0),D2(0),D3(0),
235 /* 15 iChannelNames */ 0,
236 /* -------------------- Audio 2.0 AS Format Type I Descriptor */
237 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 6, 0x24, 0x02,
238 /* 3 bFormatType, bSubslotSize, bBitResolution */ 0x01, 2, 16,
239 /* ------------------------------------- Endpoint Descriptor */
240 /* 0 bLength, bDescriptorType */ 7, 0x05,
241 /* 2 bEndpointAddress, bmAttributes */ 0x81, 0x0D,
242 /* 4 wMaxPacketSize, bInterval */ D0(256),D1(256), 1,
243 /* ---------- Audio 2.0 AS ISO Audio Data Endpoint Descriptor */
244 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 8, 0x25, 0x01,
245 /* 3 bmAttributes, bmControls */ 0x00, 0x00,
246 /* 5 bLockDelayUnits, wLockDelay */ 0x00, D0(0),D1(0),
247
248 /* ------------------------------------ Interface Descriptor *//* 2 Stream OUT (9+9+16+6+7+8=55) */
249 /* 0 bLength, bDescriptorType */ 9, 0x04,
250 /* 2 bInterfaceNumber, bAlternateSetting */ 2, 0,
251 /* 4 bNumEndpoints */ 0,
252 /* 5 bInterfaceClass, bInterfaceSubClass, bInterfaceProtocol */ 0x01, 0x02, 0x20,
253 /* 8 iInterface */ 0,
254 /* ------------------------------------ Interface Descriptor */
255 /* 0 bLength, bDescriptorType */ 9, 0x04,
256 /* 2 bInterfaceNumber, bAlternateSetting */ 2, 1,
257 /* 4 bNumEndpoints */ 1,
258 /* 5 bInterfaceClass, bInterfaceSubClass, bInterfaceProtocol */ 0x01, 0x02, 0x20,
259 /* 8 iInterface */ 0,
260 /* ------------------------ Audio 2.0 AS Interface Descriptor */
261 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 16, 0x24, 0x01,
262 /* 3 bTerminalLink, bmControls */ 0x04,0x00,
263 /* 5 bFormatType, bmFormats */ 0x01,D0(1),D1(1),D2(1),D3(1),
264 /* 10 bNrChannels, bmChannelConfig */ 2, D0(0),D1(0),D2(0),D3(0),
265 /* 15 iChannelNames */ 0,
266 /* ---------------------- Audio 2.0 AS Format Type Descriptor */
267 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 6, 0x24, 0x02,
268 /* 3 bFormatType, bSubslotSize, bBitResolution */ 0x01, 2, 16,
269 /* ------------------------------------- Endpoint Descriptor */
270 /* 0 bLength, bDescriptorType */ 7, 0x05,
271 /* 2 bEndpointAddress, bmAttributes */ 0x02, 0x0D,
272 /* 4 wMaxPacketSize, bInterval */ D0(256),D1(256), 1,
273 /* ---------- Audio 2.0 AS ISO Audio Data Endpoint Descriptor */
274 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 8, 0x25, 0x01,
275 /* 3 bmAttributes, bmControls */ 0x00, 0x00,
276 /* 5 bLockDelayUnits, wLockDelay */ 0x00, D0(0),D1(0),
277
278 };
279 #define DEVICE_FRAMEWORK_LENGTH_FULL_SPEED sizeof(device_framework_full_speed)
280
281 static unsigned char device_framework_high_speed[] = {
282 /* --------------------------------------- Device Descriptor */
283 /* 0 bLength, bDescriptorType */ 18, 0x01,
284 /* 2 bcdUSB */ D0(0x200),D1(0x200),
285 /* 4 bDeviceClass, bDeviceSubClass, bDeviceProtocol */ 0x00, 0x00, 0x00,
286 /* 7 bMaxPacketSize0 */ 0x08,
287 /* 8 idVendor, idProduct */ 0x84, 0x84, 0x02, 0x00,
288 /* 12 bcdDevice */ D0(0x200),D1(0x200),
289 /* 14 iManufacturer, iProduct, iSerialNumber */ 0, 0, 0,
290 /* 17 bNumConfigurations */ 1,
291
292 /* ----------------------------- Device Qualifier Descriptor */
293 /* 0 bLength, bDescriptorType */ 10, 0x06,
294 /* 2 bcdUSB */ D0(0x200),D1(0x200),
295 /* 4 bDeviceClass, bDeviceSubClass, bDeviceProtocol */ 0x00, 0x00, 0x00,
296 /* 7 bMaxPacketSize0 */ 8,
297 /* 8 bNumConfigurations */ 1,
298 /* 9 bReserved */ 0,
299
300 /* -------------------------------- Configuration Descriptor *//* 9+8+120+55*2=247 */
301 /* 0 bLength, bDescriptorType */ 9, 0x02,
302 /* 2 wTotalLength */ D0(247),D1(247),
303 /* 4 bNumInterfaces, bConfigurationValue */ 3, 1,
304 /* 6 iConfiguration */ 0,
305 /* 7 bmAttributes, bMaxPower */ 0x80, 50,
306
307 /* ------------------------ Interface Association Descriptor */
308 /* 0 bLength, bDescriptorType */ 8, 0x0B,
309 /* 2 bFirstInterface, bInterfaceCount */ 0, 3,
310 /* 4 bFunctionClass, bFunctionSubClass, bFunctionProtocol */ 0x01, 0x00, 0x20,
311 /* 7 iFunction */ 0,
312
313 /* ------------------------------------ Interface Descriptor *//* 0 Control (9+111=120) */
314 /* 0 bLength, bDescriptorType */ 9, 0x04,
315 /* 2 bInterfaceNumber, bAlternateSetting */ 0, 0,
316 /* 4 bNumEndpoints */ 0,
317 /* 5 bInterfaceClass, bInterfaceSubClass, bInterfaceProtocol */ 0x01, 0x01, 0x20,
318 /* 8 iInterface */ 0,
319 /* ---------------- Audio 2.0 AC Interface Header Descriptor *//* (9+8+17*2+18*2+12*2=111) */
320 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 9, 0x24, 0x01,
321 /* 3 bcdADC, bCategory */ D0(0x200),D1(0x200), 0x08,
322 /* 6 wTotalLength */ D0(111),D1(111),
323 /* 8 bmControls */ 0x00,
324 /* -------------------- Audio 2.0 AC Clock Source Descriptor */
325 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 8, 0x24, 0x0A,
326 /* 3 bClockID, bmAttributes, bmControls */ 0x10, 0x05, 0x01,
327 /* 6 bAssocTerminal, iClockSource */ 0x00, 0,
328 /* ------------------- Audio 2.0 AC Input Terminal Descriptor */
329 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 17, 0x24, 0x02,
330 /* 3 bTerminalID, wTerminalType */ 0x01, D0(0x0201),D1(0x0201),
331 /* 6 bAssocTerminal, bCSourceID */ 0x00, 0x10,
332 /* 8 bNrChannels, bmChannelConfig */ 0x02, D0(0),D1(0),D2(0),D3(0),
333 /* 13 iChannelNames, bmControls, iTerminal */ 0, D0(0),D1(0), 0,
334 /* --------------------- Audio 2.0 AC Feature Unit Descriptor */
335 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 18, 0x24, 0x06,
336 /* 3 bUnitID, bSourceID */ 0x02, 0x01,
337 /* 5 bmaControls(0), bmaControls(...) ... */ D0(0xF),D1(0xF),D2(0xF),D3(0xF), D0(0),D1(0),D2(0),D3(0), D0(0),D1(0),D2(0),D3(0),
338 /* . iFeature */ 0,
339 /* ------------------ Audio 2.0 AC Output Terminal Descriptor */
340 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 12, 0x24, 0x03,
341 /* 3 bTerminalID, wTerminalType */ 0x03, D0(0x0101),D1(0x0101),
342 /* 6 bAssocTerminal, bSourceID, bCSourceID */ 0x00, 0x02, 0x10,
343 /* 9 bmControls, iTerminal */ D0(0),D1(0), 0,
344 /* ------------------- Audio 2.0 AC Input Terminal Descriptor */
345 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 17, 0x24, 0x02,
346 /* 3 bTerminalID, wTerminalType */ 0x04, D0(0x0101),D1(0x0101),
347 /* 6 bAssocTerminal, bCSourceID */ 0x00, 0x10,
348 /* 8 bNrChannels, bmChannelConfig */ 0x02, D0(0),D1(0),D2(0),D3(0),
349 /* 13 iChannelNames, bmControls, iTerminal */ 0, D0(0),D1(0), 0,
350 /* --------------------- Audio 2.0 AC Feature Unit Descriptor */
351 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 18, 0x24, 0x06,
352 /* 3 bUnitID, bSourceID */ 0x05, 0x04,
353 /* 5 bmaControls(0), bmaControls(...) ... */ D0(0xF),D1(0xF),D2(0xF),D3(0xF), D0(0),D1(0),D2(0),D3(0), D0(0),D1(0),D2(0),D3(0),
354 /* . iFeature */ 0,
355 /* ------------------ Audio 2.0 AC Output Terminal Descriptor */
356 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 12, 0x24, 0x03,
357 /* 3 bTerminalID, wTerminalType */ 0x06, D0(0x0301),D1(0x0301),
358 /* 6 bAssocTerminal, bSourceID, bCSourceID */ 0x00, 0x05, 0x10,
359 /* 9 bmControls, iTerminal */ D0(0),D1(0), 0,
360
361 /* ------------------------------------ Interface Descriptor *//* 1 Stream IN (9+9+16+6+7+8=55) */
362 /* 0 bLength, bDescriptorType */ 9, 0x04,
363 /* 2 bInterfaceNumber, bAlternateSetting */ 1, 0,
364 /* 4 bNumEndpoints */ 0,
365 /* 5 bInterfaceClass, bInterfaceSubClass, bInterfaceProtocol */ 0x01, 0x02, 0x20,
366 /* 8 iInterface */ 0,
367 /* ------------------------------------ Interface Descriptor */
368 /* 0 bLength, bDescriptorType */ 9, 0x04,
369 /* 2 bInterfaceNumber, bAlternateSetting */ 1, 1,
370 /* 4 bNumEndpoints */ 1,
371 /* 5 bInterfaceClass, bInterfaceSubClass, bInterfaceProtocol */ 0x01, 0x02, 0x20,
372 /* 8 iInterface */ 0,
373 /* ------------------------ Audio 2.0 AS Interface Descriptor */
374 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 16, 0x24, 0x01,
375 /* 3 bTerminalLink, bmControls */ 0x03,0x00,
376 /* 5 bFormatType, bmFormats */ 0x01,D0(1),D1(1),D2(1),D3(1),
377 /* 10 bNrChannels, bmChannelConfig */ 2, D0(0),D1(0),D2(0),D3(0),
378 /* 15 iChannelNames */ 0,
379 /* -------------------- Audio 2.0 AS Format Type I Descriptor */
380 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 6, 0x24, 0x02,
381 /* 3 bFormatType, bSubslotSize, bBitResolution */ 0x01, 2, 16,
382 /* ------------------------------------- Endpoint Descriptor */
383 /* 0 bLength, bDescriptorType */ 7, 0x05,
384 /* 2 bEndpointAddress, bmAttributes */ 0x81, 0x0D,
385 /* 4 wMaxPacketSize, bInterval */ D0(256),D1(256), 4,
386 /* ---------- Audio 2.0 AS ISO Audio Data Endpoint Descriptor */
387 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 8, 0x25, 0x01,
388 /* 3 bmAttributes, bmControls */ 0x00, 0x00,
389 /* 5 bLockDelayUnits, wLockDelay */ 0x00, D0(0),D1(0),
390
391 /* ------------------------------------ Interface Descriptor *//* 2 Stream OUT (9+9+16+6+7+8=55) */
392 /* 0 bLength, bDescriptorType */ 9, 0x04,
393 /* 2 bInterfaceNumber, bAlternateSetting */ 2, 0,
394 /* 4 bNumEndpoints */ 0,
395 /* 5 bInterfaceClass, bInterfaceSubClass, bInterfaceProtocol */ 0x01, 0x02, 0x20,
396 /* 8 iInterface */ 0,
397 /* ------------------------------------ Interface Descriptor */
398 /* 0 bLength, bDescriptorType */ 9, 0x04,
399 /* 2 bInterfaceNumber, bAlternateSetting */ 2, 1,
400 /* 4 bNumEndpoints */ 1,
401 /* 5 bInterfaceClass, bInterfaceSubClass, bInterfaceProtocol */ 0x01, 0x02, 0x20,
402 /* 8 iInterface */ 0,
403 /* ------------------------ Audio 2.0 AS Interface Descriptor */
404 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 16, 0x24, 0x01,
405 /* 3 bTerminalLink, bmControls */ 0x04,0x00,
406 /* 5 bFormatType, bmFormats */ 0x01,D0(1),D1(1),D2(1),D3(1),
407 /* 10 bNrChannels, bmChannelConfig */ 2, D0(0),D1(0),D2(0),D3(0),
408 /* 15 iChannelNames */ 0,
409 /* ---------------------- Audio 2.0 AS Format Type Descriptor */
410 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 6, 0x24, 0x02,
411 /* 3 bFormatType, bSubslotSize, bBitResolution */ 0x01, 2, 16,
412 /* ------------------------------------- Endpoint Descriptor */
413 /* 0 bLength, bDescriptorType */ 7, 0x05,
414 /* 2 bEndpointAddress, bmAttributes */ 0x02, 0x0D,
415 /* 4 wMaxPacketSize, bInterval */ D0(256),D1(256), 4,
416 /* ---------- Audio 2.0 AS ISO Audio Data Endpoint Descriptor */
417 /* 0 bLength, bDescriptorType, bDescriptorSubtype */ 8, 0x25, 0x01,
418 /* 3 bmAttributes, bmControls */ 0x00, 0x00,
419 /* 5 bLockDelayUnits, wLockDelay */ 0x00, D0(0),D1(0),
420
421 };
422 #define DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED sizeof(device_framework_high_speed)
423
424 static unsigned char string_framework[] = {
425
426 /* Manufacturer string descriptor : Index 1 - "Express Logic" */
427 0x09, 0x04, 0x01, 0x0c,
428 0x45, 0x78, 0x70, 0x72,0x65, 0x73, 0x20, 0x4c,
429 0x6f, 0x67, 0x69, 0x63,
430
431 /* Product string descriptor : Index 2 - "EL Composite device" */
432 0x09, 0x04, 0x02, 0x13,
433 0x45, 0x4c, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x6f,
434 0x73, 0x69, 0x74, 0x65, 0x20, 0x64, 0x65, 0x76,
435 0x69, 0x63, 0x65,
436
437 /* Serial Number string descriptor : Index 3 - "0001" */
438 0x09, 0x04, 0x03, 0x04,
439 0x30, 0x30, 0x30, 0x31
440 };
441 #define STRING_FRAMEWORK_LENGTH sizeof(string_framework)
442
443
444 /* Multiple languages are supported on the device, to add
445 a language besides English, the Unicode language code must
446 be appended to the language_id_framework array and the length
447 adjusted accordingly. */
448 static unsigned char language_id_framework[] = {
449
450 /* English. */
451 0x09, 0x04
452 };
453 #define LANGUAGE_ID_FRAMEWORK_LENGTH sizeof(language_id_framework)
454
455 /* Setup requests */
456
457 static UX_TEST_SETUP _SetConfigure = UX_TEST_SETUP_SetConfigure;
458 static UX_TEST_SETUP _GetCfgDescr = UX_TEST_SETUP_GetCfgDescr;
459 static UX_TEST_SETUP _SetAddress = UX_TEST_SETUP_SetAddress;
460 static UX_TEST_SETUP _GetDeviceDescriptor = UX_TEST_SETUP_GetDevDescr;
461 static UX_TEST_SETUP _GetConfigDescriptor = UX_TEST_SETUP_GetCfgDescr;
462
463 /* Interaction define */
464
465 /* Hooks define */
466
ux_device_class_audio_tx_hook(struct UX_TEST_ACTION_STRUCT * action,VOID * params)467 static VOID ux_device_class_audio_tx_hook(struct UX_TEST_ACTION_STRUCT *action, VOID *params)
468 {
469
470 UX_TEST_OVERRIDE_UX_DCD_SIM_SLAVE_FUNCTION_PARAMS *p = (UX_TEST_OVERRIDE_UX_DCD_SIM_SLAVE_FUNCTION_PARAMS *)params;
471 UX_SLAVE_TRANSFER *transfer = (UX_SLAVE_TRANSFER *)p -> parameter;
472 UCHAR tmp[32] = {'i','n','s','e','r','t','A',0};
473
474
475 (void)params;
476 // printf("tTX\n");
477
478 /* Acknowledge frame sent. */
479 if (test_tx_ack_count)
480 {
481 SAVE_BUFFER_LOG(transfer -> ux_slave_transfer_request_data_pointer, transfer -> ux_slave_transfer_request_requested_length);
482 transfer -> ux_slave_transfer_request_actual_length = transfer -> ux_slave_transfer_request_requested_length;
483 transfer -> ux_slave_transfer_request_completion_code = UX_SUCCESS;
484 ux_test_dcd_sim_slave_transfer_done(transfer, UX_SUCCESS);
485 }
486 if (test_tx_ack_count != 0xFFFFFFFF && test_tx_ack_count > 0)
487 test_tx_ack_count --;
488
489 /* Insert frames when sent. */
490 if (test_tx_ins_count)
491 {
492 tmp[6] = (test_tx_ins_count % 26) + 'A';
493 if (test_tx_ins_way == 0)
494 ux_device_class_audio_frame_write(slave_audio_tx_stream, tmp, 32);
495 else
496 {
497
498 UCHAR *frame;
499 ULONG frame_length;
500
501
502 ux_device_class_audio_write_frame_get(slave_audio_tx_stream, &frame, &frame_length);
503 _ux_utility_memory_copy(frame, tmp, 32);
504 ux_device_class_audio_write_frame_commit(slave_audio_tx_stream, 32);
505 }
506 }
507 if (test_tx_ins_count != 0xFFFFFFFF && test_tx_ins_count > 0)
508 test_tx_ins_count --;
509 }
510
ux_device_class_audio_rx_hook(struct UX_TEST_ACTION_STRUCT * action,VOID * params)511 static VOID ux_device_class_audio_rx_hook(struct UX_TEST_ACTION_STRUCT *action, VOID *params)
512 {
513
514 UX_TEST_OVERRIDE_UX_DCD_SIM_SLAVE_FUNCTION_PARAMS *p = (UX_TEST_OVERRIDE_UX_DCD_SIM_SLAVE_FUNCTION_PARAMS *)params;
515 UX_SLAVE_TRANSFER *transfer = (UX_SLAVE_TRANSFER *)p -> parameter;
516
517
518 (void)action;
519 (void)params;
520 (void)p;
521 (void)transfer;
522 // printf("tRX\n");
523 slave_audio_rx_transfer = transfer;
524 }
slave_audio_rx_simulate_one_frame(UCHAR * frame,ULONG frame_length)525 static VOID slave_audio_rx_simulate_one_frame(UCHAR *frame, ULONG frame_length)
526 {
527 UX_TEST_ASSERT(slave_audio_rx_transfer);
528 if (frame_length)
529 {
530 _ux_utility_memory_copy(slave_audio_rx_transfer->ux_slave_transfer_request_data_pointer, frame, frame_length);
531 slave_audio_rx_transfer->ux_slave_transfer_request_actual_length = frame_length;
532 slave_audio_rx_transfer->ux_slave_transfer_request_completion_code = UX_SUCCESS;
533 }
534 ux_test_dcd_sim_slave_transfer_done(slave_audio_rx_transfer, UX_SUCCESS);
535 _ux_utility_thread_sleep(1);
536 }
537
538 static UX_TEST_ACTION ux_device_class_audio_transfer_hook[] =
539 {
540 {
541 .usbx_function = UX_TEST_OVERRIDE_UX_DCD_SIM_SLAVE_FUNCTION,
542 .function = UX_DCD_TRANSFER_REQUEST,
543 .action_func = ux_device_class_audio_tx_hook,
544 .req_setup = UX_NULL,
545 .req_action = UX_TEST_MATCH_EP,
546 .req_ep_address = 0x81,
547 .do_after = UX_FALSE,
548 .no_return = UX_FALSE,
549 },
550 {
551 .usbx_function = UX_TEST_OVERRIDE_UX_DCD_SIM_SLAVE_FUNCTION,
552 .function = UX_DCD_TRANSFER_REQUEST,
553 .action_func = ux_device_class_audio_rx_hook,
554 .req_setup = UX_NULL,
555 .req_action = UX_TEST_MATCH_EP,
556 .req_ep_address = 0x02,
557 .do_after = UX_FALSE,
558 .no_return = UX_FALSE,
559 },
560 { 0 },
561 };
562
563 /* Define the ISR dispatch. */
564
565 extern VOID (*test_isr_dispatch)(void);
566
567
568 /* Prototype for test control return. */
569
570 void test_control_return(UINT status);
571
error_callback(UINT system_level,UINT system_context,UINT error_code)572 static VOID error_callback(UINT system_level, UINT system_context, UINT error_code)
573 {
574
575 error_callback_counter ++;
576 // printf("Error #%d, system_level: %d, system_context: %d, error_code: 0x%x\n", __LINE__, system_level, system_context, error_code);
577
578 if (!error_callback_ignore)
579 {
580 {
581 /* Failed test. */
582 test_control_return(1);
583 }
584 }
585 }
586
sleep_break_on_error(VOID)587 static UINT sleep_break_on_error(VOID)
588 {
589
590 if (error_callback_counter >= 3)
591 return error_callback_counter;
592
593 return UX_SUCCESS;
594 }
595
596 /* Define the ISR dispatch routine. */
597
test_isr(void)598 static void test_isr(void)
599 {
600
601 /* For further expansion of interrupt-level testing. */
602 }
603
slave_audio_activate(VOID * audio_instance)604 static VOID slave_audio_activate(VOID *audio_instance)
605 {
606 slave_audio = (UX_DEVICE_CLASS_AUDIO *)audio_instance;
607 ux_device_class_audio_stream_get(slave_audio, 0, &slave_audio_tx_stream);
608 ux_device_class_audio_stream_get(slave_audio, 1, &slave_audio_rx_stream);
609 // printf("sAUD:%p;%p,%p\n", audio_instance, slave_audio_tx_stream, slave_audio_rx_stream);
610 }
slave_audio_deactivate(VOID * audio_instance)611 static VOID slave_audio_deactivate(VOID *audio_instance)
612 {
613 if ((VOID *)slave_audio == audio_instance)
614 {
615 slave_audio = UX_NULL;
616 slave_audio_tx_stream = UX_NULL;
617 slave_audio_rx_stream = UX_NULL;
618 }
619 }
slave_audio_tx_stream_change(UX_DEVICE_CLASS_AUDIO_STREAM * audio,ULONG alt)620 static VOID slave_audio_tx_stream_change(UX_DEVICE_CLASS_AUDIO_STREAM *audio, ULONG alt)
621 {
622 SAVE_CALLBACK_INVOKE_LOG(slave_audio_tx_stream_change, audio, (ALIGN_TYPE)alt, 0);
623 }
slave_audio_rx_stream_change(UX_DEVICE_CLASS_AUDIO_STREAM * audio,ULONG alt)624 static VOID slave_audio_rx_stream_change(UX_DEVICE_CLASS_AUDIO_STREAM *audio, ULONG alt)
625 {
626 SAVE_CALLBACK_INVOKE_LOG(slave_audio_rx_stream_change, audio, (ALIGN_TYPE)alt, 0);
627
628 slave_audio_rx_transfer = UX_NULL;
629 }
slave_audio_control_process(UX_DEVICE_CLASS_AUDIO * audio,UX_SLAVE_TRANSFER * transfer)630 static UINT slave_audio_control_process(UX_DEVICE_CLASS_AUDIO *audio, UX_SLAVE_TRANSFER *transfer)
631 {
632
633
634 UINT status;
635 UX_DEVICE_CLASS_AUDIO20_CONTROL_GROUP group =
636 {2, g_slave_audio20_control};
637
638
639 SAVE_CALLBACK_INVOKE_LOG(slave_audio_control_process, audio, transfer, 0);
640
641 status = ux_device_class_audio20_control_process(audio, transfer, &group);
642 if (status == UX_SUCCESS)
643 {
644 if (g_slave_audio20_control[0].ux_device_class_audio20_control_changed == UX_DEVICE_CLASS_AUDIO20_CONTROL_MUTE_CHANGED)
645 {
646 /* Mute change! */
647 }
648 if (g_slave_audio20_control[0].ux_device_class_audio20_control_changed == UX_DEVICE_CLASS_AUDIO20_CONTROL_VOLUME_CHANGED)
649 {
650 /* Volume change! */
651 }
652 if (g_slave_audio20_control[1].ux_device_class_audio20_control_changed == UX_DEVICE_CLASS_AUDIO20_CONTROL_MUTE_CHANGED)
653 {
654 /* Mute change! */
655 }
656 if (g_slave_audio20_control[1].ux_device_class_audio20_control_changed == UX_DEVICE_CLASS_AUDIO20_CONTROL_VOLUME_CHANGED)
657 {
658 /* Volume change! */
659 }
660 }
661 return(status);
662 }
slave_audio_tx_done(UX_DEVICE_CLASS_AUDIO_STREAM * audio,ULONG length)663 static VOID slave_audio_tx_done(UX_DEVICE_CLASS_AUDIO_STREAM *audio, ULONG length)
664 {
665 SAVE_CALLBACK_INVOKE_LOG(slave_audio_tx_done, audio, (ALIGN_TYPE)length, 0);
666 }
slave_audio_rx_done(UX_DEVICE_CLASS_AUDIO_STREAM * audio,ULONG length)667 static VOID slave_audio_rx_done(UX_DEVICE_CLASS_AUDIO_STREAM *audio, ULONG length)
668 {
669 SAVE_CALLBACK_INVOKE_LOG(slave_audio_rx_done, audio, (ALIGN_TYPE)length, 0);
670 }
671
test_host_change_function(ULONG event,UX_HOST_CLASS * cls,VOID * inst)672 static UINT test_host_change_function(ULONG event, UX_HOST_CLASS *cls, VOID *inst)
673 {
674
675 UX_HOST_CLASS_DUMMY *dummy = (UX_HOST_CLASS_DUMMY *) inst;
676
677
678 switch(event)
679 {
680
681 case UX_DEVICE_INSERTION:
682
683 // printf("hINS:%p,%p:%ld\n", cls, inst, dummy -> ux_host_class_dummy_interface -> ux_interface_descriptor.bInterfaceNumber);
684 switch(dummy -> ux_host_class_dummy_interface -> ux_interface_descriptor.bInterfaceNumber)
685 {
686 case 0: dummy_control = dummy; break;
687 case 1: dummy_rx = dummy; break;
688 case 2: dummy_tx = dummy; break;
689 }
690 break;
691
692 case UX_DEVICE_REMOVAL:
693
694 // printf("hRMV:%p,%p:%ld\n", cls, inst, dummy -> ux_host_class_dummy_interface -> ux_interface_descriptor.bInterfaceNumber);
695 switch(dummy -> ux_host_class_dummy_interface -> ux_interface_descriptor.bInterfaceNumber)
696 {
697 case 0: dummy_control = UX_NULL; break;
698 case 1: dummy_rx = UX_NULL; break;
699 case 2: dummy_tx = UX_NULL; break;
700 }
701 break;
702
703 default:
704 break;
705 }
706 return 0;
707 }
708
ux_test_hcd_entry_set_cfg(UX_TEST_ACTION * action,VOID * params)709 static VOID ux_test_hcd_entry_set_cfg(UX_TEST_ACTION *action, VOID *params)
710 {
711
712 set_cfg_counter ++;
713
714 rsc_mem_free_on_set_cfg = _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available;
715 rsc_sem_on_set_cfg = ux_test_utility_sim_sem_create_count();
716 rsc_mutex_on_set_cfg = ux_test_utility_sim_mutex_create_count();
717 }
718
719
720 /* Define what the initial system looks like. */
721
722 #ifdef CTEST
test_application_define(void * first_unused_memory)723 void test_application_define(void *first_unused_memory)
724 #else
725 void usbx_audio20_device_basic_test_application_define(void *first_unused_memory)
726 #endif
727 {
728
729 UINT status;
730 CHAR * stack_pointer;
731 CHAR * memory_pointer;
732
733
734 /* Inform user. */
735 printf("Running Audio 2.0 Device Basic Functionality Test................... ");
736 stepinfo("\n");
737
738 /* Reset testing counts. */
739 ux_test_utility_sim_mutex_create_count_reset();
740 ux_test_utility_sim_sem_create_count_reset();
741 ux_test_utility_sim_sem_get_count_reset();
742 /* Reset error generations */
743 ux_test_utility_sim_sem_error_generation_stop();
744 ux_test_utility_sim_mutex_error_generation_stop();
745 ux_test_utility_sim_sem_get_error_generation_stop();
746
747 /* Initialize the free memory pointer */
748 stack_pointer = (CHAR *) usbx_memory;
749 memory_pointer = stack_pointer + (UX_DEMO_STACK_SIZE * 2);
750
751 /* Initialize USBX Memory */
752 status = ux_system_initialize(memory_pointer, UX_DEMO_MEMORY_SIZE, UX_NULL,0);
753 UX_TEST_CHECK_SUCCESS(status);
754
755 /* Register the error callback. */
756 _ux_utility_error_callback_register(error_callback);
757
758 /* The code below is required for installing the host portion of USBX */
759 status = ux_host_stack_initialize(test_host_change_function);
760 UX_TEST_CHECK_SUCCESS(status);
761
762 /* Register Audio class. */
763 status = ux_host_stack_class_register(_ux_host_class_dummy_name, _ux_host_class_dummy_entry);
764 UX_TEST_CHECK_SUCCESS(status);
765
766 /* The code below is required for installing the device portion of USBX. No call back for
767 device status change in this example. */
768 status = ux_device_stack_initialize(device_framework_high_speed, DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED,
769 device_framework_full_speed, DEVICE_FRAMEWORK_LENGTH_FULL_SPEED,
770 string_framework, STRING_FRAMEWORK_LENGTH,
771 language_id_framework, LANGUAGE_ID_FRAMEWORK_LENGTH,UX_NULL);
772 UX_TEST_CHECK_SUCCESS(status);
773
774 /* Set the parameters for callback when insertion/extraction of a Audio 2.0 device, no IAD. */
775 ux_utility_memory_set(&slave_audio_parameter, 0, sizeof(slave_audio_parameter));
776 ux_utility_memory_set(slave_audio_stream_parameter, 0, sizeof(slave_audio_stream_parameter));
777 #if !defined(UX_DEVICE_STANDALONE)
778 slave_audio_stream_parameter[0].ux_device_class_audio_stream_parameter_thread_entry = ux_device_class_audio_write_thread_entry;
779 #else
780 slave_audio_stream_parameter[0].ux_device_class_audio_stream_parameter_task_function = _ux_device_class_audio_write_task_function;
781 #endif
782 slave_audio_stream_parameter[0].ux_device_class_audio_stream_parameter_callbacks.ux_device_class_audio_stream_change = slave_audio_tx_stream_change;
783 slave_audio_stream_parameter[0].ux_device_class_audio_stream_parameter_callbacks.ux_device_class_audio_stream_frame_done = slave_audio_tx_done;
784 slave_audio_stream_parameter[0].ux_device_class_audio_stream_parameter_max_frame_buffer_size = 256;
785 slave_audio_stream_parameter[0].ux_device_class_audio_stream_parameter_max_frame_buffer_nb = 8;
786
787 #if !defined(UX_DEVICE_STANDALONE)
788 slave_audio_stream_parameter[1].ux_device_class_audio_stream_parameter_thread_entry = ux_device_class_audio_read_thread_entry;
789 #else
790 slave_audio_stream_parameter[1].ux_device_class_audio_stream_parameter_task_function = _ux_device_class_audio_read_task_function;
791 #endif
792 slave_audio_stream_parameter[1].ux_device_class_audio_stream_parameter_callbacks.ux_device_class_audio_stream_change = slave_audio_rx_stream_change;
793 slave_audio_stream_parameter[1].ux_device_class_audio_stream_parameter_callbacks.ux_device_class_audio_stream_frame_done = slave_audio_rx_done;
794 slave_audio_stream_parameter[1].ux_device_class_audio_stream_parameter_max_frame_buffer_size = 256;
795 slave_audio_stream_parameter[1].ux_device_class_audio_stream_parameter_max_frame_buffer_nb = 8;
796 slave_audio_parameter.ux_device_class_audio_parameter_streams = slave_audio_stream_parameter;
797 slave_audio_parameter.ux_device_class_audio_parameter_streams_nb = 2;
798 slave_audio_parameter.ux_device_class_audio_parameter_callbacks.ux_slave_class_audio_instance_activate = slave_audio_activate;
799 slave_audio_parameter.ux_device_class_audio_parameter_callbacks.ux_slave_class_audio_instance_deactivate = slave_audio_deactivate;
800 slave_audio_parameter.ux_device_class_audio_parameter_callbacks.ux_device_class_audio_control_process = slave_audio_control_process;
801 slave_audio_parameter.ux_device_class_audio_parameter_callbacks.ux_device_class_audio_arg = UX_NULL;
802
803 #if defined(UX_DEVICE_CLASS_AUDIO_INTERRUPT_SUPPORT)
804 slave_audio_parameter.ux_device_class_audio_parameter_status_queue_size = 2;
805 slave_audio_parameter.ux_device_class_audio_parameter_status_size = 6;
806 #endif
807
808 g_slave_audio20_control[0].ux_device_class_audio20_control_cs_id = 0x10;
809 g_slave_audio20_control[0].ux_device_class_audio20_control_sampling_frequency = 48000;
810 g_slave_audio20_control[0].ux_device_class_audio20_control_fu_id = 2;
811 g_slave_audio20_control[0].ux_device_class_audio20_control_mute[0] = 0;
812 g_slave_audio20_control[0].ux_device_class_audio20_control_volume[0] = 0;
813 g_slave_audio20_control[1].ux_device_class_audio20_control_cs_id = 0x10;
814 g_slave_audio20_control[1].ux_device_class_audio20_control_sampling_frequency = 48000;
815 g_slave_audio20_control[1].ux_device_class_audio20_control_fu_id = 5;
816 g_slave_audio20_control[1].ux_device_class_audio20_control_mute[0] = 0;
817 g_slave_audio20_control[1].ux_device_class_audio20_control_volume[0] = 0;
818
819 /* Initialize the device Audio class. This class owns interfaces starting with 0, 1, 2. */
820 status = ux_device_stack_class_register(_ux_system_slave_class_audio_name, ux_device_class_audio_entry,
821 1, 0, &slave_audio_parameter);
822 UX_TEST_CHECK_SUCCESS(status);
823
824 /* Initialize the simulated device controller. */
825 status = _ux_test_dcd_sim_slave_initialize();
826 UX_TEST_CHECK_SUCCESS(status);
827
828 /* Register all the USB host controllers available in this system */
829 status = ux_host_stack_hcd_register(_ux_system_host_hcd_simulator_name, _ux_test_hcd_sim_host_initialize,0,0);
830 UX_TEST_CHECK_SUCCESS(status);
831
832 /* Create the main host simulation thread. */
833 status = tx_thread_create(&tx_test_thread_host_simulation, "tx demo host simulation", tx_test_thread_host_simulation_entry, 0,
834 stack_pointer, UX_DEMO_STACK_SIZE,
835 20, 20, 1, TX_AUTO_START);
836 UX_TEST_CHECK_SUCCESS(status);
837
838 /* Create the main slave simulation thread. */
839 status = tx_thread_create(&tx_test_thread_slave_simulation, "tx demo slave simulation", tx_test_thread_slave_simulation_entry, 0,
840 stack_pointer + UX_DEMO_STACK_SIZE, UX_DEMO_STACK_SIZE,
841 20, 20, 1, TX_AUTO_START);
842 UX_TEST_CHECK_SUCCESS(status);
843 }
844
test_wait_until_expected(VOID ** ptr,ULONG loop,VOID * expected)845 static UINT test_wait_until_expected(VOID **ptr, ULONG loop, VOID *expected)
846 {
847 while(loop)
848 {
849 _ux_utility_delay_ms(10);
850 if (*ptr == expected)
851 return UX_SUCCESS;
852 }
853 return UX_ERROR;
854 }
test_wait_until_not_expected(VOID ** ptr,ULONG loop,VOID * expected)855 static UINT test_wait_until_not_expected(VOID **ptr, ULONG loop, VOID *expected)
856 {
857 while(loop)
858 {
859 _ux_utility_delay_ms(10);
860 if (*ptr != expected)
861 return UX_SUCCESS;
862 }
863 return UX_ERROR;
864 }
865 #define test_wait_until_not_null(ptr, loop) test_wait_until_not_expected(ptr, loop, UX_NULL)
866 #define test_wait_until_null(ptr, loop) test_wait_until_expected(ptr, loop, UX_NULL)
867
tx_test_thread_host_simulation_entry(ULONG arg)868 void tx_test_thread_host_simulation_entry(ULONG arg)
869 {
870
871 UINT status;
872 ULONG test_n;
873 // ULONG mem_free;
874 UX_DEVICE *device;
875 UX_CONFIGURATION *configuration;
876 UX_INTERFACE *interface;
877 UX_INTERFACE *interface_inst[3][2];
878 UX_ENDPOINT *control_endpoint;
879 UX_TRANSFER *transfer_request;
880 UCHAR test_tmp[32];
881 ULONG temp;
882
883
884 /* Test connect. */
885 status = test_wait_until_not_null((void**)&dummy_control, 100);
886 status |= test_wait_until_not_null((void**)&dummy_tx, 100);
887 status |= test_wait_until_not_null((void**)&dummy_rx, 100);
888 status |= test_wait_until_not_null((void**)&slave_audio_tx_stream, 100);
889 status |= test_wait_until_not_null((void**)&slave_audio_rx_stream, 100);
890 UX_TEST_CHECK_SUCCESS(status);
891
892 // /* Test disconnect. */
893 // ux_test_dcd_sim_slave_disconnect();
894 // ux_test_hcd_sim_host_disconnect();
895
896 // /* Reset testing counts. */
897 // ux_test_utility_sim_mutex_create_count_reset();
898 // ux_test_utility_sim_sem_create_count_reset();
899 // ux_test_hcd_sim_host_set_actions(log_on_SetCfg);
900 // /* Save free memory usage. */
901 // mem_free = _ux_system->ux_system_regular_memory_pool_free;
902 // ux_test_dcd_sim_slave_connect(UX_FULL_SPEED_DEVICE);
903 // ux_test_hcd_sim_host_connect(UX_FULL_SPEED_DEVICE);
904 // tx_thread_sleep(100);
905 // /* Log create counts for further tests. */
906 // rsc_enum_mutex_usage = rsc_mutex_on_set_cfg;
907 // rsc_enum_sem_usage = rsc_sem_on_set_cfg;
908 // rsc_enum_mem_usage = mem_free - rsc_mem_free_on_set_cfg;
909 // /* Log create counts when instances active for further tests. */
910 // rsc_cdc_mutex_usage = ux_test_utility_sim_mutex_create_count() - rsc_enum_mutex_usage;
911 // rsc_cdc_sem_usage = ux_test_utility_sim_sem_create_count() - rsc_enum_sem_usage;
912 // rsc_cdc_mem_usage = rsc_mem_free_on_set_cfg - _ux_system->ux_system_regular_memory_pool_free;
913 // stepinfo("mem free: %ld\n", _ux_system->ux_system_regular_memory_pool_free);
914
915 /* Validate configuration descriptors. */
916 /* ... */
917
918 /* Get testing instances. */
919
920 status = ux_host_stack_device_get(0, &device);
921 UX_TEST_CHECK_SUCCESS(status);
922
923 control_endpoint = &device->ux_device_control_endpoint;
924 transfer_request = &control_endpoint->ux_endpoint_transfer_request;
925
926 status = ux_host_stack_device_configuration_get(device, 0, &configuration);
927 UX_TEST_CHECK_SUCCESS(status);
928
929 interface = configuration -> ux_configuration_first_interface;
930 while(interface)
931 {
932 // printf("Interface: %ld.%ld\n", interface -> ux_interface_descriptor.bInterfaceNumber, interface -> ux_interface_descriptor.bAlternateSetting);
933 interface_inst[interface -> ux_interface_descriptor.bInterfaceNumber][interface -> ux_interface_descriptor.bAlternateSetting] = interface;
934 interface = interface -> ux_interface_next_interface;
935 }
936
937 /* Test interface change. */
938 /* Reset log. */
939 RESET_CALLBACK_INVOKE_LOG();
940 status = ux_host_stack_interface_setting_select(interface_inst[1][1]);
941 status |= ux_host_stack_interface_setting_select(interface_inst[1][0]);
942 status |= ux_host_stack_interface_setting_select(interface_inst[1][1]);
943
944 UX_TEST_CHECK_SUCCESS(status);
945 UX_TEST_ASSERT(callback_invoke_count == 3);
946 UX_TEST_ASSERT(callback_invoke_log[0].func == slave_audio_tx_stream_change);
947 UX_TEST_ASSERT(callback_invoke_log[0].param1 == slave_audio_tx_stream);
948 UX_TEST_ASSERT(callback_invoke_log[0].param2 == (VOID*)1);
949 UX_TEST_ASSERT(callback_invoke_log[1].func == slave_audio_tx_stream_change);
950 UX_TEST_ASSERT(callback_invoke_log[1].param1 == slave_audio_tx_stream);
951 UX_TEST_ASSERT(callback_invoke_log[1].param2 == 0);
952
953 RESET_CALLBACK_INVOKE_LOG();
954 status = ux_host_stack_interface_setting_select(interface_inst[2][1]);
955 status |= ux_host_stack_interface_setting_select(interface_inst[2][0]);
956 status |= ux_host_stack_interface_setting_select(interface_inst[2][1]);
957
958 UX_TEST_CHECK_SUCCESS(status);
959 UX_TEST_ASSERT(callback_invoke_count == 3);
960 UX_TEST_ASSERT(callback_invoke_log[0].func == slave_audio_rx_stream_change);
961 UX_TEST_ASSERT(callback_invoke_log[0].param1 == slave_audio_rx_stream);
962 UX_TEST_ASSERT(callback_invoke_log[0].param2 == (VOID*)1);
963 UX_TEST_ASSERT(callback_invoke_log[1].func == slave_audio_rx_stream_change);
964 UX_TEST_ASSERT(callback_invoke_log[1].param1 == slave_audio_rx_stream);
965 UX_TEST_ASSERT(callback_invoke_log[1].param2 == 0);
966
967 /* Test data streaming. */
968
969 /* Wrong interface! */
970 status = ux_device_class_audio_transmission_start(slave_audio_rx_stream);
971 status |= ux_device_class_audio_reception_start(slave_audio_tx_stream);
972 UX_TEST_CHECK_NOT_SUCCESS(status);
973
974 ux_test_link_hooks_from_array(ux_device_class_audio_transfer_hook);
975
976 /* ------------------ Write test. */
977
978 status = ux_device_class_audio_frame_write(slave_audio_tx_stream, "test0", 16);
979 status |= ux_device_class_audio_frame_write(slave_audio_tx_stream, "test1", 16);
980 status |= ux_device_class_audio_frame_write(slave_audio_tx_stream, "test2", 16);
981 status |= ux_device_class_audio_frame_write(slave_audio_tx_stream, "test3", 16);
982 status |= ux_device_class_audio_frame_write(slave_audio_tx_stream, "test4", 16);
983 status |= ux_device_class_audio_frame_write(slave_audio_tx_stream, "test5", 16);
984 status |= ux_device_class_audio_frame_write(slave_audio_tx_stream, "test6", 16);
985 status |= ux_device_class_audio_frame_write(slave_audio_tx_stream, "test7", 16);
986 UX_TEST_CHECK_SUCCESS(status);
987
988 error_callback_counter = 0;
989 status = ux_device_class_audio_frame_write(slave_audio_tx_stream, "test8", 16);
990 UX_TEST_CHECK_CODE(UX_BUFFER_OVERFLOW, status);
991
992 /*
993 Keep sending until under-run.
994 No buffer appended while running.
995 */
996
997 buffer_log_count = 0;
998 test_tx_ack_count = 10;
999 status = ux_device_class_audio_transmission_start(slave_audio_tx_stream);
1000 UX_TEST_CHECK_SUCCESS(status);
1001
1002 /* Delay to let thread runs. */
1003 _ux_utility_delay_ms(100);
1004
1005 /* Prepare data for checking. */
1006 _ux_utility_memory_set(test_tmp, 0, 16);
1007 _ux_utility_memory_copy(test_tmp, "test", 4);
1008
1009 /* 8 frame should be available. */
1010 for (test_n = 0; test_n < 8; test_n ++)
1011 {
1012 // printf("%ld: %ld: %s\n", test_n, buffer_log[test_n].length, buffer_log[test_n].data);
1013 test_tmp[4] = (UCHAR)(test_n + '0');
1014
1015 UX_TEST_ASSERT(buffer_log[test_n].length == 16);
1016
1017 status = _ux_utility_memory_compare(buffer_log[test_n].data, test_tmp, 6);
1018 UX_TEST_CHECK_SUCCESS(status);
1019 }
1020 /* Then under-run, 0 length packets. */
1021 for(;test_n < buffer_log_count; test_n ++)
1022 {
1023 // printf("%ld: %ld\n", test_n, buffer_log[test_n].length);
1024 UX_TEST_ASSERT(buffer_log[test_n].length == 0);
1025 }
1026
1027 /*
1028 Keep sending until under-run.
1029 Specific number of buffer appended while running.
1030 */
1031
1032 for (test_tx_ins_way = 0; test_tx_ins_way < 2; test_tx_ins_way ++)
1033 {
1034
1035 /* Switch interface to clean up status. */
1036 status = ux_host_stack_interface_setting_select(interface_inst[1][0]);
1037 status |= ux_host_stack_interface_setting_select(interface_inst[1][1]);
1038
1039 status = ux_device_class_audio_frame_write(slave_audio_tx_stream, "test0", 20);
1040 status |= ux_device_class_audio_frame_write(slave_audio_tx_stream, "test1", 20);
1041 status |= ux_device_class_audio_frame_write(slave_audio_tx_stream, "test2", 20);
1042 status |= ux_device_class_audio_frame_write(slave_audio_tx_stream, "test3", 20);
1043 UX_TEST_CHECK_SUCCESS(status);
1044
1045 test_tx_ins_count = 10;
1046 test_tx_ack_count = 20;
1047 buffer_log_count = 0;
1048 status = ux_device_class_audio_transmission_start(slave_audio_tx_stream);
1049 UX_TEST_CHECK_SUCCESS(status);
1050
1051 /* Delay to let thread runs. */
1052 _ux_utility_delay_ms(300);
1053
1054 /* Prepare data for checking. */
1055 _ux_utility_memory_set(test_tmp, 0, 32);
1056
1057 /* 4 frame should be available. */
1058 _ux_utility_memory_copy(test_tmp, "test", 4);
1059 for (test_n = 0; test_n < 4; test_n ++)
1060 {
1061 // printf("%ld: %ld: %s\n", test_n, buffer_log[test_n].length, buffer_log[test_n].data);
1062 test_tmp[4] = (UCHAR)(test_n + '0');
1063
1064 UX_TEST_ASSERT(buffer_log[test_n].length == 20);
1065
1066 status = _ux_utility_memory_compare(buffer_log[test_n].data, test_tmp, 6);
1067 UX_TEST_CHECK_SUCCESS(status);
1068 }
1069 /* 10 more frame should be available. */
1070 _ux_utility_memory_copy(test_tmp, "insert", 6);
1071 for (; test_n < 14; test_n ++)
1072 {
1073 // printf("%ld: %ld: %s\n", test_n, buffer_log[test_n].length, buffer_log[test_n].data);
1074 test_tmp[6] = (UCHAR)(((10 - (test_n - 4)) % 26) + 'A');
1075
1076 UX_TEST_ASSERT(buffer_log[test_n].length == 32);
1077
1078 status = _ux_utility_memory_compare(buffer_log[test_n].data, test_tmp, 8);
1079 UX_TEST_CHECK_SUCCESS(status);
1080 }
1081 /* Then under-run, 0 length packets. */
1082 for(;test_n < buffer_log_count; test_n ++)
1083 {
1084 // printf("%ld: %ld\n", test_n, buffer_log[test_n].length);
1085 UX_TEST_ASSERT(buffer_log[test_n].length == 0);
1086 }
1087 }
1088
1089 UX_TEST_ASSERT(slave_audio_tx_stream->ux_device_class_audio_stream_transfer_pos == slave_audio_tx_stream->ux_device_class_audio_stream_access_pos);
1090
1091 /* ------------------ Read - 8 test. */
1092
1093 UX_TEST_ASSERT(slave_audio_rx_transfer == UX_NULL);
1094
1095 temp = 0;
1096 status = ux_device_class_audio_sample_read8(slave_audio_rx_stream, (UCHAR *)&temp);
1097 UX_TEST_CHECK_CODE(UX_BUFFER_OVERFLOW, status);
1098
1099 status = ux_device_class_audio_reception_start(slave_audio_rx_stream);
1100 UX_TEST_CHECK_SUCCESS(status);
1101 _ux_utility_thread_sleep(1);
1102
1103 UX_TEST_ASSERT(slave_audio_rx_transfer != UX_NULL);
1104
1105 status = ux_device_class_audio_sample_read8(slave_audio_rx_stream, (UCHAR *)&temp);
1106 UX_TEST_CHECK_CODE(UX_BUFFER_OVERFLOW, status);
1107
1108 RESET_CALLBACK_INVOKE_LOG();
1109
1110 slave_audio_rx_simulate_one_frame("012345", 6);
1111 for (test_n = 0; test_n < 6; test_n ++)
1112 {
1113 status = ux_device_class_audio_sample_read8(slave_audio_rx_stream, (UCHAR *)&temp);
1114 UX_TEST_CHECK_SUCCESS(status);
1115 UX_TEST_ASSERT(temp == (test_n + '0'));
1116 }
1117
1118 slave_audio_rx_simulate_one_frame("012345", 6);
1119 slave_audio_rx_simulate_one_frame("67", 2);
1120 slave_audio_rx_simulate_one_frame("89", 2);
1121
1122 for (test_n = 0; test_n < 10; test_n ++)
1123 {
1124 status = ux_device_class_audio_sample_read8(slave_audio_rx_stream, (UCHAR *)&temp);
1125 UX_TEST_CHECK_SUCCESS(status);
1126 UX_TEST_ASSERT(temp == (test_n + '0'));
1127 }
1128
1129 UX_TEST_ASSERT(callback_invoke_count == 4);
1130 UX_TEST_ASSERT(callback_invoke_log[0].func == slave_audio_rx_done);
1131 UX_TEST_ASSERT(callback_invoke_log[0].param1 == slave_audio_rx_stream);
1132 UX_TEST_ASSERT(callback_invoke_log[1].func == slave_audio_rx_done);
1133 UX_TEST_ASSERT(callback_invoke_log[1].param1 == slave_audio_rx_stream);
1134 UX_TEST_ASSERT(callback_invoke_log[2].func == slave_audio_rx_done);
1135 UX_TEST_ASSERT(callback_invoke_log[2].param1 == slave_audio_rx_stream);
1136 UX_TEST_ASSERT(callback_invoke_log[3].func == slave_audio_rx_done);
1137 UX_TEST_ASSERT(callback_invoke_log[3].param1 == slave_audio_rx_stream);
1138
1139 RESET_CALLBACK_INVOKE_LOG();
1140 error_callback_counter = 0;
1141 for (test_n = 0; test_n < 10; test_n ++)
1142 {
1143 test_tmp[0] = (UCHAR)(test_n + '0');
1144 slave_audio_rx_simulate_one_frame(test_tmp, 1);
1145 }
1146
1147 UX_TEST_ASSERT(callback_invoke_count == 10);
1148 UX_TEST_ASSERT(error_callback_counter == 3);
1149 for (test_n = 0; test_n < 7; test_n ++)
1150 {
1151 status = ux_device_class_audio_sample_read8(slave_audio_rx_stream, (UCHAR *)&temp);
1152 UX_TEST_CHECK_SUCCESS(status);
1153 // printf("(%lx)%c\n", temp, (char)temp);
1154 UX_TEST_ASSERT(temp == (test_n + '0'));
1155 }
1156 UX_TEST_CHECK_SUCCESS(ux_device_class_audio_sample_read8(slave_audio_rx_stream, (UCHAR *)&temp));
1157 UX_TEST_ASSERT(temp == '9');
1158 UX_TEST_CHECK_CODE(UX_BUFFER_OVERFLOW, ux_device_class_audio_sample_read8(slave_audio_rx_stream, (UCHAR *)&temp));
1159
1160 /* ------------------ Read - 16 test. */
1161
1162 status = ux_device_class_audio_sample_read16(slave_audio_rx_stream, (USHORT *)&temp);
1163 UX_TEST_CHECK_CODE(UX_BUFFER_OVERFLOW, status);
1164
1165 RESET_CALLBACK_INVOKE_LOG();
1166 slave_audio_rx_simulate_one_frame("012345", 6);
1167 slave_audio_rx_simulate_one_frame("67", 2);
1168 UX_TEST_ASSERT(callback_invoke_count == 2);
1169 UX_TEST_ASSERT(callback_invoke_log[0].func == slave_audio_rx_done);
1170 UX_TEST_ASSERT(callback_invoke_log[0].param1 == slave_audio_rx_stream);
1171 UX_TEST_ASSERT(callback_invoke_log[0].param2 == (VOID*)6);
1172 UX_TEST_ASSERT(callback_invoke_log[1].func == slave_audio_rx_done);
1173 UX_TEST_ASSERT(callback_invoke_log[1].param1 == slave_audio_rx_stream);
1174 UX_TEST_ASSERT(callback_invoke_log[1].param2 == (VOID*)2);
1175 for (test_n = 0; test_n < 4; test_n ++)
1176 {
1177 status = ux_device_class_audio_sample_read16(slave_audio_rx_stream, (USHORT *)&temp);
1178 UX_TEST_CHECK_SUCCESS(status);
1179 // printf("%lx\n", temp);
1180 test_tmp[0] = (UCHAR)(test_n * 2 + '0');
1181 test_tmp[1] = (UCHAR)(test_n * 2 + '1');
1182 UX_TEST_CHECK_SUCCESS(_ux_utility_memory_compare(test_tmp, &temp, 2));
1183 }
1184
1185 /* ------------------ Read - 24 test. */
1186
1187 status = ux_device_class_audio_sample_read24(slave_audio_rx_stream, &temp);
1188 UX_TEST_CHECK_CODE(UX_BUFFER_OVERFLOW, status);
1189
1190 RESET_CALLBACK_INVOKE_LOG();
1191 slave_audio_rx_simulate_one_frame("012345", 6);
1192 slave_audio_rx_simulate_one_frame("678", 3);
1193 UX_TEST_ASSERT(callback_invoke_count == 2);
1194 UX_TEST_ASSERT(callback_invoke_log[0].func == slave_audio_rx_done);
1195 UX_TEST_ASSERT(callback_invoke_log[0].param1 == slave_audio_rx_stream);
1196 UX_TEST_ASSERT(callback_invoke_log[0].param2 == (VOID*)6);
1197 UX_TEST_ASSERT(callback_invoke_log[1].func == slave_audio_rx_done);
1198 UX_TEST_ASSERT(callback_invoke_log[1].param1 == slave_audio_rx_stream);
1199 UX_TEST_ASSERT(callback_invoke_log[1].param2 == (VOID*)3);
1200 for (test_n = 0; test_n < 3; test_n ++)
1201 {
1202 status = ux_device_class_audio_sample_read24(slave_audio_rx_stream, &temp);
1203 UX_TEST_CHECK_SUCCESS(status);
1204 // printf("%lx\n", temp);
1205 test_tmp[0] = (UCHAR)(test_n * 3 + '0');
1206 test_tmp[1] = (UCHAR)(test_n * 3 + '1');
1207 test_tmp[2] = (UCHAR)(test_n * 3 + '2');
1208 UX_TEST_CHECK_SUCCESS(_ux_utility_memory_compare(test_tmp, &temp, 3));
1209 }
1210
1211 /* ------------------ Read - 32 test. */
1212
1213 status = ux_device_class_audio_sample_read32(slave_audio_rx_stream, &temp);
1214 UX_TEST_CHECK_CODE(UX_BUFFER_OVERFLOW, status);
1215
1216 RESET_CALLBACK_INVOKE_LOG();
1217 slave_audio_rx_simulate_one_frame("01234567", 8);
1218 slave_audio_rx_simulate_one_frame("8901", 4);
1219 UX_TEST_ASSERT(callback_invoke_count == 2);
1220 UX_TEST_ASSERT(callback_invoke_log[0].func == slave_audio_rx_done);
1221 UX_TEST_ASSERT(callback_invoke_log[0].param1 == slave_audio_rx_stream);
1222 UX_TEST_ASSERT(callback_invoke_log[0].param2 == (VOID*)8);
1223 UX_TEST_ASSERT(callback_invoke_log[1].func == slave_audio_rx_done);
1224 UX_TEST_ASSERT(callback_invoke_log[1].param1 == slave_audio_rx_stream);
1225 UX_TEST_ASSERT(callback_invoke_log[1].param2 == (VOID*)4);
1226 for (test_n = 0; test_n < 3; test_n ++)
1227 {
1228 status = ux_device_class_audio_sample_read32(slave_audio_rx_stream, &temp);
1229 UX_TEST_CHECK_SUCCESS(status);
1230 // printf("%lx\n", temp);
1231 test_tmp[0] = ((test_n * 4 + 0) % 10) + '0';
1232 test_tmp[1] = ((test_n * 4 + 1) % 10) + '0';
1233 test_tmp[2] = ((test_n * 4 + 2) % 10) + '0';
1234 test_tmp[3] = ((test_n * 4 + 3) % 10) + '0';
1235 UX_TEST_CHECK_SUCCESS(_ux_utility_memory_compare(test_tmp, &temp, 4));
1236 }
1237
1238 UX_TEST_ASSERT(slave_audio_tx_stream->ux_device_class_audio_stream_transfer_pos == slave_audio_tx_stream->ux_device_class_audio_stream_access_pos);
1239
1240 /**************************************************************************/
1241
1242 /* Control requests test. */
1243
1244 transfer_request -> ux_transfer_request_data_pointer = buffer;
1245
1246 test_tmp[0] = 2;
1247 test_tmp[1] = 5;
1248
1249 for (test_n = 0; test_n < 2; test_n ++)
1250 {
1251 transfer_request -> ux_transfer_request_function = UX_DEVICE_CLASS_AUDIO20_CUR;
1252 transfer_request -> ux_transfer_request_type = UX_REQUEST_OUT | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
1253
1254 /* Issue SetFeatureMute(test_tmp[test_n], 0). */
1255 transfer_request -> ux_transfer_request_requested_length = 1;
1256 transfer_request -> ux_transfer_request_index = (test_tmp[test_n] << 8) | 0;
1257 transfer_request -> ux_transfer_request_value = (UX_DEVICE_CLASS_AUDIO20_FU_MUTE_CONTROL << 8) | 0;
1258 buffer[0] = 0;
1259 status = ux_host_stack_transfer_request(transfer_request);
1260 UX_TEST_CHECK_SUCCESS(status);
1261 UX_TEST_ASSERT(g_slave_audio20_control[test_n].ux_device_class_audio20_control_changed == 0);
1262
1263 /* Issue SetFeatureMute(test_tmp[test_n], 1). */
1264 buffer[0] = 1;
1265 status = ux_host_stack_transfer_request(transfer_request);
1266 UX_TEST_CHECK_SUCCESS(status);
1267 UX_TEST_ASSERT(g_slave_audio20_control[test_n].ux_device_class_audio20_control_changed == UX_DEVICE_CLASS_AUDIO20_CONTROL_MUTE_CHANGED);
1268 UX_TEST_ASSERT(g_slave_audio20_control[test_n].ux_device_class_audio20_control_mute[0] == 1);
1269
1270 /* Issue SetFeatureMute(test_tmp[test_n], 0). */
1271 buffer[0] = 0;
1272 status = ux_host_stack_transfer_request(transfer_request);
1273 UX_TEST_CHECK_SUCCESS(status);
1274 UX_TEST_ASSERT(g_slave_audio20_control[test_n].ux_device_class_audio20_control_changed == UX_DEVICE_CLASS_AUDIO20_CONTROL_MUTE_CHANGED);
1275 UX_TEST_ASSERT(g_slave_audio20_control[test_n].ux_device_class_audio20_control_mute[0] == 0);
1276
1277 /* Issue SetFeatureMute(test_tmp[test_n], 1). */
1278 buffer[0] = 1;
1279 status = ux_host_stack_transfer_request(transfer_request);
1280 UX_TEST_CHECK_SUCCESS(status);
1281 UX_TEST_ASSERT(g_slave_audio20_control[test_n].ux_device_class_audio20_control_changed == UX_DEVICE_CLASS_AUDIO20_CONTROL_MUTE_CHANGED);
1282 UX_TEST_ASSERT(g_slave_audio20_control[test_n].ux_device_class_audio20_control_mute[0] == 1);
1283
1284 /* Issue SetFeatureVolume(test_tmp[test_n], 0x0003). */
1285 transfer_request -> ux_transfer_request_requested_length = 2;
1286 transfer_request -> ux_transfer_request_index = (test_tmp[test_n] << 8) | 0;
1287 transfer_request -> ux_transfer_request_value = (UX_DEVICE_CLASS_AUDIO20_FU_VOLUME_CONTROL << 8) | 0;
1288 buffer[0] = 3; buffer[1] = 0;
1289 status = ux_host_stack_transfer_request(transfer_request);
1290 UX_TEST_CHECK_SUCCESS(status);
1291 UX_TEST_ASSERT(g_slave_audio20_control[test_n].ux_device_class_audio20_control_changed == UX_DEVICE_CLASS_AUDIO20_CONTROL_VOLUME_CHANGED);
1292 UX_TEST_ASSERT(g_slave_audio20_control[test_n].ux_device_class_audio20_control_volume[0] == 0x0003);
1293
1294 /* Issue SetFeatureVolume(test_tmp[test_n], 0x0103). */
1295 buffer[1] = 1;
1296 status = ux_host_stack_transfer_request(transfer_request);
1297 UX_TEST_CHECK_SUCCESS(status);
1298 UX_TEST_ASSERT(g_slave_audio20_control[test_n].ux_device_class_audio20_control_changed == UX_DEVICE_CLASS_AUDIO20_CONTROL_VOLUME_CHANGED);
1299 UX_TEST_ASSERT(g_slave_audio20_control[test_n].ux_device_class_audio20_control_volume[0] == 0x0103);
1300
1301 /* Issue SetFeatureVolume(test_tmp[test_n], 0x0103). */
1302 status = ux_host_stack_transfer_request(transfer_request);
1303 UX_TEST_CHECK_SUCCESS(status);
1304 UX_TEST_ASSERT(g_slave_audio20_control[test_n].ux_device_class_audio20_control_changed == 0);
1305
1306 /* Issue GetFeatureMute(test_tmp[test_n]). */
1307 transfer_request -> ux_transfer_request_function = UX_DEVICE_CLASS_AUDIO20_CUR;
1308 transfer_request -> ux_transfer_request_type = UX_REQUEST_IN | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
1309
1310 transfer_request -> ux_transfer_request_requested_length = 1;
1311 transfer_request -> ux_transfer_request_index = (test_tmp[test_n] << 8) | 0;
1312 transfer_request -> ux_transfer_request_value = (UX_DEVICE_CLASS_AUDIO20_FU_MUTE_CONTROL << 8) | 0;
1313 status = ux_host_stack_transfer_request(transfer_request);
1314 UX_TEST_CHECK_SUCCESS(status);
1315 UX_TEST_ASSERT(transfer_request -> ux_transfer_request_actual_length == 1);
1316 UX_TEST_ASSERT(buffer[0] == 1);
1317
1318 /* Issue GetFeatureMute(test_tmp[test_n]). */
1319 transfer_request -> ux_transfer_request_requested_length = 2;
1320 transfer_request -> ux_transfer_request_index = (test_tmp[test_n] << 8) | 0;
1321 transfer_request -> ux_transfer_request_value = (UX_DEVICE_CLASS_AUDIO20_FU_VOLUME_CONTROL << 8) | 0;
1322 status = ux_host_stack_transfer_request(transfer_request);
1323 UX_TEST_CHECK_SUCCESS(status);
1324 UX_TEST_ASSERT(transfer_request -> ux_transfer_request_actual_length == 2);
1325 UX_TEST_ASSERT(buffer[0] == 3);
1326 UX_TEST_ASSERT(buffer[1] == 1);
1327
1328 /* Issue GetClockSamplingFrequency(0x10). */
1329 transfer_request -> ux_transfer_request_function = UX_DEVICE_CLASS_AUDIO20_CUR;
1330 transfer_request -> ux_transfer_request_requested_length = 4;
1331 transfer_request -> ux_transfer_request_index = (0x10 << 8) | 0;
1332 transfer_request -> ux_transfer_request_value = (UX_DEVICE_CLASS_AUDIO20_CS_SAM_FREQ_CONTROL << 8) | 0;
1333 status = ux_host_stack_transfer_request(transfer_request);
1334 UX_TEST_CHECK_SUCCESS(status);
1335 UX_TEST_ASSERT(transfer_request -> ux_transfer_request_actual_length == 4);
1336 UX_TEST_ASSERT(buffer[0] == D0(48000));
1337 UX_TEST_ASSERT(buffer[1] == D1(48000));
1338 UX_TEST_ASSERT(buffer[2] == D2(48000));
1339 UX_TEST_ASSERT(buffer[3] == D3(48000));
1340
1341 /* Issue GetClockSamplingFrequencyRange(0x10). */
1342 transfer_request -> ux_transfer_request_function = UX_DEVICE_CLASS_AUDIO20_RANGE;
1343 transfer_request -> ux_transfer_request_requested_length = 14;
1344 transfer_request -> ux_transfer_request_index = (0x10 << 8) | 0;
1345 transfer_request -> ux_transfer_request_value = (UX_DEVICE_CLASS_AUDIO20_CS_SAM_FREQ_CONTROL << 8) | 0;
1346 status = ux_host_stack_transfer_request(transfer_request);
1347 UX_TEST_CHECK_SUCCESS(status);
1348 UX_TEST_ASSERT(transfer_request -> ux_transfer_request_actual_length == 14);
1349 UX_TEST_ASSERT(buffer[ 0] == D0(1));
1350 UX_TEST_ASSERT(buffer[ 1] == D1(1));
1351 UX_TEST_ASSERT(buffer[ 2] == D0(48000));
1352 UX_TEST_ASSERT(buffer[ 3] == D1(48000));
1353 UX_TEST_ASSERT(buffer[ 4] == D2(48000));
1354 UX_TEST_ASSERT(buffer[ 5] == D3(48000));
1355 UX_TEST_ASSERT(buffer[ 6] == D0(48000));
1356 UX_TEST_ASSERT(buffer[ 7] == D1(48000));
1357 UX_TEST_ASSERT(buffer[ 8] == D2(48000));
1358 UX_TEST_ASSERT(buffer[ 9] == D3(48000));
1359 }
1360
1361 /* Wait pending threads. */
1362 _ux_utility_thread_sleep(1);
1363
1364 /* Finally disconnect the device. */
1365 ux_device_stack_disconnect();
1366
1367 /* And deinitialize the class. */
1368 ux_device_stack_class_unregister(_ux_system_slave_class_audio_name, ux_device_class_audio_entry);
1369
1370 /* Deinitialize the device side of usbx. */
1371 _ux_device_stack_uninitialize();
1372
1373 /* And finally the usbx system resources. */
1374 _ux_system_uninitialize();
1375
1376 /* Successful test. */
1377 printf("SUCCESS!\n");
1378 test_control_return(0);
1379
1380 }
1381
1382
1383
tx_test_thread_slave_simulation_entry(ULONG arg)1384 void tx_test_thread_slave_simulation_entry(ULONG arg)
1385 {
1386 while(1)
1387 {
1388 #if defined(UX_DEVICE_STANDALONE)
1389
1390 /* Standalone background task. */
1391 ux_system_tasks_run();
1392 #else
1393 /* Sleep so ThreadX on Win32 will delete this thread. */
1394 tx_thread_sleep(10);
1395 #endif
1396 }
1397 }
1398