1
10
13
14
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
120
121
122
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
156
157
158
164
165
166
167
168
169
170
171
172
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
220
221
222
228
229
230
236
237
238
244
245
246
252
253
254
260
261
262
268
269
270
271
272
284
285
286
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
...
...
...
#define TX_SOURCE_CODE
#include "tx_api.h"
#include "tx_initialize.h"
#include "tx_thread.h"
#include "tx_timer.h"
...
...
UINT _txe_thread_create(TX_THREAD *thread_ptr, CHAR *name_ptr,
VOID (*entry_function)(ULONG id), ULONG entry_input,
VOID *stack_start, ULONG stack_size,
UINT priority, UINT preempt_threshold,
ULONG time_slice, UINT auto_start, UINT thread_control_block_size)
{
TX_INTERRUPT_SAVE_AREA
UINT status;
UINT break_flag;
ULONG i;
TX_THREAD *next_thread;
VOID *stack_end;
UCHAR *work_ptr;
#ifndef TX_TIMER_PROCESS_IN_ISR
TX_THREAD *current_thread;
#endif
status = TX_SUCCESS;
if (thread_ptr == TX_NULL)
{
status = TX_THREAD_ERROR;
}if (thread_ptr == TX_NULL) { ... }
else if (thread_control_block_size != (sizeof(TX_THREAD)))
{
status = TX_THREAD_ERROR;
}else if (thread_control_block_size != (sizeof(TX_THREAD))) { ... }
else
{
TX_DISABLE
_tx_thread_preempt_disable++;
TX_RESTORE
break_flag = TX_FALSE;
next_thread = _tx_thread_created_ptr;
work_ptr = TX_VOID_TO_UCHAR_POINTER_CONVERT(stack_start);
work_ptr = TX_UCHAR_POINTER_ADD(work_ptr, (stack_size - ((ULONG) 1)));
stack_end = TX_UCHAR_TO_VOID_POINTER_CONVERT(work_ptr);
for (i = ((ULONG) 0); i < _tx_thread_created_count; i++)
{
if (thread_ptr == next_thread)
{
break_flag = TX_TRUE;
}if (thread_ptr == next_thread) { ... }
if (break_flag == TX_TRUE)
{
break;
}if (break_flag == TX_TRUE) { ... }
if (stack_start >= next_thread -> tx_thread_stack_start)
{
if (stack_start < next_thread -> tx_thread_stack_end)
{
/* ... */
stack_start = TX_NULL;
break_flag = TX_TRUE;
}if (stack_start < next_thread -> tx_thread_stack_end) { ... }
}if (stack_start >= next_thread -> tx_thread_stack_start) { ... }
if (stack_end >= next_thread -> tx_thread_stack_start)
{
if (stack_end < next_thread -> tx_thread_stack_end)
{
/* ... */
stack_start = TX_NULL;
break_flag = TX_TRUE;
}if (stack_end < next_thread -> tx_thread_stack_end) { ... }
}if (stack_end >= next_thread -> tx_thread_stack_start) { ... }
next_thread = next_thread -> tx_thread_created_next;
}for (i = ((ULONG) 0); i < _tx_thread_created_count; i++) { ... }
TX_DISABLE
_tx_thread_preempt_disable--;
TX_RESTORE
_tx_thread_system_preempt_check();
if (thread_ptr == next_thread)
{
status = TX_THREAD_ERROR;
}if (thread_ptr == next_thread) { ... }
else if (stack_start == TX_NULL)
{
status = TX_PTR_ERROR;
}else if (stack_start == TX_NULL) { ... }
else if (entry_function == TX_NULL)
{
status = TX_PTR_ERROR;
}else if (entry_function == TX_NULL) { ... }
else if (stack_size < ((ULONG) TX_MINIMUM_STACK))
{
status = TX_SIZE_ERROR;
}else if (stack_size < ((ULONG) TX_MINIMUM_STACK)) { ... }
else if (priority >= ((UINT) TX_MAX_PRIORITIES))
{
status = TX_PRIORITY_ERROR;
}else if (priority >= ((UINT) TX_MAX_PRIORITIES)) { ... }
else if (preempt_threshold > priority)
{
status = TX_THRESH_ERROR;
}else if (preempt_threshold > priority) { ... }
else if (auto_start > TX_AUTO_START)
{
status = TX_START_ERROR;
}else if (auto_start > TX_AUTO_START) { ... }
else
{
#ifndef TX_TIMER_PROCESS_IN_ISR
TX_THREAD_GET_CURRENT(current_thread)
if (current_thread == &_tx_timer_thread)
{
status = TX_CALLER_ERROR;
}if (current_thread == &_tx_timer_thread) { ... }
/* ... */#endif
if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0))
{
if (TX_THREAD_GET_SYSTEM_STATE() < TX_INITIALIZE_IN_PROGRESS)
{
status = TX_CALLER_ERROR;
}if (TX_THREAD_GET_SYSTEM_STATE() < TX_INITIALIZE_IN_PROGRESS) { ... }
}if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0)) { ... }
}else { ... }
}else { ... }
if (status == TX_SUCCESS)
{
status = _tx_thread_create(thread_ptr, name_ptr, entry_function, entry_input,
stack_start, stack_size, priority, preempt_threshold,
time_slice, auto_start);
}if (status == TX_SUCCESS) { ... }
return(status);
}{ ... }