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