diff options
| author | tameraw <[email protected]> | 2020-07-16 14:32:40 -0700 |
|---|---|---|
| committer | tameraw <[email protected]> | 2020-07-16 14:32:40 -0700 |
| commit | 2c35570dc9ced8690ea269d1efab201c361fea98 (patch) | |
| tree | a950c056346ab9a2260ba92a6be8ee3dd91ab7b6 /ports/linux/gnu/example_build | |
| parent | f8e91d47625881614fe28efbcd43470922590d42 (diff) | |
updated to 6.0.1 and added additional processors/toolchains
Diffstat (limited to 'ports/linux/gnu/example_build')
| -rw-r--r-- | ports/linux/gnu/example_build/file_list.mk | 201 | ||||
| -rw-r--r-- | ports/linux/gnu/example_build/sample_threadx.c | 380 |
2 files changed, 581 insertions, 0 deletions
diff --git a/ports/linux/gnu/example_build/file_list.mk b/ports/linux/gnu/example_build/file_list.mk new file mode 100644 index 00000000..73497590 --- /dev/null +++ b/ports/linux/gnu/example_build/file_list.mk @@ -0,0 +1,201 @@ +LINUX_SRCS = \ +tx_initialize_low_level.c \ +tx_thread_context_restore.c \ +tx_thread_context_save.c \ +tx_thread_interrupt_control.c \ +tx_thread_schedule.c \ +tx_thread_stack_build.c \ +tx_thread_system_return.c \ +tx_timer_interrupt.c \ + +LINUX_OBJS = $(LINUX_SRCS:%.c=.tmp/%.o) + + +GENERIC_SRCS = \ +tx_block_allocate.c \ +tx_block_pool_cleanup.c \ +tx_block_pool_create.c \ +tx_block_pool_delete.c \ +tx_block_pool_info_get.c \ +tx_block_pool_initialize.c \ +tx_block_pool_performance_info_get.c \ +tx_block_pool_performance_system_info_get.c \ +tx_block_pool_prioritize.c \ +tx_block_release.c \ +tx_byte_allocate.c \ +tx_byte_pool_cleanup.c \ +tx_byte_pool_create.c \ +tx_byte_pool_delete.c \ +tx_byte_pool_info_get.c \ +tx_byte_pool_initialize.c \ +tx_byte_pool_performance_info_get.c \ +tx_byte_pool_performance_system_info_get.c \ +tx_byte_pool_prioritize.c \ +tx_byte_pool_search.c \ +tx_byte_release.c \ +txe_block_allocate.c \ +txe_block_pool_create.c \ +txe_block_pool_delete.c \ +txe_block_pool_info_get.c \ +txe_block_pool_prioritize.c \ +txe_block_release.c \ +txe_byte_allocate.c \ +txe_byte_pool_create.c \ +txe_byte_pool_delete.c \ +txe_byte_pool_info_get.c \ +txe_byte_pool_prioritize.c \ +txe_byte_release.c \ +txe_event_flags_create.c \ +txe_event_flags_delete.c \ +txe_event_flags_get.c \ +txe_event_flags_info_get.c \ +txe_event_flags_set.c \ +txe_event_flags_set_notify.c \ +txe_mutex_create.c \ +txe_mutex_delete.c \ +txe_mutex_get.c \ +txe_mutex_info_get.c \ +txe_mutex_prioritize.c \ +txe_mutex_put.c \ +txe_queue_create.c \ +txe_queue_delete.c \ +txe_queue_flush.c \ +txe_queue_front_send.c \ +txe_queue_info_get.c \ +txe_queue_prioritize.c \ +txe_queue_receive.c \ +txe_queue_send.c \ +txe_queue_send_notify.c \ +txe_semaphore_ceiling_put.c \ +txe_semaphore_create.c \ +txe_semaphore_delete.c \ +txe_semaphore_get.c \ +txe_semaphore_info_get.c \ +txe_semaphore_prioritize.c \ +txe_semaphore_put.c \ +txe_semaphore_put_notify.c \ +txe_thread_create.c \ +txe_thread_delete.c \ +txe_thread_entry_exit_notify.c \ +txe_thread_info_get.c \ +txe_thread_preemption_change.c \ +txe_thread_priority_change.c \ +txe_thread_relinquish.c \ +txe_thread_reset.c \ +txe_thread_resume.c \ +txe_thread_suspend.c \ +txe_thread_terminate.c \ +txe_thread_time_slice_change.c \ +txe_thread_wait_abort.c \ +txe_timer_activate.c \ +txe_timer_change.c \ +txe_timer_create.c \ +txe_timer_deactivate.c \ +txe_timer_delete.c \ +txe_timer_info_get.c \ +tx_event_flags_cleanup.c \ +tx_event_flags_create.c \ +tx_event_flags_delete.c \ +tx_event_flags_get.c \ +tx_event_flags_info_get.c \ +tx_event_flags_initialize.c \ +tx_event_flags_performance_info_get.c \ +tx_event_flags_performance_system_info_get.c \ +tx_event_flags_set.c \ +tx_event_flags_set_notify.c \ +tx_initialize_high_level.c \ +tx_initialize_kernel_enter.c \ +tx_initialize_kernel_setup.c \ +tx_misra.c \ +tx_mutex_cleanup.c \ +tx_mutex_create.c \ +tx_mutex_delete.c \ +tx_mutex_get.c \ +tx_mutex_info_get.c \ +tx_mutex_initialize.c \ +tx_mutex_performance_info_get.c \ +tx_mutex_performance_system_info_get.c \ +tx_mutex_prioritize.c \ +tx_mutex_priority_change.c \ +tx_mutex_put.c \ +tx_queue_cleanup.c \ +tx_queue_create.c \ +tx_queue_delete.c \ +tx_queue_flush.c \ +tx_queue_front_send.c \ +tx_queue_info_get.c \ +tx_queue_initialize.c \ +tx_queue_performance_info_get.c \ +tx_queue_performance_system_info_get.c \ +tx_queue_prioritize.c \ +tx_queue_receive.c \ +tx_queue_send.c \ +tx_queue_send_notify.c \ +tx_semaphore_ceiling_put.c \ +tx_semaphore_cleanup.c \ +tx_semaphore_create.c \ +tx_semaphore_delete.c \ +tx_semaphore_get.c \ +tx_semaphore_info_get.c \ +tx_semaphore_initialize.c \ +tx_semaphore_performance_info_get.c \ +tx_semaphore_performance_system_info_get.c \ +tx_semaphore_prioritize.c \ +tx_semaphore_put.c \ +tx_semaphore_put_notify.c \ +tx_thread_create.c \ +tx_thread_delete.c \ +tx_thread_entry_exit_notify.c \ +tx_thread_identify.c \ +tx_thread_info_get.c \ +tx_thread_initialize.c \ +tx_thread_performance_info_get.c \ +tx_thread_performance_system_info_get.c \ +tx_thread_preemption_change.c \ +tx_thread_priority_change.c \ +tx_thread_relinquish.c \ +tx_thread_reset.c \ +tx_thread_resume.c \ +tx_thread_shell_entry.c \ +tx_thread_sleep.c \ +tx_thread_stack_analyze.c \ +tx_thread_stack_error_handler.c \ +tx_thread_stack_error_notify.c \ +tx_thread_suspend.c \ +tx_thread_system_preempt_check.c \ +tx_thread_system_resume.c \ +tx_thread_system_suspend.c \ +tx_thread_terminate.c \ +tx_thread_timeout.c \ +tx_thread_time_slice.c \ +tx_thread_time_slice_change.c \ +tx_thread_wait_abort.c \ +tx_time_get.c \ +tx_timer_activate.c \ +tx_timer_change.c \ +tx_timer_create.c \ +tx_timer_deactivate.c \ +tx_timer_delete.c \ +tx_timer_expiration_process.c \ +tx_timer_info_get.c \ +tx_timer_initialize.c \ +tx_timer_performance_info_get.c \ +tx_timer_performance_system_info_get.c \ +tx_timer_system_activate.c \ +tx_timer_system_deactivate.c \ +tx_timer_thread_entry.c \ +tx_time_set.c \ +tx_trace_buffer_full_notify.c \ +tx_trace_disable.c \ +tx_trace_enable.c \ +tx_trace_event_filter.c \ +tx_trace_event_unfilter.c \ +tx_trace_initialize.c \ +tx_trace_interrupt_control.c \ +tx_trace_isr_enter_insert.c \ +tx_trace_isr_exit_insert.c \ +tx_trace_object_register.c \ +tx_trace_object_unregister.c \ +tx_trace_user_event_insert.c \ + +GENERIC_OBJS = $(GENERIC_SRCS:%.c=.tmp/generic/%.o) diff --git a/ports/linux/gnu/example_build/sample_threadx.c b/ports/linux/gnu/example_build/sample_threadx.c new file mode 100644 index 00000000..080be3c4 --- /dev/null +++ b/ports/linux/gnu/example_build/sample_threadx.c @@ -0,0 +1,380 @@ +/* This is a small demo of the high-performance ThreadX kernel. It includes examples of eight + threads of different priorities, using a message queue, semaphore, mutex, event flags group, + byte pool, and block pool. */ + +#include "tx_api.h" +#include <stdio.h> + +#define DEMO_STACK_SIZE 1024 +#define DEMO_BYTE_POOL_SIZE 9120 +#define DEMO_BLOCK_POOL_SIZE 100 +#define DEMO_QUEUE_SIZE 100 + + +/* Define the ThreadX object control blocks... */ + +TX_THREAD thread_0; +TX_THREAD thread_1; +TX_THREAD thread_2; +TX_THREAD thread_3; +TX_THREAD thread_4; +TX_THREAD thread_5; +TX_THREAD thread_6; +TX_THREAD thread_7; +TX_QUEUE queue_0; +TX_SEMAPHORE semaphore_0; +TX_MUTEX mutex_0; +TX_EVENT_FLAGS_GROUP event_flags_0; +TX_BYTE_POOL byte_pool_0; +TX_BLOCK_POOL block_pool_0; + + +/* Define the counters used in the demo application... */ + +ULONG thread_0_counter; +ULONG thread_1_counter; +ULONG thread_1_messages_sent; +ULONG thread_2_counter; +ULONG thread_2_messages_received; +ULONG thread_3_counter; +ULONG thread_4_counter; +ULONG thread_5_counter; +ULONG thread_6_counter; +ULONG thread_7_counter; + + +/* Define thread prototypes. */ + +void thread_0_entry(ULONG thread_input); +void thread_1_entry(ULONG thread_input); +void thread_2_entry(ULONG thread_input); +void thread_3_and_4_entry(ULONG thread_input); +void thread_5_entry(ULONG thread_input); +void thread_6_and_7_entry(ULONG thread_input); + + +/* Define main entry point. */ + +int main() +{ + + /* Enter the ThreadX kernel. */ + tx_kernel_enter(); +} + + +/* Define what the initial system looks like. */ + +void tx_application_define(void *first_unused_memory) +{ + +CHAR *pointer = TX_NULL; + + /* Create a byte memory pool from which to allocate the thread stacks. */ + tx_byte_pool_create(&byte_pool_0, "byte pool 0", first_unused_memory, 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, "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, "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, "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, "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, "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, "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, "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, "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, "queue 0", TX_1_ULONG, pointer, DEMO_QUEUE_SIZE*sizeof(ULONG)); + + /* Create the semaphore used by threads 3 and 4. */ + tx_semaphore_create(&semaphore_0, "semaphore 0", 1); + + /* Create the event flags group used by threads 1 and 5. */ + tx_event_flags_create(&event_flags_0, "event flags 0"); + + /* Create the mutex used by thread 6 and 7 without priority inheritance. */ + tx_mutex_create(&mutex_0, "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, "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 test threads. */ + +void thread_0_entry(ULONG thread_input) +{ + +UINT status; + + + /* This thread simply sits in while-forever-sleep loop. */ + while(1) + { + + /* Increment the thread counter. */ + thread_0_counter++; + + /* Print results. */ + printf("**** ThreadX Linux Demonstration **** (c) 1996-2020 Microsoft Corporation\n\n"); + printf(" thread 0 events sent: %lu\n", thread_0_counter); + printf(" thread 1 messages sent: %lu\n", thread_1_counter); + printf(" thread 2 messages received: %lu\n", thread_2_counter); + printf(" thread 3 obtained semaphore: %lu\n", thread_3_counter); + printf(" thread 4 obtained semaphore: %lu\n", thread_4_counter); + printf(" thread 5 events received: %lu\n", thread_5_counter); + printf(" thread 6 mutex obtained: %lu\n", thread_6_counter); + printf(" thread 7 mutex obtained: %lu\n\n", thread_7_counter); + + /* Sleep for 10 ticks. */ + tx_thread_sleep(10); + + /* Set event flag 0 to wakeup thread 5. */ + status = tx_event_flags_set(&event_flags_0, 0x1, TX_OR); + + /* Check status. */ + if (status != TX_SUCCESS) + break; + } +} + + +void thread_1_entry(ULONG thread_input) +{ + +UINT status; + + + /* This thread simply sends messages to a queue shared by thread 2. */ + while(1) + { + + /* Increment the thread counter. */ + thread_1_counter++; + + /* Send message to queue 0. */ + status = tx_queue_send(&queue_0, &thread_1_messages_sent, TX_WAIT_FOREVER); + + /* Check completion status. */ + if (status != TX_SUCCESS) + break; + + /* Increment the message sent. */ + thread_1_messages_sent++; + } +} + + +void thread_2_entry(ULONG thread_input) +{ + +ULONG received_message; +UINT status; + + /* This thread retrieves messages placed on the queue by thread 1. */ + while(1) + { + + /* Increment the thread counter. */ + thread_2_counter++; + + /* Retrieve a message from the queue. */ + status = tx_queue_receive(&queue_0, &received_message, TX_WAIT_FOREVER); + + /* Check completion status and make sure the message is what we + expected. */ + if ((status != TX_SUCCESS) || (received_message != thread_2_messages_received)) + break; + + /* Otherwise, all is okay. Increment the received message count. */ + thread_2_messages_received++; + } +} + + +void thread_3_and_4_entry(ULONG thread_input) +{ + +UINT status; + + + /* This function is executed from thread 3 and thread 4. As the loop + below shows, these function compete for ownership of semaphore_0. */ + while(1) + { + + /* Increment the thread counter. */ + if (thread_input == 3) + thread_3_counter++; + else + thread_4_counter++; + + /* Get the semaphore with suspension. */ + status = tx_semaphore_get(&semaphore_0, TX_WAIT_FOREVER); + + /* Check status. */ + if (status != TX_SUCCESS) + break; + + /* Sleep for 2 ticks to hold the semaphore. */ + tx_thread_sleep(2); + + /* Release the semaphore. */ + status = tx_semaphore_put(&semaphore_0); + + /* Check status. */ + if (status != TX_SUCCESS) + break; + } +} + + +void thread_5_entry(ULONG thread_input) +{ + +UINT status; +ULONG actual_flags; + + + /* This thread simply waits for an event in a forever loop. */ + while(1) + { + + /* Increment the thread counter. */ + thread_5_counter++; + + /* Wait for event flag 0. */ + status = tx_event_flags_get(&event_flags_0, 0x1, TX_OR_CLEAR, + &actual_flags, TX_WAIT_FOREVER); + + /* Check status. */ + if ((status != TX_SUCCESS) || (actual_flags != 0x1)) + break; + } +} + + +void thread_6_and_7_entry(ULONG thread_input) +{ + +UINT status; + + + /* This function is executed from thread 6 and thread 7. As the loop + below shows, these function compete for ownership of mutex_0. */ + while(1) + { + + /* Increment the thread counter. */ + if (thread_input == 6) + thread_6_counter++; + else + thread_7_counter++; + + /* Get the mutex with suspension. */ + status = tx_mutex_get(&mutex_0, TX_WAIT_FOREVER); + + /* Check status. */ + if (status != TX_SUCCESS) + break; + + /* Get the mutex again with suspension. This shows + that an owning thread may retrieve the mutex it + owns multiple times. */ + status = tx_mutex_get(&mutex_0, TX_WAIT_FOREVER); + + /* Check status. */ + if (status != TX_SUCCESS) + break; + + /* Sleep for 2 ticks to hold the mutex. */ + tx_thread_sleep(2); + + /* Release the mutex. */ + status = tx_mutex_put(&mutex_0); + + /* Check status. */ + if (status != TX_SUCCESS) + break; + + /* Release the mutex again. This will actually + release ownership since it was obtained twice. */ + status = tx_mutex_put(&mutex_0); + + /* Check status. */ + if (status != TX_SUCCESS) + break; + } +} |
