1 /* This test is designed to test the ux_utility_thread_identify. */
2
3 #include <stdio.h>
4 #include "tx_api.h"
5 #include "tx_thread.h"
6 #include "ux_api.h"
7 #include "ux_system.h"
8 #include "ux_utility.h"
9
10 #include "ux_host_stack.h"
11 #include "ux_device_stack.h"
12
13 #include "ux_device_class_cdc_acm.h"
14 #include "ux_host_class_cdc_acm.h"
15
16 #include "ux_host_class_dpump.h"
17 #include "ux_device_class_dpump.h"
18
19 #include "ux_host_class_hid.h"
20 #include "ux_device_class_hid.h"
21
22 #include "ux_host_class_storage.h"
23 #include "ux_device_class_storage.h"
24
25 /* Define USBX test constants. */
26
27 #define UX_TEST_STACK_SIZE 4096
28 #define UX_TEST_BUFFER_SIZE 2048
29 #define UX_TEST_RUN 1
30 #define UX_TEST_MEMORY_SIZE (64*1024)
31
32 /* Define the counters used in the test application... */
33
34 static CHAR *stack_pointer;
35 static CHAR *memory_pointer;
36
37 static ULONG thread_0_counter;
38 static ULONG thread_1_counter;
39 static ULONG error_counter;
40
41 static UCHAR error_callback_ignore = UX_FALSE;
42 static ULONG error_callback_counter;
43
44 static UCHAR buffer[UX_TEST_BUFFER_SIZE];
45
46 /* Define USBX test global variables. */
47
48 /* Define prototypes for external Host Controller's (HCDs), classes and clients. */
49
50 static TX_THREAD ux_test_thread_simulation_0;
51 static TX_THREAD ux_test_thread_simulation_1;
52 static void ux_test_thread_simulation_0_entry(ULONG);
53 static void ux_test_thread_simulation_1_entry(ULONG);
54
55
56 /* Define the ISR dispatch. */
57
58 extern VOID (*test_isr_dispatch)(void);
59
60
61 /* Prototype for test control return. */
62
63 void test_control_return(UINT status);
64
65 /* Simulator actions. */
66
67 /* Define the ISR dispatch routine. */
68
test_isr(void)69 static void test_isr(void)
70 {
71
72 /* For further expansion of interrupt-level testing. */
73 }
74
75
error_callback(UINT system_level,UINT system_context,UINT error_code)76 static VOID error_callback(UINT system_level, UINT system_context, UINT error_code)
77 {
78
79 error_callback_counter ++;
80
81 if (!error_callback_ignore)
82 {
83 {
84 /* Failed test. */
85 printf("Error #%d, system_level: %d, system_context: %d, error_code: 0x%x\n", __LINE__, system_level, system_context, error_code);
86 // test_control_return(1);
87 }
88 }
89 }
90
91 /* Define what the initial system looks like. */
92
93 #ifdef CTEST
test_application_define(void * first_unused_memory)94 void test_application_define(void *first_unused_memory)
95 #else
96 void usbx_ux_utility_thread_identify_test_application_define(void *first_unused_memory)
97 #endif
98 {
99
100 UINT status;
101
102
103 /* Inform user. */
104 printf("Running ux_utility_thread_identify Test............................. ");
105
106 /* Initialize the free memory pointer. */
107 stack_pointer = (CHAR *) first_unused_memory;
108 memory_pointer = stack_pointer + (UX_TEST_STACK_SIZE * 2);
109
110 /* Initialize USBX Memory. */
111 status = ux_system_initialize(memory_pointer, UX_TEST_MEMORY_SIZE, UX_NULL, 0);
112
113 /* Check for error. */
114 if (status != UX_SUCCESS)
115 {
116
117 printf("ERROR #%d\n", __LINE__);
118 test_control_return(1);
119 }
120
121 /* Register the error callback. */
122 _ux_utility_error_callback_register(error_callback);
123
124 /* Create the simulation thread. */
125 status = ux_utility_thread_create(&ux_test_thread_simulation_0, "test simulation 0", ux_test_thread_simulation_0_entry, 0,
126 stack_pointer, UX_TEST_STACK_SIZE,
127 20, 20, 1, TX_AUTO_START);
128
129 /* Check for error. */
130 if (status != TX_SUCCESS)
131 {
132
133 printf("ERROR #%d: thread create fail 0x%x\n", __LINE__, status);
134 error_counter ++;
135 }
136
137 /* Reset threads. */
138 _ux_utility_memory_set(&ux_test_thread_simulation_1, 0, sizeof(ux_test_thread_simulation_1));
139 }
140
141
ux_test_thread_simulation_0_entry(ULONG arg)142 static void ux_test_thread_simulation_0_entry(ULONG arg)
143 {
144
145 TX_THREAD *this_thread;
146
147
148 /* Create the simulation thread. */
149 this_thread = ux_utility_thread_identify();
150
151 /* Check for error. */
152 if (this_thread != &ux_test_thread_simulation_0)
153 {
154
155 printf("ERROR #%d: thread different %p <> %p\n", __LINE__, this_thread, &ux_test_thread_simulation_0);
156 error_counter ++;
157 }
158
159 /* Simulate ISR enter */
160 _tx_thread_system_state ++;
161
162 this_thread = ux_utility_thread_identify();
163
164 /* Check for error. */
165 if (this_thread != UX_NULL)
166 {
167
168 printf("ERROR #%d: thread different %p <> NULL\n", __LINE__, this_thread);
169 error_counter ++;
170 }
171
172 /* Simulate ISR exit. */
173 _tx_thread_system_state --;
174
175 /* Check for errors. */
176 if (error_counter)
177 {
178
179 /* Test error. */
180 printf("ERROR #%d: total %ld errors\n", __LINE__, error_counter);
181 test_control_return(1);
182 }
183 else
184 {
185
186 /* Successful test. */
187 printf("SUCCESS!\n");
188 test_control_return(0);
189 }
190 }
191
ux_test_thread_simulation_1_entry(ULONG arg)192 static void ux_test_thread_simulation_1_entry(ULONG arg)
193 {
194 while(1)
195 {
196 _ux_utility_delay_ms(100);
197 }
198 }
199