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
9 #include "fx_api.h"
10
11 #include "ux_device_class_storage.h"
12 #include "ux_device_stack.h"
13 #include "ux_host_class_storage.h"
14
15 #include "usbx_test_common.h"
16
17 /* Define constants. */
18 #define UX_DEMO_STACK_SIZE 2048
19 #define UX_DEMO_BUFFER_SIZE 2048
20 #define UX_DEMO_RECEPTION_BUFFER_SIZE 512
21 #define UX_DEMO_FILE_BUFFER_SIZE 512
22 #define UX_DEMO_RECEPTION_BLOCK_SIZE 64
23 #define UX_DEMO_MEMORY_SIZE (256 * 1024)
24 #define UX_DEMO_FILE_SIZE (128 * 1024)
25 #define UX_RAM_DISK_SIZE (200 * 1024)
26 #define UX_RAM_DISK_LAST_LBA ((UX_RAM_DISK_SIZE / 512) -1)
27
28 /* Define local/extern function prototypes. */
29 static void demo_thread_entry(ULONG);
30 static TX_THREAD tx_demo_thread_host_simulation;
31 static TX_THREAD tx_demo_thread_slave_simulation;
32 static void tx_demo_thread_host_simulation_entry(ULONG);
33
34
35 VOID _fx_ram_driver(FX_MEDIA *media_ptr);
36 static UINT demo_device_state_change(ULONG event);
37 static void demo_thread_entry(ULONG);
38 static UINT default_device_media_read(VOID *storage, ULONG lun, UCHAR * data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status);
39 static UINT default_device_media_write(VOID *storage, ULONG lun, UCHAR * data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status);
40 static UINT default_device_media_status(VOID *storage, ULONG lun, ULONG media_id, ULONG *media_status);
41
42
43 /* Define global data structures. */
44 static UCHAR usbx_memory[UX_DEMO_MEMORY_SIZE + (UX_DEMO_STACK_SIZE * 2)];
45 static ULONG error_counter;
46 static TX_THREAD demo_thread;
47 static UX_HOST_CLASS_STORAGE *global_storage;
48 static UX_HOST_CLASS_STORAGE_MEDIA *global_storage_media;
49 static FX_MEDIA *global_media;
50 static UINT status;
51 static UINT transfer_completed;
52 static ULONG requested_length;
53 static FX_FILE my_file;
54 static TX_SEMAPHORE demo_semaphore;
55 static CHAR file_name[64];
56 static UCHAR global_buffer[UX_DEMO_FILE_BUFFER_SIZE];
57 static UCHAR global_ram_disk_working_buffer[512];
58 static FX_MEDIA global_ram_disk;
59 static CHAR global_ram_disk_memory[UX_RAM_DISK_SIZE];
60 static UX_SLAVE_CLASS_STORAGE_PARAMETER global_storage_parameter;
61 static TX_SEMAPHORE storage_instance_live_semaphore;
62
63
64
65 /* Prototype for test control return. */
66
67 void test_control_return(UINT status);
68
69 /* Prototype for _ux_hcd_sim_host_entry */
70 UINT _ux_hcd_sim_host_entry(UX_HCD *, UINT, VOID *);
71
host_storage_instance_get(void)72 static UINT host_storage_instance_get(void)
73 {
74
75 UINT status;
76 UX_HOST_CLASS *host_class;
77
78
79 /* Find the main storage container */
80 status = ux_host_stack_class_get(_ux_system_host_class_storage_name, &host_class);
81 if (status != UX_SUCCESS)
82 return(status);
83
84 status = ux_utility_semaphore_get(&storage_instance_live_semaphore, 5000);
85 if (status != UX_SUCCESS)
86 {
87
88 printf("Error on line %d, error code: %d\n", __LINE__, status);
89 test_control_return(1);
90 }
91
92 status = ux_host_stack_class_instance_get(host_class, 0, (void **) &global_storage);
93 if (status != UX_SUCCESS)
94 {
95
96 printf("Error on line %d, error code: %d\n", __LINE__, status);
97 test_control_return(1);
98 }
99
100 if (global_storage -> ux_host_class_storage_state != UX_HOST_CLASS_INSTANCE_LIVE)
101 {
102
103 printf("Error on line %d, error code: %d\n", __LINE__, status);
104 test_control_return(1);
105 }
106
107 if (host_class -> ux_host_class_media == UX_NULL)
108 {
109
110 printf("Error on line %d, error code: %d\n", __LINE__, status);
111 test_control_return(1);
112 }
113
114 /* Setup media pointer. */
115 global_storage_media = (UX_HOST_CLASS_STORAGE_MEDIA *) host_class -> ux_host_class_media;
116 global_media = &global_storage_media -> ux_host_class_storage_media;
117
118 if (global_media == UX_NULL)
119 {
120
121 printf("Error on line %d, error code: %d\n", __LINE__, status);
122 test_control_return(1);
123 }
124
125 return(UX_SUCCESS);
126 }
127