1 /* This test is designed to test the ux_device_stack_initialize */
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 "ux_host_stack.h"
10 #include "ux_device_stack.h"
11
12 #include "ux_device_class_cdc_acm.h"
13 #include "ux_host_class_cdc_acm.h"
14
15 #include "ux_host_class_dpump.h"
16 #include "ux_device_class_dpump.h"
17
18 #include "ux_host_class_hid.h"
19 #include "ux_device_class_hid.h"
20
21 #include "ux_host_class_storage.h"
22 #include "ux_device_class_storage.h"
23
24 #include "ux_test_dcd_sim_slave.h"
25 #include "ux_test_hcd_sim_host.h"
26 #include "ux_test_utility_sim.h"
27
28
29 /* Define USBX test constants. */
30
31 #define UX_TEST_STACK_SIZE 4096
32 #define UX_TEST_BUFFER_SIZE 2048
33 #define UX_TEST_RUN 1
34 #define UX_TEST_MEMORY_SIZE (64*1024)
35
36 /* HID mouse related descriptors */
37
38 static UCHAR hid_mouse_report[] = {
39
40 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
41 0x09, 0x02, // USAGE (Mouse)
42 0xa1, 0x01, // COLLECTION (Application)
43 0x09, 0x01, // USAGE (Pointer)
44 0xa1, 0x00, // COLLECTION (Physical)
45 0x05, 0x09, // USAGE_PAGE (Button)
46 0x19, 0x01, // USAGE_MINIMUM (Button 1)
47 0x29, 0x03, // USAGE_MAXIMUM (Button 3)
48 0x15, 0x00, // LOGICAL_MINIMUM (0)
49 0x25, 0x01, // LOGICAL_MAXIMUM (1)
50 0x95, 0x03, // REPORT_COUNT (3)
51 0x75, 0x01, // REPORT_SIZE (1)
52 0x81, 0x02, // INPUT (Data,Var,Abs)
53 0x95, 0x01, // REPORT_COUNT (1)
54 0x75, 0x05, // REPORT_SIZE (5)
55 0x81, 0x03, // INPUT (Cnst,Var,Abs)
56 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
57 0x09, 0x30, // USAGE (X)
58 0x09, 0x31, // USAGE (Y)
59 0x15, 0x81, // LOGICAL_MINIMUM (-127)
60 0x25, 0x7f, // LOGICAL_MAXIMUM (127)
61 0x75, 0x08, // REPORT_SIZE (8)
62 0x95, 0x02, // REPORT_COUNT (2)
63 0x81, 0x06, // INPUT (Data,Var,Rel)
64 0x09, 0x38, // USAGE (Mouse Wheel)
65 0x15, 0x81, // LOGICAL_MINIMUM (-127)
66 0x25, 0x7f, // LOGICAL_MAXIMUM (127)
67 0x75, 0x08, // REPORT_SIZE (8)
68 0x95, 0x01, // REPORT_COUNT (1)
69 0x81, 0x06, // INPUT (Data,Var,Rel)
70 0xc0, // END_COLLECTION
71 0xc0 // END_COLLECTION
72 };
73 #define HID_MOUSE_REPORT_LENGTH (sizeof(hid_mouse_report)/sizeof(hid_mouse_report[0]))
74
75 #define LSB(x) (x & 0x00ff)
76 #define MSB(x) ((x & 0xff00) >> 8)
77
78 /* Configuration descriptor 9 bytes */
79 #define CFG_DESC(wTotalLength, bNumInterfaces, bConfigurationValue)\
80 /* Configuration 1 descriptor 9 bytes */\
81 0x09, 0x02, LSB(wTotalLength), MSB(wTotalLength),\
82 (bNumInterfaces), (bConfigurationValue), 0x00,\
83 0x20, 0x00,
84 #define CFG_DESC_LEN 9
85
86 /* DPUMP interface descriptors 9+7+7=23 bytes. */
87 #define DPUMP_IFC_DESC_ALL(ifc, bulk_in_epa, bulk_out_epa) \
88 /* Interface descriptor */\
89 0x09, 0x04, (ifc), 0x00, 0x02, 0x99, 0x99, 0x99, 0x00,\
90 /* Endpoint descriptor (Bulk Out) */\
91 0x07, 0x05, (bulk_out_epa), 0x02, 0x40, 0x00, 0x00,\
92 /* Endpoint descriptor (Bulk In) */\
93 0x07, 0x05, (bulk_in_epa), 0x02, 0x40, 0x00, 0x00,
94 #define DPUMP_IFC_DESC_ALL_LEN 23
95
96 /* HID Mouse interface descriptors 9+9=18 bytes */
97 #define HID_MOUSE_IFC0_DESC_ALL(ifc) \
98 /* Interface descriptor */\
99 0x09, 0x04, (ifc), 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,\
100 /* HID descriptor */\
101 0x09, 0x21, 0x10, 0x01, 0x21, 0x01, 0x22, LSB(HID_MOUSE_REPORT_LENGTH),\
102 MSB(HID_MOUSE_REPORT_LENGTH),
103 #define HID_MOUSE_IFC0_DESC_ALL_LEN 18
104
105 /* HID Mouse interface descriptors 9+9+7=25 bytes */
106 #define HID_MOUSE_IFC1_DESC_ALL(ifc, interrupt_epa) \
107 /* Interface descriptor */\
108 0x09, 0x04, (ifc), 0x01, 0x01, 0x03, 0x00, 0x00, 0x00,\
109 /* HID descriptor */\
110 0x09, 0x21, 0x10, 0x01, 0x21, 0x01, 0x22, LSB(HID_MOUSE_REPORT_LENGTH),\
111 MSB(HID_MOUSE_REPORT_LENGTH),\
112 /* Endpoint descriptor (Interrupt) */\
113 0x07, 0x05, (interrupt_epa), 0x03, 0x08, 0x00, 0x08,
114 #define HID_MOUSE_IFC1_DESC_ALL_LEN 25
115
116 static UCHAR device_framework_full_speed[] = {
117
118 /* Device descriptor 18 bytes */
119 0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08,
120 0xec, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
121 0x00, 0x01,
122
123 /* Configuration descriptor 9 bytes */
124 CFG_DESC(CFG_DESC_LEN + DPUMP_IFC_DESC_ALL_LEN + HID_MOUSE_IFC0_DESC_ALL_LEN + HID_MOUSE_IFC1_DESC_ALL_LEN, 2, 1)
125 /* DPUMP 9+9+7 =25 */
126 DPUMP_IFC_DESC_ALL(0, 0x81, 0x02)
127 /* HID 9+9 + 9+9+7=43 */
128 HID_MOUSE_IFC0_DESC_ALL(0x11)
129 HID_MOUSE_IFC1_DESC_ALL(0x11, 0x83)
130 };
131 #define DEVICE_FRAMEWORK_LENGTH_FULL_SPEED sizeof(device_framework_full_speed)
132
133 static UCHAR device_framework_high_speed[] = {
134
135 /* Device descriptor */
136 0x12, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40,
137 0x0a, 0x07, 0x25, 0x40, 0x01, 0x00, 0x01, 0x02,
138 0x03, 0x01,
139
140 /* Device qualifier descriptor */
141 0x0a, 0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40,
142 0x01, 0x00,
143
144 /* Configuration descriptor */
145 CFG_DESC(CFG_DESC_LEN + DPUMP_IFC_DESC_ALL_LEN + HID_MOUSE_IFC0_DESC_ALL_LEN + HID_MOUSE_IFC1_DESC_ALL_LEN, 2, 1)
146 /* DPUMP */
147 DPUMP_IFC_DESC_ALL(0, 0x81, 0x02)
148 /* HID */
149 HID_MOUSE_IFC0_DESC_ALL(0x11)
150 HID_MOUSE_IFC1_DESC_ALL(0x11, 0x83)
151 };
152 #define DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED sizeof(device_framework_high_speed)
153
154 /* String Device Framework :
155 Byte 0 and 1 : Word containing the language ID : 0x0904 for US
156 Byte 2 : Byte containing the index of the descriptor
157 Byte 3 : Byte containing the length of the descriptor string
158 */
159
160 static UCHAR string_framework[] = {
161
162 /* Manufacturer string descriptor : Index 1 */
163 0x09, 0x04, 0x01, 0x0c,
164 0x45, 0x78, 0x70, 0x72,0x65, 0x73, 0x20, 0x4c,
165 0x6f, 0x67, 0x69, 0x63,
166
167 /* Product string descriptor : Index 2 */
168 0x09, 0x04, 0x02, 0x0c,
169 0x44, 0x61, 0x74, 0x61, 0x50, 0x75, 0x6d, 0x70,
170 0x44, 0x65, 0x6d, 0x6f,
171
172 /* Serial Number string descriptor : Index 3 */
173 0x09, 0x04, 0x03, 0x04,
174 0x30, 0x30, 0x30, 0x31
175 };
176 #define STRING_FRAMEWORK_LENGTH sizeof(string_framework)
177
178 /* Multiple languages are supported on the device, to add
179 a language besides English, the unicode language code must
180 be appended to the language_id_framework array and the length
181 adjusted accordingly. */
182 static UCHAR language_id_framework[] = {
183
184 /* English. */
185 0x09, 0x04
186 };
187 #define LANGUAGE_ID_FRAMEWORK_LENGTH sizeof(language_id_framework)
188
189 /* Simulation actions. */
190
191 static UX_TEST_SIM_ENTRY_ACTION dcd_endpoint_create_fail[] = {
192 /* function, request to match,
193 port action, port status,
194 request action, request EP, request data, request actual length, request status,
195 status, additional callback,
196 no_return */
197 { UX_DCD_CREATE_ENDPOINT, NULL,
198 UX_FALSE, 0,
199 0 , 0, UX_NULL, 0, 0,
200 UX_ERROR , UX_NULL},
201 { 0 }
202 };
203
204 /* Prototype for test control return. */
205
206 void test_control_return(UINT status);
207
208
209 /* Define what the initial system looks like. */
210
211 #ifdef CTEST
test_application_define(void * first_unused_memory)212 void test_application_define(void *first_unused_memory)
213 #else
214 void usbx_ux_device_stack_initialize_test_application_define(void *first_unused_memory)
215 #endif
216 {
217
218 UINT status;
219 CHAR *stack_pointer;
220 CHAR *memory_pointer;
221 UX_SLAVE_CLASS_DPUMP_PARAMETER parameter;
222 UX_SLAVE_CLASS_HID_PARAMETER hid_parameter;
223
224
225 /* Inform user. */
226 printf("Running ux_device_stack_initialize Test.................. ");
227
228 /* Initialize the free memory pointer. */
229 stack_pointer = (CHAR *) first_unused_memory;
230 memory_pointer = stack_pointer + (UX_TEST_STACK_SIZE * 2);
231
232 /* Initialize USBX Memory. */
233 status = ux_system_initialize(memory_pointer, UX_TEST_MEMORY_SIZE, UX_NULL, 0);
234
235 /* Check for error. */
236 if (status != UX_SUCCESS)
237 {
238
239 printf("ERROR #%d\n", __LINE__);
240 test_control_return(1);
241 }
242
243 #if !defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE) && (UX_MAX_SLAVE_INTERFACE <= 16)
244 /* The code below is required for installing the device portion of USBX */
245 status = ux_device_stack_initialize(device_framework_high_speed, DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED,
246 device_framework_full_speed, DEVICE_FRAMEWORK_LENGTH_FULL_SPEED,
247 string_framework, STRING_FRAMEWORK_LENGTH,
248 language_id_framework, LANGUAGE_ID_FRAMEWORK_LENGTH, UX_NULL);
249
250 /* Check for error. */
251 if (status == UX_MEMORY_INSUFFICIENT) {
252 /* Successful test. */
253 printf("SUCCESS!\n");
254 test_control_return(0);
255 } else {
256 printf("ERROR #%d\n", __LINE__);
257 test_control_return(1);
258 }
259 #else
260 /* Successful test. */
261 printf("SUCCESS!\n");
262 test_control_return(0);
263 #endif
264 }
265