1 /* Small demonstration of the ThreadX module manager.  */
2 
3 #include "tx_api.h"
4 #include "txm_module.h"
5 
6 
7 #define DEMO_STACK_SIZE         1024
8 
9 /* Define the ThreadX object control blocks...  */
10 
11 TX_THREAD               module_manager;
12 TXM_MODULE_INSTANCE     my_module;
13 
14 
15 /* Define the object pool area.  */
16 
17 UCHAR                   object_memory[8192];
18 
19 
20 /* Define the count of memory faults.  */
21 
22 ULONG                   memory_faults;
23 
24 
25 /* Define thread prototypes.  */
26 
27 void    module_manager_entry(ULONG thread_input);
28 
29 
30 /* Define fault handler.  */
31 
module_fault_handler(TX_THREAD * thread,TXM_MODULE_INSTANCE * module)32 VOID module_fault_handler(TX_THREAD *thread, TXM_MODULE_INSTANCE *module)
33 {
34 
35     /* Just increment the fault counter.   */
36     memory_faults++;
37 }
38 
39 /* Define main entry point.  */
40 
main()41 int main()
42 {
43 
44     /* Enter the ThreadX kernel.  */
45     tx_kernel_enter();
46 }
47 
48 
49 /* Define what the initial system looks like.  */
50 
tx_application_define(void * first_unused_memory)51 void    tx_application_define(void *first_unused_memory)
52 {
53 
54 CHAR    *pointer = (CHAR*)first_unused_memory;
55 
56 
57     tx_thread_create(&module_manager, "Module Manager Thread", module_manager_entry, 0,
58                      pointer, DEMO_STACK_SIZE,
59                      1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
60     pointer =  pointer + DEMO_STACK_SIZE;
61 }
62 
63 
64 
65 
66 /* Define the test threads.  */
67 
module_manager_entry(ULONG thread_input)68 void    module_manager_entry(ULONG thread_input)
69 {
70 
71     /* Initialize the module manager.   */
72     txm_module_manager_initialize((VOID *) 0x00018000, 0x00008000);
73 
74     txm_module_manager_object_pool_create(object_memory, sizeof(object_memory));
75 
76     /* Register a fault handler.  */
77     txm_module_manager_memory_fault_notify(module_fault_handler);
78 
79     /* Load the module that is already there, in this example it is placed there by the multiple image download.  */
80     txm_module_manager_in_place_load(&my_module, "my module", (VOID *) 0xFFF10400);
81 
82 
83     /* Enable 128 byte read/write shared memory region at 0x00020000.  */
84     txm_module_manager_external_memory_enable(&my_module, (void *) 0x00020000, 128, TXM_MODULE_MANAGER_SHARED_ATTRIBUTE_READ | TXM_MODULE_MANAGER_SHARED_ATTRIBUTE_WRITE);
85 
86     /* Start the module.  */
87     txm_module_manager_start(&my_module);
88 
89     /* Sleep for a while....  */
90     tx_thread_sleep(1000);
91 
92     /* Stop the module.  */
93     txm_module_manager_stop(&my_module);
94 
95     /* Unload the module.  */
96     txm_module_manager_unload(&my_module);
97 
98     /* Load the module that is already there.  */
99     txm_module_manager_in_place_load(&my_module, "my module", (VOID *) 0xFFF10400);
100 
101     /* Set maximum module priority to 5.  */
102     txm_module_manager_maximum_module_priority_set(&my_module, 5);
103 
104     /* Start the module again.  */
105     txm_module_manager_start(&my_module);
106 
107     /* Now just spin...  */
108     while(1)
109     {
110 
111         tx_thread_sleep(100);
112     }
113 }
114