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