1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** ThreadX Component                                                     */
16 /**                                                                       */
17 /**   Module Interface (API)                                              */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 
23 /**************************************************************************/
24 /*                                                                        */
25 /*  APPLICATION INTERFACE DEFINITION                       RELEASE        */
26 /*                                                                        */
27 /*    txm_module.h                                        PORTABLE C      */
28 /*                                                           6.1.10       */
29 /*  AUTHOR                                                                */
30 /*                                                                        */
31 /*    Scott Larson, Microsoft Corporation                                 */
32 /*                                                                        */
33 /*  DESCRIPTION                                                           */
34 /*                                                                        */
35 /*    This file defines the basic module constants, interface structures, */
36 /*    and function prototypes.                                            */
37 /*                                                                        */
38 /*  RELEASE HISTORY                                                       */
39 /*                                                                        */
40 /*    DATE              NAME                      DESCRIPTION             */
41 /*                                                                        */
42 /*  09-30-2020      Scott Larson            Initial Version 6.1           */
43 /*  12-31-2020      Scott Larson            Modified comment(s), added    */
44 /*                                            port-specific extension,    */
45 /*                                            resulting in version 6.1.3  */
46 /*  01-31-2022      Scott Larson            Modified comment(s), added    */
47 /*                                            callback thread prototype,  */
48 /*                                            resulting in version 6.1.10 */
49 /*                                                                        */
50 /**************************************************************************/
51 
52 #ifndef TXM_MODULE_H
53 #define TXM_MODULE_H
54 
55 
56 /* Include the standard ThreadX API file.  */
57 
58 #include "tx_api.h"
59 
60 /* Include the module port specific file.  */
61 
62 #include "txm_module_port.h"
63 
64 
65 /* Include any supported external component include files.  */
66 
67 #ifdef TXM_MODULE_ENABLE_FILEX
68 #include "txm_module_filex.h"
69 #endif
70 
71 #ifdef TXM_MODULE_ENABLE_GUIX
72 #include "txm_module_guix.h"
73 #endif
74 
75 #ifdef TXM_MODULE_ENABLE_NETX
76 #include "txm_module_netx.h"
77 #endif
78 
79 #ifdef TXM_MODULE_ENABLE_NETXDUO
80 #include "txm_module_netxduo.h"
81 #endif
82 
83 #ifdef TXM_MODULE_ENABLE_USBX
84 #include "txm_module_usbx.h"
85 #endif
86 
87 
88 #ifdef FX_FILEX_PRESENT
89 #include "fx_api.h"
90 #endif
91 
92 
93 /* Determine if a C++ compiler is being used.  If so, ensure that standard
94    C is used to process the API information.  */
95 
96 #ifdef __cplusplus
97 
98 /* Yes, C++ compiler is present.  Use standard C.  */
99 extern   "C" {
100 
101 #endif
102 
103 
104 /* Define the Module ID, which is used to indicate a module is valid.  */
105 
106 #define TXM_MODULE_ID                                       0x4D4F4455
107 
108 
109 /* Define valid module states.  */
110 
111 #define TXM_MODULE_LOADED                                   1
112 #define TXM_MODULE_STARTED                                  2
113 #define TXM_MODULE_STOPPING                                 3
114 #define TXM_MODULE_STOPPED                                  4
115 #define TXM_MODULE_UNLOADED                                 5
116 
117 
118 /* Define module manager error codes.  */
119 
120 #define TXM_MODULE_ALIGNMENT_ERROR                          0xF0
121 #define TXM_MODULE_ALREADY_LOADED                           0xF1
122 #define TXM_MODULE_INVALID                                  0xF2
123 #define TXM_MODULE_INVALID_PROPERTIES                       0xF3
124 #define TXM_MODULE_INVALID_MEMORY                           0xF4
125 #define TXM_MODULE_INVALID_CALLBACK                         0xF5
126 #define TXM_MODULE_INVALID_STACK_SIZE                       0xF6
127 #define TXM_MODULE_FILEX_INVALID_BYTES_READ                 0xF7
128 #define TXM_MODULE_MATH_OVERFLOW                            0xF8
129 
130 
131 /* Define the data area alignment mask, must be a power of 2.  */
132 
133 #ifndef TXM_MODULE_DATA_ALIGNMENT
134 #define TXM_MODULE_DATA_ALIGNMENT                           4
135 #endif
136 
137 
138 /* Define the code area alignment mask, must be a power of 2.  */
139 
140 #ifndef TXM_MODULE_CODE_ALIGNMENT
141 #define TXM_MODULE_CODE_ALIGNMENT                           4
142 #endif
143 
144 
145 /* Define module timeout for waiting for module to finish.  */
146 
147 #ifndef TXM_MODULE_TIMEOUT
148 #define TXM_MODULE_TIMEOUT                                  100
149 #endif
150 
151 
152 /* Define module thread time-slice default.  */
153 
154 #ifndef TXM_MODULE_TIME_SLICE
155 #define TXM_MODULE_TIME_SLICE                               4
156 #endif
157 
158 
159 /* Define each module's callback queue depth. This is used to queue up incoming call back requests.  */
160 
161 #ifndef TXM_MODULE_CALLBACKS_QUEUE_DEPTH
162 #define TXM_MODULE_CALLBACKS_QUEUE_DEPTH                    8       /* Number queued callback requests.  */
163 #endif
164 
165 
166 /* Define the module manager thread's stack size.  */
167 
168 #ifndef TXM_MODULE_MANAGER_THREAD_STACK_SIZE
169 #define TXM_MODULE_MANAGER_THREAD_STACK_SIZE                1024
170 #endif
171 
172 
173 /* Define the module manager thread's priority.  */
174 
175 #ifndef TXM_MODULE_MANAGER_THREAD_PRIORITY
176 #define TXM_MODULE_MANAGER_THREAD_PRIORITY                  1
177 #endif
178 
179 
180 /* Define the module's callback handler thread's stack size.  */
181 
182 #ifndef TXM_MODULE_CALLBACK_THREAD_STACK_SIZE
183 #define TXM_MODULE_CALLBACK_THREAD_STACK_SIZE                1024
184 #endif
185 
186 
187 /* Define the default port-specific macro for resetting the thread.  */
188 
189 #ifndef TXM_MODULE_MANAGER_THREAD_RESET_PORT_COMPLETION
190 #define TXM_MODULE_MANAGER_THREAD_RESET_PORT_COMPLETION(thread_ptr, module_instance)
191 #endif
192 
193 
194 /* Define object types for object search requests.  */
195 
196 #define TXM_BLOCK_POOL_OBJECT                               1
197 #define TXM_BYTE_POOL_OBJECT                                2
198 #define TXM_EVENT_FLAGS_OBJECT                              3
199 #define TXM_MUTEX_OBJECT                                    4
200 #define TXM_QUEUE_OBJECT                                    5
201 #define TXM_SEMAPHORE_OBJECT                                6
202 #define TXM_THREAD_OBJECT                                   7
203 #define TXM_TIMER_OBJECT                                    8
204 #define TXM_THREAD_KERNEL_STACK_OBJECT                      77
205 #define TXM_FILEX_OBJECTS_START                             100
206 #define TXM_FILEX_OBJECTS_END                               199
207 #define TXM_NETX_OBJECTS_START                              200
208 #define TXM_NETX_OBJECTS_END                                299
209 #define TXM_NETXDUO_OBJECTS_START                           300
210 #define TXM_NETXDUO_OBJECTS_END                             399
211 #define TXM_USBX_OBJECTS_START                              400
212 #define TXM_USBX_OBJECTS_END                                499
213 #define TXM_GUIX_OBJECTS_START                              500
214 #define TXM_GUIX_OBJECT_END                                 599
215 
216 
217 /* Define callback types.  */
218 #define TXM_THREADX_CALLBACKS_START                         0
219 #define TXM_THREADX_CALLBACKS_END                           99
220 #define TXM_FILEX_CALLBACKS_START                           100
221 #define TXM_FILEX_CALLBACKS_END                             199
222 #define TXM_NETX_CALLBACKS_START                            200
223 #define TXM_NETX_CALLBACKS_END                              299
224 #define TXM_NETXDUO_CALLBACKS_START                         300
225 #define TXM_NETXDUO_CALLBACKS_END                           399
226 #define TXM_USBX_CALLBACKS_START                            400
227 #define TXM_USBX_CALLBACKS_END                              499
228 #define TXM_GUIX_CALLBACKS_START                            500
229 #define TXM_GUIX_CALLBACKS_END                              599
230 
231 #define TXM_TIMER_CALLBACK                                  0
232 #define TXM_EVENTS_SET_CALLBACK                             1
233 #define TXM_QUEUE_SEND_CALLBACK                             2
234 #define TXM_SEMAPHORE_PUT_CALLBACK                          3
235 #define TXM_THREAD_ENTRY_EXIT_CALLBACK                      4
236 
237 
238 /* Determine the ThreadX kernel API call IDs.  */
239 
240 #define TXM_BLOCK_ALLOCATE_CALL                             1
241 #define TXM_BLOCK_POOL_CREATE_CALL                          2
242 #define TXM_BLOCK_POOL_DELETE_CALL                          3
243 #define TXM_BLOCK_POOL_INFO_GET_CALL                        4
244 #define TXM_BLOCK_POOL_PERFORMANCE_INFO_GET_CALL            5
245 #define TXM_BLOCK_POOL_PERFORMANCE_SYSTEM_INFO_GET_CALL     6
246 #define TXM_BLOCK_POOL_PRIORITIZE_CALL                      7
247 #define TXM_BLOCK_RELEASE_CALL                              8
248 #define TXM_BYTE_ALLOCATE_CALL                              9
249 #define TXM_BYTE_POOL_CREATE_CALL                           10
250 #define TXM_BYTE_POOL_DELETE_CALL                           11
251 #define TXM_BYTE_POOL_INFO_GET_CALL                         12
252 #define TXM_BYTE_POOL_PERFORMANCE_INFO_GET_CALL             13
253 #define TXM_BYTE_POOL_PERFORMANCE_SYSTEM_INFO_GET_CALL      14
254 #define TXM_BYTE_POOL_PRIORITIZE_CALL                       15
255 #define TXM_BYTE_RELEASE_CALL                               16
256 #define TXM_EVENT_FLAGS_CREATE_CALL                         17
257 #define TXM_EVENT_FLAGS_DELETE_CALL                         18
258 #define TXM_EVENT_FLAGS_GET_CALL                            19
259 #define TXM_EVENT_FLAGS_INFO_GET_CALL                       20
260 #define TXM_EVENT_FLAGS_PERFORMANCE_INFO_GET_CALL           21
261 #define TXM_EVENT_FLAGS_PERFORMANCE_SYSTEM_INFO_GET_CALL    22
262 #define TXM_EVENT_FLAGS_SET_CALL                            23
263 #define TXM_EVENT_FLAGS_SET_NOTIFY_CALL                     24
264 #define TXM_THREAD_INTERRUPT_CONTROL_CALL                   25
265 #define TXM_MUTEX_CREATE_CALL                               26
266 #define TXM_MUTEX_DELETE_CALL                               27
267 #define TXM_MUTEX_GET_CALL                                  28
268 #define TXM_MUTEX_INFO_GET_CALL                             29
269 #define TXM_MUTEX_PERFORMANCE_INFO_GET_CALL                 30
270 #define TXM_MUTEX_PERFORMANCE_SYSTEM_INFO_GET_CALL          31
271 #define TXM_MUTEX_PRIORITIZE_CALL                           32
272 #define TXM_MUTEX_PUT_CALL                                  33
273 #define TXM_QUEUE_CREATE_CALL                               34
274 #define TXM_QUEUE_DELETE_CALL                               35
275 #define TXM_QUEUE_FLUSH_CALL                                36
276 #define TXM_QUEUE_FRONT_SEND_CALL                           37
277 #define TXM_QUEUE_INFO_GET_CALL                             38
278 #define TXM_QUEUE_PERFORMANCE_INFO_GET_CALL                 39
279 #define TXM_QUEUE_PERFORMANCE_SYSTEM_INFO_GET_CALL          40
280 #define TXM_QUEUE_PRIORITIZE_CALL                           41
281 #define TXM_QUEUE_RECEIVE_CALL                              42
282 #define TXM_QUEUE_SEND_CALL                                 43
283 #define TXM_QUEUE_SEND_NOTIFY_CALL                          44
284 #define TXM_SEMAPHORE_CEILING_PUT_CALL                      45
285 #define TXM_SEMAPHORE_CREATE_CALL                           46
286 #define TXM_SEMAPHORE_DELETE_CALL                           47
287 #define TXM_SEMAPHORE_GET_CALL                              48
288 #define TXM_SEMAPHORE_INFO_GET_CALL                         49
289 #define TXM_SEMAPHORE_PERFORMANCE_INFO_GET_CALL             50
290 #define TXM_SEMAPHORE_PERFORMANCE_SYSTEM_INFO_GET_CALL      51
291 #define TXM_SEMAPHORE_PRIORITIZE_CALL                       52
292 #define TXM_SEMAPHORE_PUT_CALL                              53
293 #define TXM_SEMAPHORE_PUT_NOTIFY_CALL                       54
294 #define TXM_THREAD_CREATE_CALL                              55
295 #define TXM_THREAD_DELETE_CALL                              56
296 #define TXM_THREAD_ENTRY_EXIT_NOTIFY_CALL                   57
297 #define TXM_THREAD_IDENTIFY_CALL                            58
298 #define TXM_THREAD_INFO_GET_CALL                            59
299 #define TXM_THREAD_PERFORMANCE_INFO_GET_CALL                60
300 #define TXM_THREAD_PERFORMANCE_SYSTEM_INFO_GET_CALL         61
301 #define TXM_THREAD_PREEMPTION_CHANGE_CALL                   62
302 #define TXM_THREAD_PRIORITY_CHANGE_CALL                     63
303 #define TXM_THREAD_RELINQUISH_CALL                          64
304 #define TXM_THREAD_RESET_CALL                               65
305 #define TXM_THREAD_RESUME_CALL                              66
306 #define TXM_THREAD_SLEEP_CALL                               67
307 #define TXM_THREAD_STACK_ERROR_NOTIFY_CALL                  68
308 #define TXM_THREAD_SUSPEND_CALL                             69
309 #define TXM_THREAD_TERMINATE_CALL                           70
310 #define TXM_THREAD_TIME_SLICE_CHANGE_CALL                   71
311 #define TXM_THREAD_WAIT_ABORT_CALL                          72
312 #define TXM_TIME_GET_CALL                                   73
313 #define TXM_TIME_SET_CALL                                   74
314 #define TXM_TIMER_ACTIVATE_CALL                             75
315 #define TXM_TIMER_CHANGE_CALL                               76
316 #define TXM_TIMER_CREATE_CALL                               77
317 #define TXM_TIMER_DEACTIVATE_CALL                           78
318 #define TXM_TIMER_DELETE_CALL                               79
319 #define TXM_TIMER_INFO_GET_CALL                             80
320 #define TXM_TIMER_PERFORMANCE_INFO_GET_CALL                 81
321 #define TXM_TIMER_PERFORMANCE_SYSTEM_INFO_GET_CALL          82
322 #define TXM_TRACE_ENABLE_CALL                               83
323 #define TXM_TRACE_EVENT_FILTER_CALL                         84
324 #define TXM_TRACE_EVENT_UNFILTER_CALL                       85
325 #define TXM_TRACE_DISABLE_CALL                              86
326 #define TXM_TRACE_INTERRUPT_CONTROL_CALL                    87
327 #define TXM_TRACE_ISR_ENTER_INSERT_CALL                     88
328 #define TXM_TRACE_ISR_EXIT_INSERT_CALL                      89
329 #define TXM_TRACE_BUFFER_FULL_NOTIFY_CALL                   90
330 #define TXM_TRACE_USER_EVENT_INSERT_CALL                    91
331 #define TXM_THREAD_SYSTEM_SUSPEND_CALL                      92
332 #define TXM_MODULE_OBJECT_POINTER_GET_CALL                  93
333 #define TXM_MODULE_OBJECT_POINTER_GET_EXTENDED_CALL         94
334 #define TXM_MODULE_OBJECT_ALLOCATE_CALL                     95
335 #define TXM_MODULE_OBJECT_DEALLOCATE_CALL                   96
336 
337 #define TXM_MODULE_PORT_EXTENSION_API_ID_START              500
338 #define TXM_MODULE_PORT_EXTENSION_API_ID_END                999
339 
340 /* Determine the API call IDs for other components.  */
341 
342 #define TXM_FILEX_API_ID_START                              1000
343 #define TXM_FILEX_API_ID_END                                1999
344 #define TXM_NETX_API_ID_START                               2000
345 #define TXM_NETX_API_ID_END                                 2999
346 #define TXM_NETXDUO_API_ID_START                            3000
347 #define TXM_NETXDUO_API_ID_END                              3999
348 #define TXM_USBX_API_ID_START                               4000
349 #define TXM_USBX_API_ID_END                                 4999
350 #define TXM_GUIX_API_ID_START                               5000
351 #define TXM_GUIX_API_ID_END                                 5999
352 
353 
354 /* Determine the application's IDs for calling application code in the resident area.  */
355 
356 #define TXM_APPLICATION_REQUEST_ID_BASE                     0x10000
357 
358 
359 /* Define the overlay for the module's preamble.  */
360 
361 typedef struct TXM_MODULE_PREAMBLE_STRUCT
362 {
363                                                                         /* Meaning                                      */
364     ULONG               txm_module_preamble_id;                         /* Download Module ID (0x54584D44)              */
365     ULONG               txm_module_preamble_version_major;              /* Major Version ID                             */
366     ULONG               txm_module_preamble_version_minor;              /* Minor Version ID                             */
367     ULONG               txm_module_preamble_preamble_size;              /* Module Preamble Size, in 32-bit words        */
368     ULONG               txm_module_preamble_application_module_id;      /* Module ID (application defined)              */
369     ULONG               txm_module_preamble_property_flags;             /* Properties Bit Map                           */
370     ULONG               txm_module_preamble_shell_entry_function;       /* Module shell Entry Function                  */
371     ULONG               txm_module_preamble_start_function;             /* Module Thread Start Function                 */
372     ULONG               txm_module_preamble_stop_function;              /* Module Thread Stop Function                  */
373     ULONG               txm_module_preamble_start_stop_priority;        /* Module Start/Stop Thread Priority            */
374     ULONG               txm_module_preamble_start_stop_stack_size;      /* Module Start/Stop Thread Priority            */
375     ULONG               txm_module_preamble_callback_function;          /* Module Callback Thread Function              */
376     ULONG               txm_module_preamble_callback_priority;          /* Module Callback Thread Priority              */
377     ULONG               txm_module_preamble_callback_stack_size;        /* Module Callback Thread Stack Size            */
378     ULONG               txm_module_preamble_code_size;                  /* Module Instruction Area Size                 */
379     ULONG               txm_module_preamble_data_size;                  /* Module Data Area Size                        */
380     ULONG               txm_module_preamble_reserved_0;                 /* Reserved                                     */
381     ULONG               txm_module_preamble_reserved_1;                 /* Reserved                                     */
382     ULONG               txm_module_preamble_reserved_2;                 /* Reserved                                     */
383     ULONG               txm_module_preamble_reserved_3;                 /* Reserved                                     */
384     ULONG               txm_module_preamble_reserved_4;                 /* Reserved                                     */
385     ULONG               txm_module_preamble_reserved_5;                 /* Reserved                                     */
386     ULONG               txm_module_preamble_reserved_6;                 /* Reserved                                     */
387     ULONG               txm_module_preamble_reserved_7;                 /* Reserved                                     */
388     ULONG               txm_module_preamble_reserved_8;                 /* Reserved                                     */
389     ULONG               txm_module_preamble_reserved_9;                 /* Reserved                                     */
390     ULONG               txm_module_preamble_reserved_10;                /* Reserved                                     */
391     ULONG               txm_module_preamble_reserved_11;                /* Reserved                                     */
392     ULONG               txm_module_preamble_reserved_12;                /* Reserved                                     */
393     ULONG               txm_module_preamble_reserved_13;                /* Reserved                                     */
394     ULONG               txm_module_preamble_reserved_14;                /* Reserved                                     */
395     ULONG               txm_module_preamble_checksum;                   /* Module Instruction Area Checksum [Optional]  */
396 
397 } TXM_MODULE_PREAMBLE;
398 
399 
400 struct TXM_MODULE_ALLOCATED_OBJECT_STRUCT;
401 
402 
403 /* Define the callback notification structure used to communicate between the module's callback handling thread
404    and the module manager.  */
405 
406 typedef struct TXM_MODULE_CALLBACK_MESSAGE_STRUCT
407 {
408     ULONG               txm_module_callback_message_type;
409     ULONG               txm_module_callback_message_activation_count;
410     VOID                (*txm_module_callback_message_application_function)(VOID);
411     ALIGN_TYPE          txm_module_callback_message_param_1;
412     ALIGN_TYPE          txm_module_callback_message_param_2;
413     ALIGN_TYPE          txm_module_callback_message_param_3;
414     ALIGN_TYPE          txm_module_callback_message_param_4;
415     ALIGN_TYPE          txm_module_callback_message_param_5;
416     ALIGN_TYPE          txm_module_callback_message_param_6;
417     ALIGN_TYPE          txm_module_callback_message_param_7;
418     ALIGN_TYPE          txm_module_callback_message_param_8;
419     ALIGN_TYPE          txm_module_callback_message_reserved1;
420     ALIGN_TYPE          txm_module_callback_message_reserved2;
421 } TXM_MODULE_CALLBACK_MESSAGE;
422 
423 
424 /* Define the module's instance for the manager.  */
425 
426 typedef struct TXM_MODULE_INSTANCE_STRUCT
427 {
428     ULONG               txm_module_instance_id;
429     CHAR                *txm_module_instance_name;
430     ULONG               txm_module_instance_state;
431     ULONG               txm_module_instance_property_flags;
432     VOID                *txm_module_instance_code_allocation_ptr;
433     ULONG               txm_module_instance_code_allocation_size;
434     VOID                *txm_module_instance_code_start;
435     VOID                *txm_module_instance_code_end;
436     ULONG               txm_module_instance_code_size;
437     VOID                *txm_module_instance_data_allocation_ptr;
438     ULONG               txm_module_instance_data_allocation_size;
439     VOID                *txm_module_instance_data_start;
440     VOID                *txm_module_instance_data_end;
441     VOID                *txm_module_instance_module_data_base_address;
442     ULONG               txm_module_instance_data_size;
443     ULONG               txm_module_instance_total_ram_usage;
444     VOID                *txm_module_instance_start_stop_stack_start_address;
445     VOID                *txm_module_instance_start_stop_stack_end_address;
446     VOID                *txm_module_instance_callback_stack_start_address;
447     VOID                *txm_module_instance_callback_stack_end_address;
448     TXM_MODULE_PREAMBLE *txm_module_instance_preamble_ptr;
449     VOID                (*txm_module_instance_shell_entry_function)(TX_THREAD *, struct TXM_MODULE_INSTANCE_STRUCT *);
450     VOID                (*txm_module_instance_start_thread_entry)(ULONG);
451     VOID                (*txm_module_instance_stop_thread_entry)(ULONG);
452     VOID                (*txm_module_instance_callback_request_thread_entry)(ULONG);
453 
454     /* Define the port extention to the module manager structure.  */
455     TXM_MODULE_MANAGER_PORT_EXTENSION
456 
457     TX_THREAD           txm_module_instance_start_stop_thread;
458     TX_THREAD           txm_module_instance_callback_request_thread;
459     TX_QUEUE            txm_module_instance_callback_request_queue;
460     ULONG               txm_module_instance_callback_request_queue_area[TXM_MODULE_CALLBACKS_QUEUE_DEPTH * (sizeof(TXM_MODULE_CALLBACK_MESSAGE)/sizeof(ULONG))];
461     ULONG               txm_module_instance_start_stop_stack_size;
462     ULONG               txm_module_instance_start_stop_priority;
463     ULONG               txm_module_instance_callback_stack_size;
464     ULONG               txm_module_instance_callback_priority;
465     ULONG               txm_module_instance_application_module_id;
466     UINT                txm_module_instance_maximum_priority;
467 
468     /* Define the head pointer of the list of objects allocated by the module.  */
469     struct TXM_MODULE_ALLOCATED_OBJECT_STRUCT
470                         *txm_module_instance_object_list_head;
471     ULONG               txm_module_instance_object_list_count;
472 
473     struct TXM_MODULE_INSTANCE_STRUCT
474                         *txm_module_instance_loaded_next,
475                         *txm_module_instance_loaded_previous;
476 } TXM_MODULE_INSTANCE;
477 
478 
479 /* Determine if the thread entry info control block has an extension defined. If not, define the extension to
480    whitespace.  */
481 
482 #ifndef TXM_MODULE_THREAD_ENTRY_INFO_USER_EXTENSION
483 #define TXM_MODULE_THREAD_ENTRY_INFO_USER_EXTENSION
484 #endif
485 
486 
487 /* Define the thread entry information structure. This structure is placed on the thread's stack such that the
488    module's _txm_thread_shell_entry function does not need to access anything in the thread control block.  */
489 
490 typedef struct TXM_MODULE_THREAD_ENTRY_INFO_STRUCT
491 {
492     TX_THREAD           *txm_module_thread_entry_info_thread;
493     TXM_MODULE_INSTANCE *txm_module_thread_entry_info_module;
494     VOID                *txm_module_thread_entry_info_data_base_address;     /* Don't move this, referenced in stack build to setup module data base register. */
495     VOID                *txm_module_thread_entry_info_code_base_address;
496     VOID               (*txm_module_thread_entry_info_entry)(ULONG);
497     ULONG                txm_module_thread_entry_info_parameter;
498     VOID               (*txm_module_thread_entry_info_exit_notify)(struct TX_THREAD_STRUCT *, UINT);
499     UINT                 txm_module_thread_entry_info_start_thread;
500     TX_THREAD           *txm_module_thread_entry_info_callback_request_thread;
501     TX_QUEUE            *txm_module_thread_entry_info_callback_request_queue;
502     VOID                *txm_module_thread_entry_info_reserved;
503     ALIGN_TYPE          (*txm_module_thread_entry_info_kernel_call_dispatcher)(ULONG kernel_request, ALIGN_TYPE param_1, ALIGN_TYPE param_2, ALIGN_TYPE param_3);
504     TXM_MODULE_THREAD_ENTRY_INFO_USER_EXTENSION
505 } TXM_MODULE_THREAD_ENTRY_INFO;
506 
507 
508 /* Define the linked-list structure used to maintain the module's object allocation.  */
509 
510 typedef struct TXM_MODULE_ALLOCATED_OBJECT_STRUCT
511 {
512 
513     TXM_MODULE_INSTANCE *txm_module_allocated_object_module_instance;
514     struct TXM_MODULE_ALLOCATED_OBJECT_STRUCT
515                         *txm_module_allocated_object_next,
516                         *txm_module_allocated_object_previous;
517     ULONG               txm_module_object_size;
518 } TXM_MODULE_ALLOCATED_OBJECT;
519 
520 
521 /*  Determine if module code is being compiled. If so, remap the ThreadX API to
522     the module shell functions that will go through the module <-> module manager
523     interface.  */
524 
525 #ifdef TXM_MODULE
526 
527 
528 /* Define the external reference to the module manager kernel dispatcher function pointer. This is supplied to the module by the module
529    manager when the module is created and started.  */
530 
531 extern ALIGN_TYPE (*_txm_module_kernel_call_dispatcher)(ULONG type, ALIGN_TYPE param_1, ALIGN_TYPE param_2, ALIGN_TYPE param3);
532 
533 
534 /* Define specific module function prototypes.  */
535 
536 #define txm_module_application_request                  _txm_module_application_request
537 #define txm_module_object_allocate                      _txm_module_object_allocate
538 #define txm_module_object_deallocate                    _txm_module_object_deallocate
539 #define txm_module_object_pointer_get                   _txm_module_object_pointer_get
540 #define txm_module_object_pointer_get_extended          _txm_module_object_pointer_get_extended
541 
542 VOID  _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_ENTRY_INFO *thread_info);
543 UINT  _txm_module_thread_system_suspend(TX_THREAD *thread_ptr);
544 
545 UINT  _txm_module_application_request(ULONG request, ALIGN_TYPE param_1, ALIGN_TYPE param_2, ALIGN_TYPE param_3);
546 VOID  _txm_module_callback_request_thread_entry(ULONG id);
547 UINT  _txm_module_object_allocate(VOID **object_ptr, ULONG object_size);
548 UINT  _txm_module_object_deallocate(VOID *object_ptr);
549 UINT  _txm_module_object_pointer_get(UINT object_type, CHAR *name, VOID **object_ptr);
550 UINT  _txm_module_object_pointer_get_extended(UINT object_type, CHAR *name, UINT name_length, VOID **object_ptr);
551 
552 /* Module callback functions.  */
553 
554 #ifdef TXM_MODULE_ENABLE_NETX
555 VOID  _txm_module_netx_callback_request(TXM_MODULE_CALLBACK_MESSAGE *callback_message);
556 #endif
557 #ifdef TXM_MODULE_ENABLE_NETXDUO
558 VOID  _txm_module_netxduo_callback_request(TXM_MODULE_CALLBACK_MESSAGE *callback_message);
559 #endif
560 #ifdef TXM_MODULE_ENABLE_FILEX
561 VOID  _txm_module_filex_callback_request(TXM_MODULE_CALLBACK_MESSAGE *callback_message);
562 #endif
563 #ifdef TXM_MODULE_ENABLE_GUIX
564 VOID  _txm_module_guix_duo_callback_request(TXM_MODULE_CALLBACK_MESSAGE *callback_message);
565 #endif
566 #ifdef TXM_MODULE_ENABLE_USBX
567 VOID  _txm_module_usbx_duo_callback_request(TXM_MODULE_CALLBACK_MESSAGE *callback_message);
568 #endif
569 
570 /* Define the module's thread shell entry function macros.  */
571 
572 #define TXM_THREAD_COMPLETED_EXTENSION(a)
573 #define TXM_THREAD_STATE_CHANGE(a, b)
574 
575 #else
576 
577 
578 /* Map the module manager APIs just in case this is being included from the module manager in the
579    resident portion of the application.  */
580 
581 #define txm_module_manager_initialize                   _txm_module_manager_initialize
582 #define txm_module_manager_absolute_load                _txm_module_manager_absolute_load
583 #define txm_module_manager_in_place_load                _txm_module_manager_in_place_load
584 #define txm_module_manager_file_load                    _txm_module_manager_file_load
585 #define txm_module_manager_memory_load                  _txm_module_manager_memory_load
586 #define txm_module_manager_object_pointer_get           _txm_module_manager_object_pointer_get
587 #define txm_module_manager_object_pointer_get_extended  _txm_module_manager_object_pointer_get_extended
588 #define txm_module_manager_object_pool_create           _txm_module_manager_object_pool_create
589 #define txm_module_manager_properties_get               _txm_module_manager_properties_get
590 #define txm_module_manager_start                        _txm_module_manager_start
591 #define txm_module_manager_stop                         _txm_module_manager_stop
592 #define txm_module_manager_unload                       _txm_module_manager_unload
593 #define txm_module_manager_maximum_module_priority_set  _txm_module_manager_maximum_module_priority_set
594 #define txm_module_manager_external_memory_enable       _txm_module_manager_external_memory_enable
595 
596 /* Define external variables used by module manager functions.  */
597 
598 #ifndef TX_MODULE_MANAGER_INIT
599 extern ULONG                                        _txm_module_manager_properties_supported;
600 extern ULONG                                        _txm_module_manager_properties_required;
601 extern TX_BYTE_POOL                                 _txm_module_manager_byte_pool;
602 extern TX_BYTE_POOL                                 _txm_module_manager_object_pool;
603 extern UINT                                         _txm_module_manager_object_pool_created;
604 extern TXM_MODULE_INSTANCE                          *_txm_module_manager_loaded_list_ptr;
605 extern ULONG                                        _txm_module_manger_loaded_count;
606 extern UINT                                         _txm_module_manager_ready;
607 extern TX_MUTEX                                     _txm_module_manager_mutex;
608 extern ULONG                                        _txm_module_manager_callback_total_count;
609 extern ULONG                                        _txm_module_manager_callback_error_count;
610 #endif
611 
612 /* Define internal module manager function prototypes.  */
613 
614 UINT  _txm_module_manager_application_request(ULONG request, ALIGN_TYPE param_1, ALIGN_TYPE param_2, ALIGN_TYPE param_3);
615 #ifdef FX_FILEX_PRESENT
616 UINT  _txm_module_manager_file_load(TXM_MODULE_INSTANCE *module_instance, CHAR *module_name, FX_MEDIA *media_ptr, CHAR *file_name);
617 #endif
618 UINT  _txm_module_manager_initialize(VOID *module_memory_start, ULONG module_memory_size);
619 UINT  _txm_module_manager_absolute_load(TXM_MODULE_INSTANCE *module_instance, CHAR *name, VOID *module_location);
620 UINT  _txm_module_manager_in_place_load(TXM_MODULE_INSTANCE *module_instance, CHAR *name, VOID *module_location);
621 UINT  _txm_module_manager_internal_load(TXM_MODULE_INSTANCE *module_instance, CHAR *name, VOID *module_location,
622                                         ULONG code_size, VOID *code_allocation_ptr, ULONG code_allocation_size);
623 ALIGN_TYPE _txm_module_manager_kernel_dispatch(ULONG kernel_request, ALIGN_TYPE param_0, ALIGN_TYPE param_1, ALIGN_TYPE param_2);
624 UINT  _txm_module_manager_object_allocate(VOID **object_ptr_ptr, ULONG object_size, TXM_MODULE_INSTANCE *module_instance);
625 UINT  _txm_module_manager_object_deallocate(VOID *object_ptr);
626 UINT  _txm_module_manager_object_pointer_get(UINT object_type, CHAR *name, VOID **object_ptr);
627 UINT  _txm_module_manager_object_pointer_get_extended(UINT object_type, CHAR *name, UINT name_length, VOID **object_ptr);
628 UINT  _txm_module_manager_object_pool_create(VOID *object_memory, ULONG object_memory_size);
629 VOID  _txm_module_manager_object_type_set(ULONG object_ptr, ULONG object_size, ULONG object_type);
630 UINT  _txm_module_manager_memory_load(TXM_MODULE_INSTANCE *module_instance, CHAR *module_name, VOID *module_location);
631 UINT  _txm_module_manager_properties_get(TXM_MODULE_INSTANCE *module_instance, ULONG *module_properties_ptr);
632 UINT  _txm_module_manager_start(TXM_MODULE_INSTANCE *module_instance);
633 UINT  _txm_module_manager_stop(TXM_MODULE_INSTANCE *module_instance);
634 UINT  _txm_module_manager_thread_create(TX_THREAD *thread_ptr, CHAR *name, VOID (*shell_function)(TX_THREAD *, TXM_MODULE_INSTANCE *),
635                                VOID (*entry_function)(ULONG), ULONG entry_input,
636                                VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold,
637                                ULONG time_slice, UINT auto_start, UINT thread_control_block_size, TXM_MODULE_INSTANCE *module_instance);
638 UINT  _txm_module_manager_thread_reset(TX_THREAD *thread_ptr);
639 VOID  _txm_module_manager_name_build(CHAR *module_name, CHAR *thread_name, CHAR *combined_name);
640 VOID  _txm_module_manager_thread_stack_build(TX_THREAD *thread_ptr, VOID (*shell_function)(TX_THREAD *, TXM_MODULE_INSTANCE *));
641 UINT  _txm_module_manager_unload(TXM_MODULE_INSTANCE *module_instance);
642 ALIGN_TYPE  _txm_module_manager_user_mode_entry(ULONG kernel_request, ALIGN_TYPE param_1, ALIGN_TYPE param_2, ALIGN_TYPE param_3);
643 UINT  _txm_module_manager_maximum_module_priority_set(TXM_MODULE_INSTANCE *module_instance, UINT priority);
644 UINT  _txm_module_manager_external_memory_enable(TXM_MODULE_INSTANCE *module_instance, VOID *start_address, ULONG length, UINT attributes);
645 
646 #ifdef TXM_MODULE_ENABLE_NETX
647 ULONG  _txm_module_manager_netx_dispatch(TXM_MODULE_INSTANCE *module_instance, ULONG kernel_request, ULONG param_1, ULONG param_2, ULONG param_3);
648 UINT  _txm_module_manager_netx_object_pointer_get(UINT object_type, CHAR *name, UINT name_length, VOID **object_ptr);
649 #endif
650 
651 #ifdef TXM_MODULE_ENABLE_NETXDUO
652 ALIGN_TYPE  _txm_module_manager_netxduo_dispatch(TXM_MODULE_INSTANCE *module_instance, ULONG kernel_request, ALIGN_TYPE param_1, ALIGN_TYPE param_2, ALIGN_TYPE param_3);
653 UINT  _txm_module_manager_netxduo_object_pointer_get(UINT object_type, CHAR *name, UINT name_length, VOID **object_ptr);
654 #endif
655 
656 #ifdef TXM_MODULE_ENABLE_FILEX
657 ALIGN_TYPE _txm_module_manager_filex_dispatch(TXM_MODULE_INSTANCE *module_instance, ULONG kernel_request, ALIGN_TYPE param_0, ALIGN_TYPE param_1, ALIGN_TYPE param_2);
658 UINT  _txm_module_manager_filex_object_pointer_get(UINT object_type, CHAR *name, UINT name_length, VOID **object_ptr);
659 #endif
660 
661 #ifdef TXM_MODULE_ENABLE_GUIX
662 ULONG  _txm_module_manager_guix_dispatch(TXM_MODULE_INSTANCE *module_instance, ULONG kernel_request, ULONG param_1, ULONG param_2, ULONG param_3);
663 UINT  _txm_module_manager_guix_object_pointer_get(UINT object_type, CHAR *name, UINT name_length, VOID **object_ptr);
664 #endif
665 
666 #ifdef TXM_MODULE_ENABLE_USBX
667 ULONG  _txm_module_manager_usbx_dispatch(TXM_MODULE_INSTANCE *module_instance, ULONG kernel_request, ULONG param_1, ULONG param_2, ULONG param_3);
668 UINT  _txm_module_manager_usbx_object_pointer_get(UINT object_type, CHAR *name, UINT name_length, VOID **object_ptr);
669 #endif
670 
671 /* Define the callback deferred processing routines necessary for executing callbacks in the module code.  */
672 
673 VOID  _txm_module_manager_callback_request(TX_QUEUE *module_callback_queue, TXM_MODULE_CALLBACK_MESSAGE  *callback_request);
674 VOID  _txm_module_manager_event_flags_notify_trampoline(TX_EVENT_FLAGS_GROUP *group_ptr);
675 VOID  _txm_module_manager_queue_notify_trampoline(TX_QUEUE *queue_ptr);
676 VOID  _txm_module_manager_semaphore_notify_trampoline(TX_SEMAPHORE *semaphore_ptr);
677 VOID  _txm_module_manager_thread_notify_trampoline(TX_THREAD *thread_ptr, UINT type);
678 VOID  _txm_module_manager_timer_notify_trampoline(ULONG id);
679 
680 
681 /* Define port specific module manager prototypes.  */
682 
683 TXM_MODULE_MANAGER_ADDITIONAL_PROTOTYPES
684 
685 #endif
686 
687 
688 /* Determine if a C++ compiler is being used.  If so, complete the standard
689    C conditional started above.  */
690 #ifdef __cplusplus
691         }
692 #endif
693 
694 #endif
695