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_api_tracex_id_test_application_define(void *first_unused_memory)
97 #endif
98 {
99 
100 UINT status;
101 
102 
103     /* Inform user.  */
104     printf("Running usbx_ux_api_tracex_id 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 =  tx_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 UINT      tracex_id = 0;
147 #if defined(TX_ENABLE_EVENT_TRACE) && defined(UX_TRACE_INSERT_MACROS)
148     /* The fix is to make sure below trace ID are different, if it is not fixed, the compile will fail*/
149     switch(tracex_id){
150         case UX_TRACE_DEVICE_STACK_CONFIGURATION_GET:
151         case UX_TRACE_DEVICE_STACK_CONFIGURATION_SET:
152         case UX_TRACE_DEVICE_CLASS_DPUMP_WRITE:
153         case UX_TRACE_DEVICE_CLASS_DPUMP_CHANGE:
154         default:
155             break;
156     }
157 #endif
158     /* Successful test.  */
159     printf("SUCCESS!\n");
160     test_control_return(0);
161 }
162 
163