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