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