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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
147
148
149
155
156
157
166
167
168
174
175
176
182
183
184
185
186
187
188
189
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
215
216
217
218
219
220
221
222
223
224
225
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
267
269
270
271
274
275
276
277
280
281
282
283
286
287
288
289
292
293
294
295
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
374
375
376
377
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
408
409
410
411
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
442
443
444
445
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
517
518
519
520
521
522
523
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
...
...
...
#define TX_SOURCE_CODE
#include "tx_api.h"
#include "tx_initialize.h"
#include "tx_thread.h"
#include "tx_timer.h"
#include "tx_queue.h"
#include "tx_event_flags.h"
#include "tx_semaphore.h"
#include "tx_mutex.h"
#include "tx_block_pool.h"
#include "tx_byte_pool.h"
#include "txm_module.h"
#include "txm_module_manager_util.h"
12 includes
#ifdef TXM_MODULE_ENABLE_FILEX
extern UINT _txm_module_manager_filex_stop(TXM_MODULE_INSTANCE *module_instance);
#endif
#ifdef TXM_MODULE_ENABLE_NETX
extern UINT _txm_module_manager_netx_stop(TXM_MODULE_INSTANCE *module_instance);
#endif
#ifdef TXM_MODULE_ENABLE_NETXDUO
extern UINT _txm_module_manager_netxduo_stop(TXM_MODULE_INSTANCE *module_instance);
#endif
#ifdef TXM_MODULE_ENABLE_GUIX
extern UINT _txm_module_manager_guix_stop(TXM_MODULE_INSTANCE *module_instance);
#endif
#ifdef TXM_MODULE_ENABLE_USBX
extern UINT _txm_module_manager_usbx_stop(TXM_MODULE_INSTANCE *module_instance);
#endif
...
...
UINT _txm_module_manager_stop(TXM_MODULE_INSTANCE *module_instance)
{
TX_INTERRUPT_SAVE_AREA
TX_THREAD *thread_ptr, *next_thread_ptr;
TX_TIMER *timer_ptr, *next_timer_ptr;
TX_QUEUE *queue_ptr, *next_queue_ptr;
TX_EVENT_FLAGS_GROUP *events_ptr, *next_events_ptr;
TX_SEMAPHORE *semaphore_ptr, *next_semaphore_ptr;
TX_MUTEX *mutex_ptr, *next_mutex_ptr;
TX_BLOCK_POOL *block_pool_ptr, *next_block_pool_ptr;
TX_BYTE_POOL *byte_pool_ptr, *next_byte_pool_ptr;
UCHAR created_by_module;
ULONG i;
TXM_MODULE_ALLOCATED_OBJECT *object_ptr;
TX_THREAD_GET_CURRENT(thread_ptr)
if (thread_ptr == TX_NULL)
{
return(TX_CALLER_ERROR);
}if (thread_ptr == TX_NULL) { ... }
if (TX_THREAD_GET_SYSTEM_STATE() != 0)
{
return(TX_CALLER_ERROR);
}if (TX_THREAD_GET_SYSTEM_STATE() != 0) { ... }
#ifndef TX_TIMER_PROCESS_IN_ISR
if (thread_ptr == &_tx_timer_thread)
{
return(TX_CALLER_ERROR);
}if (thread_ptr == &_tx_timer_thread) { ... }
/* ... */#endif
if (_txm_module_manager_ready != TX_TRUE)
{
return(TX_NOT_AVAILABLE);
}if (_txm_module_manager_ready != TX_TRUE) { ... }
if (module_instance == TX_NULL)
{
return(TX_PTR_ERROR);
}if (module_instance == TX_NULL) { ... }
_tx_mutex_get(&_txm_module_manager_mutex, TX_WAIT_FOREVER);
if (module_instance -> txm_module_instance_id != TXM_MODULE_ID)
{
_tx_mutex_put(&_txm_module_manager_mutex);
return(TX_PTR_ERROR);
}if (module_instance -> txm_module_instance_id != TXM_MODULE_ID) { ... }
if (module_instance -> txm_module_instance_state != TXM_MODULE_STARTED)
{
_tx_mutex_put(&_txm_module_manager_mutex);
return(TX_START_ERROR);
}if (module_instance -> txm_module_instance_state != TXM_MODULE_STARTED) { ... }
module_instance -> txm_module_instance_state = TXM_MODULE_STOPPING;
_tx_thread_terminate(&(module_instance -> txm_module_instance_start_stop_thread));
_tx_thread_delete(&(module_instance -> txm_module_instance_start_stop_thread));
if (module_instance -> txm_module_instance_stop_thread_entry)
{
_txm_module_manager_thread_create(&(module_instance -> txm_module_instance_start_stop_thread),
"Module Stop Thread",
module_instance -> txm_module_instance_shell_entry_function,
module_instance -> txm_module_instance_stop_thread_entry,
module_instance -> txm_module_instance_application_module_id,
module_instance -> txm_module_instance_start_stop_stack_start_address,
module_instance -> txm_module_instance_start_stop_stack_size,
(UINT) module_instance -> txm_module_instance_start_stop_priority,
(UINT) module_instance -> txm_module_instance_start_stop_priority,
TXM_MODULE_TIME_SLICE,
TX_AUTO_START,
sizeof(TX_THREAD),
module_instance);
i = 0;
while ((i < TXM_MODULE_TIMEOUT) && (module_instance -> txm_module_instance_start_stop_thread.tx_thread_state != TX_COMPLETED))
{
_tx_thread_sleep(1);
i++;
}while ((i < TXM_MODULE_TIMEOUT) && (module_instance -> txm_module_instance_start_stop_thread.tx_thread_state != TX_COMPLETED)) { ... }
_tx_thread_terminate(&(module_instance -> txm_module_instance_start_stop_thread));
_tx_thread_delete(&(module_instance -> txm_module_instance_start_stop_thread));
}if (module_instance -> txm_module_instance_stop_thread_entry) { ... }
_tx_thread_terminate(&(module_instance -> txm_module_instance_callback_request_thread));
_tx_thread_delete(&(module_instance -> txm_module_instance_callback_request_thread));
_tx_queue_delete(&(module_instance -> txm_module_instance_callback_request_queue));
TX_DISABLE
_tx_thread_preempt_disable++;
TX_RESTORE
/* ... */
#ifdef TXM_MODULE_ENABLE_FILEX
_txm_module_manager_filex_stop(module_instance);/* ... */
#endif
#ifdef TXM_MODULE_ENABLE_NETX
_txm_module_manager_netx_stop(module_instance);/* ... */
#endif
#ifdef TXM_MODULE_ENABLE_NETXDUO
_txm_module_manager_netxduo_stop(module_instance);/* ... */
#endif
#ifdef TXM_MODULE_ENABLE_GUIX
_txm_module_manager_guix_stop(module_instance);/* ... */
#endif
#ifdef TXM_MODULE_ENABLE_USBX
_txm_module_manager_usbx_stop(module_instance);/* ... */
#endif
i = _tx_thread_created_count;
thread_ptr = _tx_thread_created_ptr;
while (i--)
{
next_thread_ptr = thread_ptr -> tx_thread_created_next;
if ( (((CHAR *) thread_ptr) >= ((CHAR *) module_instance -> txm_module_instance_data_start)) &&
(((CHAR *) thread_ptr) < ((CHAR *) module_instance -> txm_module_instance_data_end)))
{
_tx_thread_terminate(thread_ptr);
_tx_thread_delete(thread_ptr);
}if ((((CHAR *) thread_ptr) >= ((CHAR *) module_instance -> txm_module_instance_data_start)) && (((CHAR *) thread_ptr) < ((CHAR *) module_instance -> txm_module_instance_data_end))) { ... }
else if (thread_ptr -> tx_thread_module_instance_ptr == module_instance)
{
_tx_thread_terminate(thread_ptr);
_tx_thread_delete(thread_ptr);
}else if (thread_ptr -> tx_thread_module_instance_ptr == module_instance) { ... }
thread_ptr = next_thread_ptr;
}while (i--) { ... }
i = _tx_timer_created_count;
timer_ptr = _tx_timer_created_ptr;
while (i--)
{
next_timer_ptr = timer_ptr -> tx_timer_created_next;
created_by_module = _txm_module_manager_created_object_check(module_instance, (VOID *) timer_ptr);
if (created_by_module == TX_TRUE)
{
_tx_timer_delete(timer_ptr);
}if (created_by_module == TX_TRUE) { ... }
timer_ptr = next_timer_ptr;
}while (i--) { ... }
i = _tx_queue_created_count;
queue_ptr = _tx_queue_created_ptr;
while (i--)
{
next_queue_ptr = queue_ptr -> tx_queue_created_next;
#ifndef TX_DISABLE_NOTIFY_CALLBACKS
if ((queue_ptr -> tx_queue_module_instance == module_instance) &&
(queue_ptr -> tx_queue_send_notify == _txm_module_manager_queue_notify_trampoline))
{
queue_ptr -> tx_queue_send_notify = TX_NULL;
}if ((queue_ptr -> tx_queue_module_instance == module_instance) && (queue_ptr -> tx_queue_send_notify == _txm_module_manager_queue_notify_trampoline)) { ... }
/* ... */#endif
created_by_module = _txm_module_manager_created_object_check(module_instance, (VOID *) queue_ptr);
if (created_by_module == TX_TRUE)
{
_tx_queue_delete(queue_ptr);
}if (created_by_module == TX_TRUE) { ... }
queue_ptr = next_queue_ptr;
}while (i--) { ... }
i = _tx_event_flags_created_count;
events_ptr = _tx_event_flags_created_ptr;
while (i--)
{
next_events_ptr = events_ptr -> tx_event_flags_group_created_next;
#ifndef TX_DISABLE_NOTIFY_CALLBACKS
if ((events_ptr -> tx_event_flags_group_module_instance == module_instance) &&
(events_ptr -> tx_event_flags_group_set_notify == _txm_module_manager_event_flags_notify_trampoline))
{
events_ptr -> tx_event_flags_group_set_notify = TX_NULL;
}if ((events_ptr -> tx_event_flags_group_module_instance == module_instance) && (events_ptr -> tx_event_flags_group_set_notify == _txm_module_manager_event_flags_notify_trampoline)) { ... }
/* ... */#endif
created_by_module = _txm_module_manager_created_object_check(module_instance, (VOID *) events_ptr);
if (created_by_module == TX_TRUE)
{
_tx_event_flags_delete(events_ptr);
}if (created_by_module == TX_TRUE) { ... }
events_ptr = next_events_ptr;
}while (i--) { ... }
i = _tx_semaphore_created_count;
semaphore_ptr = _tx_semaphore_created_ptr;
while (i--)
{
next_semaphore_ptr = semaphore_ptr -> tx_semaphore_created_next;
#ifndef TX_DISABLE_NOTIFY_CALLBACKS
if ((semaphore_ptr -> tx_semaphore_module_instance == module_instance) &&
(semaphore_ptr -> tx_semaphore_put_notify == _txm_module_manager_semaphore_notify_trampoline))
{
semaphore_ptr -> tx_semaphore_put_notify = TX_NULL;
}if ((semaphore_ptr -> tx_semaphore_module_instance == module_instance) && (semaphore_ptr -> tx_semaphore_put_notify == _txm_module_manager_semaphore_notify_trampoline)) { ... }
/* ... */#endif
created_by_module = _txm_module_manager_created_object_check(module_instance, (VOID *) semaphore_ptr);
if (created_by_module == TX_TRUE)
{
_tx_semaphore_delete(semaphore_ptr);
}if (created_by_module == TX_TRUE) { ... }
semaphore_ptr = next_semaphore_ptr;
}while (i--) { ... }
i = _tx_mutex_created_count;
mutex_ptr = _tx_mutex_created_ptr;
while (i--)
{
next_mutex_ptr = mutex_ptr -> tx_mutex_created_next;
created_by_module = _txm_module_manager_created_object_check(module_instance, (VOID *) mutex_ptr);
if (created_by_module == TX_TRUE)
{
_tx_mutex_delete(mutex_ptr);
}if (created_by_module == TX_TRUE) { ... }
mutex_ptr = next_mutex_ptr;
}while (i--) { ... }
i = _tx_block_pool_created_count;
block_pool_ptr = _tx_block_pool_created_ptr;
while (i--)
{
next_block_pool_ptr = block_pool_ptr -> tx_block_pool_created_next;
created_by_module = _txm_module_manager_created_object_check(module_instance, (VOID *) block_pool_ptr);
if (created_by_module == TX_TRUE)
{
_tx_block_pool_delete(block_pool_ptr);
}if (created_by_module == TX_TRUE) { ... }
block_pool_ptr = next_block_pool_ptr;
}while (i--) { ... }
i = _tx_byte_pool_created_count;
byte_pool_ptr = _tx_byte_pool_created_ptr;
while (i--)
{
next_byte_pool_ptr = byte_pool_ptr -> tx_byte_pool_created_next;
created_by_module = _txm_module_manager_created_object_check(module_instance, (VOID *) byte_pool_ptr);
if (created_by_module == TX_TRUE)
{
_tx_byte_pool_delete(byte_pool_ptr);
}if (created_by_module == TX_TRUE) { ... }
byte_pool_ptr = next_byte_pool_ptr;
}while (i--) { ... }
#ifdef TX_ENABLE_EVENT_TRACE
if (_tx_trace_buffer_current_ptr != TX_NULL)
{
if ((ULONG) _tx_trace_header_ptr -> tx_trace_header_buffer_start_pointer >= (ULONG) module_instance -> txm_module_instance_data_start &&
(ULONG) _tx_trace_header_ptr -> tx_trace_header_buffer_start_pointer < (ULONG) module_instance -> txm_module_instance_data_end)
{
_tx_trace_disable();
}if ((ULONG) _tx_trace_header_ptr -> tx_trace_header_buffer_start_pointer >= (ULONG) module_instance -> txm_module_instance_data_start && (ULONG) _tx_trace_header_ptr -> tx_trace_header_buffer_start_pointer < (ULONG) module_instance -> txm_module_instance_data_end) { ... }
}if (_tx_trace_buffer_current_ptr != TX_NULL) { ... }
/* ... */#endif
while (module_instance -> txm_module_instance_object_list_count != 0)
{
object_ptr = module_instance -> txm_module_instance_object_list_head;
module_instance -> txm_module_instance_object_list_head = object_ptr -> txm_module_allocated_object_next;
_tx_byte_release((VOID *) object_ptr);
module_instance -> txm_module_instance_object_list_count--;
}while (module_instance -> txm_module_instance_object_list_count != 0) { ... }
module_instance -> txm_module_instance_object_list_head = TX_NULL;
TX_DISABLE
_tx_thread_preempt_disable--;
module_instance -> txm_module_instance_state = TXM_MODULE_STOPPED;
TX_RESTORE
_tx_mutex_put(&_txm_module_manager_mutex);
_tx_thread_system_preempt_check();
return(TX_SUCCESS);
}{ ... }