diff options
Diffstat (limited to 'ports/linux')
| -rw-r--r-- | ports/linux/gnu/example_build/Makefile | 6 | ||||
| -rw-r--r-- | ports/linux/gnu/example_build/sample_threadx.c | 46 | ||||
| -rw-r--r-- | ports/linux/gnu/inc/tx_port.h | 50 | ||||
| -rw-r--r-- | ports/linux/gnu/readme_threadx.txt | 58 | ||||
| -rw-r--r-- | ports/linux/gnu/src/tx_initialize_low_level.c | 113 | ||||
| -rw-r--r-- | ports/linux/gnu/src/tx_thread_context_restore.c | 79 | ||||
| -rw-r--r-- | ports/linux/gnu/src/tx_thread_context_save.c | 71 | ||||
| -rw-r--r-- | ports/linux/gnu/src/tx_thread_interrupt_control.c | 87 | ||||
| -rw-r--r-- | ports/linux/gnu/src/tx_thread_schedule.c | 19 | ||||
| -rw-r--r-- | ports/linux/gnu/src/tx_thread_stack_build.c | 73 | ||||
| -rw-r--r-- | ports/linux/gnu/src/tx_thread_system_return.c | 107 | ||||
| -rw-r--r-- | ports/linux/gnu/src/tx_timer_interrupt.c | 77 |
12 files changed, 366 insertions, 420 deletions
diff --git a/ports/linux/gnu/example_build/Makefile b/ports/linux/gnu/example_build/Makefile index 17607360..ddce0164 100644 --- a/ports/linux/gnu/example_build/Makefile +++ b/ports/linux/gnu/example_build/Makefile @@ -34,7 +34,7 @@ $(OUTPUT_FOLDER): sample_threadx: $(OUTPUT_FOLDER)/sample_threadx.o tx.a echo LD $@ - $(LINK) -o $@ $^ $(LIBS) + $(LINK) -o $@ $^ $(LIBS) tx.a: $(OUTPUT_FOLDER) $(LINUX_OBJS) $(GENERIC_OBJS) echo AR $@ @@ -68,7 +68,7 @@ files: do \ filename=`basename $$file`; \ [ "$$file" == "sample_threadx.c" ] || echo "$$filename \\" >> $(FILE_LIST); \ - done; + done; @printf "\n" >> $(FILE_LIST); @echo 'LINUX_OBJS = $$(LINUX_SRCS:%.c=$(OUTPUT_FOLDER)/%.o)' >> $(FILE_LIST); @printf "\n\n" >> $(FILE_LIST); @@ -77,7 +77,7 @@ files: do \ filename=`basename $$file`; \ [ "$$file" == "sample_threadx.c" ] || echo "$$filename \\" >> $(FILE_LIST); \ - done; + done; @printf "\n" >> $(FILE_LIST); @echo 'GENERIC_OBJS = $$(GENERIC_SRCS:%.c=$(OUTPUT_FOLDER)/generic/%.o)' >> $(FILE_LIST); diff --git a/ports/linux/gnu/example_build/sample_threadx.c b/ports/linux/gnu/example_build/sample_threadx.c index 080be3c4..43c0bdd4 100644 --- a/ports/linux/gnu/example_build/sample_threadx.c +++ b/ports/linux/gnu/example_build/sample_threadx.c @@ -1,5 +1,5 @@ /* 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, + threads of different priorities, using a message queue, semaphore, mutex, event flags group, byte pool, and block pool. */ #include "tx_api.h" @@ -80,42 +80,42 @@ CHAR *pointer = TX_NULL; 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, + 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 + /* 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, + 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, + 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. + /* 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, + 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, + 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. */ @@ -123,23 +123,23 @@ CHAR *pointer = TX_NULL; /* 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, + 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, + 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, + 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. */ @@ -253,11 +253,11 @@ UINT status; /* 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 + /* 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++; } @@ -316,7 +316,7 @@ ULONG actual_flags; thread_5_counter++; /* Wait for event flag 0. */ - status = tx_event_flags_get(&event_flags_0, 0x1, TX_OR_CLEAR, + status = tx_event_flags_get(&event_flags_0, 0x1, TX_OR_CLEAR, &actual_flags, TX_WAIT_FOREVER); /* Check status. */ @@ -369,7 +369,7 @@ UINT status; if (status != TX_SUCCESS) break; - /* Release the mutex again. This will actually + /* Release the mutex again. This will actually release ownership since it was obtained twice. */ status = tx_mutex_put(&mutex_0); diff --git a/ports/linux/gnu/inc/tx_port.h b/ports/linux/gnu/inc/tx_port.h index 7ca6161d..83d72df0 100644 --- a/ports/linux/gnu/inc/tx_port.h +++ b/ports/linux/gnu/inc/tx_port.h @@ -1,10 +1,11 @@ /*************************************************************************** - * Copyright (c) 2024 Microsoft Corporation - * + * Copyright (c) 2024 Microsoft Corporation + * Copyright (c) 2026-present Eclipse ThreadX contributors + * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. - * + * * SPDX-License-Identifier: MIT **************************************************************************/ @@ -20,11 +21,11 @@ /**************************************************************************/ -/**************************************************************************/ -/* */ -/* PORT SPECIFIC C INFORMATION RELEASE */ -/* */ -/* tx_port.h Linux/GNU */ +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* tx_port.h Linux/GNU */ /* 6.3.0 */ /* */ /* AUTHOR */ @@ -32,30 +33,15 @@ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This file contains data type definitions that make the ThreadX */ -/* real-time kernel function identically on a variety of different */ -/* processor architectures. For example, the size or number of bits */ -/* in an "int" data type vary between microprocessor architectures and */ -/* even C compilers for the same microprocessor. ThreadX does not */ -/* directly use native C data types. Instead, ThreadX creates its */ -/* own special types that can be mapped to actual data types by this */ -/* file to guarantee consistency in the interface and functionality. */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ /* */ -/* 09-30-2020 William E. Lamie Initial Version 6.1 */ -/* 10-15-2021 William E. Lamie Modified comment(s), added */ -/* symbol ULONG64_DEFINED, */ -/* resulting in version 6.1.9 */ -/* 04-25-2022 William E. Lamie Modified comment(s), removed */ -/* useless definition, */ -/* resulting in version 6.1.11 */ -/* 10-31-2023 Yanwu Cai Modified comment(s), fixed */ -/* compile warnings, */ -/* resulting in version 6.3.0 */ +/* This file contains data type definitions that make the ThreadX */ +/* real-time kernel function identically on a variety of different */ +/* processor architectures. For example, the size or number of bits */ +/* in an "int" data type vary between microprocessor architectures and */ +/* even C compilers for the same microprocessor. ThreadX does not */ +/* directly use native C data types. Instead, ThreadX creates its */ +/* own special types that can be mapped to actual data types by this */ +/* file to guarantee consistency in the interface and functionality. */ /* */ /**************************************************************************/ @@ -547,7 +533,7 @@ VOID _tx_thread_interrupt_restore(UINT previous_posture); #ifdef TX_THREAD_INIT CHAR _tx_version_id[] = - "Copyright (c) Microsoft Corporation * ThreadX Linux/gcc Version 6.4.2 *"; + "Copyright (c) Microsoft Corporation * ThreadX Linux/gcc Version 6.5.0.202601 *"; #else extern CHAR _tx_version_id[]; #endif diff --git a/ports/linux/gnu/readme_threadx.txt b/ports/linux/gnu/readme_threadx.txt index 997607c7..ba546d83 100644 --- a/ports/linux/gnu/readme_threadx.txt +++ b/ports/linux/gnu/readme_threadx.txt @@ -1,4 +1,4 @@ - Microsoft's Azure RTOS ThreadX for Linux + Microsoft's Azure RTOS ThreadX for Linux Using the GNU GCC Tools @@ -8,29 +8,29 @@ First make sure you are in the "example_build" directory. Also, make sure that you have setup your path and other environment variables necessary for the GNU development environment. The following command retrieves and installs GCC multilib on a Ubuntu system: - + sudo apt-get install gcc-multilib -At this point you may run the GNU make command to build the ThreadX core -library. This will build the ThreadX run-time environment in the -"example_build" directory. +At this point you may run the GNU make command to build the ThreadX core +library. This will build the ThreadX run-time environment in the +"example_build" directory. make tx.a -you should now observe the compilation of the ThreadX library source. At the +you should now observe the compilation of the ThreadX library source. At the end of the make, they are all combined into the run-time library file: tx.a. This file must be linked with your application in order to use ThreadX. - + 2. Demonstration System -Building the demonstration is easy; simply execute the GNU make command while -inside the "example_build" directory. +Building the demonstration is easy; simply execute the GNU make command while +inside the "example_build" directory. make sample_threadx -You should observe the compilation of sample_threadx.c (which is the demonstration -application) and linking with tx.a. The resulting file DEMO is a binary file +You should observe the compilation of sample_threadx.c (which is the demonstration +application) and linking with tx.a. The resulting file DEMO is a binary file that can be executed. 2.1 Includes @@ -56,15 +56,15 @@ the tx_port.h header to include tx_user.h. 3. System Initialization -The system entry point is at main(), which is defined in the application. -Once the application calls tx_kernel_enter, ThreadX starts running and -performs various initialization duties prior to starting the scheduler. The +The system entry point is at main(), which is defined in the application. +Once the application calls tx_kernel_enter, ThreadX starts running and +performs various initialization duties prior to starting the scheduler. The Linux-specific initialization is done in the function _tx_initialize_low_level, -which is located in the file tx_initialize_low_level.c. This function is -responsible for setting up various system data structures and simulated +which is located in the file tx_initialize_low_level.c. This function is +responsible for setting up various system data structures and simulated interrupts - including the periodic timer interrupt source for ThreadX. -In addition, _tx_initialize_low_level determines the first available +In addition, _tx_initialize_low_level determines the first available address for use by the application. In Linux, this is basically done by using malloc to get a big block of memory from Linux. @@ -73,12 +73,12 @@ by using malloc to get a big block of memory from Linux. ThreadX for Linux is implemented using POSIX pthreads. Each application thread in ThreadX actually runs as a Linux pthread. The determination of -which application thread to run is made by the ThreadX scheduler, which -itself is a Linux pthread. The ThreadX scheduler is the highest priority +which application thread to run is made by the ThreadX scheduler, which +itself is a Linux pthread. The ThreadX scheduler is the highest priority thread in the system. Interrupts in ThreadX/Linux are also simulated by pthreads. A good example -is the ThreadX system timer interrupt, which can be found in +is the ThreadX system timer interrupt, which can be found in tx_initialize_low_level.c. ThreadX for linux utilizes the API pthread_setschedparam() which requires @@ -89,12 +89,12 @@ to run a ThreadX application: 5. Improving Performance -The distribution version of ThreadX is built without any compiler -optimizations. This makes it easy to debug because you can trace or set -breakpoints inside of ThreadX itself. Of course, this costs some -performance. To make it run faster, you can change the makefile to -enable all compiler optimizations. In addition, you can eliminate the -ThreadX basic API error checking by compiling your application code with the +The distribution version of ThreadX is built without any compiler +optimizations. This makes it easy to debug because you can trace or set +breakpoints inside of ThreadX itself. Of course, this costs some +performance. To make it run faster, you can change the makefile to +enable all compiler optimizations. In addition, you can eliminate the +ThreadX basic API error checking by compiling your application code with the symbol TX_DISABLE_ERROR_CHECKING defined. @@ -102,7 +102,7 @@ symbol TX_DISABLE_ERROR_CHECKING defined. ThreadX provides simulated interrupt handling with Linux pthreads. Simulated interrupt threads may be created by the application or may be added to the -simulated timer interrupt defined in tx_initialize_low_level.c. The following +simulated timer interrupt defined in tx_initialize_low_level.c. The following format for creating simulated interrupts should be used: 6.1 Data structures @@ -133,7 +133,7 @@ struct sched_param sp; 6.3 Simulated Interrupt Thread Template The following is a template for the simulated interrupt thread. This interrupt will occur on -a periodic basis. +a periodic basis. void *_sample_linux_interrupt_entry(void *p) { @@ -154,7 +154,7 @@ struct timespec ts; /* Call ThreadX context restore for interrupt completion. */ _tx_thread_context_restore(); - } + } } diff --git a/ports/linux/gnu/src/tx_initialize_low_level.c b/ports/linux/gnu/src/tx_initialize_low_level.c index d3516aaa..32de408f 100644 --- a/ports/linux/gnu/src/tx_initialize_low_level.c +++ b/ports/linux/gnu/src/tx_initialize_low_level.c @@ -1,18 +1,19 @@ /*************************************************************************** - * Copyright (c) 2024 Microsoft Corporation - * + * Copyright (c) 2024 Microsoft Corporation + * Copyright (c) 2026-present Eclipse ThreadX contributors + * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. - * + * * SPDX-License-Identifier: MIT **************************************************************************/ /**************************************************************************/ /**************************************************************************/ -/** */ -/** ThreadX Component */ +/** */ +/** ThreadX Component */ /** */ /** Initialize */ /** */ @@ -42,18 +43,18 @@ sem_t _tx_linux_semaphore_no_idle; ULONG _tx_linux_global_int_disabled_flag; struct timespec _tx_linux_time_stamp; __thread int _tx_linux_threadx_thread = 0; - + /* Define signals for linux thread. */ #define SUSPEND_SIG SIGUSR1 #define RESUME_SIG SIGUSR2 static sigset_t _tx_linux_thread_wait_mask; -static __thread int _tx_linux_thread_suspended; +static __thread int _tx_linux_thread_suspended; static sem_t _tx_linux_thread_timer_wait; static sem_t _tx_linux_thread_other_wait; /* Define simulated timer interrupt. This is done inside a thread, which is - how other interrupts may be defined as well. See code below for an + how other interrupts may be defined as well. See code below for an example. */ pthread_t _tx_linux_timer_id; @@ -136,11 +137,11 @@ pthread_mutex_t temp_copy; /* Now move to the next entry. */ _tx_linux_debug_entry_index++; - + /* Determine if we need to wrap the list. */ if (_tx_linux_debug_entry_index >= TX_LINUX_DEBUG_EVENT_SIZE) { - + /* Yes, wrap the list! */ _tx_linux_debug_entry_index = 0; } @@ -169,54 +170,48 @@ VOID _tx_thread_context_restore(VOID); extern VOID *_tx_initialize_unused_memory; -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _tx_initialize_low_level Linux/GNU */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_initialize_low_level Linux/GNU */ /* 6.1 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function is responsible for any low-level processor */ -/* initialization, including setting up interrupt vectors, setting */ -/* up a periodic timer interrupt source, saving the system stack */ -/* pointer for use in ISR processing later, and finding the first */ -/* available RAM memory address for tx_application_define. */ -/* */ -/* INPUT */ -/* */ -/* None */ -/* */ -/* OUTPUT */ -/* */ -/* None */ -/* */ -/* CALLS */ -/* */ -/* sched_setaffinity */ -/* getpid */ -/* _tx_linux_thread_init */ -/* pthread_setschedparam */ -/* pthread_mutexattr_init */ -/* pthread_mutex_init */ -/* _tx_linux_thread_suspend */ -/* sem_init */ -/* pthread_create */ -/* printf */ -/* */ -/* CALLED BY */ -/* */ -/* _tx_initialize_kernel_enter ThreadX entry function */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ /* */ -/* 09-30-2020 William E. Lamie Initial Version 6.1 */ +/* This function is responsible for any low-level processor */ +/* initialization, including setting up interrupt vectors, setting */ +/* up a periodic timer interrupt source, saving the system stack */ +/* pointer for use in ISR processing later, and finding the first */ +/* available RAM memory address for tx_application_define. */ +/* */ +/* INPUT */ +/* */ +/* None */ +/* */ +/* OUTPUT */ +/* */ +/* None */ +/* */ +/* CALLS */ +/* */ +/* sched_setaffinity */ +/* getpid */ +/* _tx_linux_thread_init */ +/* pthread_setschedparam */ +/* pthread_mutexattr_init */ +/* pthread_mutex_init */ +/* _tx_linux_thread_suspend */ +/* sem_init */ +/* pthread_create */ +/* printf */ +/* */ +/* CALLED BY */ +/* */ +/* _tx_initialize_kernel_enter ThreadX entry function */ /* */ /**************************************************************************/ VOID _tx_initialize_low_level(VOID) @@ -238,7 +233,7 @@ cpu_set_t mask; CPU_SET(rand() % get_nprocs(), &mask); if (sched_setaffinity(getpid(), sizeof(mask), &mask) != 0) { - + /* Error restricting the process to one core. */ printf("ThreadX Linux error restricting the process to one core!\n"); while(1) @@ -260,7 +255,7 @@ cpu_set_t mask; sp.sched_priority = TX_LINUX_PRIORITY_SCHEDULE; pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp); - /* Create the system critical section. This is used by the + /* Create the system critical section. This is used by the scheduler thread (which is the main thread) to block all other stuff out. */ pthread_mutexattr_init(&attr); @@ -273,10 +268,10 @@ cpu_set_t mask; /* Initialize the global interrupt disabled flag. */ _tx_linux_global_int_disabled_flag = TX_FALSE; - + /* Create semaphore for timer thread. */ sem_init(&_tx_linux_timer_semaphore, 0, 0); - + /* Create semaphore for ISR thread. */ sem_init(&_tx_linux_isr_semaphore, 0, 0); @@ -302,7 +297,7 @@ cpu_set_t mask; /* This routine is called after initialization is complete in order to start - all interrupt threads. Interrupt threads in addition to the timer may + all interrupt threads. Interrupt threads in addition to the timer may be added to this routine as well. */ void _tx_initialize_start_interrupts(void) @@ -377,7 +372,7 @@ int err; tx_linux_mutex_unlock(_tx_linux_mutex); #endif /* TX_LINUX_NO_IDLE_ENABLE */ - } + } } /* Define functions for linux thread. */ @@ -395,11 +390,11 @@ void _tx_linux_thread_suspend_handler(int sig) else tx_linux_sem_post_nolock(&_tx_linux_thread_other_wait); - if(_tx_linux_thread_suspended) + if(_tx_linux_thread_suspended) return; _tx_linux_thread_suspended = 1; - sigsuspend(&_tx_linux_thread_wait_mask); + sigsuspend(&_tx_linux_thread_wait_mask); _tx_linux_thread_suspended = 0; } diff --git a/ports/linux/gnu/src/tx_thread_context_restore.c b/ports/linux/gnu/src/tx_thread_context_restore.c index 5466b30e..3d7b44bb 100644 --- a/ports/linux/gnu/src/tx_thread_context_restore.c +++ b/ports/linux/gnu/src/tx_thread_context_restore.c @@ -1,18 +1,19 @@ /*************************************************************************** - * Copyright (c) 2024 Microsoft Corporation - * + * Copyright (c) 2024 Microsoft Corporation + * Copyright (c) 2026-present Eclipse ThreadX contributors + * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. - * + * * SPDX-License-Identifier: MIT **************************************************************************/ /**************************************************************************/ /**************************************************************************/ -/** */ -/** ThreadX Component */ +/** */ +/** ThreadX Component */ /** */ /** Thread */ /** */ @@ -31,50 +32,44 @@ extern sem_t _tx_linux_isr_semaphore; UINT _tx_linux_timer_waiting = 0; -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _tx_thread_context_restore Linux/GNU */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_thread_context_restore Linux/GNU */ /* 6.1 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function restores the interrupt context if it is processing a */ -/* nested interrupt. If not, it returns to the interrupt thread if no */ -/* preemption is necessary. Otherwise, if preemption is necessary or */ -/* if no thread was running, the function returns to the scheduler. */ -/* */ -/* INPUT */ -/* */ -/* None */ -/* */ -/* OUTPUT */ -/* */ -/* None */ -/* */ -/* CALLS */ -/* */ -/* _tx_linux_debug_entry_insert */ -/* tx_linux_mutex_lock */ +/* */ +/* This function restores the interrupt context if it is processing a */ +/* nested interrupt. If not, it returns to the interrupt thread if no */ +/* preemption is necessary. Otherwise, if preemption is necessary or */ +/* if no thread was running, the function returns to the scheduler. */ +/* */ +/* INPUT */ +/* */ +/* None */ +/* */ +/* OUTPUT */ +/* */ +/* None */ +/* */ +/* CALLS */ +/* */ +/* _tx_linux_debug_entry_insert */ +/* tx_linux_mutex_lock */ /* sem_trywait */ -/* tx_linux_sem_post */ -/* tx_linux_sem_wait */ -/* _tx_linux_thread_resume */ -/* tx_linux_mutex_recursive_unlock */ -/* */ -/* CALLED BY */ -/* */ -/* ISRs Interrupt Service Routines */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ +/* tx_linux_sem_post */ +/* tx_linux_sem_wait */ +/* _tx_linux_thread_resume */ +/* tx_linux_mutex_recursive_unlock */ +/* */ +/* CALLED BY */ /* */ -/* 09-30-2020 William E. Lamie Initial Version 6.1 */ +/* ISRs Interrupt Service Routines */ /* */ /**************************************************************************/ VOID _tx_thread_context_restore(VOID) @@ -101,7 +96,7 @@ VOID _tx_thread_context_restore(VOID) if ((_tx_thread_preempt_disable == 0) && (_tx_thread_current_ptr != _tx_thread_execute_ptr)) { - /* Preempt the running application thread. We don't need to suspend the + /* Preempt the running application thread. We don't need to suspend the application thread since that is done in the context save processing. */ /* Indicate that this thread was suspended asynchronously. */ diff --git a/ports/linux/gnu/src/tx_thread_context_save.c b/ports/linux/gnu/src/tx_thread_context_save.c index c98943fa..7bca3945 100644 --- a/ports/linux/gnu/src/tx_thread_context_save.c +++ b/ports/linux/gnu/src/tx_thread_context_save.c @@ -1,18 +1,19 @@ /*************************************************************************** - * Copyright (c) 2024 Microsoft Corporation - * + * Copyright (c) 2024 Microsoft Corporation + * Copyright (c) 2026-present Eclipse ThreadX contributors + * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. - * + * * SPDX-License-Identifier: MIT **************************************************************************/ /**************************************************************************/ /**************************************************************************/ -/** */ -/** ThreadX Component */ +/** */ +/** ThreadX Component */ /** */ /** Thread */ /** */ @@ -30,46 +31,40 @@ #include "tx_timer.h" -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _tx_thread_context_save Linux/GNU */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_thread_context_save Linux/GNU */ /* 6.1 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function saves the context of an executing thread in the */ -/* beginning of interrupt processing. The function also ensures that */ -/* the system stack is used upon return to the calling ISR. */ -/* */ -/* INPUT */ -/* */ -/* None */ -/* */ -/* OUTPUT */ -/* */ -/* None */ -/* */ -/* CALLS */ -/* */ -/* _tx_linux_debug_entry_insert */ -/* tx_linux_mutex_lock */ -/* _tx_linux_thread_suspend */ -/* tx_linux_mutex_unlock */ -/* */ -/* CALLED BY */ -/* */ -/* ISRs */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ /* */ -/* 09-30-2020 William E. Lamie Initial Version 6.1 */ +/* This function saves the context of an executing thread in the */ +/* beginning of interrupt processing. The function also ensures that */ +/* the system stack is used upon return to the calling ISR. */ +/* */ +/* INPUT */ +/* */ +/* None */ +/* */ +/* OUTPUT */ +/* */ +/* None */ +/* */ +/* CALLS */ +/* */ +/* _tx_linux_debug_entry_insert */ +/* tx_linux_mutex_lock */ +/* _tx_linux_thread_suspend */ +/* tx_linux_mutex_unlock */ +/* */ +/* CALLED BY */ +/* */ +/* ISRs */ /* */ /**************************************************************************/ VOID _tx_thread_context_save(VOID) diff --git a/ports/linux/gnu/src/tx_thread_interrupt_control.c b/ports/linux/gnu/src/tx_thread_interrupt_control.c index 657cf72e..75b62511 100644 --- a/ports/linux/gnu/src/tx_thread_interrupt_control.c +++ b/ports/linux/gnu/src/tx_thread_interrupt_control.c @@ -1,18 +1,19 @@ /*************************************************************************** - * Copyright (c) 2024 Microsoft Corporation - * + * Copyright (c) 2024 Microsoft Corporation + * Copyright (c) 2026-present Eclipse ThreadX contributors + * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. - * + * * SPDX-License-Identifier: MIT **************************************************************************/ /**************************************************************************/ /**************************************************************************/ -/** */ -/** ThreadX Component */ +/** */ +/** ThreadX Component */ /** */ /** Thread */ /** */ @@ -47,53 +48,47 @@ VOID _tx_thread_interrupt_restore(UINT previous_posture) } -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _tx_thread_interrupt_control Linux/GNU */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_thread_interrupt_control Linux/GNU */ /* 6.1 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function is responsible for changing the interrupt lockout */ -/* posture of the system. */ -/* */ -/* INPUT */ -/* */ -/* new_posture New interrupt lockout posture */ -/* */ -/* OUTPUT */ -/* */ -/* old_posture Old interrupt lockout posture */ -/* */ -/* CALLS */ -/* */ -/* tx_linux_mutex_lock */ -/* pthread_self */ -/* pthread_getschedparam */ -/* tx_linux_mutex_recursive_unlock */ -/* pthread_exit */ -/* */ -/* CALLED BY */ -/* */ -/* Application Code */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ /* */ -/* 09-30-2020 William E. Lamie Initial Version 6.1 */ +/* This function is responsible for changing the interrupt lockout */ +/* posture of the system. */ +/* */ +/* INPUT */ +/* */ +/* new_posture New interrupt lockout posture */ +/* */ +/* OUTPUT */ +/* */ +/* old_posture Old interrupt lockout posture */ +/* */ +/* CALLS */ +/* */ +/* tx_linux_mutex_lock */ +/* pthread_self */ +/* pthread_getschedparam */ +/* tx_linux_mutex_recursive_unlock */ +/* pthread_exit */ +/* */ +/* CALLED BY */ +/* */ +/* Application Code */ /* */ /**************************************************************************/ UINT _tx_thread_interrupt_control(UINT new_posture) { UINT old_posture; -TX_THREAD *thread_ptr; +TX_THREAD *thread_ptr; pthread_t thread_id; int exit_code = 0; @@ -107,18 +102,18 @@ int exit_code = 0; /* Pickup the current thread pointer. */ thread_ptr = _tx_thread_current_ptr; - /* Determine if this is a thread and it does not + /* Determine if this is a thread and it does not match the current thread pointer. */ - if ((_tx_linux_threadx_thread) && - ((!thread_ptr) || (!pthread_equal(thread_ptr -> tx_thread_linux_thread_id, thread_id)))) - { + if ((_tx_linux_threadx_thread) && + ((!thread_ptr) || (!pthread_equal(thread_ptr -> tx_thread_linux_thread_id, thread_id)))) + { - /* This indicates the Linux thread was actually terminated by ThreadX is only + /* This indicates the Linux thread was actually terminated by ThreadX is only being allowed to run in order to cleanup its resources. */ /* Unlock linux mutex. */ tx_linux_mutex_recursive_unlock(_tx_linux_mutex); pthread_exit((void *)&exit_code); - } + } /* Determine the current interrupt lockout condition. */ if (tx_linux_mutex_recursive_count == 1) @@ -155,7 +150,7 @@ int exit_code = 0; _tx_linux_global_int_disabled_flag = TX_TRUE; } } - else if (thread_ptr) + else if (thread_ptr) { /* Determine how to apply the new posture. */ diff --git a/ports/linux/gnu/src/tx_thread_schedule.c b/ports/linux/gnu/src/tx_thread_schedule.c index d65104a1..eeff680f 100644 --- a/ports/linux/gnu/src/tx_thread_schedule.c +++ b/ports/linux/gnu/src/tx_thread_schedule.c @@ -1,10 +1,11 @@ /*************************************************************************** - * Copyright (c) 2024 Microsoft Corporation - * + * Copyright (c) 2024 Microsoft Corporation + * Copyright (c) 2026-present Eclipse ThreadX contributors + * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. - * + * * SPDX-License-Identifier: MIT **************************************************************************/ @@ -39,7 +40,7 @@ extern pthread_t _tx_linux_timer_id; /* */ /* FUNCTION RELEASE */ /* */ -/* _tx_thread_schedule Linux/GNU */ +/* _tx_thread_schedule Linux/GNU */ /* 6.1 */ /* AUTHOR */ /* */ @@ -73,12 +74,6 @@ extern pthread_t _tx_linux_timer_id; /* */ /* _tx_initialize_kernel_enter ThreadX entry function */ /* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ -/* 09-30-2020 William E. Lamie Initial Version 6.1 */ -/* */ /**************************************************************************/ VOID _tx_thread_schedule(VOID) { @@ -127,9 +122,9 @@ struct timespec ts; ts.tv_sec++; } sem_timedwait(&_tx_linux_semaphore_no_idle, &ts); -#else +#else nanosleep(&ts, &ts); -#endif /* TX_LINUX_NO_IDLE_ENABLE */ +#endif /* TX_LINUX_NO_IDLE_ENABLE */ } } diff --git a/ports/linux/gnu/src/tx_thread_stack_build.c b/ports/linux/gnu/src/tx_thread_stack_build.c index 424f53e2..cdadba6c 100644 --- a/ports/linux/gnu/src/tx_thread_stack_build.c +++ b/ports/linux/gnu/src/tx_thread_stack_build.c @@ -1,18 +1,19 @@ /*************************************************************************** - * Copyright (c) 2024 Microsoft Corporation - * + * Copyright (c) 2024 Microsoft Corporation + * Copyright (c) 2026-present Eclipse ThreadX contributors + * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. - * + * * SPDX-License-Identifier: MIT **************************************************************************/ /**************************************************************************/ /**************************************************************************/ -/** */ -/** ThreadX Component */ +/** */ +/** ThreadX Component */ /** */ /** Thread */ /** */ @@ -36,50 +37,44 @@ void *_tx_linux_thread_entry(void *ptr); -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _tx_thread_stack_build Linux/GNU */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_thread_stack_build Linux/GNU */ /* 6.1 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ +/* */ /* This function builds a stack frame on the supplied thread's stack. */ /* The stack frame results in a fake interrupt return to the supplied */ -/* function pointer. */ -/* */ -/* INPUT */ -/* */ +/* function pointer. */ +/* */ +/* INPUT */ +/* */ /* thread_ptr Pointer to thread control blk */ /* function_ptr Pointer to return function */ -/* */ -/* OUTPUT */ -/* */ +/* */ +/* OUTPUT */ +/* */ /* None */ -/* */ -/* CALLS */ -/* */ -/* pthread_create */ -/* pthread_setschedparam */ -/* _tx_linux_thread_suspend */ -/* sem_init */ -/* printf */ -/* _tx_linux_thread_resume */ -/* */ -/* CALLED BY */ -/* */ -/* _tx_thread_create Create thread service */ -/* _tx_thread_reset Reset thread service */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ /* */ -/* 09-30-2020 William E. Lamie Initial Version 6.1 */ +/* CALLS */ +/* */ +/* pthread_create */ +/* pthread_setschedparam */ +/* _tx_linux_thread_suspend */ +/* sem_init */ +/* printf */ +/* _tx_linux_thread_resume */ +/* */ +/* CALLED BY */ +/* */ +/* _tx_thread_create Create thread service */ +/* _tx_thread_reset Reset thread service */ /* */ /**************************************************************************/ VOID _tx_thread_stack_build(TX_THREAD *thread_ptr, VOID (*function_ptr)(VOID)) @@ -115,11 +110,11 @@ struct sched_param sp; sp.sched_priority = TX_LINUX_PRIORITY_USER_THREAD; pthread_setschedparam(thread_ptr -> tx_thread_linux_thread_id, SCHED_FIFO, &sp); - /* Setup the thread suspension type to solicited thread suspension. + /* Setup the thread suspension type to solicited thread suspension. Pseudo interrupt handlers will suspend with this field set to 1. */ thread_ptr -> tx_thread_linux_suspension_type = 0; - /* Clear the disabled count that will keep track of the + /* Clear the disabled count that will keep track of the tx_interrupt_control nesting. */ thread_ptr -> tx_thread_linux_int_disabled_flag = 0; diff --git a/ports/linux/gnu/src/tx_thread_system_return.c b/ports/linux/gnu/src/tx_thread_system_return.c index 16d81d59..cc876721 100644 --- a/ports/linux/gnu/src/tx_thread_system_return.c +++ b/ports/linux/gnu/src/tx_thread_system_return.c @@ -1,18 +1,19 @@ /*************************************************************************** - * Copyright (c) 2024 Microsoft Corporation - * + * Copyright (c) 2024 Microsoft Corporation + * Copyright (c) 2026-present Eclipse ThreadX contributors + * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. - * + * * SPDX-License-Identifier: MIT **************************************************************************/ /**************************************************************************/ /**************************************************************************/ -/** */ -/** ThreadX Component */ +/** */ +/** ThreadX Component */ /** */ /** Thread */ /** */ @@ -30,54 +31,48 @@ #include <stdio.h> -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _tx_thread_system_return Linux/GNU */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_thread_system_return Linux/GNU */ /* 6.1 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function is target processor specific. It is used to transfer */ -/* control from a thread back to the system. Only a minimal context */ -/* is saved since the compiler assumes temp registers are going to get */ -/* slicked by a function call anyway. */ -/* */ -/* INPUT */ -/* */ -/* None */ -/* */ -/* OUTPUT */ -/* */ -/* None */ -/* */ -/* CALLS */ -/* */ -/* _tx_linux_debug_entry_insert */ -/* tx_linux_mutex_lock */ -/* pthread_self */ -/* pthread_getschedparam */ -/* pthread_equal */ -/* tx_linux_mutex_recursive_unlock */ -/* tx_linux_mutex_unlock */ -/* pthread_exit */ -/* tx_linux_sem_post */ +/* */ +/* This function is target processor specific. It is used to transfer */ +/* control from a thread back to the system. Only a minimal context */ +/* is saved since the compiler assumes temp registers are going to get */ +/* slicked by a function call anyway. */ +/* */ +/* INPUT */ +/* */ +/* None */ +/* */ +/* OUTPUT */ +/* */ +/* None */ +/* */ +/* CALLS */ +/* */ +/* _tx_linux_debug_entry_insert */ +/* tx_linux_mutex_lock */ +/* pthread_self */ +/* pthread_getschedparam */ +/* pthread_equal */ +/* tx_linux_mutex_recursive_unlock */ +/* tx_linux_mutex_unlock */ +/* pthread_exit */ +/* tx_linux_sem_post */ /* sem_trywait */ -/* tx_linux_sem_wait */ -/* */ -/* CALLED BY */ -/* */ -/* ThreadX components */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ +/* tx_linux_sem_wait */ +/* */ +/* CALLED BY */ /* */ -/* 09-30-2020 William E. Lamie Initial Version 6.1 */ +/* ThreadX components */ /* */ /**************************************************************************/ VOID _tx_thread_system_return(VOID) @@ -104,13 +99,13 @@ int exit_code = 0; /* Pickup the current thread pointer. */ temp_thread_ptr = _tx_thread_current_ptr; - /* Determine if this is a thread (0) and it does not + /* Determine if this is a thread (0) and it does not match the current thread pointer. */ - if ((_tx_linux_threadx_thread) && - ((!temp_thread_ptr) || (!pthread_equal(temp_thread_ptr -> tx_thread_linux_thread_id, thread_id)))) - { + if ((_tx_linux_threadx_thread) && + ((!temp_thread_ptr) || (!pthread_equal(temp_thread_ptr -> tx_thread_linux_thread_id, thread_id)))) + { - /* This indicates the Linux thread was actually terminated by ThreadX is only + /* This indicates the Linux thread was actually terminated by ThreadX is only being allowed to run in order to cleanup its resources. */ /* Unlock linux mutex. */ tx_linux_mutex_recursive_unlock(_tx_linux_mutex); @@ -176,19 +171,19 @@ int exit_code = 0; /* Pickup the current thread pointer. */ temp_thread_ptr = _tx_thread_current_ptr; - /* Determine if this is a thread and it does not + /* Determine if this is a thread and it does not match the current thread pointer. */ - if ((_tx_linux_threadx_thread) && - ((!temp_thread_ptr) || (!pthread_equal(temp_thread_ptr -> tx_thread_linux_thread_id, thread_id)))) - { + if ((_tx_linux_threadx_thread) && + ((!temp_thread_ptr) || (!pthread_equal(temp_thread_ptr -> tx_thread_linux_thread_id, thread_id)))) + { /* Unlock Linux mutex. */ tx_linux_mutex_recursive_unlock(_tx_linux_mutex); - /* This indicates the Linux thread was actually terminated by ThreadX and is only + /* This indicates the Linux thread was actually terminated by ThreadX and is only being allowed to run in order to cleanup its resources. */ pthread_exit((void *)&exit_code); - } + } /* Now determine if the application thread last had interrupts disabled. */ diff --git a/ports/linux/gnu/src/tx_timer_interrupt.c b/ports/linux/gnu/src/tx_timer_interrupt.c index 8e55ca7f..d139fd9b 100644 --- a/ports/linux/gnu/src/tx_timer_interrupt.c +++ b/ports/linux/gnu/src/tx_timer_interrupt.c @@ -1,18 +1,19 @@ /*************************************************************************** - * Copyright (c) 2024 Microsoft Corporation - * + * Copyright (c) 2024 Microsoft Corporation + * Copyright (c) 2026-present Eclipse ThreadX contributors + * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. - * + * * SPDX-License-Identifier: MIT **************************************************************************/ /**************************************************************************/ /**************************************************************************/ -/** */ -/** ThreadX Component */ +/** */ +/** ThreadX Component */ /** */ /** Timer */ /** */ @@ -30,49 +31,43 @@ VOID _tx_timer_interrupt(VOID); -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _tx_timer_interrupt Linux/GNU */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_timer_interrupt Linux/GNU */ /* 6.1 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function processes the hardware timer interrupt. This */ -/* processing includes incrementing the system clock and checking for */ -/* time slice and/or timer expiration. If either is found, the */ -/* interrupt context save/restore functions are called along with the */ -/* expiration functions. */ -/* */ -/* INPUT */ -/* */ -/* None */ -/* */ -/* OUTPUT */ -/* */ -/* None */ -/* */ -/* CALLS */ -/* */ -/* _tx_linux_debug_entry_insert */ -/* tx_linux_mutex_lock */ -/* tx_linux_mutex_unlock */ -/* _tx_timer_expiration_process */ -/* _tx_thread_time_slice */ -/* */ -/* CALLED BY */ -/* */ -/* interrupt vector */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ /* */ -/* 09-30-2020 William E. Lamie Initial Version 6.1 */ +/* This function processes the hardware timer interrupt. This */ +/* processing includes incrementing the system clock and checking for */ +/* time slice and/or timer expiration. If either is found, the */ +/* interrupt context save/restore functions are called along with the */ +/* expiration functions. */ +/* */ +/* INPUT */ +/* */ +/* None */ +/* */ +/* OUTPUT */ +/* */ +/* None */ +/* */ +/* CALLS */ +/* */ +/* _tx_linux_debug_entry_insert */ +/* tx_linux_mutex_lock */ +/* tx_linux_mutex_unlock */ +/* _tx_timer_expiration_process */ +/* _tx_thread_time_slice */ +/* */ +/* CALLED BY */ +/* */ +/* interrupt vector */ /* */ /**************************************************************************/ VOID _tx_timer_interrupt(VOID) |
