There are several additional APIs available to the resident portion of the application, as follows.
Module’s code and data are at absolute (fixed) addresses.
UINT txm_module_manager_absolute_load(
TXM_MODULE_INSTANCE *module_instance,
CHAR *module_name,
VOID *module_location);
This service initializes the module contained in the specified location and prepares it for execution. There is no code or data relocation, thus position-independence is not necessary.
Initialization and threads
TXM_MODULE_INSTANCE my_module;
/* Initialize the module manager. */
status = txm_module_manager_initialize((VOID*)0x64010000,0x10000);
/* Load the module that has its code area at address 0x080F0000. */
txm_module_manager_absolute_load(&my_module, "my module", (VOID *) 0x080F0000);
/* Start the module. */
status = txm_module_manager_start(&my_module);
Enable module to access a shared memory space.
UINT txm_module_manager_external_memory_enable(
TXM_MODULE_INSTANCE *module_instance,
VOID *start_address,
ULONG length,
UINT attributes);
This service creates an entry in the memory management hardware table for a shared memory region that the module can access.
Initialization and threads
TXM_MODULE_INSTANCE my_module;
/* Initialize the module manager with 64KB of RAM starting at address 0x64010000. */
txm_module_manager_initialize((VOID *) 0x64010000, 0x10000);
/* Load the module that has its code area at address 0x080F0000. */
txm_module_manager_in_place_load(&my_module, "my module", (VOID *) 0x080F0000);
/* Create a shared memory space 256 bytes long at address 0x64005000
with read & write, no execute, outer & inner write back cache
attributes. Note that these attributes are port-specific. */
txm_module_manager_external_memory_enable(&my_module, (VOID*)0x64005000, 256, 0x3F);
Load module from file via FileX.
UINT txm_module_manager_file_load(
TXM_MODULE_INSTANCE *module_instance,
CHAR *module_name,
FX_MEDIA *media_ptr,
CHAR *file_name);
This service loads the binary image of the module contained in the specified file into the module memory area and prepares it for execution. It is assumed that the supplied media is already opened.
Note: The FileX system is utilized to load the file. In order to enable FileX access, the module, module library, Module Manager and the ThreadX library (with the Module Manager sources) must be built with FX_FILEX_PRESENT defined in the projects.
| TXM_MODULE_INVALID (0xF2) | Invalid module preamble. |
Threads
TXM_MODULE_INSTANCE my_module;
/* Initialize the module manager. */
status = txm_module_manager_initialize((VOID*)0x64010000,0x10000);
/* Load the module from a binary file. */
status = txm_module_manager_file_load(&my_module, "my module",
&sdio_disk, "demo_thread_module.bin");
/* Start the module. */
status = txm_module_manager_start(&my_module);
Load module data only, execute module in existing location.
UINT txm_module_manager_in_place_load(
TXM_MODULE_INSTANCE *module_instance,
CHAR *module_name,
VOID *location);
This service loads the module’s data area only into the module memory area and prepares it for execution. Module code execution will be in-place, that is, from the address offset specified by the module preamble at the supplied location.
Initialization and threads
TXM_MODULE_INSTANCE my_module;
/* Initialize the module manager with 64KB of RAM starting at address 0x64010000. */
txm_module_manager_initialize((VOID *) 0x64010000, 0x10000);
/* Load the module that has its code area at address 0x080F0000. */
txm_module_manager_in_place_load(&my_module, "my module", (VOID *) 0x080F0000);
/* Start the module. */
txm_module_manager_start(&my_module);
Initialize the module manager.
UINT txm_module_manager_initialize(
VOID *module_memory_start,
ULONG module_memory_size);
This service initializes the Module Manager’s internal resources, including the memory area used for loading modules.
Initialization and threads
/* Initialize the module manager with 64KB of RAM starting at
address 0x64010000. */
txm_module_manager_initialize((VOID *) 0x64010000, 0x10000);
Initialize the memory management hardware.
UINT txm_module_manager_initialize_mmu(VOID);
This service initializes the MMU.
none
Initialization and Threads
/* Initialize the module manager with 64KB of RAM starting at address 0x64010000. */
txm_module_manager_initialize((VOID *) 0x64010000, 0x10000);
/* Initialize the MMU. */
txm_module_manager_initialize_mmu();
Set the maximum thread priority allowed in a module.
UINT txm_module_manager_maximum_module_priority_set(
TXM_MODULE_INSTANCE *module_instance,
UINT priority);
This service sets the maximum thread priority allowed in a module.
Initialization and threads
/* Load the module that has its code area at address 0x080F0000. */
txm_module_manager_in_place_load(&my_module, "my module", (VOID *) 0x080F0000);
/* Set the maximum thread priority in my_module to 5. */
txm_module_manager_maximum_module_priority_set(&my_module, 5);
Register an application callback on memory fault.
UINT txm_module_manager_memory_fault_notify(
VOID (*notify_function)(TX_THREAD *, MODULE_INSTANCE *));
This service registers the specified application memory fault notification callback function with the Module Manager. If a memory fault occurs, this function is called with a pointer to the offending thread and the module instance corresponding to the offending thread. The Module Manager processing automatically terminates the offending thread, but leaves any other threads in the module untouched. It is up to the application to decide what to do with the module associated with the memory fault.
Please see the internal _txm_module_manager_memory_fault_info struct for specific information on the memory fault itself.
Note: The memory fault notification callback function is executed directly from the memory fault exception, so only ThreadX APIs Allowed from interrupt service routines can be called. Thus, in order to stop and unload the offending module, the application notification callback must send a signal to an application task so that the module can be stopped and unloaded.
Initialization and threads
/* Register a memory fault callback. */
txm_module_manager_memory_fault_notify(my_memory_fault_handler);
Load module from memory.
UINT txm_module_manager_memory_load (
TXM_MODULE_INSTANCE *module_instance,
CHAR *module_name,
VOID *location);
This service loads the module’s code and data area into the module memory area set up by txm_module_manager_initialize and prepares it for execution.
Initialization and threads
TXM_MODULE_INSTANCE my_module;
/* Initialize the module manager with 64KB of RAM starting at address 0x64010000. */
txm_module_manager_initialize((VOID *) 0x64010000, 0x10000);
/* Load the module that has its code area at address 0x080F0000. */
txm_module_manager_memory_load(&my_module, "my module", (VOID *) 0x080F0000);
Create an object pool for modules.
UINT txm_module_manager_object_pool_create(
VOID *pool_memory_start,
ULONG pool_memory_size);
This service creates a Module Manager object memory pool that the modules can allocate ThreadX/NetX Duo objects from, thereby keeping the system object out of the module’s memory area.
Initialization and threads
TXM_MODULE_INSTANCE my_module;
/* Initialize the module manager with 64KB of RAM starting at address 0x64010000. */
txm_module_manager_initialize((VOID *) 0x64010000, 0x10000);
/* Create an object memory pool in the next 64KB of memory. */
txm_module_manager_object_pool_create((VOID *) 0x64020000, 0x10000);
Get module properties.
UINT txm_module_manager_properties_get(
TXM_MODULE_INSTANCE *module_instance,
ULONG *module_properties_ptr);
This service returns the properties (specified in the preamble) of a module.
Threads
TXM_MODULE_INSTANCE my_module;
ULONG module_properties;
/* Initialize the module manager with 64KB of RAM starting at address 0x64010000. */
txm_module_manager_initialize((VOID *) 0x64010000, 0x10000);
/* Create an object memory pool in the next 64KB of memory. */
txm_module_manager_object_pool_create((VOID *) 0x64020000, 0x10000);
/* Load the module that has its code area at address 0x080F0000. */
txm_module_manager_in_place_load(&my_module, "my module", (VOID *) 0x080F0000);
/* Get module properties. */
txm_module_manager_properties_get(&my_module, &module_properties);
Start execution of the module.
UINT txm_module_manager_start(TXM_MODULE_INSTANCE *module_instance);
This service starts execution of the specified, already loaded module.
Initialization and threads
/* Start the module. */
txm_module_manager_start(&my_module);
/* Let the module run for a while. */
tx_thread_sleep(2000);
/* Stop the module. */
txm_module_manager_stop(&my_module);
/* Unload the module. */
txm_module_manager_unload(&my_module);
Stop execution of the module.
UINT txm_module_manager_stop(TXM_MODULE_INSTANCE *module_instance);
This service stops a module that was previously loaded and started. Stopping a module includes executing the module’s optional stop thread, terminating all threads, and deleting all resources associated with the module.
Threads
/* Start the module. */
txm_module_manager_start(&my_module);
/* Let the module run for a while. */
tx_thread_sleep(20000);
/* Stop the module. */
txm_module_manager_stop(&my_module);
/* Unload the module. */
txm_module_manager_unload(&my_module);
Unload the module.
UINT txm_module_manager_unload(TXM_MODULE_INSTANCE *module_instance);
This service unloads the previously loaded and stopped module, freeing all the associated module memory resources.
Initialization and threads
/* Stop the module. */
txm_module_manager_stop(&my_module);
/* Unload the module. */
status = txm_module_manager_unload(&my_module);