1 #include "usbx_test_common_storage.h"
2 
3 #include "tx_thread.h"
4 
5 
6 #define DUMMY_USBX_MEMORY_SIZE (64*1024)
7 static UCHAR dummy_usbx_memory[DUMMY_USBX_MEMORY_SIZE];
8 
9 #define DEVICE_FRAMEWORK_LENGTH_FULL_SPEED 50
10 static UCHAR device_framework_full_speed[] = {
11 
12     /* Device descriptor */
13         0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08,
14         0x81, 0x07, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02,
15         0x03, 0x01,
16 
17     /* Configuration descriptor */
18         0x09, 0x02, 0x20, 0x00, 0x01, 0x01, 0x00, 0xc0,
19         0x32,
20 
21     /* Interface descriptor */
22         0x09, 0x04, 0x00, 0x00, 0x02, 0x08, 0x06, 0x50,
23         0x00,
24 
25     /* Endpoint descriptor (Bulk In) */
26         0x07, 0x05, 0x81, 0x02, 0x40, 0x00, 0x00,
27 
28     /* Endpoint descriptor (Bulk Out) */
29         0x07, 0x05, 0x02, 0x02, 0x40, 0x00, 0x00
30 
31     };
32 
33 
34 #define DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED 60
35 static UCHAR device_framework_high_speed[] = {
36 
37     /* Device descriptor */
38         0x12, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40,
39         0x81, 0x07, 0x00, 0x00, 0x01, 0x00, 0x01, 0x02,
40         0x03, 0x01,
41 
42     /* Device qualifier descriptor */
43         0x0a, 0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40,
44         0x01, 0x00,
45 
46     /* Configuration descriptor */
47         0x09, 0x02, 0x20, 0x00, 0x01, 0x01, 0x00, 0xc0,
48         0x32,
49 
50     /* Interface descriptor */
51         0x09, 0x04, 0x00, 0x00, 0x02, 0x08, 0x06, 0x50,
52         0x00,
53 
54     /* Endpoint descriptor (Bulk In) */
55         0x07, 0x05, 0x81, 0x02, 0x00, 0x01, 0x00,
56 
57     /* Endpoint descriptor (Bulk Out) */
58         0x07, 0x05, 0x02, 0x02, 0x00, 0x01, 0x00
59 
60     };
61 
62 
63     /* String Device Framework :
64      Byte 0 and 1 : Word containing the language ID : 0x0904 for US
65      Byte 2       : Byte containing the index of the descriptor
66      Byte 3       : Byte containing the length of the descriptor string
67     */
68 
69 #define STRING_FRAMEWORK_LENGTH 38
70 static UCHAR string_framework[] = {
71 
72     /* Manufacturer string descriptor : Index 1 */
73         0x09, 0x04, 0x01, 0x0c,
74         0x45, 0x78, 0x70, 0x72,0x65, 0x73, 0x20, 0x4c,
75         0x6f, 0x67, 0x69, 0x63,
76 
77     /* Product string descriptor : Index 2 */
78         0x09, 0x04, 0x02, 0x0a,
79         0x46, 0x6c, 0x61, 0x73, 0x68, 0x20, 0x44, 0x69,
80         0x73, 0x6b,
81 
82     /* Serial Number string descriptor : Index 3 */
83         0x09, 0x04, 0x03, 0x04,
84         0x30, 0x30, 0x30, 0x31
85     };
86 
87 
88     /* Multiple languages are supported on the device, to add
89        a language besides english, the unicode language code must
90        be appended to the language_id_framework array and the length
91        adjusted accordingly. */
92 #define LANGUAGE_ID_FRAMEWORK_LENGTH 2
93 static UCHAR language_id_framework[] = {
94 
95     /* English. */
96         0x09, 0x04
97     };
98 
99 
error_callback(UINT system_level,UINT system_context,UINT error_code)100 static VOID error_callback(UINT system_level, UINT system_context, UINT error_code)
101 {
102 
103     //printf("Error on line %d, system_level: %d, system_context: %d, error code: %d\n", __LINE__, system_level, system_context, error_code);
104 }
105 
demo_system_host_change_function(ULONG event_code,UX_HOST_CLASS * class,VOID * instance)106 static UINT    demo_system_host_change_function(ULONG event_code, UX_HOST_CLASS *class, VOID *instance)
107 {
108 
109 UINT    status;
110 
111 
112     if (event_code == UX_DEVICE_INSERTION)
113     {
114 
115         status = ux_utility_semaphore_put(&storage_instance_live_semaphore);
116         if (status)
117         {
118 
119             printf("Error on line %d, error code: %d\n", __LINE__, status);
120             test_control_return(1);
121         }
122     }
123 
124     return 0;
125 }
126 
127 /* Define what the initial system looks like.  */
128 
129 #ifdef CTEST
test_application_define(void * first_unused_memory)130 void test_application_define(void *first_unused_memory)
131 #else
132 void    usbx_storage_direct_calls_test_application_define(void *first_unused_memory)
133 #endif
134 {
135 
136 UINT                            status;
137 CHAR *                          stack_pointer;
138 CHAR *                          memory_pointer;
139 
140 
141     printf("Running Storage Direct Calls Test............................ ");
142 
143     status = ux_utility_semaphore_create(&storage_instance_live_semaphore, "storage_instance_live_semaphore", 0);
144     if (status != UX_SUCCESS)
145     {
146 
147         printf("Error on line %d, error code: %d\n", __LINE__, status);
148         test_control_return(1);
149     }
150 
151     /* Initialize FileX.  */
152     fx_system_initialize();
153 
154     /* Initialize the free memory pointer */
155     stack_pointer = (CHAR *) usbx_memory;
156     memory_pointer = stack_pointer + (UX_DEMO_STACK_SIZE * 2);
157 
158     /* Initialize USBX. Memory */
159     ux_system_initialize(memory_pointer, UX_DEMO_MEMORY_SIZE, UX_NULL,0);
160 
161     /* The code below is required for installing the host portion of USBX */
162     status =  ux_host_stack_initialize(demo_system_host_change_function);
163 
164     /* Check for error.  */
165     if (status != UX_SUCCESS)
166     {
167 
168         printf("Error on line %d, error code: %d\n", __LINE__, status);
169         test_control_return(1);
170     }
171 
172     /* Register the error callback. */
173     _ux_utility_error_callback_register(error_callback);
174 
175     /* Register storage class.  */
176     status =  ux_host_stack_class_register(_ux_system_host_class_storage_name, ux_host_class_storage_entry);
177     if (status != UX_SUCCESS)
178     {
179 
180         printf("Error on line %d, error code: %d\n", __LINE__, status);
181         test_control_return(1);
182     }
183 
184     /* Reset ram disk memory.  */
185     ux_utility_memory_set(global_ram_disk_memory, 0, UX_RAM_DISK_SIZE);
186 
187     /* The code below is required for installing the device portion of USBX.
188        In this demo, DFU is possible and we have a call back for state change. */
189     status =  ux_device_stack_initialize(device_framework_high_speed, DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED,
190                                        device_framework_full_speed, DEVICE_FRAMEWORK_LENGTH_FULL_SPEED,
191                                        string_framework, STRING_FRAMEWORK_LENGTH,
192                                        language_id_framework, LANGUAGE_ID_FRAMEWORK_LENGTH,UX_NULL);
193     if(status!=UX_SUCCESS)
194     {
195 
196         printf("Error on line %d, error code: %d\n", __LINE__, status);
197         test_control_return(1);
198     }
199 
200     /* Store the number of LUN in this device storage instance.  */
201     global_storage_parameter.ux_slave_class_storage_parameter_number_lun = 1;
202 
203     /* Initialize the storage class parameters for reading/writing to the Flash Disk.  */
204     global_storage_parameter.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_last_lba        =  UX_RAM_DISK_LAST_LBA;
205     global_storage_parameter.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_block_length    =  512;
206     global_storage_parameter.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_type            =  0;
207     global_storage_parameter.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_removable_flag  =  0x80;
208     global_storage_parameter.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_read            =  default_device_media_read;
209     global_storage_parameter.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_write           =  default_device_media_write;
210     global_storage_parameter.ux_slave_class_storage_parameter_lun[0].ux_slave_class_storage_media_status          =  default_device_media_status;
211 
212     /* Initilize the device storage class. The class is connected with interface 0 on configuration 1. */
213     status =  ux_device_stack_class_register(_ux_system_slave_class_storage_name, ux_device_class_storage_entry,
214                                                 1, 0, (VOID *)&global_storage_parameter);
215     if(status!=UX_SUCCESS)
216     {
217 
218         printf("Error on line %d, error code: %d\n", __LINE__, status);
219         test_control_return(1);
220     }
221 
222     /* Initialize the simulated device controller.  */
223     status =  _ux_dcd_sim_slave_initialize();
224 
225     /* Check for error.  */
226     if (status != UX_SUCCESS)
227     {
228 
229         printf("Error on line %d, error code: %d\n", __LINE__, status);
230         test_control_return(1);
231     }
232 
233     /* Register all the USB host controllers available in this system */
234     status =  ux_host_stack_hcd_register(_ux_system_host_hcd_simulator_name, ux_hcd_sim_host_initialize,0,0);
235 
236     /* Check for error.  */
237     if (status != UX_SUCCESS)
238     {
239 
240         printf("Error on line %d, error code: %d\n", __LINE__, status);
241         test_control_return(1);
242     }
243 
244     /* Create the main host simulation thread.  */
245     status =  tx_thread_create(&tx_demo_thread_host_simulation, "tx demo host simulation", tx_demo_thread_host_simulation_entry, 0,
246             stack_pointer, UX_DEMO_STACK_SIZE,
247             20, 20, 1, TX_AUTO_START);
248 
249     /* Check for error.  */
250     if (status != TX_SUCCESS)
251     {
252 
253         printf("Error on line %d, error code: %d\n", __LINE__, status);
254         test_control_return(1);
255     }
256 
257 }
258 
259 
ux_hcd_sim_host_entry_filter_transfer_request_failed_test1(UX_HCD * hcd,UINT function,VOID * parameter)260 static UINT ux_hcd_sim_host_entry_filter_transfer_request_failed_test1(UX_HCD *hcd, UINT function, VOID *parameter)
261 {
262 
263 UINT                        status;
264 UX_TRANSFER                 *transfer_request;
265 UINT                        is_csw = UX_ERROR;
266 UX_MEMORY_BLOCK             *dummy_memory_block_first = (UX_MEMORY_BLOCK *)dummy_usbx_memory;
267 
268 
269     if (function == UX_HCD_TRANSFER_REQUEST)
270     {
271 
272         transfer_request = parameter;
273 
274         if (transfer_request->ux_transfer_request_data_pointer != UX_NULL)
275             is_csw = ux_utility_memory_compare("IS_CSW", transfer_request -> ux_transfer_request_data_pointer, 6);
276     }
277 
278     status = _ux_hcd_sim_host_entry(hcd, function, parameter);
279 
280     /* Get Port Status requests don't return UX_SUCCESS. */
281     if (status != UX_SUCCESS && function != UX_HCD_GET_PORT_STATUS)
282     {
283 
284         printf("Error on line %d, error code: %d\n", __LINE__, status);
285         test_control_return(1);
286     }
287 
288     if (function == UX_HCD_TRANSFER_REQUEST)
289     {
290 
291         transfer_request = parameter;
292 
293         /* Is it bulk? */
294         if ((transfer_request->ux_transfer_request_endpoint->ux_endpoint_descriptor.bmAttributes & 3) == 2)
295         {
296 
297             status = ux_utility_semaphore_get(&transfer_request->ux_transfer_request_semaphore, UX_WAIT_FOREVER);
298             if (status)
299             {
300 
301                 printf("Error on line %d, error code: %d\n", __LINE__, status);
302                 test_control_return(1);
303             }
304 
305             if (transfer_request->ux_transfer_request_completion_code != UX_SUCCESS)
306             {
307 
308                 printf("Error on line %d, error code: %d\n", __LINE__, status);
309                 test_control_return(1);
310             }
311         }
312 
313         /* Is this the CSW? */
314         if (is_csw == UX_SUCCESS &&
315             transfer_request -> ux_transfer_request_requested_length == 0x0d &&
316             transfer_request -> ux_transfer_request_function == 0 &&
317             transfer_request -> ux_transfer_request_type == 0x80 &&
318             transfer_request -> ux_transfer_request_value == 0 &&
319             transfer_request -> ux_transfer_request_index == 0)
320         {
321 
322             dummy_memory_block_first -> ux_memory_block_next = UX_NULL;
323             dummy_memory_block_first -> ux_memory_block_previous = UX_NULL;
324             dummy_memory_block_first -> ux_memory_block_status = UX_MEMORY_UNUSED;
325             dummy_memory_block_first -> ux_memory_block_size = 0;
326             _ux_system -> ux_system_regular_memory_pool_start = dummy_memory_block_first;
327             _ux_system -> ux_system_cache_safe_memory_pool_start = dummy_memory_block_first;
328         }
329 
330         /* Is it bulk? */
331         if ((transfer_request->ux_transfer_request_endpoint->ux_endpoint_descriptor.bmAttributes & 3) == 2)
332         {
333 
334             status = ux_utility_semaphore_put(&transfer_request -> ux_transfer_request_semaphore);
335             if (status)
336             {
337 
338                 printf("Error on line %d, error code: %d\n", __LINE__, status);
339                 test_control_return(1);
340             }
341         }
342     }
343 
344     return status;
345 }
346 
ux_hcd_sim_host_entry_filter_transfer_request_failed_test2(UX_HCD * hcd,UINT function,VOID * parameter)347 static UINT ux_hcd_sim_host_entry_filter_transfer_request_failed_test2(UX_HCD *hcd, UINT function, VOID *parameter)
348 {
349 
350 UINT                        status;
351 UX_TRANSFER                 *transfer_request;
352 
353 
354     if (function == UX_HCD_TRANSFER_REQUEST)
355     {
356 
357         transfer_request = parameter;
358 
359         if (ux_utility_memory_compare("IS_CBW", transfer_request -> ux_transfer_request_data_pointer, 6) == UX_SUCCESS)
360         {
361 
362             transfer_request -> ux_transfer_request_semaphore.tx_semaphore_id++;
363 
364             return UX_SUCCESS;
365         }
366     }
367 
368     status = _ux_hcd_sim_host_entry(hcd, function, parameter);
369 
370     /* Get Port Status requests don't return UX_SUCCESS. */
371     if (status != UX_SUCCESS && function != UX_HCD_GET_PORT_STATUS)
372     {
373 
374         printf("Error on line %d, error code: %d\n", __LINE__, status);
375         test_control_return(1);
376     }
377 
378     return status;
379 }
380 
ux_hcd_sim_host_entry_filter_transfer_request_failed_test3(UX_HCD * hcd,UINT function,VOID * parameter)381 static UINT ux_hcd_sim_host_entry_filter_transfer_request_failed_test3(UX_HCD *hcd, UINT function, VOID *parameter)
382 {
383 
384 UINT                        status;
385 UX_TRANSFER                 *transfer_request;
386 
387 
388     if (function == UX_HCD_TRANSFER_REQUEST)
389     {
390 
391         transfer_request = parameter;
392 
393         if (ux_utility_memory_compare("IS_CBW", transfer_request -> ux_transfer_request_data_pointer, 6) == UX_SUCCESS)
394         {
395 
396             status = ux_utility_semaphore_put(&transfer_request -> ux_transfer_request_semaphore);
397             if (status != UX_SUCCESS)
398             {
399 
400                 printf("Error on line %d, error code: %d\n", __LINE__, status);
401                 test_control_return(1);
402             }
403 
404             transfer_request -> ux_transfer_request_completion_code = UX_SUCCESS;
405 
406             return UX_SUCCESS;
407         }
408 
409         if (ux_utility_memory_compare("IS_DATA", transfer_request -> ux_transfer_request_data_pointer, 7) == UX_SUCCESS)
410         {
411 
412             transfer_request -> ux_transfer_request_completion_code = UX_SUCCESS;
413 
414             transfer_request -> ux_transfer_request_semaphore.tx_semaphore_id++;
415 
416             return UX_SUCCESS;
417         }
418     }
419 
420     status = _ux_hcd_sim_host_entry(hcd, function, parameter);
421 
422     /* Get Port Status requests don't return UX_SUCCESS. */
423     if (status != UX_SUCCESS && function != UX_HCD_GET_PORT_STATUS)
424     {
425 
426         printf("Error on line %d, error code: %d\n", __LINE__, status);
427         test_control_return(1);
428     }
429 
430     return status;
431 }
432 
ux_hcd_sim_host_entry_filter_transfer_request_failed_test4(UX_HCD * hcd,UINT function,VOID * parameter)433 static UINT ux_hcd_sim_host_entry_filter_transfer_request_failed_test4(UX_HCD *hcd, UINT function, VOID *parameter)
434 {
435 
436 UINT                        status;
437 UX_TRANSFER                 *transfer_request;
438 static UINT                 csw_retries = 0;
439 
440 
441     if (function == UX_HCD_TRANSFER_REQUEST)
442     {
443 
444         transfer_request = parameter;
445 
446         if (transfer_request -> ux_transfer_request_data_pointer != UX_NULL)
447         {
448 
449             if (ux_utility_memory_compare("IS_CBW", transfer_request->ux_transfer_request_data_pointer, 6) == UX_SUCCESS ||
450                 ux_utility_memory_compare("IS_DATA", transfer_request->ux_transfer_request_data_pointer, 7) == UX_SUCCESS)
451             {
452 
453                 /* Release the semaphore because sim_host_entry() won't (doesn't get invoked). */
454                 status = ux_utility_semaphore_put(&transfer_request->ux_transfer_request_semaphore);
455                 if (status != UX_SUCCESS)
456                 {
457 
458                     printf("Error on line %d, error code: %d\n", __LINE__, status);
459                     test_control_return(1);
460                 }
461 
462                 transfer_request->ux_transfer_request_completion_code = UX_SUCCESS;
463 
464                 return UX_SUCCESS;
465             }
466 
467             if (ux_utility_memory_compare("IS_CSW", transfer_request->ux_transfer_request_data_pointer, 6) == UX_SUCCESS)
468             {
469 
470                 if (csw_retries++ == 0)
471                 {
472 
473                     transfer_request->ux_transfer_request_semaphore.tx_semaphore_id++;
474                 }
475 
476                 transfer_request->ux_transfer_request_completion_code = UX_ERROR;
477 
478                 return UX_SUCCESS;
479             }
480         }
481         else
482         {
483 
484             /* Is this a port reset? */
485             if (transfer_request->ux_transfer_request_data_pointer == UX_NULL &&
486             transfer_request->ux_transfer_request_requested_length == 0 &&
487             transfer_request->ux_transfer_request_function == UX_CLEAR_FEATURE &&
488             (transfer_request->ux_transfer_request_type == (UX_REQUEST_OUT | UX_REQUEST_TYPE_STANDARD | UX_REQUEST_TARGET_ENDPOINT)) &&
489             transfer_request->ux_transfer_request_value == UX_ENDPOINT_HALT)
490             {
491 
492                 transfer_request->ux_transfer_request_completion_code = UX_SUCCESS;
493 
494                 return UX_SUCCESS;
495             }
496         }
497     }
498     else if (function == UX_HCD_RESET_ENDPOINT)
499     {
500 
501         return UX_SUCCESS;
502     }
503 
504     status = _ux_hcd_sim_host_entry(hcd, function, parameter);
505 
506     /* Get Port Status requests don't return UX_SUCCESS. */
507     if (status != UX_SUCCESS && function != UX_HCD_GET_PORT_STATUS)
508     {
509 
510         printf("Error on line %d, error code: %d\n", __LINE__, status);
511         test_control_return(1);
512     }
513 
514     return status;
515 }
516 
ux_hcd_sim_host_entry_filter_transfer_request_failed_test5(UX_HCD * hcd,UINT function,VOID * parameter)517 static UINT ux_hcd_sim_host_entry_filter_transfer_request_failed_test5(UX_HCD *hcd, UINT function, VOID *parameter)
518 {
519 
520 UINT                        status;
521 UX_TRANSFER                 *transfer_request;
522 
523 
524     if (function == UX_HCD_TRANSFER_REQUEST)
525     {
526 
527         transfer_request = parameter;
528 
529         if (ux_utility_memory_compare("IS_UFI", transfer_request -> ux_transfer_request_data_pointer, 6) == UX_SUCCESS)
530         {
531 
532             status = ux_utility_semaphore_put(&transfer_request -> ux_transfer_request_semaphore);
533             if (status != UX_SUCCESS)
534             {
535 
536                 printf("Error on line %d, error code: %d\n", __LINE__, status);
537                 test_control_return(1);
538             }
539 
540             transfer_request -> ux_transfer_request_completion_code = UX_SUCCESS;
541 
542             return UX_SUCCESS;
543         }
544 
545         if (ux_utility_memory_compare("IS_DATA", transfer_request -> ux_transfer_request_data_pointer, 7) == UX_SUCCESS)
546         {
547 
548             transfer_request -> ux_transfer_request_completion_code = UX_SUCCESS;
549 
550             transfer_request -> ux_transfer_request_semaphore.tx_semaphore_id++;
551 
552             return UX_SUCCESS;
553         }
554     }
555 
556     status = _ux_hcd_sim_host_entry(hcd, function, parameter);
557 
558     /* Get Port Status requests don't return UX_SUCCESS. */
559     if (status != UX_SUCCESS && function != UX_HCD_GET_PORT_STATUS)
560     {
561 
562         printf("Error on line %d, error code: %d\n", __LINE__, status);
563         test_control_return(1);
564     }
565 
566     return status;
567 }
568 
ux_hcd_sim_host_entry_filter_transfer_request_failed_test6(UX_HCD * hcd,UINT function,VOID * parameter)569 static UINT ux_hcd_sim_host_entry_filter_transfer_request_failed_test6(UX_HCD *hcd, UINT function, VOID *parameter)
570 {
571 
572 UINT                        status;
573 UX_TRANSFER                 *transfer_request;
574 
575 
576     if (function == UX_HCD_TRANSFER_REQUEST)
577     {
578 
579         transfer_request = parameter;
580 
581         if (ux_utility_memory_compare("IS_UFI", transfer_request -> ux_transfer_request_data_pointer, 6) == UX_SUCCESS)
582         {
583 
584             status = ux_utility_semaphore_put(&transfer_request -> ux_transfer_request_semaphore);
585             if (status != UX_SUCCESS)
586             {
587 
588                 printf("Error on line %d, error code: %d\n", __LINE__, status);
589                 test_control_return(1);
590             }
591 
592             transfer_request -> ux_transfer_request_completion_code = UX_SUCCESS;
593 
594             return UX_SUCCESS;
595         }
596 
597         if (ux_utility_memory_compare("IS_DATA", transfer_request -> ux_transfer_request_data_pointer, 7) == UX_SUCCESS)
598         {
599 
600             transfer_request -> ux_transfer_request_completion_code = UX_SUCCESS;
601 
602             transfer_request -> ux_transfer_request_semaphore.tx_semaphore_id++;
603 
604             return UX_SUCCESS;
605         }
606     }
607 
608     status = _ux_hcd_sim_host_entry(hcd, function, parameter);
609 
610     /* Get Port Status requests don't return UX_SUCCESS. */
611     if (status != UX_SUCCESS && function != UX_HCD_GET_PORT_STATUS)
612     {
613 
614         printf("Error on line %d, error code: %d\n", __LINE__, status);
615         test_control_return(1);
616     }
617 
618     return status;
619 }
620 
ux_hcd_sim_host_entry_filter_transfer_request_failed_test7(UX_HCD * hcd,UINT function,VOID * parameter)621 static UINT ux_hcd_sim_host_entry_filter_transfer_request_failed_test7(UX_HCD *hcd, UINT function, VOID *parameter)
622 {
623 
624 UINT                        status;
625 UX_TRANSFER                 *transfer_request;
626 
627 
628     if (function == UX_HCD_TRANSFER_REQUEST)
629     {
630 
631         transfer_request = parameter;
632 
633         if (transfer_request -> ux_transfer_request_data_pointer != UX_NULL)
634         {
635 
636             if (ux_utility_memory_compare("IS_UFI", transfer_request->ux_transfer_request_data_pointer, 6) == UX_SUCCESS ||
637                 ux_utility_memory_compare("IS_DATA", transfer_request->ux_transfer_request_data_pointer, 7) == UX_SUCCESS)
638             {
639 
640                 /* Release the semaphore because sim_host_entry() won't (doesn't get invoked). */
641                 status = ux_utility_semaphore_put(&transfer_request->ux_transfer_request_semaphore);
642                 if (status != UX_SUCCESS)
643                 {
644 
645                     printf("Error on line %d, error code: %d\n", __LINE__, status);
646                     test_control_return(1);
647                 }
648 
649                 transfer_request->ux_transfer_request_completion_code = UX_SUCCESS;
650 
651                 return UX_SUCCESS;
652             }
653 
654             /* Is this the status request via interrupt endpoint? */
655             if (ux_utility_memory_compare("IS_INTERRUPT", transfer_request->ux_transfer_request_data_pointer, 12) == UX_SUCCESS)
656             {
657 
658                 /* We never created the interrupt endpoint's semaphore, so it will fail without having to do this. */
659                 //transfer_request->ux_transfer_request_semaphore.tx_semaphore_id++;
660 
661                 transfer_request->ux_transfer_request_completion_code = UX_SUCCESS;
662 
663                 return UX_SUCCESS;
664             }
665         }
666     }
667 
668     status = _ux_hcd_sim_host_entry(hcd, function, parameter);
669 
670     /* Get Port Status requests don't return UX_SUCCESS. */
671     if (status != UX_SUCCESS && function != UX_HCD_GET_PORT_STATUS)
672     {
673 
674         printf("Error on line %d, error code: %d\n", __LINE__, status);
675         test_control_return(1);
676     }
677 
678     return status;
679 }
680 
tx_demo_thread_host_simulation_entry(ULONG arg)681 static void  tx_demo_thread_host_simulation_entry(ULONG arg)
682 {
683 
684 UINT                            status;
685 UX_HOST_CLASS                   host_class;
686 UX_DEVICE                       device;
687 UX_CONFIGURATION                configuration;
688 UX_MEMORY_BLOCK                 *dummy_memory_block_first = (UX_MEMORY_BLOCK *)dummy_usbx_memory;
689 UX_MEMORY_BLOCK                 *original_regular_memory_block = _ux_system -> ux_system_regular_memory_pool_start;
690 UX_MEMORY_BLOCK                 *original_cache_safe_memory_block = _ux_system -> ux_system_cache_safe_memory_pool_start;
691 UX_INTERFACE                    interface;
692 UX_HOST_CLASS_COMMAND           command;
693 UX_HOST_CLASS_STORAGE           *storage_instance;
694 TX_SEMAPHORE                    storage_instance_semaphore_copy;
695 ALIGN_TYPE                      tmp;
696 UCHAR                           thread_stack[UX_HOST_CLASS_STORAGE_THREAD_STACK_SIZE];
697 UX_HCD                          *hcd;
698 UCHAR                           data_pointer[128];
699 UX_ENDPOINT                     interrupt_endpoint;
700 UCHAR                           interrupt_endopint_data_pointer[128];
701 UX_TRANSFER                     *transfer_request_ptr;
702 
703 
704     /* Format the ram drive. */
705     status =  fx_media_format(&global_ram_disk, _fx_ram_driver, global_ram_disk_memory, global_ram_disk_working_buffer, 512, "RAM DISK", 2, 512, 0, UX_RAM_DISK_SIZE/512, 512, 4, 1, 1);
706 
707     /* Check the media format status.  */
708     if (status != FX_SUCCESS)
709     {
710 
711         /* Storage basic test error.  */
712         printf("Error on line %d, error code: %d\n", __LINE__, status);
713         test_control_return(1);
714     }
715 
716     /* Open the ram_disk.  */
717     status =  fx_media_open(&global_ram_disk, "RAM DISK", _fx_ram_driver, global_ram_disk_memory, global_ram_disk_working_buffer, 512);
718 
719     /* Check the media open status.  */
720     if (status != FX_SUCCESS)
721     {
722 
723         /* Storage basic test error.  */
724         printf("Error on line %d, error code: %d\n", __LINE__, status);
725         test_control_return(1);
726     }
727 
728     /* Find the storage class */
729     status =  host_storage_instance_get();
730     if (status != UX_SUCCESS)
731     {
732 
733         /* Storage basic test error.  */
734         printf("Error on line %d, error code: %d\n", __LINE__, status);
735         test_control_return(1);
736     }
737 #ifdef UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT
738     /**************************************************/
739     /**************************************************/
740     /** Testing _ux_host_class_storage_transport_cbi() **/
741     /**************************************************/
742     /**************************************************/
743 
744     /**************************************************/
745     /** Test case: status =  _ux_utility_semaphore_get(&transfer_request -> ux_transfer_request_semaphore, UX_HOST_CLASS_STORAGE_TRANSFER_TIMEOUT); (first one) fails **/
746     /**************************************************/
747 
748     /* Swap the hcd entry function. */
749     hcd = UX_DEVICE_HCD_GET(global_storage -> ux_host_class_storage_device);
750     tmp = (ULONG)hcd -> ux_hcd_entry_function;
751     hcd -> ux_hcd_entry_function = ux_hcd_sim_host_entry_filter_transfer_request_failed_test6;
752 
753     /* Make sure we use the bulk out endpoint. */
754     global_storage -> ux_host_class_storage_cbw[UX_HOST_CLASS_STORAGE_CBW_FLAGS] = UX_HOST_CLASS_STORAGE_DATA_OUT;
755 
756     /* Make the UFI portion easily detectable from filter function. */
757     ux_utility_memory_copy(global_storage -> ux_host_class_storage_cbw + UX_HOST_CLASS_STORAGE_CBW_CB, "IS_UFI", 6);
758 
759     /* Make the data something easily detectable from filter function. */
760     ux_utility_memory_copy(data_pointer, "IS_DATA", 7);
761 
762     /* Make sure storage_thread_entry() doesn't send a request at the same time. */
763     status =  _ux_utility_semaphore_get(&global_storage -> ux_host_class_storage_semaphore, UX_WAIT_FOREVER);
764     if(status != UX_SUCCESS)
765     {
766 
767         printf("Error on line %d, error code: %d\n", __LINE__, status);
768         test_control_return(1);
769     }
770 
771     status = _ux_host_class_storage_transport_cbi(global_storage, data_pointer);
772     if(status != UX_TRANSFER_TIMEOUT)
773     {
774 
775         printf("Error on line %d, error code: %d\n", __LINE__, status);
776         test_control_return(1);
777     }
778 
779     status =  _ux_utility_semaphore_put(&global_storage -> ux_host_class_storage_semaphore);
780     if(status != UX_SUCCESS)
781     {
782 
783         printf("Error on line %d, error code: %d\n", __LINE__, status);
784         test_control_return(1);
785     }
786 
787     /* Restore state for next test. */
788     hcd -> ux_hcd_entry_function = (UINT (*) (struct UX_HCD_STRUCT *, UINT, VOID *))tmp;
789     global_storage -> ux_host_class_storage_bulk_out_endpoint -> ux_endpoint_transfer_request.ux_transfer_request_semaphore.tx_semaphore_id--;
790 
791     /**************************************************/
792     /** Test case: status =  _ux_utility_semaphore_get(&transfer_request -> ux_transfer_request_semaphore, UX_HOST_CLASS_STORAGE_TRANSFER_TIMEOUT); (second one) fails **/
793     /**************************************************/
794 
795     /* Swap the hcd entry function. */
796     hcd = UX_DEVICE_HCD_GET(global_storage -> ux_host_class_storage_device);
797     tmp = (ULONG)hcd -> ux_hcd_entry_function;
798     hcd -> ux_hcd_entry_function = ux_hcd_sim_host_entry_filter_transfer_request_failed_test7;
799 
800     /* The framework doesn't describe an interrupt endpoint, so give it one.  */
801     transfer_request_ptr = &interrupt_endpoint.ux_endpoint_transfer_request;
802     transfer_request_ptr->ux_transfer_request_data_pointer = interrupt_endopint_data_pointer;
803     transfer_request_ptr->ux_transfer_request_endpoint = &interrupt_endpoint;
804     interrupt_endpoint.ux_endpoint_device = global_storage -> ux_host_class_storage_device;
805     interrupt_endpoint.ux_endpoint_descriptor.bmAttributes = UX_INTERRUPT_ENDPOINT_IN;
806     global_storage -> ux_host_class_storage_interrupt_endpoint = &interrupt_endpoint;
807     ux_utility_memory_copy(transfer_request_ptr -> ux_transfer_request_data_pointer, "IS_INTERRUPT", 12);
808 
809     /* Make sure we use the bulk out endpoint. */
810     global_storage -> ux_host_class_storage_cbw[UX_HOST_CLASS_STORAGE_CBW_FLAGS] = UX_HOST_CLASS_STORAGE_DATA_OUT;
811 
812     /* Make the UFI portion easily detectable from filter function. */
813     ux_utility_memory_copy(global_storage -> ux_host_class_storage_cbw + UX_HOST_CLASS_STORAGE_CBW_CB, "IS_UFI", 6);
814 
815     /* Make the data something easily detectable from filter function. */
816     ux_utility_memory_copy(data_pointer, "IS_DATA", 7);
817 
818     /* Make sure storage_thread_entry() doesn't send a request at the same time. */
819     status =  _ux_utility_semaphore_get(&global_storage -> ux_host_class_storage_semaphore, UX_WAIT_FOREVER);
820     if(status != UX_SUCCESS)
821     {
822 
823         printf("Error on line %d, error code: %d\n", __LINE__, status);
824         test_control_return(1);
825     }
826 
827     status = _ux_host_class_storage_transport_cbi(global_storage, data_pointer);
828     if(status != TX_SEMAPHORE_ERROR)
829     {
830 
831         printf("Error on line %d, error code: %d\n", __LINE__, status);
832         test_control_return(1);
833     }
834 
835     status =  _ux_utility_semaphore_put(&global_storage -> ux_host_class_storage_semaphore);
836     if(status != UX_SUCCESS)
837     {
838 
839         printf("Error on line %d, error code: %d\n", __LINE__, status);
840         test_control_return(1);
841     }
842 
843     /* Restore state for next test. */
844     hcd -> ux_hcd_entry_function = (UINT (*) (struct UX_HCD_STRUCT *, UINT, VOID *))tmp;
845     global_storage -> ux_host_class_storage_interrupt_endpoint = UX_NULL;
846 
847     /**************************************************/
848     /**************************************************/
849     /** Testing _ux_host_class_storage_transport_cb() **/
850     /**************************************************/
851     /**************************************************/
852 
853     /**************************************************/
854     /** Test case: status =  _ux_utility_semaphore_get(&transfer_request -> ux_transfer_request_semaphore, UX_HOST_CLASS_STORAGE_TRANSFER_TIMEOUT); fails **/
855     /**************************************************/
856 
857     /* Swap the hcd entry function. */
858     hcd = UX_DEVICE_HCD_GET(global_storage -> ux_host_class_storage_device);
859     tmp = (ULONG)hcd -> ux_hcd_entry_function;
860     hcd -> ux_hcd_entry_function = ux_hcd_sim_host_entry_filter_transfer_request_failed_test5;
861 
862     /* Make sure we use the bulk out endpoint. */
863     global_storage -> ux_host_class_storage_cbw[UX_HOST_CLASS_STORAGE_CBW_FLAGS] = UX_HOST_CLASS_STORAGE_DATA_OUT;
864 
865     /* Make the UFI portion easily detectable from filter function. */
866     ux_utility_memory_copy(global_storage -> ux_host_class_storage_cbw + UX_HOST_CLASS_STORAGE_CBW_CB, "IS_UFI", 6);
867 
868     /* Make the data something easily detectable from filter function. */
869     ux_utility_memory_copy(data_pointer, "IS_DATA", 7);
870 
871     /* Make sure storage_thread_entry() doesn't send a request at the same time. */
872     status =  _ux_utility_semaphore_get(&global_storage -> ux_host_class_storage_semaphore, UX_WAIT_FOREVER);
873     if(status != UX_SUCCESS)
874     {
875 
876         printf("Error on line %d, error code: %d\n", __LINE__, status);
877         test_control_return(1);
878     }
879 
880     status = _ux_host_class_storage_transport_cb(global_storage, data_pointer);
881     if(status != UX_TRANSFER_TIMEOUT)
882     {
883 
884         printf("Error on line %d, error code: %d\n", __LINE__, status);
885         test_control_return(1);
886     }
887 
888     status =  _ux_utility_semaphore_put(&global_storage -> ux_host_class_storage_semaphore);
889     if(status != UX_SUCCESS)
890     {
891 
892         printf("Error on line %d, error code: %d\n", __LINE__, status);
893         test_control_return(1);
894     }
895 
896     /* Restore state for next test. */
897     hcd -> ux_hcd_entry_function = (UINT (*) (struct UX_HCD_STRUCT *, UINT, VOID *))tmp;
898     global_storage -> ux_host_class_storage_bulk_out_endpoint -> ux_endpoint_transfer_request.ux_transfer_request_semaphore.tx_semaphore_id--;
899 #endif
900     /**************************************************/
901     /**************************************************/
902     /** Testing _ux_host_class_storage_transport_bo() **/
903     /**************************************************/
904     /**************************************************/
905 
906     /**************************************************/
907     /** Test case: status =  _ux_utility_semaphore_get(&transfer_request -> ux_transfer_request_semaphore, UX_HOST_CLASS_STORAGE_TRANSFER_TIMEOUT); (first one) fails **/
908     /**************************************************/
909 
910     /* Swap the hcd entry function. */
911     hcd = UX_DEVICE_HCD_GET(global_storage -> ux_host_class_storage_device);
912     tmp = (ALIGN_TYPE)hcd -> ux_hcd_entry_function;
913     hcd -> ux_hcd_entry_function = ux_hcd_sim_host_entry_filter_transfer_request_failed_test2;
914 
915     /* Make the CBW something easily detectable from filter function. */
916     ux_utility_memory_copy(global_storage -> ux_host_class_storage_cbw, "IS_CBW", 6);
917 
918     /* Make sure storage_thread_entry() doesn't send a request at the same time. */
919     status =  _ux_utility_semaphore_get(&global_storage -> ux_host_class_storage_semaphore, UX_WAIT_FOREVER);
920     if(status != UX_SUCCESS)
921     {
922 
923         printf("Error on line %d, error code: %d\n", __LINE__, status);
924         test_control_return(1);
925     }
926 
927     status = _ux_host_class_storage_transport_bo(global_storage, UX_NULL);
928     if(status != UX_TRANSFER_TIMEOUT)
929     {
930 
931         printf("Error on line %d, error code: %d\n", __LINE__, status);
932         test_control_return(1);
933     }
934 
935     status =  _ux_utility_semaphore_put(&global_storage -> ux_host_class_storage_semaphore);
936     if(status != UX_SUCCESS)
937     {
938 
939         printf("Error on line %d, error code: %d\n", __LINE__, status);
940         test_control_return(1);
941     }
942 
943     /* Restore state for next test. */
944     hcd -> ux_hcd_entry_function = (UINT (*) (struct UX_HCD_STRUCT *, UINT, VOID *))tmp;
945     global_storage -> ux_host_class_storage_bulk_out_endpoint -> ux_endpoint_transfer_request.ux_transfer_request_semaphore.tx_semaphore_id--;
946 
947     /**************************************************/
948     /** Test case: status =  _ux_utility_semaphore_get(&transfer_request -> ux_transfer_request_semaphore, UX_HOST_CLASS_STORAGE_TRANSFER_TIMEOUT); (second one) fails **/
949     /**************************************************/
950 
951     /* Swap the hcd entry function. */
952     hcd = UX_DEVICE_HCD_GET(global_storage -> ux_host_class_storage_device);
953     tmp = (ALIGN_TYPE)hcd -> ux_hcd_entry_function;
954     hcd -> ux_hcd_entry_function = ux_hcd_sim_host_entry_filter_transfer_request_failed_test3;
955 
956     /* Make the CBW something easily detectable from filter function. */
957     ux_utility_memory_copy(global_storage -> ux_host_class_storage_cbw, "IS_CBW", 6);
958 
959     /* Make sure we use the bulk out endpoint. */
960     global_storage -> ux_host_class_storage_cbw[UX_HOST_CLASS_STORAGE_CBW_FLAGS] = UX_HOST_CLASS_STORAGE_DATA_OUT;
961 
962     /* Make the data something easily detectable from filter function. */
963     ux_utility_memory_copy(data_pointer, "IS_DATA", 7);
964 
965     _ux_utility_long_put(global_storage -> ux_host_class_storage_cbw + UX_HOST_CLASS_STORAGE_CBW_DATA_LENGTH, 10);
966 
967     /* Make sure storage_thread_entry() doesn't send a request at the same time. */
968     status =  _ux_utility_semaphore_get(&global_storage -> ux_host_class_storage_semaphore, UX_WAIT_FOREVER);
969     if(status != UX_SUCCESS)
970     {
971 
972         printf("Error on line %d, error code: %d\n", __LINE__, status);
973         test_control_return(1);
974     }
975 
976     status = _ux_host_class_storage_transport_bo(global_storage, data_pointer);
977     if(status != UX_TRANSFER_TIMEOUT)
978     {
979 
980         printf("Error on line %d, error code: %d\n", __LINE__, status);
981         test_control_return(1);
982     }
983 
984     status =  _ux_utility_semaphore_put(&global_storage -> ux_host_class_storage_semaphore);
985     if(status != UX_SUCCESS)
986     {
987 
988         printf("Error on line %d, error code: %d\n", __LINE__, status);
989         test_control_return(1);
990     }
991 
992     /* Restore state for next test. */
993     hcd -> ux_hcd_entry_function = (UINT (*) (struct UX_HCD_STRUCT *, UINT, VOID *))tmp;
994     global_storage -> ux_host_class_storage_bulk_out_endpoint -> ux_endpoint_transfer_request.ux_transfer_request_semaphore.tx_semaphore_id--;
995 
996     /**************************************************/
997     /** Test case: status =  _ux_utility_semaphore_get(&transfer_request -> ux_transfer_request_semaphore, UX_HOST_CLASS_STORAGE_TRANSFER_TIMEOUT); (third one) fails **/
998     /**************************************************/
999 
1000     /* Swap the hcd entry function. */
1001     hcd = UX_DEVICE_HCD_GET(global_storage -> ux_host_class_storage_device);
1002     tmp = (ALIGN_TYPE)hcd -> ux_hcd_entry_function;
1003     hcd -> ux_hcd_entry_function = ux_hcd_sim_host_entry_filter_transfer_request_failed_test4;
1004 
1005     /* Make the CBW something easily detectable from filter function. */
1006     ux_utility_memory_copy(global_storage -> ux_host_class_storage_cbw, "IS_CBW", 6);
1007 
1008     /* Make the data something easily detectable from filter function. */
1009     ux_utility_memory_copy(data_pointer, "IS_DATA", 7);
1010 
1011     /* Make sure we use the bulk out endpoint. */
1012     global_storage -> ux_host_class_storage_cbw[UX_HOST_CLASS_STORAGE_CBW_FLAGS] = UX_HOST_CLASS_STORAGE_DATA_OUT;
1013 
1014     /* Make the CSW something easily detectable from filter function. */
1015     ux_utility_memory_copy(global_storage -> ux_host_class_storage_csw, "IS_CSW", 6);
1016 
1017     _ux_utility_long_put(global_storage -> ux_host_class_storage_cbw + UX_HOST_CLASS_STORAGE_CBW_DATA_LENGTH, 10);
1018 
1019     /* Make sure storage_thread_entry() doesn't send a request at the same time. */
1020     status =  _ux_utility_semaphore_get(&global_storage -> ux_host_class_storage_semaphore, UX_WAIT_FOREVER);
1021     if(status != UX_SUCCESS)
1022     {
1023 
1024         printf("Error on line %d, error code: %d\n", __LINE__, status);
1025         test_control_return(1);
1026     }
1027 
1028     status = _ux_host_class_storage_transport_bo(global_storage, data_pointer);
1029     if(status != UX_ERROR)
1030     {
1031 
1032         printf("Error on line %d, error code: %d\n", __LINE__, status);
1033         test_control_return(1);
1034     }
1035 
1036     status =  _ux_utility_semaphore_put(&global_storage -> ux_host_class_storage_semaphore);
1037     if(status != UX_SUCCESS)
1038     {
1039 
1040         printf("Error on line %d, error code: %d\n", __LINE__, status);
1041         test_control_return(1);
1042     }
1043 
1044     /* Restore state for next test. */
1045     hcd -> ux_hcd_entry_function = (UINT (*) (struct UX_HCD_STRUCT *, UINT, VOID *))tmp;
1046     global_storage -> ux_host_class_storage_bulk_in_endpoint -> ux_endpoint_transfer_request.ux_transfer_request_semaphore.tx_semaphore_id--;
1047 
1048     /**************************************************/
1049     /**************************************************/
1050     /** Testing _ux_host_class_storage_media_capacity_get() **/
1051     /**************************************************/
1052     /**************************************************/
1053 
1054     /**************************************************/
1055     /** Test case: capacity_response =  _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, UX_HOST_CLASS_STORAGE_READ_FORMAT_RESPONSE_LENGTH); fails **/
1056     /**************************************************/
1057 
1058     /* Set up the dummy memory block. */
1059     dummy_memory_block_first -> ux_memory_block_next = UX_NULL;
1060     dummy_memory_block_first -> ux_memory_block_previous = UX_NULL;
1061     dummy_memory_block_first -> ux_memory_block_status = UX_MEMORY_UNUSED;
1062     dummy_memory_block_first -> ux_memory_block_size = 0;
1063     _ux_system -> ux_system_regular_memory_pool_start = dummy_memory_block_first;
1064     _ux_system -> ux_system_cache_safe_memory_pool_start = dummy_memory_block_first;
1065 
1066     status = _ux_host_class_storage_media_capacity_get(global_storage);
1067     if (status != UX_MEMORY_INSUFFICIENT)
1068     {
1069 
1070         printf("Error on line %d, error code: %d\n", __LINE__, status);
1071         test_control_return(1);
1072     }
1073 
1074     /* Restore state for next test. */
1075     _ux_system -> ux_system_regular_memory_pool_start = original_regular_memory_block;
1076     _ux_system -> ux_system_cache_safe_memory_pool_start = original_cache_safe_memory_block;
1077 
1078     /**************************************************/
1079     /** Test case: capacity_response =  _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, UX_HOST_CLASS_STORAGE_READ_CAPACITY_RESPONSE_LENGTH); fails **/
1080     /** How: "But Nick, that's impossible! It's simply too dangerous! You'll die!" Modify the memory blocks _after_ the first memory allocate via transfer request. **/
1081     /**************************************************/
1082 
1083     ux_utility_memory_copy(global_storage -> ux_host_class_storage_csw, "IS_CSW", 6);
1084 
1085     /* Swap the hcd entry function. */
1086     hcd = UX_DEVICE_HCD_GET(global_storage -> ux_host_class_storage_device);
1087     tmp = (ALIGN_TYPE)hcd -> ux_hcd_entry_function;
1088     hcd -> ux_hcd_entry_function = ux_hcd_sim_host_entry_filter_transfer_request_failed_test1;
1089 
1090     /* Make sure storage_thread_entry() doesn't send a request at the same time. */
1091     status =  _ux_utility_semaphore_get(&global_storage -> ux_host_class_storage_semaphore, UX_WAIT_FOREVER);
1092     if(status != UX_SUCCESS)
1093     {
1094 
1095         printf("Error on line %d, error code: %d\n", __LINE__, status);
1096         test_control_return(1);
1097     }
1098 
1099     status = _ux_host_class_storage_media_capacity_get(global_storage);
1100     if (status != UX_MEMORY_INSUFFICIENT)
1101     {
1102 
1103         printf("Error on line %d, error code: %d\n", __LINE__, status);
1104         test_control_return(1);
1105     }
1106 
1107     status =  _ux_utility_semaphore_put(&global_storage -> ux_host_class_storage_semaphore);
1108     if(status != UX_SUCCESS)
1109     {
1110 
1111         printf("Error on line %d, error code: %d\n", __LINE__, status);
1112         test_control_return(1);
1113     }
1114 
1115     /* Restore state for next test. */
1116     _ux_system -> ux_system_regular_memory_pool_start = original_regular_memory_block;
1117     _ux_system -> ux_system_cache_safe_memory_pool_start = original_cache_safe_memory_block;
1118     hcd -> ux_hcd_entry_function = (UINT (*) (struct UX_HCD_STRUCT *, UINT, VOID *))tmp;
1119 
1120     /**************************************************/
1121     /**************************************************/
1122     /** Testing _ux_host_class_storage_request_sense() **/
1123     /**************************************************/
1124     /**************************************************/
1125 
1126     /**************************************************/
1127     /** Test case: request_sense_response =  _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, UX_HOST_CLASS_STORAGE_REQUEST_SENSE_RESPONSE_LENGTH); fails **/
1128     /**************************************************/
1129 
1130     /* Set up the dummy memory block. */
1131     dummy_memory_block_first -> ux_memory_block_next = UX_NULL;
1132     dummy_memory_block_first -> ux_memory_block_previous = UX_NULL;
1133     dummy_memory_block_first -> ux_memory_block_status = UX_MEMORY_UNUSED;
1134     dummy_memory_block_first -> ux_memory_block_size = 0;
1135     _ux_system -> ux_system_regular_memory_pool_start = dummy_memory_block_first;
1136     _ux_system -> ux_system_cache_safe_memory_pool_start = dummy_memory_block_first;
1137 
1138     status = _ux_host_class_storage_request_sense(global_storage);
1139     if (status != UX_MEMORY_INSUFFICIENT)
1140     {
1141 
1142         printf("Error on line %d, error code: %d\n", __LINE__, status);
1143         test_control_return(1);
1144     }
1145 
1146     /* Restore state for next test. */
1147     _ux_system -> ux_system_regular_memory_pool_start = original_regular_memory_block;
1148     _ux_system -> ux_system_cache_safe_memory_pool_start = original_cache_safe_memory_block;
1149 
1150     /**************************************************/
1151     /**************************************************/
1152     /** Testing _ux_host_class_storage_media_open() **/
1153     /**************************************************/
1154     /**************************************************/
1155 
1156     /**************************************************/
1157     /** Test case: storage_media -> ux_host_class_storage_media_memory =  _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, UX_HOST_CLASS_STORAGE_MEMORY_BUFFER_SIZE); fails **/
1158     /**************************************************/
1159 
1160     /* Set up the dummy memory block. */
1161     dummy_memory_block_first -> ux_memory_block_next = UX_NULL;
1162     dummy_memory_block_first -> ux_memory_block_previous = UX_NULL;
1163     dummy_memory_block_first -> ux_memory_block_status = UX_MEMORY_UNUSED;
1164     dummy_memory_block_first -> ux_memory_block_size = 0;
1165     _ux_system -> ux_system_regular_memory_pool_start = dummy_memory_block_first;
1166     _ux_system -> ux_system_cache_safe_memory_pool_start = dummy_memory_block_first;
1167 
1168     status = _ux_host_class_storage_media_open(global_storage, 0);
1169     if (status != UX_MEMORY_INSUFFICIENT)
1170     {
1171 
1172         printf("Error on line %d, error code: %d\n", __LINE__, status);
1173         test_control_return(1);
1174     }
1175 
1176     /* Restore state for next test. */
1177     _ux_system -> ux_system_regular_memory_pool_start = original_regular_memory_block;
1178     _ux_system -> ux_system_cache_safe_memory_pool_start = original_cache_safe_memory_block;
1179 
1180     /**************************************************/
1181     /**************************************************/
1182     /** Testing _ux_host_class_storage_media_mount() **/
1183     /**************************************************/
1184     /**************************************************/
1185 
1186     /**************************************************/
1187     /** Test case: sector_memory =  _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, storage -> ux_host_class_storage_sector_size); fails **/
1188     /**************************************************/
1189 
1190     /* Set up the dummy memory block. */
1191     dummy_memory_block_first -> ux_memory_block_next = UX_NULL;
1192     dummy_memory_block_first -> ux_memory_block_previous = UX_NULL;
1193     dummy_memory_block_first -> ux_memory_block_status = UX_MEMORY_UNUSED;
1194     dummy_memory_block_first -> ux_memory_block_size = 0;
1195     _ux_system -> ux_system_regular_memory_pool_start = dummy_memory_block_first;
1196     _ux_system -> ux_system_cache_safe_memory_pool_start = dummy_memory_block_first;
1197 
1198     status = _ux_host_class_storage_media_mount(global_storage, 0);
1199     if (status != UX_MEMORY_INSUFFICIENT)
1200     {
1201 
1202         printf("Error on line %d, error code: %d\n", __LINE__, status);
1203         test_control_return(1);
1204     }
1205 
1206     /* Restore state for next test. */
1207     _ux_system -> ux_system_regular_memory_pool_start = original_regular_memory_block;
1208     _ux_system -> ux_system_cache_safe_memory_pool_start = original_cache_safe_memory_block;
1209 
1210     /**************************************************/
1211     /**************************************************/
1212     /** Testing _ux_host_class_storage_media_format_capacity_get() **/
1213     /**************************************************/
1214     /**************************************************/
1215 
1216     /**************************************************/
1217     /** Test case: read_format_capacity_response =  _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, UX_HOST_CLASS_STORAGE_READ_FORMAT_RESPONSE_LENGTH); fails **/
1218     /**************************************************/
1219 
1220     /* Set up the dummy memory block. */
1221     dummy_memory_block_first -> ux_memory_block_next = UX_NULL;
1222     dummy_memory_block_first -> ux_memory_block_previous = UX_NULL;
1223     dummy_memory_block_first -> ux_memory_block_status = UX_MEMORY_UNUSED;
1224     dummy_memory_block_first -> ux_memory_block_size = 0;
1225     _ux_system -> ux_system_regular_memory_pool_start = dummy_memory_block_first;
1226     _ux_system -> ux_system_cache_safe_memory_pool_start = dummy_memory_block_first;
1227 
1228     status = _ux_host_class_storage_media_format_capacity_get(global_storage);
1229     if (status != UX_MEMORY_INSUFFICIENT)
1230     {
1231 
1232         printf("Error on line %d, error code: %d\n", __LINE__, status);
1233         test_control_return(1);
1234     }
1235 
1236     /* Restore state for next test. */
1237     _ux_system -> ux_system_regular_memory_pool_start = original_regular_memory_block;
1238     _ux_system -> ux_system_cache_safe_memory_pool_start = original_cache_safe_memory_block;
1239 
1240     /**************************************************/
1241     /**************************************************/
1242     /** Testing _ux_host_class_storage_media_characteristics_get() **/
1243     /**************************************************/
1244     /**************************************************/
1245 
1246     /**************************************************/
1247     /** Test case: inquiry_response =  _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, UX_HOST_CLASS_STORAGE_INQUIRY_RESPONSE_LENGTH); fails **/
1248     /**************************************************/
1249 
1250     /* Set up the dummy memory block. */
1251     dummy_memory_block_first -> ux_memory_block_next = UX_NULL;
1252     dummy_memory_block_first -> ux_memory_block_previous = UX_NULL;
1253     dummy_memory_block_first -> ux_memory_block_status = UX_MEMORY_UNUSED;
1254     dummy_memory_block_first -> ux_memory_block_size = 0;
1255     _ux_system -> ux_system_regular_memory_pool_start = dummy_memory_block_first;
1256     _ux_system -> ux_system_cache_safe_memory_pool_start = dummy_memory_block_first;
1257 
1258     status = _ux_host_class_storage_media_characteristics_get(global_storage);
1259     if (status != UX_MEMORY_INSUFFICIENT)
1260     {
1261 
1262         printf("Error on line %d, error code: %d\n", __LINE__, status);
1263         test_control_return(1);
1264     }
1265 
1266     /* Restore state for next test. */
1267     _ux_system -> ux_system_regular_memory_pool_start = original_regular_memory_block;
1268     _ux_system -> ux_system_cache_safe_memory_pool_start = original_cache_safe_memory_block;
1269 
1270     /**************************************************/
1271     /**************************************************/
1272     /** Testing _ux_host_class_storage_max_lun_get() **/
1273     /**************************************************/
1274     /**************************************************/
1275 
1276     /**************************************************/
1277     /** Test case: storage_data_buffer =  _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, 1); fails **/
1278     /**************************************************/
1279 
1280     /* ux_host_class_storage_max_lun is set to 0 at start of max_lun_get() in case of error. */
1281     tmp = global_storage -> ux_host_class_storage_max_lun;
1282 
1283     /* Set up the dummy memory block. */
1284     dummy_memory_block_first -> ux_memory_block_next = UX_NULL;
1285     dummy_memory_block_first -> ux_memory_block_previous = UX_NULL;
1286     dummy_memory_block_first -> ux_memory_block_status = UX_MEMORY_UNUSED;
1287     dummy_memory_block_first -> ux_memory_block_size = 0;
1288     _ux_system -> ux_system_regular_memory_pool_start = dummy_memory_block_first;
1289     _ux_system -> ux_system_cache_safe_memory_pool_start = dummy_memory_block_first;
1290 
1291     status = _ux_host_class_storage_max_lun_get(global_storage);
1292     if (status != UX_MEMORY_INSUFFICIENT)
1293     {
1294 
1295         printf("Error on line %d, error code: %d\n", __LINE__, status);
1296         test_control_return(1);
1297     }
1298 
1299     /* Restore state for next test. */
1300     global_storage -> ux_host_class_storage_max_lun = tmp;
1301     _ux_system -> ux_system_regular_memory_pool_start = original_regular_memory_block;
1302     _ux_system -> ux_system_cache_safe_memory_pool_start = original_cache_safe_memory_block;
1303 
1304     /**************************************************/
1305     /**************************************************/
1306     /** Testing _ux_host_class_storage_entry() **/
1307     /**************************************************/
1308     /**************************************************/
1309 
1310     /**************************************************/
1311     /** Test case: command -> ux_host_class_command_class_ptr -> ux_host_class_thread_stack =
1312                     _ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY, UX_HOST_CLASS_STORAGE_THREAD_STACK_SIZE); fails **/
1313     /**************************************************/
1314 
1315     host_class.ux_host_class_thread_stack = UX_NULL;
1316     command.ux_host_class_command_class_ptr = &host_class;
1317     command.ux_host_class_command_request = UX_HOST_CLASS_COMMAND_ACTIVATE;
1318     command.ux_host_class_command_class_ptr -> ux_host_class_thread_stack = UX_NULL;
1319 
1320     /* Set up the dummy memory block. */
1321     dummy_memory_block_first -> ux_memory_block_next = UX_NULL;
1322     dummy_memory_block_first -> ux_memory_block_previous = UX_NULL;
1323     dummy_memory_block_first -> ux_memory_block_status = UX_MEMORY_UNUSED;
1324     dummy_memory_block_first -> ux_memory_block_size = 0;
1325     _ux_system -> ux_system_regular_memory_pool_start = dummy_memory_block_first;
1326     _ux_system -> ux_system_cache_safe_memory_pool_start = dummy_memory_block_first;
1327 
1328     status = _ux_host_class_storage_entry(&command);
1329     if (status != UX_MEMORY_INSUFFICIENT)
1330     {
1331 
1332         printf("Error on line %d, error code: %d\n", __LINE__, status);
1333         test_control_return(1);
1334     }
1335 
1336     /* Restore state for next test. */
1337     _ux_system -> ux_system_regular_memory_pool_start = original_regular_memory_block;
1338     _ux_system -> ux_system_cache_safe_memory_pool_start = original_cache_safe_memory_block;
1339 
1340     /**************************************************/
1341     /** Test case: command -> ux_host_class_command_class_ptr -> ux_host_class_thread_stack =
1342                     _ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY, UX_HOST_CLASS_STORAGE_THREAD_STACK_SIZE); fails **/
1343     /**************************************************/
1344 
1345     host_class.ux_host_class_thread_stack = UX_NULL;
1346     command.ux_host_class_command_class_ptr = &host_class;
1347     command.ux_host_class_command_request = UX_HOST_CLASS_COMMAND_ACTIVATE;
1348     command.ux_host_class_command_class_ptr -> ux_host_class_thread_stack = UX_NULL;
1349 
1350     /* Set up the dummy memory block. */
1351     dummy_memory_block_first -> ux_memory_block_next = UX_NULL;
1352     dummy_memory_block_first -> ux_memory_block_previous = UX_NULL;
1353     dummy_memory_block_first -> ux_memory_block_status = UX_MEMORY_UNUSED;
1354     dummy_memory_block_first -> ux_memory_block_size = calculate_final_memory_request_size(1, UX_HOST_CLASS_STORAGE_THREAD_STACK_SIZE);
1355     _ux_system -> ux_system_regular_memory_pool_start = dummy_memory_block_first;
1356     _ux_system -> ux_system_cache_safe_memory_pool_start = dummy_memory_block_first;
1357 
1358     status = _ux_host_class_storage_entry(&command);
1359     if (status != UX_MEMORY_INSUFFICIENT)
1360     {
1361 
1362         printf("Error on line %d, error code: %d\n", __LINE__, status);
1363         test_control_return(1);
1364     }
1365 
1366     /* Restore state for next test. */
1367 
1368     /* Delete thread that was created during call. */
1369     status = ux_utility_thread_delete(&command.ux_host_class_command_class_ptr -> ux_host_class_thread);
1370     if (status != UX_SUCCESS)
1371     {
1372 
1373         printf("Error on line %d, error code: %d\n", __LINE__, status);
1374         test_control_return(1);
1375     }
1376 
1377     _ux_system -> ux_system_regular_memory_pool_start = original_regular_memory_block;
1378     _ux_system -> ux_system_cache_safe_memory_pool_start = original_cache_safe_memory_block;
1379 
1380     /**************************************************/
1381     /** Test case: status =  _ux_utility_thread_create(&command -> ux_host_class_command_class_ptr -> ux_host_class_thread,
1382                                     "ux_storage_thread", _ux_host_class_storage_thread_entry,
1383                                     (ULONG) command -> ux_host_class_command_class_ptr,
1384                                     command -> ux_host_class_command_class_ptr -> ux_host_class_thread_stack,
1385                                     UX_HOST_CLASS_STORAGE_THREAD_STACK_SIZE,
1386                                     UX_HOST_CLASS_STORAGE_THREAD_PRIORITY_CLASS,
1387                                     UX_HOST_CLASS_STORAGE_THREAD_PRIORITY_CLASS,
1388                                     TX_NO_TIME_SLICE, TX_AUTO_START); fails **/
1389     /**************************************************/
1390 
1391     host_class.ux_host_class_thread_stack = UX_NULL;
1392     command.ux_host_class_command_class_ptr = &host_class;
1393     command.ux_host_class_command_request = UX_HOST_CLASS_COMMAND_ACTIVATE;
1394     command.ux_host_class_command_class_ptr -> ux_host_class_thread_stack = thread_stack;
1395 
1396     /* Create thread that storage_entry() will try to create. */
1397     status =  _ux_utility_thread_create(&command.ux_host_class_command_class_ptr -> ux_host_class_thread,
1398                                         "ux_storage_thread", _ux_host_class_storage_thread_entry,
1399                                         (ULONG) (ALIGN_TYPE) command.ux_host_class_command_class_ptr,
1400                                         command.ux_host_class_command_class_ptr -> ux_host_class_thread_stack,
1401                                         UX_HOST_CLASS_STORAGE_THREAD_STACK_SIZE,
1402                                         UX_HOST_CLASS_STORAGE_THREAD_PRIORITY_CLASS,
1403                                         UX_HOST_CLASS_STORAGE_THREAD_PRIORITY_CLASS,
1404                                         TX_NO_TIME_SLICE, TX_DONT_START);
1405     if (status != UX_SUCCESS)
1406     {
1407 
1408         printf("Error on line %d, error code: %d\n", __LINE__, status);
1409         test_control_return(1);
1410     }
1411     UX_THREAD_EXTENSION_PTR_SET(&command.ux_host_class_command_class_ptr -> ux_host_class_thread, command.ux_host_class_command_class_ptr)
1412     tx_thread_resume(&command.ux_host_class_command_class_ptr -> ux_host_class_thread);
1413 
1414     command.ux_host_class_command_class_ptr -> ux_host_class_thread_stack = UX_NULL;
1415 
1416     status = _ux_host_class_storage_entry(&command);
1417     if (status != UX_THREAD_ERROR)
1418     {
1419 
1420         printf("Error on line %d, error code: %d\n", __LINE__, status);
1421         test_control_return(1);
1422     }
1423 
1424     /* Restore state for next test. */
1425     status = ux_utility_thread_delete(&command.ux_host_class_command_class_ptr -> ux_host_class_thread);
1426     if (status != UX_SUCCESS)
1427     {
1428 
1429         printf("Error on line %d, error code: %d\n", __LINE__, status);
1430         test_control_return(1);
1431     }
1432 
1433     /**************************************************/
1434     /**************************************************/
1435     /** Testing _ux_host_class_storage_activate() **/
1436     /**************************************************/
1437     /**************************************************/
1438 
1439     /**************************************************/
1440     /** Test case: storage =  _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, sizeof(UX_HOST_CLASS_STORAGE)); fails **/
1441     /**************************************************/
1442 
1443     command.ux_host_class_command_container = &interface;
1444 
1445     /* Set up the dummy memory block. */
1446     dummy_memory_block_first -> ux_memory_block_next = UX_NULL;
1447     dummy_memory_block_first -> ux_memory_block_previous = UX_NULL;
1448     dummy_memory_block_first -> ux_memory_block_status = UX_MEMORY_UNUSED;
1449     dummy_memory_block_first -> ux_memory_block_size = 0;
1450     _ux_system -> ux_system_regular_memory_pool_start = dummy_memory_block_first;
1451     _ux_system -> ux_system_cache_safe_memory_pool_start = dummy_memory_block_first;
1452 
1453     status = _ux_host_class_storage_activate(&command);
1454     if (status != UX_MEMORY_INSUFFICIENT)
1455     {
1456 
1457         printf("Error on line %d, error code: %d\n", __LINE__, status);
1458         test_control_return(1);
1459     }
1460 
1461     /* Restore state for next test. */
1462     _ux_system -> ux_system_regular_memory_pool_start = original_regular_memory_block;
1463     _ux_system -> ux_system_cache_safe_memory_pool_start = original_cache_safe_memory_block;
1464 
1465 #if 0
1466     /**************************************************/
1467     /** Test case: _ux_host_class_hid_configure() fails. **/
1468     /** Why direct: When called normally, the device is already configured (via ux_host_stack_class_interface_scan, which always happens before hid_activate()), so _ux_host_class_hid_configure() returns immediately. **/
1469     /**************************************************/
1470 
1471     /* Make sure we pass _ux_host_stack_class_instance_create(). */
1472     host_class.ux_host_class_first_instance = UX_NULL;
1473 
1474     /* Make sure _ux_host_class_hid_configure() fails. */
1475     device.ux_device_state = ~UX_DEVICE_CONFIGURED;
1476     device.ux_device_handle = 0;
1477 
1478     configuration.ux_configuration_device = &device;
1479     interface.ux_interface_configuration = &configuration;
1480     command.ux_host_class_command_container = &interface;
1481     command.ux_host_class_command_class_ptr = &host_class;
1482 
1483     status = _ux_host_class_storage_activate(&command);
1484     if (status != UX_CONFIGURATION_HANDLE_UNKNOWN)
1485     {
1486 
1487         printf("Error on line %d, error code: %d\n", __LINE__, status);
1488         test_control_return(1);
1489     }
1490 #endif
1491 
1492     /**************************************************/
1493     /** Test case: status =  _ux_utility_semaphore_create(&storage -> ux_host_class_storage_semaphore, "ux_host_class_storage_semaphore", 1); fails **/
1494     /**************************************************/
1495 
1496     /* Allocate a keyboard instance like storage_activate(). */
1497     storage_instance =  (UX_HOST_CLASS_STORAGE *) _ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY, sizeof(UX_HOST_CLASS_STORAGE));
1498     if (storage_instance == UX_NULL)
1499     {
1500 
1501         printf("Error on line %d\n", __LINE__);
1502         test_control_return(1);
1503     }
1504 
1505     /* Create the semaphore like storage_activate(). */
1506     status =  _ux_utility_semaphore_create(&storage_instance -> ux_host_class_storage_semaphore, "ux_host_class_storage_semaphore", 0);
1507     if (status != UX_SUCCESS)
1508     {
1509 
1510         printf("Error on line %d, error code: %d\n", __LINE__, status);
1511         test_control_return(1);
1512     }
1513 
1514     /* Make a copy of the semaphore. */
1515     storage_instance_semaphore_copy = storage_instance -> ux_host_class_storage_semaphore;
1516 
1517     /* Free the memory so storage_activate() uses the same memory as us, which will cause threadx to detect a semaphore duplicate. */
1518     ux_utility_memory_free(storage_instance);
1519 
1520     /* Make sure we pass _ux_host_stack_class_instance_create(). */
1521     host_class.ux_host_class_first_instance = UX_NULL;
1522 
1523     device.ux_device_state = UX_DEVICE_CONFIGURED;
1524     configuration.ux_configuration_device = &device;
1525     interface.ux_interface_configuration = &configuration;
1526     command.ux_host_class_command_container = &interface;
1527 
1528     status = _ux_host_class_storage_activate(&command);
1529     if (status != UX_SEMAPHORE_ERROR)
1530     {
1531 
1532         printf("Error on line %d, error code: %d\n", __LINE__, status);
1533         test_control_return(1);
1534     }
1535 
1536     /* ux_utility_memory_allocate() zero'd out our keyboard instance semaphore! Good thing we made a copy! */
1537     storage_instance -> ux_host_class_storage_semaphore = storage_instance_semaphore_copy;
1538 
1539     /* Restore state for next test. */
1540     status = ux_utility_semaphore_delete(&storage_instance -> ux_host_class_storage_semaphore);
1541     if (status != UX_SUCCESS)
1542     {
1543 
1544         printf("Error on line %d, error code: %d\n", __LINE__, status);
1545         test_control_return(1);
1546     }
1547 
1548     /**************************************************/
1549     /**************************************************/
1550     /** Testing _ux_host_class_storage_driver_entry() **/
1551     /**************************************************/
1552     /**************************************************/
1553 
1554     /**************************************************/
1555     /** Test case: status =  _ux_utility_semaphore_get(&storage -> ux_host_class_storage_semaphore, UX_WAIT_FOREVER); fails **/
1556     /**************************************************/
1557 
1558     /* Make sure it fails. */
1559     global_storage -> ux_host_class_storage_semaphore.tx_semaphore_id++;
1560 
1561     command.ux_host_class_command_instance = global_storage;
1562 
1563     /* Returns VOID. */
1564     _ux_host_class_storage_driver_entry(global_media);
1565 
1566     /* Restore state. */
1567     global_storage -> ux_host_class_storage_semaphore.tx_semaphore_id--;
1568 
1569     /**************************************************/
1570     /**************************************************/
1571     /** Testing _ux_host_class_storage_configure() **/
1572     /** Why direct: When called normally, the device is already configured (via ux_host_stack_class_interface_scan, which always happens before hid_activate()), so _ux_host_class_hid_configure() returns immediately. **/
1573     /**************************************************/
1574     /**************************************************/
1575 
1576     /**************************************************/
1577     /**************************************************/
1578     /** Testing _ux_host_class_storage_deactivate() **/
1579     /** NOTE: This should be last. **/
1580     /**************************************************/
1581     /**************************************************/
1582 
1583     /**************************************************/
1584     /** Test case: status =  _ux_utility_semaphore_get(&storage -> ux_host_class_storage_semaphore, UX_WAIT_FOREVER); fails **/
1585     /**************************************************/
1586 
1587     /* Make sure it fails. */
1588     global_storage -> ux_host_class_storage_semaphore.tx_semaphore_id++;
1589 
1590     command.ux_host_class_command_instance = global_storage;
1591 
1592     status = _ux_host_class_storage_deactivate(&command);
1593     if(status != TX_SEMAPHORE_ERROR)
1594     {
1595 
1596         printf("Error on line %d, error code: %d\n", __LINE__, status);
1597         test_control_return(1);
1598     }
1599 
1600     /* Restore state. */
1601     global_storage -> ux_host_class_storage_semaphore.tx_semaphore_id--;
1602 
1603     /* The function did a get() on the hid semaphore and never put() it since we error'd out, so we must do it! */
1604     status = ux_utility_semaphore_put(&global_storage -> ux_host_class_storage_semaphore);
1605     if (status != UX_SUCCESS)
1606     {
1607 
1608         printf("Error on line %d, error code: %d\n", __LINE__, status);
1609         test_control_return(1);
1610     }
1611 
1612     /* Successful test.  */
1613     printf("SUCCESS!\n");
1614     test_control_return(0);
1615 }
1616 
1617 
default_device_media_read(VOID * storage,ULONG lun,UCHAR * data_pointer,ULONG number_blocks,ULONG lba,ULONG * media_status)1618 static UINT    default_device_media_read(VOID *storage, ULONG lun, UCHAR * data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status)
1619 {
1620 
1621 UINT status;
1622 
1623 
1624     if(lba == 0)
1625     {
1626         global_ram_disk.fx_media_driver_logical_sector =  0;
1627         global_ram_disk.fx_media_driver_sectors =  1;
1628         global_ram_disk.fx_media_driver_request =  FX_DRIVER_BOOT_READ;
1629         global_ram_disk.fx_media_driver_buffer =  data_pointer;
1630         _fx_ram_driver(&global_ram_disk);
1631         *(data_pointer) =  0xeb;
1632         *(data_pointer+1) =  0x3c;
1633         *(data_pointer+2) =  0x90;
1634         *(data_pointer+21) =  0xF8;
1635 
1636         *(data_pointer+24) =  0x01;
1637         *(data_pointer+26) =  0x10;
1638         *(data_pointer+28) =  0x01;
1639 
1640         *(data_pointer+510) =  0x55;
1641         *(data_pointer+511) =  0xaa;
1642         ux_utility_memory_copy(data_pointer+0x36,"FAT12",5);
1643 
1644 
1645         status = global_ram_disk.fx_media_driver_status;
1646     }
1647     else
1648     {
1649         while(number_blocks--)
1650         {
1651             status =  fx_media_read(&global_ram_disk,lba,data_pointer);
1652             data_pointer+=512;
1653             lba++;
1654         }
1655     }
1656     return(status);
1657 }
1658 
default_device_media_write(VOID * storage,ULONG lun,UCHAR * data_pointer,ULONG number_blocks,ULONG lba,ULONG * media_status)1659 static UINT    default_device_media_write(VOID *storage, ULONG lun, UCHAR * data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status)
1660 {
1661 
1662 UINT status;
1663 
1664     if(lba == 0)
1665     {
1666         global_ram_disk.fx_media_driver_logical_sector =  0;
1667         global_ram_disk.fx_media_driver_sectors =  1;
1668         global_ram_disk.fx_media_driver_request =  FX_DRIVER_BOOT_WRITE;
1669         global_ram_disk.fx_media_driver_buffer =  data_pointer;
1670         _fx_ram_driver(&global_ram_disk);
1671 
1672         status = global_ram_disk.fx_media_driver_status;
1673 
1674     }
1675     else
1676     {
1677 
1678         while(number_blocks--)
1679         {
1680             status =  fx_media_write(&global_ram_disk,lba,data_pointer);
1681             data_pointer+=512;
1682             lba++;
1683         }
1684         return(status);
1685     }
1686     return(status);
1687 }
1688 
default_device_media_status(VOID * storage,ULONG lun,ULONG media_id,ULONG * media_status)1689 UINT    default_device_media_status(VOID *storage, ULONG lun, ULONG media_id, ULONG *media_status)
1690 {
1691 
1692     /* The ATA drive never fails. This is just for demo only !!!! */
1693     return(UX_SUCCESS);
1694 }
1695