AzureMXChip/MXCHIPAZ3166/core/lib/threadx/ports_module/cortex-r4/ac6/example_build/sample_threadx_module/sample_threadx_module.c
void    demo_module_start(ULONG id)
{

CHAR    *pointer;

    /* Allocate all the objects. In MMU mode, modules cannot allocate control blocks within
       their own memory area so they cannot corrupt the resident portion of ThreadX by overwriting 
       the control block(s).  */
    txm_module_object_allocate((void *) &thread_0, sizeof(TX_THREAD));
    txm_module_object_allocate((void *) &thread_1, sizeof(TX_THREAD));
    txm_module_object_allocate((void *) &thread_2, sizeof(TX_THREAD));
    txm_module_object_allocate((void *) &thread_3, sizeof(TX_THREAD));
    txm_module_object_allocate((void *) &thread_4, sizeof(TX_THREAD));
    txm_module_object_allocate((void *) &thread_5, sizeof(TX_THREAD));
    txm_module_object_allocate((void *) &thread_6, sizeof(TX_THREAD));
    txm_module_object_allocate((void *) &thread_7, sizeof(TX_THREAD));
    txm_module_object_allocate((void *) &queue_0, sizeof(TX_QUEUE));
    txm_module_object_allocate((void *) &semaphore_0, sizeof(TX_SEMAPHORE));
    txm_module_object_allocate((void *) &mutex_0, sizeof(TX_MUTEX));
    txm_module_object_allocate((void *) &event_flags_0, sizeof(TX_EVENT_FLAGS_GROUP));
    txm_module_object_allocate((void *) &byte_pool_0, sizeof(TX_BYTE_POOL));
    txm_module_object_allocate((void *) &block_pool_0, sizeof(TX_BLOCK_POOL));
    
    /* Create a byte memory pool from which to allocate the thread stacks.  */
    tx_byte_pool_create(byte_pool_0, "module byte pool 0", demo_module_pool_space, DEMO_BYTE_POOL_SIZE);

    /* Put system definition stuff in here, e.g. thread creates and other assorted
       create information.  */

    /* Allocate the stack for thread 0.  */
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);

    /* Create the main thread.  */
    tx_thread_create(thread_0, "module thread 0", thread_0_entry, 0,
            pointer, DEMO_STACK_SIZE, 
            1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);


    /* Allocate the stack for thread 1.  */
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);

    /* Create threads 1 and 2. These threads pass information through a ThreadX 
       message queue.  It is also interesting to note that these threads have a time
       slice.  */
    tx_thread_create(thread_1, "module thread 1", thread_1_entry, 1,
            pointer, DEMO_STACK_SIZE,
            16, 16, 4, TX_AUTO_START);

    /* Allocate the stack for thread 2.  */
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);

    tx_thread_create(thread_2, "module thread 2", thread_2_entry, 2,
            pointer, DEMO_STACK_SIZE,
            16, 16, 4, TX_AUTO_START);

    /* Allocate the stack for thread 3.  */
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);

    /* Create threads 3 and 4.  These threads compete for a ThreadX counting semaphore.
       An interesting thing here is that both threads share the same instruction area.  */
    tx_thread_create(thread_3, "module thread 3", thread_3_and_4_entry, 3,
            pointer, DEMO_STACK_SIZE, 
            8, 8, TX_NO_TIME_SLICE, TX_AUTO_START);

    /* Allocate the stack for thread 4.  */
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);

    tx_thread_create(thread_4, "module thread 4", thread_3_and_4_entry, 4,
            pointer, DEMO_STACK_SIZE, 
            8, 8, TX_NO_TIME_SLICE, TX_AUTO_START);

    /* Allocate the stack for thread 5.  */
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);

    /* Create thread 5.  This thread simply pends on an event flag which will be set
       by thread_0.  */
    tx_thread_create(thread_5, "module thread 5", thread_5_entry, 5,
            pointer, DEMO_STACK_SIZE, 
            4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);

    /* Allocate the stack for thread 6.  */
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);

    /* Create threads 6 and 7.  These threads compete for a ThreadX mutex.  */
    tx_thread_create(thread_6, "module thread 6", thread_6_and_7_entry, 6,
            pointer, DEMO_STACK_SIZE, 
            8, 8, TX_NO_TIME_SLICE, TX_AUTO_START);

    /* Allocate the stack for thread 7.  */
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);

    tx_thread_create(thread_7, "module thread 7", thread_6_and_7_entry, 7,
            pointer, DEMO_STACK_SIZE, 
            8, 8, TX_NO_TIME_SLICE, TX_AUTO_START);

    /* Allocate the message queue.  */
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_QUEUE_SIZE*sizeof(ULONG), TX_NO_WAIT);

    /* Create the message queue shared by threads 1 and 2.  */
    tx_queue_create(queue_0, "module queue 0", TX_1_ULONG, pointer, DEMO_QUEUE_SIZE*sizeof(ULONG));

    tx_queue_send_notify(queue_0, queue_0_notify);

    /* Create the semaphore used by threads 3 and 4.  */
    tx_semaphore_create(semaphore_0, "module semaphore 0", 1);

    tx_semaphore_put_notify(semaphore_0, semaphore_0_notify);

    /* Create the event flags group used by threads 1 and 5.  */
    tx_event_flags_create(event_flags_0, "module event flags 0");

    tx_event_flags_set_notify(event_flags_0, event_0_notify);

    /* Create the mutex used by thread 6 and 7 without priority inheritance.  */
    tx_mutex_create(mutex_0, "module mutex 0", TX_NO_INHERIT);

    /* Allocate the memory for a small block pool.  */
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_BLOCK_POOL_SIZE, TX_NO_WAIT);

    /* Create a block memory pool to allocate a message buffer from.  */
    tx_block_pool_create(block_pool_0, "module block pool 0", sizeof(ULONG), pointer, DEMO_BLOCK_POOL_SIZE);

    /* Allocate a block and release the block memory.  */
    tx_block_allocate(block_pool_0, (VOID **) &pointer, TX_NO_WAIT);

    /* Release the block back to the pool.  */
    tx_block_release(pointer);
}
/* Define the module start function.  */
Define the module start function.
Define the module start function .
void    demo_module_start(ULONG id)
{
CHAR    *pointer;
    txm_module_object_allocate((void *) &thread_0, sizeof(TX_THREAD));
    txm_module_object_allocate((void *) &thread_1, sizeof(TX_THREAD));
    txm_module_object_allocate((void *) &thread_2, sizeof(TX_THREAD));
    txm_module_object_allocate((void *) &thread_3, sizeof(TX_THREAD));
    txm_module_object_allocate((void *) &thread_4, sizeof(TX_THREAD));
    txm_module_object_allocate((void *) &thread_5, sizeof(TX_THREAD));
    txm_module_object_allocate((void *) &thread_6, sizeof(TX_THREAD));
    txm_module_object_allocate((void *) &thread_7, sizeof(TX_THREAD));
    txm_module_object_allocate((void *) &queue_0, sizeof(TX_QUEUE));
    txm_module_object_allocate((void *) &semaphore_0, sizeof(TX_SEMAPHORE));
    txm_module_object_allocate((void *) &mutex_0, sizeof(TX_MUTEX));
    txm_module_object_allocate((void *) &event_flags_0, sizeof(TX_EVENT_FLAGS_GROUP));
    txm_module_object_allocate((void *) &byte_pool_0, sizeof(TX_BYTE_POOL));
    txm_module_object_allocate((void *) &block_pool_0, sizeof(TX_BLOCK_POOL));
    tx_byte_pool_create(byte_pool_0, "module byte pool 0", demo_module_pool_space, DEMO_BYTE_POOL_SIZE);
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);
    tx_thread_create(thread_0, "module thread 0", thread_0_entry, 0,
            pointer, DEMO_STACK_SIZE, 
            1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);
    tx_thread_create(thread_1, "module thread 1", thread_1_entry, 1,
            pointer, DEMO_STACK_SIZE,
            16, 16, 4, TX_AUTO_START);
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);
    tx_thread_create(thread_2, "module thread 2", thread_2_entry, 2,
            pointer, DEMO_STACK_SIZE,
            16, 16, 4, TX_AUTO_START);
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);
    tx_thread_create(thread_3, "module thread 3", thread_3_and_4_entry, 3,
            pointer, DEMO_STACK_SIZE, 
            8, 8, TX_NO_TIME_SLICE, TX_AUTO_START);
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);
    tx_thread_create(thread_4, "module thread 4", thread_3_and_4_entry, 4,
            pointer, DEMO_STACK_SIZE, 
            8, 8, TX_NO_TIME_SLICE, TX_AUTO_START);
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);
    tx_thread_create(thread_5, "module thread 5", thread_5_entry, 5,
            pointer, DEMO_STACK_SIZE, 
            4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);
    tx_thread_create(thread_6, "module thread 6", thread_6_and_7_entry, 6,
            pointer, DEMO_STACK_SIZE, 
            8, 8, TX_NO_TIME_SLICE, TX_AUTO_START);
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);
    tx_thread_create(thread_7, "module thread 7", thread_6_and_7_entry, 7,
            pointer, DEMO_STACK_SIZE, 
            8, 8, TX_NO_TIME_SLICE, TX_AUTO_START);
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_QUEUE_SIZE*sizeof(ULONG), TX_NO_WAIT);
    tx_queue_create(queue_0, "module queue 0", TX_1_ULONG, pointer, DEMO_QUEUE_SIZE*sizeof(ULONG));
    tx_queue_send_notify(queue_0, queue_0_notify);
    tx_semaphore_create(semaphore_0, "module semaphore 0", 1);
    tx_semaphore_put_notify(semaphore_0, semaphore_0_notify);
    tx_event_flags_create(event_flags_0, "module event flags 0");
    tx_event_flags_set_notify(event_flags_0, event_0_notify);
    tx_mutex_create(mutex_0, "module mutex 0", TX_NO_INHERIT);
    tx_byte_allocate(byte_pool_0, (VOID **) &pointer, DEMO_BLOCK_POOL_SIZE, TX_NO_WAIT);
    tx_block_pool_create(block_pool_0, "module block pool 0", sizeof(ULONG), pointer, DEMO_BLOCK_POOL_SIZE);
    tx_block_allocate(block_pool_0, (VOID **) &pointer, TX_NO_WAIT);
    tx_block_release(pointer);
}
void demo_module_start ( ULONG id ) { CHAR * pointer ; txm_module_object_allocate ( ( void * ) & thread_0 , sizeof ( TX_THREAD ) ) ; txm_module_object_allocate ( ( void * ) & thread_1 , sizeof ( TX_THREAD ) ) ; txm_module_object_allocate ( ( void * ) & thread_2 , sizeof ( TX_THREAD ) ) ; txm_module_object_allocate ( ( void * ) & thread_3 , sizeof ( TX_THREAD ) ) ; txm_module_object_allocate ( ( void * ) & thread_4 , sizeof ( TX_THREAD ) ) ; txm_module_object_allocate ( ( void * ) & thread_5 , sizeof ( TX_THREAD ) ) ; txm_module_object_allocate ( ( void * ) & thread_6 , sizeof ( TX_THREAD ) ) ; txm_module_object_allocate ( ( void * ) & thread_7 , sizeof ( TX_THREAD ) ) ; txm_module_object_allocate ( ( void * ) & queue_0 , sizeof ( TX_QUEUE ) ) ; txm_module_object_allocate ( ( void * ) & semaphore_0 , sizeof ( TX_SEMAPHORE ) ) ; txm_module_object_allocate ( ( void * ) & mutex_0 , sizeof ( TX_MUTEX ) ) ; txm_module_object_allocate ( ( void * ) & event_flags_0 , sizeof ( TX_EVENT_FLAGS_GROUP ) ) ; txm_module_object_allocate ( ( void * ) & byte_pool_0 , sizeof ( TX_BYTE_POOL ) ) ; txm_module_object_allocate ( ( void * ) & block_pool_0 , sizeof ( TX_BLOCK_POOL ) ) ; tx_byte_pool_create ( byte_pool_0 , " " , demo_module_pool_space , DEMO_BYTE_POOL_SIZE ) ; tx_byte_allocate ( byte_pool_0 , ( VOID * * ) & pointer , DEMO_STACK_SIZE , TX_NO_WAIT ) ; tx_thread_create ( thread_0 , " " , thread_0_entry , 0 , pointer , DEMO_STACK_SIZE , 1 , 1 , TX_NO_TIME_SLICE , TX_AUTO_START ) ; tx_byte_allocate ( byte_pool_0 , ( VOID * * ) & pointer , DEMO_STACK_SIZE , TX_NO_WAIT ) ; tx_thread_create ( thread_1 , " " , thread_1_entry , 1 , pointer , DEMO_STACK_SIZE , 16 , 16 , 4 , TX_AUTO_START ) ; tx_byte_allocate ( byte_pool_0 , ( VOID * * ) & pointer , DEMO_STACK_SIZE , TX_NO_WAIT ) ; tx_thread_create ( thread_2 , " " , thread_2_entry , 2 , pointer , DEMO_STACK_SIZE , 16 , 16 , 4 , TX_AUTO_START ) ; tx_byte_allocate ( byte_pool_0 , ( VOID * * ) & pointer , DEMO_STACK_SIZE , TX_NO_WAIT ) ; tx_thread_create ( thread_3 , " " , thread_3_and_4_entry , 3 , pointer , DEMO_STACK_SIZE , 8 , 8 , TX_NO_TIME_SLICE , TX_AUTO_START ) ; tx_byte_allocate ( byte_pool_0 , ( VOID * * ) & pointer , DEMO_STACK_SIZE , TX_NO_WAIT ) ; tx_thread_create ( thread_4 , " " , thread_3_and_4_entry , 4 , pointer , DEMO_STACK_SIZE , 8 , 8 , TX_NO_TIME_SLICE , TX_AUTO_START ) ; tx_byte_allocate ( byte_pool_0 , ( VOID * * ) & pointer , DEMO_STACK_SIZE , TX_NO_WAIT ) ; tx_thread_create ( thread_5 , " " , thread_5_entry , 5 , pointer , DEMO_STACK_SIZE , 4 , 4 , TX_NO_TIME_SLICE , TX_AUTO_START ) ; tx_byte_allocate ( byte_pool_0 , ( VOID * * ) & pointer , DEMO_STACK_SIZE , TX_NO_WAIT ) ; tx_thread_create ( thread_6 , " " , thread_6_and_7_entry , 6 , pointer , DEMO_STACK_SIZE , 8 , 8 , TX_NO_TIME_SLICE , TX_AUTO_START ) ; tx_byte_allocate ( byte_pool_0 , ( VOID * * ) & pointer , DEMO_STACK_SIZE , TX_NO_WAIT ) ; tx_thread_create ( thread_7 , " " , thread_6_and_7_entry , 7 , pointer , DEMO_STACK_SIZE , 8 , 8 , TX_NO_TIME_SLICE , TX_AUTO_START ) ; tx_byte_allocate ( byte_pool_0 , ( VOID * * ) & pointer , DEMO_QUEUE_SIZE * sizeof ( ULONG ) , TX_NO_WAIT ) ; tx_queue_create ( queue_0 , " " , TX_1_ULONG , pointer , DEMO_QUEUE_SIZE * sizeof ( ULONG ) ) ; tx_queue_send_notify ( queue_0 , queue_0_notify ) ; tx_semaphore_create ( semaphore_0 , " " , 1 ) ; tx_semaphore_put_notify ( semaphore_0 , semaphore_0_notify ) ; tx_event_flags_create ( event_flags_0 , " " ) ; tx_event_flags_set_notify ( event_flags_0 , event_0_notify ) ; tx_mutex_create ( mutex_0 , " " , TX_NO_INHERIT ) ; tx_byte_allocate ( byte_pool_0 , ( VOID * * ) & pointer , DEMO_BLOCK_POOL_SIZE , TX_NO_WAIT ) ; tx_block_pool_create ( block_pool_0 , " " , sizeof ( ULONG ) , pointer , DEMO_BLOCK_POOL_SIZE ) ; tx_block_allocate ( block_pool_0 , ( VOID * * ) & pointer , TX_NO_WAIT ) ; tx_block_release ( pointer ) ; }
Define the module start function.
Define the module start function .
/* Allocate all the objects. In MMU mode, modules cannot allocate control blocks within
       their own memory area so they cannot corrupt the resident portion of ThreadX by overwriting 
       the control block(s).  */ /* Create a byte memory pool from which to allocate the thread stacks.  */ /* Put system definition stuff in here, e.g. thread creates and other assorted
       create information.  */ /* Allocate the stack for thread 0.  */ /* Create the main thread.  */ /* Allocate the stack for thread 1.  */ /* Create threads 1 and 2. These threads pass information through a ThreadX 
       message queue.  It is also interesting to note that these threads have a time
       slice.  */ /* Allocate the stack for thread 2.  */ /* Allocate the stack for thread 3.  */ /* Create threads 3 and 4.  These threads compete for a ThreadX counting semaphore.
       An interesting thing here is that both threads share the same instruction area.  */ /* Allocate the stack for thread 4.  */ /* Allocate the stack for thread 5.  */ /* Create thread 5.  This thread simply pends on an event flag which will be set
       by thread_0.  */ /* Allocate the stack for thread 6.  */ /* Create threads 6 and 7.  These threads compete for a ThreadX mutex.  */ /* Allocate the stack for thread 7.  */ /* Allocate the message queue.  */ /* Create the message queue shared by threads 1 and 2.  */ /* Create the semaphore used by threads 3 and 4.  */ /* Create the event flags group used by threads 1 and 5.  */ /* Create the mutex used by thread 6 and 7 without priority inheritance.  */ /* Allocate the memory for a small block pool.  */ /* Create a block memory pool to allocate a message buffer from.  */ /* Allocate a block and release the block memory.  */ /* Release the block back to the pool.  */