txm_module.h 37 KB

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