1 /* This test is designed to test the ux_utility_timer_.... */
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 /* Define USBX test constants. */
10
11 #define UX_TEST_STACK_SIZE 4096
12 #define UX_TEST_MEMORY_SIZE (64*1024)
13
14 /* Define the counters used in the test application... */
15
16 static ULONG thread_0_counter;
17 static ULONG thread_1_counter;
18 static ULONG error_counter;
19
20 static UCHAR error_callback_ignore = UX_FALSE;
21 static ULONG error_callback_counter;
22
23 /* Define USBX test global variables. */
24
25 static TX_THREAD ux_test_thread_simulation_0;
26 static TX_THREAD ux_test_thread_simulation_1;
27 static void ux_test_thread_simulation_0_entry(ULONG);
28 static void ux_test_thread_simulation_1_entry(ULONG);
29
30
31 /* Define the ISR dispatch. */
32
33 extern VOID (*test_isr_dispatch)(void);
34
35
36 /* Prototype for test control return. */
37
38 void test_control_return(UINT status);
39
40 /* Simulator actions. */
41
42
43 /* Define the ISR dispatch routine. */
44
test_isr(void)45 static void test_isr(void)
46 {
47
48 /* For further expansion of interrupt-level testing. */
49 }
50
51
error_callback(UINT system_level,UINT system_context,UINT error_code)52 static VOID error_callback(UINT system_level, UINT system_context, UINT error_code)
53 {
54
55 error_callback_counter ++;
56
57 if (!error_callback_ignore)
58 {
59 {
60 /* Failed test. */
61 printf("Error #%d, system_level: %d, system_context: %d, error_code: 0x%x\n", __LINE__, system_level, system_context, error_code);
62 // test_control_return(1);
63 }
64 }
65 }
66
67 /* Define what the initial system looks like. */
68
69 #ifdef CTEST
test_application_define(void * first_unused_memory)70 void test_application_define(void *first_unused_memory)
71 #else
72 void usbx_test_USBX_6_application_define(void *first_unused_memory)
73 #endif
74 {
75
76 UINT status;
77 CHAR *stack_pointer;
78 CHAR *memory_pointer;
79 CHAR *rpool_start;
80 CHAR *cpool_start;
81 ULONG rpool_free[2];
82 ULONG cpool_free[2];
83 VOID *ptr;
84 UINT n, i;
85 const CHAR flags[] = {
86 UX_REGULAR_MEMORY, UX_CACHE_SAFE_MEMORY, 0xFF
87 };
88 const CHAR expect_error[] = {
89 UX_FALSE, UX_FALSE, UX_TRUE
90 };
91
92 /* Inform user. */
93 printf("Running USBX-6 _ux_version_id Test.................................. ");
94
95 /* Initialize the free memory pointer. */
96 stack_pointer = (CHAR *) first_unused_memory;
97 memory_pointer = stack_pointer + (UX_TEST_STACK_SIZE * 2);
98
99 rpool_start = memory_pointer;
100 cpool_start = memory_pointer + UX_TEST_MEMORY_SIZE;
101
102 /* Initialize USBX Memory. */
103 status = ux_system_initialize(rpool_start, UX_TEST_MEMORY_SIZE, cpool_start, UX_TEST_MEMORY_SIZE);
104
105 /* Check for error. */
106 if (status != UX_SUCCESS)
107 {
108
109 printf("ERROR #%d\n", __LINE__);
110 test_control_return(1);
111 }
112
113 /* Register the error callback. */
114 _ux_utility_error_callback_register(error_callback);
115
116 /* Create the simulation thread. */
117 status = tx_thread_create(&ux_test_thread_simulation_0, "test simulation", ux_test_thread_simulation_0_entry, 0,
118 stack_pointer, UX_TEST_STACK_SIZE,
119 20, 20, 1, TX_AUTO_START);
120
121 /* Check for error. */
122 if (status != TX_SUCCESS)
123 {
124
125 printf("ERROR #%d\n", __LINE__);
126 test_control_return(1);
127 }
128 }
129
ux_test_thread_simulation_0_entry(ULONG arg)130 static void ux_test_thread_simulation_0_entry(ULONG arg)
131 {
132
133 if (_ux_version_id == UX_NULL)
134 {
135 printf("ERROR #%d: _ux_version_id is NULL\n", __LINE__);
136 error_counter ++;
137 }
138 else
139 {
140
141 /* Use _ux_version_id so if there is compile problem we know it. */
142 puts("\n_ux_version_id is: ");
143 puts(_ux_version_id);
144 }
145
146 /* Sleep for a tick to make sure everything is complete. */
147 tx_thread_sleep(1);
148
149 /* Check for errors from other threads. */
150 if (error_counter)
151 {
152
153 /* Test error. */
154 printf("ERROR #%d: total %ld errors\n", __LINE__, error_counter);
155 test_control_return(1);
156 }
157 else
158 {
159
160 /* Successful test. */
161 printf("SUCCESS!\n");
162 test_control_return(0);
163 }
164 }