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
109
110
111
112
117
118
119
120
121
124
125
126
127
128
129
130
131
132
133
134
135
141
142
143
144
145
146
147
148
149
150
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
178
179
197
198
199
200
201
202
203
204
205
206
207
210
211
212
213
216
217
218
219
220
221
222
223
224
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
269
270
271
273
274
275
276
277
278
279
280
281
282
286
287
288
289
290
291
292
293
294
295
296
297
300
301
302
303
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
340
341
342
343
344
345
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
...
...
...
#define TX_SOURCE_CODE
#include "tx_api.h"
#include "tx_trace.h"
#include "tx_thread.h"
#include "tx_initialize.h"
...
...
UINT _tx_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)
{
TX_INTERRUPT_SAVE_AREA
TX_THREAD *next_thread;
TX_THREAD *previous_thread;
TX_THREAD *saved_thread_ptr;
UINT saved_threshold = ((UINT) 0);
UCHAR *temp_ptr;
#ifdef TX_ENABLE_STACK_CHECKING
ALIGN_TYPE new_stack_start;
ALIGN_TYPE updated_stack_start;/* ... */
#endif
#ifndef TX_DISABLE_STACK_FILLING
/* ... */
TX_MEMSET(stack_start, ((UCHAR) TX_STACK_FILL), stack_size);/* ... */
#endif
#ifdef TX_ENABLE_STACK_CHECKING
/* ... */
stack_size = ((stack_size/(sizeof(ULONG))) * (sizeof(ULONG))) - (sizeof(ULONG));
#ifdef TX_MISRA_ENABLE
new_stack_start = TX_POINTER_TO_ULONG_CONVERT(stack_start);
#else
new_stack_start = TX_POINTER_TO_ALIGN_TYPE_CONVERT(stack_start);
#endif
updated_stack_start = (((new_stack_start) + ((sizeof(ULONG)) - ((ULONG) 1)) ) & (~((sizeof(ULONG)) - ((ULONG) 1))));
if (new_stack_start != updated_stack_start)
{
stack_size = stack_size - (sizeof(ULONG));
}if (new_stack_start != updated_stack_start) { ... }
#ifdef TX_MISRA_ENABLE
stack_start = TX_ULONG_TO_POINTER_CONVERT(updated_stack_start);
#else
stack_start = TX_ALIGN_TYPE_TO_POINTER_CONVERT(updated_stack_start);
#endif /* ... */
#endif
/* ... */
TX_MEMSET(thread_ptr, 0, (sizeof(TX_THREAD)));
thread_ptr -> tx_thread_name = name_ptr;
thread_ptr -> tx_thread_entry = entry_function;
thread_ptr -> tx_thread_entry_parameter = entry_input;
thread_ptr -> tx_thread_stack_start = stack_start;
thread_ptr -> tx_thread_stack_size = stack_size;
thread_ptr -> tx_thread_priority = priority;
thread_ptr -> tx_thread_user_priority = priority;
thread_ptr -> tx_thread_time_slice = time_slice;
thread_ptr -> tx_thread_new_time_slice = time_slice;
thread_ptr -> tx_thread_inherit_priority = ((UINT) TX_MAX_PRIORITIES);
temp_ptr = TX_VOID_TO_UCHAR_POINTER_CONVERT(stack_start);
temp_ptr = (TX_UCHAR_POINTER_ADD(temp_ptr, (stack_size - ((ULONG) 1))));
thread_ptr -> tx_thread_stack_end = TX_UCHAR_TO_VOID_POINTER_CONVERT(temp_ptr);
#ifndef TX_DISABLE_PREEMPTION_THRESHOLD
thread_ptr -> tx_thread_preempt_threshold = preempt_threshold;
thread_ptr -> tx_thread_user_preempt_threshold = preempt_threshold;/* ... */
#else
if (priority != preempt_threshold)
{
/* ... */
thread_ptr -> tx_thread_preempt_threshold = ((UINT) 0);
thread_ptr -> tx_thread_user_preempt_threshold = ((UINT) 0);
}if (priority != preempt_threshold) { ... }
else
{
thread_ptr -> tx_thread_preempt_threshold = priority;
thread_ptr -> tx_thread_user_preempt_threshold = priority;
}else { ... }
/* ... */#endif
thread_ptr -> tx_thread_state = TX_SUSPENDED;
TX_THREAD_CREATE_TIMEOUT_SETUP(thread_ptr)
TX_THREAD_CREATE_INTERNAL_EXTENSION(thread_ptr)
/* ... */
_tx_thread_stack_build(thread_ptr, _tx_thread_shell_entry);
#ifdef TX_ENABLE_STACK_CHECKING
thread_ptr -> tx_thread_stack_highest_ptr = thread_ptr -> tx_thread_stack_ptr;/* ... */
#endif
TX_DISABLE
thread_ptr -> tx_thread_id = TX_THREAD_ID;
/* ... */
if (_tx_thread_created_count == TX_EMPTY)
{
_tx_thread_created_ptr = thread_ptr;
thread_ptr -> tx_thread_created_next = thread_ptr;
thread_ptr -> tx_thread_created_previous = thread_ptr;
}if (_tx_thread_created_count == TX_EMPTY) { ... }
else
{
next_thread = _tx_thread_created_ptr;
previous_thread = next_thread -> tx_thread_created_previous;
next_thread -> tx_thread_created_previous = thread_ptr;
previous_thread -> tx_thread_created_next = thread_ptr;
thread_ptr -> tx_thread_created_previous = previous_thread;
thread_ptr -> tx_thread_created_next = next_thread;
}else { ... }
_tx_thread_created_count++;
TX_TRACE_OBJECT_REGISTER(TX_TRACE_OBJECT_TYPE_THREAD, thread_ptr, name_ptr, TX_POINTER_TO_ULONG_CONVERT(stack_start), stack_size)
TX_TRACE_IN_LINE_INSERT(TX_TRACE_THREAD_CREATE, thread_ptr, priority, TX_POINTER_TO_ULONG_CONVERT(stack_start), stack_size, TX_TRACE_THREAD_EVENTS)
TX_EL_THREAD_REGISTER(thread_ptr)
TX_EL_THREAD_CREATE_INSERT
#ifndef TX_NOT_INTERRUPTABLE
_tx_thread_preempt_disable++;/* ... */
#endif
/* ... */
if (auto_start == TX_AUTO_START)
{
if (TX_THREAD_GET_SYSTEM_STATE() >= TX_INITIALIZE_IN_PROGRESS)
{
/* ... */
saved_thread_ptr = _tx_thread_execute_ptr;
if (saved_thread_ptr != TX_NULL)
{
saved_threshold = saved_thread_ptr -> tx_thread_preempt_threshold;
/* ... */
saved_thread_ptr -> tx_thread_preempt_threshold = saved_thread_ptr -> tx_thread_priority;
}if (saved_thread_ptr != TX_NULL) { ... }
}if (TX_THREAD_GET_SYSTEM_STATE() >= TX_INITIALIZE_IN_PROGRESS) { ... }
else
{
saved_thread_ptr = TX_NULL;
}else { ... }
#ifdef TX_NOT_INTERRUPTABLE
TX_THREAD_CREATE_EXTENSION(thread_ptr)
_tx_thread_system_ni_resume(thread_ptr);
TX_RESTORE/* ... */
#else
TX_RESTORE
TX_THREAD_CREATE_EXTENSION(thread_ptr)
_tx_thread_system_resume(thread_ptr);/* ... */
#endif
if (saved_thread_ptr != TX_NULL)
{
/* ... */
saved_thread_ptr -> tx_thread_preempt_threshold = saved_threshold;
}if (saved_thread_ptr != TX_NULL) { ... }
}if (auto_start == TX_AUTO_START) { ... }
else
{
#ifdef TX_NOT_INTERRUPTABLE
TX_THREAD_CREATE_EXTENSION(thread_ptr)
TX_RESTORE/* ... */
#else
TX_RESTORE
TX_THREAD_CREATE_EXTENSION(thread_ptr)
TX_DISABLE
_tx_thread_preempt_disable--;
TX_RESTORE
_tx_thread_system_preempt_check();/* ... */
#endif
}else { ... }
return(TX_SUCCESS);
}{ ... }