1 /* This test is designed to test the ux_host_stack_new_device_get. */
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_host_class_dpump.h"
9 #include "ux_device_class_dpump.h"
10
11
12 /* Define USBX test constants. */
13
14 #define UX_TEST_STACK_SIZE 4096
15 #define UX_TEST_BUFFER_SIZE 2048
16 #define UX_TEST_RUN 1
17 #define UX_TEST_MEMORY_SIZE (64*1024)
18
19
20 /* Define the counters used in the test application... */
21
22 static ULONG thread_0_counter;
23 static ULONG thread_1_counter;
24 static ULONG error_counter;
25
26
27 /* Define USBX test global variables. */
28
29 static unsigned char host_out_buffer[UX_HOST_CLASS_DPUMP_PACKET_SIZE];
30 static unsigned char host_in_buffer[UX_HOST_CLASS_DPUMP_PACKET_SIZE];
31 static unsigned char slave_buffer[UX_HOST_CLASS_DPUMP_PACKET_SIZE];
32
33
34 /* Define prototypes for external Host Controller's (HCDs), classes and clients. */
35
36 static VOID ux_test_instance_activate(VOID *dpump_instance);
37 static VOID ux_test_instance_deactivate(VOID *dpump_instance);
38
39
40 static TX_THREAD ux_test_thread_host_simulation;
41 static TX_THREAD ux_test_thread_slave_simulation;
42 static void ux_test_thread_host_simulation_entry(ULONG);
43 static void ux_test_thread_slave_simulation_entry(ULONG);
44
45 extern UX_DEVICE *_ux_host_stack_new_device_get(VOID);
46
47 /* Define the ISR dispatch. */
48
49 extern VOID (*test_isr_dispatch)(void);
50
51
52 /* Prototype for test control return. */
53
54 void test_control_return(UINT status);
55
56
57 /* Define the ISR dispatch routine. */
58
test_isr(void)59 static void test_isr(void)
60 {
61
62 /* For further expansion of interrupt-level testing. */
63 }
64
65
66 /* Define what the initial system looks like. */
67
68 #ifdef CTEST
test_application_define(void * first_unused_memory)69 void test_application_define(void *first_unused_memory)
70 #else
71 void usbx_ux_host_stack_new_device_get_test_application_define(void *first_unused_memory)
72 #endif
73 {
74
75 UINT status;
76 CHAR *stack_pointer;
77 CHAR *memory_pointer;
78
79
80 /* Inform user. */
81 printf("Running ux_host_stack_new_device_get Test........................... ");
82
83 /* Initialize the free memory pointer. */
84 stack_pointer = (CHAR *) first_unused_memory;
85 memory_pointer = stack_pointer + (UX_TEST_STACK_SIZE * 2);
86
87 /* Initialize USBX Memory. */
88 status = ux_system_initialize(memory_pointer, UX_TEST_MEMORY_SIZE, UX_NULL, 0);
89
90 /* Check for error. */
91 if (status != UX_SUCCESS)
92 {
93
94 printf("ERROR #1\n");
95 test_control_return(1);
96 }
97
98 /* The code below is required for installing the host portion of USBX. */
99 status = ux_host_stack_initialize(UX_NULL);
100
101 /* Check for error. */
102 if (status != UX_SUCCESS)
103 {
104
105 printf("ERROR #2\n");
106 test_control_return(1);
107 }
108
109 /* Create the main host simulation thread. */
110 status = tx_thread_create(&ux_test_thread_host_simulation, "test host simulation", ux_test_thread_host_simulation_entry, 0,
111 stack_pointer, UX_TEST_STACK_SIZE,
112 20, 20, 1, TX_AUTO_START);
113
114 /* Check for error. */
115 if (status != TX_SUCCESS)
116 {
117
118 printf("ERROR #3\n");
119 test_control_return(1);
120 }
121
122
123 }
124
125
ux_test_thread_host_simulation_entry(ULONG arg)126 static void ux_test_thread_host_simulation_entry(ULONG arg)
127 {
128
129 UX_DEVICE *new_device;
130 UINT i;
131
132
133 /* Test ux_host_stack_new_device_get. */
134 for (i = UX_SYSTEM_HOST_MAX_DEVICES_GET(); i != 0; i--)
135 {
136 new_device = _ux_host_stack_new_device_get();
137 if (new_device == UX_NULL)
138 {
139
140 printf("ERROR #4\n");
141 test_control_return(1);
142 }
143 }
144
145 /* There is no device entry available now. Try to get new device again. */
146 new_device = _ux_host_stack_new_device_get();
147
148 /* Check if UX_NULL is returned. */
149 if (new_device != UX_NULL)
150 {
151
152 printf("ERROR #5\n");
153 test_control_return(1);
154 }
155 else
156 {
157
158 /* Successful test. */
159 printf("SUCCESS!\n");
160 test_control_return(0);
161 }
162
163 /* Sleep for a tick to make sure everything is complete. */
164 tx_thread_sleep(1);
165 }